You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

137 lines
3.8 KiB

  1. "use server";
  2. import { serverFetchBlob, serverFetchJson } from "@/app/utils/fetchUtil";
  3. import { BASE_API_URL } from "@/config/api";
  4. import { Dayjs } from "dayjs";
  5. import { cache } from "react";
  6. import { FileResponse } from "../reports/actions";
  7. export interface FinancialSummaryByClientResult {
  8. teamId:number;
  9. id:number;
  10. customerCode: string;
  11. customerName: string;
  12. projectNo: number;
  13. totalFee: number;
  14. totalBudget: number;
  15. cumulativeExpenditure: number;
  16. totalInvoiced: number;
  17. totalReceived: number;
  18. cashFlowStatus: string;
  19. cpi: number;
  20. totalUninvoiced: number;
  21. }
  22. export interface FinancialSummaryByProjectResult {
  23. teamId:number;
  24. id:number;
  25. projectCode: string;
  26. projectName: string;
  27. customerName: string;
  28. subsidiaryName: string;
  29. projectNo: number;
  30. totalFee: number;
  31. totalBudget: number;
  32. cumulativeExpenditure: number;
  33. totalInvoiced: number;
  34. totalReceived: number;
  35. cashFlowStatus: string;
  36. cpi: number;
  37. totalUninvoiced: number;
  38. }
  39. export const searchFinancialSummaryByClient = cache(async (teamId?: number) => {
  40. if (teamId === undefined) {
  41. return serverFetchJson<FinancialSummaryByClientResult[]>(
  42. `${BASE_API_URL}/dashboard/searchFinancialSummaryByClient`
  43. );
  44. } else {
  45. return serverFetchJson<FinancialSummaryByClientResult[]>(
  46. `${BASE_API_URL}/dashboard/searchFinancialSummaryByClient?teamId=${teamId}`
  47. );
  48. }
  49. });
  50. export const searchFinancialSummaryByProject = cache(async (teamId?: number) => {
  51. if (teamId === undefined) {
  52. return serverFetchJson<FinancialSummaryByProjectResult[]>(
  53. `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject`
  54. );
  55. } else {
  56. return serverFetchJson<FinancialSummaryByProjectResult[]>(
  57. `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject?teamId=${teamId}`
  58. );
  59. }
  60. });
  61. export const searchFinancialSummaryByProjectOld = cache(async (teamId?: number, customerId?:number) => {
  62. if (teamId === undefined) {
  63. return serverFetchJson<FinancialSummaryByProjectResult[]>(
  64. `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject`
  65. );
  66. } else {
  67. return serverFetchJson<FinancialSummaryByProjectResult[]>(
  68. `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject?teamId=${teamId}&customerId=${customerId}`
  69. );
  70. }
  71. });
  72. export interface FinancialSummaryByClientExcel {
  73. customerCode: string;
  74. customerName: string;
  75. projectNo: number;
  76. totalFee: number;
  77. cumulativeExpenditure: number;
  78. totalInvoiced: number;
  79. totalReceived: number;
  80. }
  81. export interface ExportFinancialSummaryByClientExcel {
  82. financialSummaryByClients: FinancialSummaryByClientExcel[]
  83. }
  84. export interface FinancialSummaryByProjectExcel {
  85. projectCode: string;
  86. projectName: string;
  87. customerName: string;
  88. subsidiaryName?: string | null;
  89. totalFee: number;
  90. cumulativeExpenditure: number;
  91. totalInvoiced: number;
  92. totalReceived: number;
  93. }
  94. export interface ExportFinancialSummaryByProjectExcel {
  95. financialSummaryByProjects: FinancialSummaryByProjectExcel[]
  96. }
  97. export const exportFinancialSummaryByClientExcel = cache(async (data: ExportFinancialSummaryByClientExcel) => {
  98. const reportBlob = await serverFetchBlob<FileResponse>(
  99. `${BASE_API_URL}/dashboard/exportFinancialSummaryByClientExcel`,
  100. {
  101. method: "POST",
  102. body: JSON.stringify(data),
  103. headers: { "Content-Type": "application/json" },
  104. },
  105. );
  106. return reportBlob
  107. })
  108. export const exportFinancialSummaryByProjectExcel = cache(async (data: ExportFinancialSummaryByProjectExcel) => {
  109. const reportBlob = await serverFetchBlob<FileResponse>(
  110. `${BASE_API_URL}/dashboard/exportFinancialSummaryByProjectExcel`,
  111. {
  112. method: "POST",
  113. body: JSON.stringify(data),
  114. headers: { "Content-Type": "application/json" },
  115. },
  116. );
  117. return reportBlob
  118. })