"use server"; import { serverFetchBlob, serverFetchJson } from "@/app/utils/fetchUtil"; import { BASE_API_URL } from "@/config/api"; import { Dayjs } from "dayjs"; import { cache } from "react"; import { FileResponse } from "../reports/actions"; export interface FinancialSummaryByClientResult { teamId:number; id:number; customerCode: string; customerName: string; projectNo: number; totalFee: number; totalBudget: number; cumulativeExpenditure: number; totalInvoiced: number; totalReceived: number; cashFlowStatus: string; cpi: number; totalUninvoiced: number; } export interface FinancialSummaryByProjectResult { teamId:number; id:number; projectCode: string; projectName: string; customerName: string; subsidiaryName: string; projectNo: number; totalFee: number; totalBudget: number; cumulativeExpenditure: number; totalInvoiced: number; totalReceived: number; cashFlowStatus: string; cpi: number; totalUninvoiced: number; } export const searchFinancialSummaryByClient = cache(async (teamId?: number) => { if (teamId === undefined) { return serverFetchJson( `${BASE_API_URL}/dashboard/searchFinancialSummaryByClient` ); } else { return serverFetchJson( `${BASE_API_URL}/dashboard/searchFinancialSummaryByClient?teamId=${teamId}` ); } }); export const searchFinancialSummaryByProject = cache(async (teamId?: number) => { if (teamId === undefined) { return serverFetchJson( `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject` ); } else { return serverFetchJson( `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject?teamId=${teamId}` ); } }); export const searchFinancialSummaryByProjectOld = cache(async (teamId?: number, customerId?:number) => { if (teamId === undefined) { return serverFetchJson( `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject` ); } else { return serverFetchJson( `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject?teamId=${teamId}&customerId=${customerId}` ); } }); export interface FinancialSummaryByClientExcel { customerCode: string; customerName: string; projectNo: number; totalFee: number; cumulativeExpenditure: number; totalInvoiced: number; totalReceived: number; } export interface ExportFinancialSummaryByClientExcel { financialSummaryByClients: FinancialSummaryByClientExcel[] } export interface FinancialSummaryByProjectExcel { projectCode: string; projectName: string; customerName: string; subsidiaryName?: string | null; totalFee: number; cumulativeExpenditure: number; totalInvoiced: number; totalReceived: number; } export interface ExportFinancialSummaryByProjectExcel { financialSummaryByProjects: FinancialSummaryByProjectExcel[] } export const exportFinancialSummaryByClientExcel = cache(async (data: ExportFinancialSummaryByClientExcel) => { const reportBlob = await serverFetchBlob( `${BASE_API_URL}/dashboard/exportFinancialSummaryByClientExcel`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }, ); return reportBlob }) export const exportFinancialSummaryByProjectExcel = cache(async (data: ExportFinancialSummaryByProjectExcel) => { const reportBlob = await serverFetchBlob( `${BASE_API_URL}/dashboard/exportFinancialSummaryByProjectExcel`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }, ); return reportBlob })