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.
 
 

133 lines
3.8 KiB

  1. "use server";
  2. import { cache } from "react";
  3. import { serverFetchJson } from "@/app/utils/fetchUtil";
  4. import { BASE_API_URL } from "@/config/api";
  5. import { IndividualTeam } from "../team";
  6. // import "server-only";
  7. export interface FinancialSummaryCardResult {
  8. teamId: number;
  9. teamName: string;
  10. projectNo: number;
  11. totalFee: number;
  12. totalBudget: number;
  13. cumulativeExpenditure: number;
  14. totalInvoiced: number;
  15. totalReceived: number;
  16. cashFlowStatus: string;
  17. cpi: number;
  18. }
  19. export type FinancialSummaryType = {
  20. team: IndividualTeam;
  21. activeProject: number;
  22. totalFees: number;
  23. totalBudget: number;
  24. cumulativeExpenditure: number;
  25. manpowerExpense: number;
  26. projectExpense: number;
  27. invoicedAmount: number;
  28. nonInvoicedAmount: number;
  29. receivedAmount: number;
  30. cashFlowStatus: String;
  31. costPerformanceIndex: number;
  32. projectedCashFlowStatus: String;
  33. projectedCostPerformanceIndex: number;
  34. }
  35. export type FinancialSummaryByProject = {
  36. // project data
  37. id: number,
  38. projectCode: string,
  39. projectName: string,
  40. custId: number,
  41. totalFee: number,
  42. totalBudget: number,
  43. customerCode: string,
  44. customerName: string,
  45. subsidiaryName: string,
  46. // timesheet data
  47. cumulativeExpenditure: number,
  48. manhourExpense: number,
  49. projectExpense: number,
  50. // invoice data
  51. invoicedAmount: number,
  52. nonInvoicedAmount: number,
  53. receivedAmount: number,
  54. // calculation
  55. cashFlowStatus: string,
  56. projectedCashFlowStatus: string,
  57. cpi: number,
  58. projectedCpi: number,
  59. }
  60. export interface FinancialSummaryByClient {
  61. id: number;
  62. customerName: string;
  63. customerCode: string;
  64. subsidiaryName: string;
  65. totalFee: number,
  66. totalBudget: number,
  67. cumulativeExpenditure: number
  68. manhourExpense: number;
  69. projectExpense: number;
  70. invoicedAmount: number;
  71. nonInvoicedAmount: number
  72. receivedAmount: number;
  73. numberOfRecords: number;
  74. }
  75. export type FinancialByProject = {
  76. id: number,
  77. projectName: string,
  78. projectCode: string,
  79. team: string,
  80. teamId: number,
  81. custId: number,
  82. customerName: string,
  83. customerCode: string,
  84. subsidiary: string,
  85. totalFee: number,
  86. totalBudget: number,
  87. manhourExpense: number,
  88. invoicedAmount: number,
  89. paidAmount: number,
  90. projectExpense: number,
  91. }
  92. export const preloadFinancialSummaryCard = () => {
  93. fetchFinancialSummaryCard();
  94. };
  95. export const fetchFinancialSummaryCard = cache(async () => {
  96. return serverFetchJson<FinancialSummaryCardResult[]>(`${BASE_API_URL}/dashboard/searchFinancialSummaryCard`);
  97. });
  98. export const fetchFinancialSummary = cache(async (endDate: string, teamId: number | null, startDate: string | null) => {
  99. var endpoint = `${BASE_API_URL}/dashboard/getFinancialSummary?endDate=${endDate}`
  100. if (teamId) endpoint += `&teamIds=${teamId}`
  101. if (startDate) endpoint += `&startDate=${startDate}`
  102. return serverFetchJson<FinancialSummaryType[]>(endpoint, {
  103. next: { tags: ["financialSummary"] },
  104. });
  105. })
  106. export const fetchFinancialSummaryByProject = cache(async (endDate: string, teamId: string, startDate?: string ) => {
  107. var endpoint = `${BASE_API_URL}/dashboard/getFinancialSummaryByProject?endDate=${endDate}&teamId=${teamId}`
  108. if (startDate) endpoint += `&startDate=${startDate}`
  109. return serverFetchJson<FinancialSummaryByProject[]>(endpoint, {
  110. next: { tags: ["financialSummaryByProject"] },
  111. });
  112. })
  113. export const fetchFinancialSummaryByProjectV2 = cache(async (teamId: number, endDate: string, startDate: string) => {
  114. var endpoint = `${BASE_API_URL}/dashboard/getFinancialSummary-final?`
  115. if (startDate.length > 0) endpoint += `&startDate=${startDate}`
  116. if (endDate.length > 0) endpoint += `&endDate=${endDate}`
  117. if (teamId > 0 ) endpoint += `&teamId=${teamId}`
  118. return serverFetchJson<FinancialByProject[]>(endpoint, {
  119. next: { tags: ["financialSummaryByProject"] },
  120. });
  121. })