瀏覽代碼

Add subsidary to cost and expense report

tags/Baseline_30082024_FRONTEND_UAT
MSI\2Fi 1 年之前
父節點
當前提交
ea1b4e99da
共有 3 個檔案被更改,包括 31 行新增8 行删除
  1. +2
    -1
      src/app/api/reports/index.ts
  2. +26
    -6
      src/components/CostAndExpenseReport/CostAndExpenseReport.tsx
  3. +3
    -1
      src/components/CostAndExpenseReport/CostAndExpenseReportWrapper.tsx

+ 2
- 1
src/app/api/reports/index.ts 查看文件

@@ -112,5 +112,6 @@ export interface CostAndExpenseReportFilter {
export interface CostAndExpenseReportRequest { export interface CostAndExpenseReportRequest {
teamId: number | null; teamId: number | null;
clientId: number | null; clientId: number | null;
budgetPercentage: number;
budgetPercentage: number | null;
type: string;
} }

+ 26
- 6
src/components/CostAndExpenseReport/CostAndExpenseReport.tsx 查看文件

@@ -5,22 +5,37 @@ import SearchBox, { Criterion } from "../SearchBox";
import { useMemo } from "react"; import { useMemo } from "react";
import { TeamResult } from "@/app/api/team"; import { TeamResult } from "@/app/api/team";
import { Customer } from "@/app/api/customer"; import { Customer } from "@/app/api/customer";
import { Subsidiary } from "@/app/api/subsidiary";
import { fetchCostAndExpenseReport } from "@/app/api/reports/actions"; import { fetchCostAndExpenseReport } from "@/app/api/reports/actions";
import { downloadFile } from "@/app/utils/commonUtil"; import { downloadFile } from "@/app/utils/commonUtil";


interface Props { interface Props {
team: TeamResult[]; team: TeamResult[];
customer: Customer[]; customer: Customer[];
subsidiary: Subsidiary[];
needAll: boolean | undefined; needAll: boolean | undefined;
} }


type SearchQuery = Partial<Omit<CostAndExpenseReportFilter, "id">>; type SearchQuery = Partial<Omit<CostAndExpenseReportFilter, "id">>;
type SearchParamNames = keyof SearchQuery; type SearchParamNames = keyof SearchQuery;


const CostAndExpenseReport: React.FC<Props> = ({ team, customer, needAll }) => {
const CostAndExpenseReport: React.FC<Props> = ({ team, customer, subsidiary, needAll }) => {
const { t } = useTranslation("report"); const { t } = useTranslation("report");
const teamCombo = team.map((t) => `${t.name} - ${t.code}`); const teamCombo = team.map((t) => `${t.name} - ${t.code}`);
const custCombo = customer.map(c => ({label: `${c.name} - ${c.code}`, value: c.id}))
// const custCombo = customer.map(c => ({label: `${c.name} - ${c.code}`, value: c.id}))
const custCombo = customer.map(customer => ({
value: `client: ${customer.id}` ,
label: `${customer.code} - ${customer.name}`,
group: t("Client")
}))

const subsidiaryCombo = subsidiary.map(subsidiary => ({
value: `subsidiary: ${subsidiary.id}`,
label: `${subsidiary.code} - ${subsidiary.name}`,
group: t("Subsidiary")
}))



const searchCriteria: Criterion<SearchParamNames>[] = useMemo( const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
() => [ () => [
@@ -35,11 +50,11 @@ const CostAndExpenseReport: React.FC<Props> = ({ team, customer, needAll }) => {
label: t("Client"), label: t("Client"),
paramName: "customer", paramName: "customer",
type: "autocomplete", type: "autocomplete",
options: custCombo,
options: [...subsidiaryCombo, ...custCombo],
needAll: true needAll: true
}, },
{ {
label: t("Remaining Percentage"),
label: t("Remaining Percentage (<= %)"),
paramName: "budgetPercentage", paramName: "budgetPercentage",
type: "number", type: "number",
}, },
@@ -57,15 +72,20 @@ const CostAndExpenseReport: React.FC<Props> = ({ team, customer, needAll }) => {
let postData: CostAndExpenseReportRequest = { let postData: CostAndExpenseReportRequest = {
teamId: null, teamId: null,
clientId: null, clientId: null,
budgetPercentage: 0.5
budgetPercentage: null,
type: "all"
} }
console.log(query.budgetPercentage) console.log(query.budgetPercentage)
const customerIndex = custCombo.findIndex(customer => customer.value === query.customer)
const subsidiaryIndex = subsidiaryCombo.findIndex(subsidiary => subsidiary.value === query.customer)
if (query.team.length > 0 && query.team.toLocaleLowerCase() !== "all") { if (query.team.length > 0 && query.team.toLocaleLowerCase() !== "all") {
index = teamCombo.findIndex(team => team === query.team) index = teamCombo.findIndex(team => team === query.team)
postData.teamId = team[index].id postData.teamId = team[index].id
} }
if (typeof query.customer === "string" && query.customer.toLocaleLowerCase() !== "all") { if (typeof query.customer === "string" && query.customer.toLocaleLowerCase() !== "all") {
postData.clientId = query.customer
// postData.clientId = query.customer
postData.clientId = customerIndex >= 0 ? customer[customerIndex].id : subsidiaryIndex >= 0 ? subsidiary[subsidiaryIndex].id : null
postData.type = customerIndex >= 0 ? "client" : subsidiaryIndex >= 0 ? "subsidiary" : "all"
} }
if (Boolean(query.budgetPercentage)) { if (Boolean(query.budgetPercentage)) {
postData.budgetPercentage = query.budgetPercentage/100 postData.budgetPercentage = query.budgetPercentage/100


+ 3
- 1
src/components/CostAndExpenseReport/CostAndExpenseReportWrapper.tsx 查看文件

@@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import { fetchAllCustomers } from "@/app/api/customer"; import { fetchAllCustomers } from "@/app/api/customer";
import { fetchAllSubsidiaries } from "@/app/api/subsidiary";
import { fetchIndivTeam, fetchTeam } from "@/app/api/team"; import { fetchIndivTeam, fetchTeam } from "@/app/api/team";
import CostAndExpenseReport from "./CostAndExpenseReport"; import CostAndExpenseReport from "./CostAndExpenseReport";
import CostAndExpenseReportLoading from "./CostAndExpenseReportLoading"; import CostAndExpenseReportLoading from "./CostAndExpenseReportLoading";
@@ -16,6 +17,7 @@ const CostAndExpenseReportWrapper: React.FC & SubComponents = async () => {
const teamId = session.staff?.team.id const teamId = session.staff?.team.id
const role = session.role const role = session.role
let customers = await fetchAllCustomers() let customers = await fetchAllCustomers()
let subsidiaries = await fetchAllSubsidiaries()
let teams = await fetchTeam() let teams = await fetchTeam()
let needAll = true let needAll = true
@@ -24,7 +26,7 @@ const CostAndExpenseReportWrapper: React.FC & SubComponents = async () => {
teams = teams.filter((team) => team.id === teamId); teams = teams.filter((team) => team.id === teamId);
} }


return <CostAndExpenseReport team={teams} customer={customers} needAll={needAll} />
return <CostAndExpenseReport team={teams} customer={customers} subsidiary={subsidiaries} needAll={needAll} />
}; };


CostAndExpenseReportWrapper.Loading = CostAndExpenseReportLoading; CostAndExpenseReportWrapper.Loading = CostAndExpenseReportLoading;


Loading…
取消
儲存