|
@@ -13,15 +13,17 @@ import { Customer } from "@/app/api/customer"; |
|
|
import { downloadFile } from "@/app/utils/commonUtil"; |
|
|
import { downloadFile } from "@/app/utils/commonUtil"; |
|
|
import { fetchLateStartReport } from "@/app/api/reports/actions"; |
|
|
import { fetchLateStartReport } from "@/app/api/reports/actions"; |
|
|
import { LateStartReportRequest } from "@/app/api/reports"; |
|
|
import { LateStartReportRequest } from "@/app/api/reports"; |
|
|
|
|
|
import { Subsidiary } from "@/app/api/subsidiary"; |
|
|
//import { GET_QC_CATEGORY_COMBO } from 'utils/ApiPathConst'; |
|
|
//import { GET_QC_CATEGORY_COMBO } from 'utils/ApiPathConst'; |
|
|
interface Props { |
|
|
interface Props { |
|
|
projects: LateStart[]; |
|
|
projects: LateStart[]; |
|
|
customers: Customer[]; |
|
|
|
|
|
|
|
|
clients: Customer[]; |
|
|
|
|
|
subsidiaries: Subsidiary[]; |
|
|
} |
|
|
} |
|
|
type SearchQuery = Partial<Omit<LateStartReportRequest, "id">>; |
|
|
type SearchQuery = Partial<Omit<LateStartReportRequest, "id">>; |
|
|
type SearchParamNames = keyof SearchQuery; |
|
|
type SearchParamNames = keyof SearchQuery; |
|
|
|
|
|
|
|
|
const ProgressByClientSearch: React.FC<Props> = ({ projects, customers }) => { |
|
|
|
|
|
|
|
|
const ProgressByClientSearch: React.FC<Props> = ({ projects, clients,subsidiaries }) => { |
|
|
//console.log(customers) |
|
|
//console.log(customers) |
|
|
const { t } = useTranslation("projects"); |
|
|
const { t } = useTranslation("projects"); |
|
|
const [teamCombo, setteamCombo] = useState<comboProp[]>([]) |
|
|
const [teamCombo, setteamCombo] = useState<comboProp[]>([]) |
|
@@ -37,6 +39,17 @@ const ProgressByClientSearch: React.FC<Props> = ({ projects, customers }) => { |
|
|
console.log(err) |
|
|
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(() => { |
|
|
useEffect(() => { |
|
|
getTeamCombo() |
|
|
getTeamCombo() |
|
@@ -45,33 +58,40 @@ const ProgressByClientSearch: React.FC<Props> = ({ projects, customers }) => { |
|
|
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( |
|
|
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( |
|
|
() => [ |
|
|
() => [ |
|
|
{ label: "Team", paramName: "teamId", type: "select", options: teamCombo.map(team => team.label) }, |
|
|
{ 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", |
|
|
paramName: "remainedDate", |
|
|
type: "dateRange", |
|
|
type: "dateRange", |
|
|
}, |
|
|
}, |
|
|
], |
|
|
], |
|
|
[t, teamCombo, customers], |
|
|
|
|
|
|
|
|
[t, teamCombo, clients], |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<> |
|
|
<> |
|
|
{!isLoading && <SearchBox |
|
|
|
|
|
|
|
|
<SearchBox |
|
|
|
|
|
formType={"download"} |
|
|
criteria={searchCriteria} |
|
|
criteria={searchCriteria} |
|
|
onSearch={async (query) => { |
|
|
onSearch={async (query) => { |
|
|
console.log(query); |
|
|
|
|
|
|
|
|
//console.log(query); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// const teamId = teamCombo.find(team => team.label === query.teamId)?.id!! |
|
|
// const teamId = teamCombo.find(team => team.label === query.teamId)?.id!! |
|
|
// const clientId = customers.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.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 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 remainedDate = query.remainedDate || "1900-01-01"; |
|
|
const remainedDateTo = query.remainedDateTo || "2100-12-31"; |
|
|
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) { |
|
|
if (fileResponse) { |
|
|
downloadFile(new Uint8Array(fileResponse.blobValue), fileResponse.filename!!) |
|
|
downloadFile(new Uint8Array(fileResponse.blobValue), fileResponse.filename!!) |
|
|
} |
|
|
} |
|
@@ -80,7 +100,7 @@ const ProgressByClientSearch: React.FC<Props> = ({ projects, customers }) => { |
|
|
} |
|
|
} |
|
|
//console.log(teamCombo.find(team => team.label === query.team)?.id); |
|
|
//console.log(teamCombo.find(team => team.label === query.team)?.id); |
|
|
}} |
|
|
}} |
|
|
/>} |
|
|
|
|
|
|
|
|
/> |
|
|
{/* <DownloadReportButton /> */} |
|
|
{/* <DownloadReportButton /> */} |
|
|
</> |
|
|
</> |
|
|
); |
|
|
); |
|
|