diff --git a/src/app/api/reports/index.ts b/src/app/api/reports/index.ts index bf39c0f..7202d2e 100644 --- a/src/app/api/reports/index.ts +++ b/src/app/api/reports/index.ts @@ -86,6 +86,7 @@ export interface LateStartReportRequest { clientId: number; remainedDate: string; remainedDateTo: string; + type: string; } export interface ProjectCompletionReportFilter { diff --git a/src/components/Report/LateStartReportGen/LateStartReportGen.tsx b/src/components/Report/LateStartReportGen/LateStartReportGen.tsx index b19bcf8..cb147c3 100644 --- a/src/components/Report/LateStartReportGen/LateStartReportGen.tsx +++ b/src/components/Report/LateStartReportGen/LateStartReportGen.tsx @@ -13,15 +13,17 @@ import { Customer } from "@/app/api/customer"; import { downloadFile } from "@/app/utils/commonUtil"; import { fetchLateStartReport } from "@/app/api/reports/actions"; import { LateStartReportRequest } from "@/app/api/reports"; +import { Subsidiary } from "@/app/api/subsidiary"; //import { GET_QC_CATEGORY_COMBO } from 'utils/ApiPathConst'; interface Props { projects: LateStart[]; - customers: Customer[]; + clients: Customer[]; + subsidiaries: Subsidiary[]; } type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; -const ProgressByClientSearch: React.FC = ({ projects, customers }) => { +const ProgressByClientSearch: React.FC = ({ projects, clients,subsidiaries }) => { //console.log(customers) const { t } = useTranslation("projects"); const [teamCombo, setteamCombo] = useState([]) @@ -37,6 +39,17 @@ const ProgressByClientSearch: React.FC = ({ projects, customers }) => { console.log(err) } } + const clientCombo = clients.map(client => ({ + value: `client: ${client.id}` , + label: `${client.code} - ${client.name}`, + group: t("Client") +})) + +const subsidiaryCombo = subsidiaries.map(subsidiary => ({ + value: `subsidiary: ${subsidiary.id}`, + label: `${subsidiary.code} - ${subsidiary.name}`, + group: t("Subsidiary") +})) useEffect(() => { getTeamCombo() @@ -45,33 +58,40 @@ const ProgressByClientSearch: React.FC = ({ projects, customers }) => { const searchCriteria: Criterion[] = useMemo( () => [ { label: "Team", paramName: "teamId", type: "select", options: teamCombo.map(team => team.label) }, - { label: "Client", paramName: "clientId", type: "select", options: customers.map(customer => `${customer.code}-${customer.name}`) }, + //{ label: "Client", paramName: "clientId", type: "autocomplete", options: clients.map(customer => `${customer.code}-${customer.name}`) }, + { label: t("Client"), paramName: "clientId", type: "autocomplete", options: [...subsidiaryCombo, ...clientCombo] }, { - label: "Remained Date From", - label2: "Remained Date To", + label: "Next Stage Due Date From", + label2: "Next Stage Due Date To", paramName: "remainedDate", type: "dateRange", }, ], - [t, teamCombo, customers], + [t, teamCombo, clients], ); return ( <> - {!isLoading && { - console.log(query); + //console.log(query); try { // const teamId = teamCombo.find(team => team.label === query.teamId)?.id!! // const clientId = customers.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id!! const teamId = teamCombo.find(team => team.label === query.teamId)?.id || 0; - const clientId = customers.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id || 0; + const clientId = clients.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id || 0; const remainedDate = query.remainedDate || "1900-01-01"; const remainedDateTo = query.remainedDateTo || "2100-12-31"; + const clientIndex = clientCombo.findIndex(client => client.value === query.clientId) + const subsidiaryIndex = subsidiaryCombo.findIndex(subsidiary => subsidiary.value === query.clientId) - const fileResponse = await fetchLateStartReport({teamId: teamId, clientId: clientId, remainedDate: remainedDate, remainedDateTo: remainedDateTo}); + const fileResponse = await fetchLateStartReport({teamId: teamId, + clientId: clientIndex >= 0 ? clients[clientIndex].id : subsidiaryIndex >= 0 ? subsidiaries[subsidiaryIndex].id : 0, + remainedDate: remainedDate, remainedDateTo: remainedDateTo, + type: clientIndex >= 0 ? "client" : subsidiaryIndex >= 0 ? "subsidiary" : "All",}); if (fileResponse) { downloadFile(new Uint8Array(fileResponse.blobValue), fileResponse.filename!!) } @@ -80,7 +100,7 @@ const ProgressByClientSearch: React.FC = ({ projects, customers }) => { } //console.log(teamCombo.find(team => team.label === query.team)?.id); }} - />} + /> {/* */} ); diff --git a/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx b/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx index 18f928a..6a06f81 100644 --- a/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx +++ b/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx @@ -3,6 +3,7 @@ import React from "react"; import LateStartReportGen from "./LateStartReportGen"; import LateStartReportGenLoading from "./LateStartReportGenLoading"; import { fetchAllCustomers } from "@/app/api/customer"; +import { fetchAllSubsidiaries } from "@/app/api/subsidiary"; interface SubComponents { Loading: typeof LateStartReportGenLoading; @@ -11,8 +12,9 @@ interface SubComponents { const LateStartReportGenWrapper: React.FC & SubComponents = async () => { const clentprojects = await fetchProjectsLateStart(); const customers = await fetchAllCustomers(); + const subsidiaries = await fetchAllSubsidiaries(); - return ; + return ; }; LateStartReportGenWrapper.Loading = LateStartReportGenLoading;