|
|
@@ -4,26 +4,38 @@ import SearchBox, { Criterion } from "../SearchBox"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import { ProjectResult } from "@/app/api/projects"; |
|
|
|
import { fetchMonthlyWorkHoursReport, fetchProjectCashFlowReport, fetchProjectResourceOverconsumptionReport } from "@/app/api/reports/actions"; |
|
|
|
import { downloadFile } from "@/app/utils/commonUtil"; |
|
|
|
import { downloadFile, readIntFromString } from "@/app/utils/commonUtil"; |
|
|
|
import { BASE_API_URL } from "@/config/api"; |
|
|
|
import { ProjectResourceOverconsumptionReportFilter, ProjectResourceOverconsumptionReportRequest } from "@/app/api/reports"; |
|
|
|
import { StaffResult } from "@/app/api/staff"; |
|
|
|
import { TeamResult } from "@/app/api/team"; |
|
|
|
import { Customer } from "@/app/api/customer"; |
|
|
|
import { Subsidiary } from "@/app/api/subsidiary"; |
|
|
|
|
|
|
|
interface Props { |
|
|
|
team: TeamResult[] |
|
|
|
customer: Customer[] |
|
|
|
subsidiaries: Subsidiary[] |
|
|
|
} |
|
|
|
|
|
|
|
type SearchQuery = Partial<Omit<ProjectResourceOverconsumptionReportFilter, "id">>; |
|
|
|
type SearchParamNames = keyof SearchQuery; |
|
|
|
|
|
|
|
const ResourceOverconsumptionReport: React.FC<Props> = ({ team, customer }) => { |
|
|
|
const ResourceOverconsumptionReport: React.FC<Props> = ({ team, customer, subsidiaries }) => { |
|
|
|
const { t } = useTranslation("report"); |
|
|
|
const teamCombo = team.map(t => `${t.name} - ${t.code}`) |
|
|
|
const custCombo = customer.map(c => ({label: `${c.name} - ${c.code}`, value: c.id})) |
|
|
|
console.log(customer) |
|
|
|
const statusCombo = ["Overconsumption", "Potential Overconsumption"] |
|
|
|
const teamCombo = team.map(t => `${t.name} - ${t.code}`) |
|
|
|
const custCombo = customer.map(c => ({ |
|
|
|
value: `custId-${c.id}`, |
|
|
|
label: `${c.code} - ${c.name}`, |
|
|
|
group: t("Client") |
|
|
|
})) |
|
|
|
const subsidiariesCombo = subsidiaries.map(sub => ({ |
|
|
|
value: `subsidiaryId-${sub.id}`, |
|
|
|
label: `${sub.code} - ${sub.name}`, |
|
|
|
group: t("Subsidiary") |
|
|
|
})) |
|
|
|
// const staffCombo = staffs.map(staff => `${staff.name} - ${staff.staffId}`) |
|
|
|
// console.log(staffs) |
|
|
|
|
|
|
@@ -40,8 +52,8 @@ const ResourceOverconsumptionReport: React.FC<Props> = ({ team, customer }) => { |
|
|
|
label: t("Client"), |
|
|
|
paramName: "customer", |
|
|
|
type: "autocomplete", |
|
|
|
options: custCombo, |
|
|
|
needAll: true |
|
|
|
options: [...subsidiariesCombo, ...custCombo], |
|
|
|
// needAll: true |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: t("Status"), |
|
|
@@ -51,7 +63,7 @@ const ResourceOverconsumptionReport: React.FC<Props> = ({ team, customer }) => { |
|
|
|
needAll: true |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: t("lowerLimit"), |
|
|
|
label: t("Potential Overconsumption Threshold"), |
|
|
|
paramName: "lowerLimit", |
|
|
|
type: "number", |
|
|
|
}, |
|
|
@@ -65,6 +77,7 @@ return ( |
|
|
|
formType={"download"} |
|
|
|
criteria={searchCriteria} |
|
|
|
onSearch={async (query: any) => { |
|
|
|
const [custType, id] = readIntFromString(query.customer) as [string, number] |
|
|
|
let index = 0 |
|
|
|
let postData: ProjectResourceOverconsumptionReportRequest = { |
|
|
|
status: "All", |
|
|
@@ -73,13 +86,13 @@ return ( |
|
|
|
if (query.team.length > 0 && query.team.toLocaleLowerCase() !== "all") { |
|
|
|
index = teamCombo.findIndex(team => team === query.team) |
|
|
|
postData.teamId = team[index].id |
|
|
|
} |
|
|
|
if (typeof query.customer === "string" && query.customer.toLocaleLowerCase() !== "all") { |
|
|
|
postData.custId = query.customer |
|
|
|
} |
|
|
|
if (Boolean(query.lowerLimit)) { |
|
|
|
postData.lowerLimit = query.lowerLimit/100 |
|
|
|
} |
|
|
|
if (id) { |
|
|
|
postData[custType] = id |
|
|
|
} |
|
|
|
postData.status = query.status |
|
|
|
console.log(postData) |
|
|
|
const response = await fetchProjectResourceOverconsumptionReport(postData) |
|
|
|