Переглянути джерело

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 {
teamId: 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 { TeamResult } from "@/app/api/team";
import { Customer } from "@/app/api/customer";
import { Subsidiary } from "@/app/api/subsidiary";
import { fetchCostAndExpenseReport } from "@/app/api/reports/actions";
import { downloadFile } from "@/app/utils/commonUtil";

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

type SearchQuery = Partial<Omit<CostAndExpenseReportFilter, "id">>;
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 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(
() => [
@@ -35,11 +50,11 @@ const CostAndExpenseReport: React.FC<Props> = ({ team, customer, needAll }) => {
label: t("Client"),
paramName: "customer",
type: "autocomplete",
options: custCombo,
options: [...subsidiaryCombo, ...custCombo],
needAll: true
},
{
label: t("Remaining Percentage"),
label: t("Remaining Percentage (<= %)"),
paramName: "budgetPercentage",
type: "number",
},
@@ -57,15 +72,20 @@ const CostAndExpenseReport: React.FC<Props> = ({ team, customer, needAll }) => {
let postData: CostAndExpenseReportRequest = {
teamId: null,
clientId: null,
budgetPercentage: 0.5
budgetPercentage: null,
type: "all"
}
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") {
index = teamCombo.findIndex(team => team === query.team)
postData.teamId = team[index].id
}
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)) {
postData.budgetPercentage = query.budgetPercentage/100


+ 3
- 1
src/components/CostAndExpenseReport/CostAndExpenseReportWrapper.tsx Переглянути файл

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


Завантаження…
Відмінити
Зберегти