mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-26 00:05:45 +00:00
refactor(FE): Generate HPP table from static rows with defaults
This commit is contained in:
@@ -23,6 +23,14 @@ type HppTableRow =
|
|||||||
type?: never;
|
type?: never;
|
||||||
budgeting?: never;
|
budgeting?: never;
|
||||||
realization?: never;
|
realization?: never;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: string;
|
||||||
|
group_name: string;
|
||||||
|
group_index: number;
|
||||||
|
isGroupHeader: false;
|
||||||
|
budgeting?: { rp_per_bird: number; rp_per_kg: number; amount: number };
|
||||||
|
realization?: { rp_per_bird: number; rp_per_kg: number; amount: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProfitLossTableRow =
|
type ProfitLossTableRow =
|
||||||
@@ -52,25 +60,117 @@ const ClosingFinanceTable = ({
|
|||||||
() => ClosingApi.getFinance(projectFlockId)
|
() => ClosingApi.getFinance(projectFlockId)
|
||||||
);
|
);
|
||||||
|
|
||||||
const hppTableData: HppTableRow[] = isResponseSuccess(finance)
|
const staticHppRows: Array<{
|
||||||
? finance.data.hpp_purchases.hpp.flatMap((hpp, groupIndex) => [
|
group_name: string;
|
||||||
// Group header row
|
type: string;
|
||||||
|
group_index: number;
|
||||||
|
}> = [
|
||||||
{
|
{
|
||||||
group_name: hpp.group_name,
|
group_name: 'HPP dan Pengeluaran',
|
||||||
group_index: groupIndex,
|
type: 'Pembelian PAKAN',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
type: 'Pembelian STARTER',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
type: 'Pembelian DOC',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
type: 'Pembelian PULLET',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
type: 'Pembelian LAYER',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Bahan Baku',
|
||||||
|
type: 'Pengeluaran Overhead',
|
||||||
|
group_index: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Bahan Baku',
|
||||||
|
type: 'Beban Ekspedisi',
|
||||||
|
group_index: 1,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const hppTableData: HppTableRow[] = [
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
group_index: 0,
|
||||||
isGroupHeader: true as const,
|
isGroupHeader: true as const,
|
||||||
},
|
},
|
||||||
// Data rows
|
...staticHppRows
|
||||||
...hpp.data.map((item) => ({
|
.filter((row) => row.group_index === 0)
|
||||||
group_name: hpp.group_name,
|
.map((staticRow) => {
|
||||||
group_index: groupIndex,
|
const apiData = isResponseSuccess(finance)
|
||||||
type: item.type,
|
? finance.data.hpp_purchases.hpp
|
||||||
budgeting: item.budgeting,
|
.find((g) => g.group_name === staticRow.group_name)
|
||||||
realization: item.realization,
|
?.data.find((d) => d.type === staticRow.type)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
group_name: staticRow.group_name,
|
||||||
|
group_index: staticRow.group_index,
|
||||||
|
type: staticRow.type,
|
||||||
|
budgeting: apiData?.budgeting || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
|
realization: apiData?.realization || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
isGroupHeader: false as const,
|
isGroupHeader: false as const,
|
||||||
})),
|
};
|
||||||
])
|
}),
|
||||||
: [];
|
{
|
||||||
|
group_name: 'HPP dan Bahan Baku',
|
||||||
|
group_index: 1,
|
||||||
|
isGroupHeader: true as const,
|
||||||
|
},
|
||||||
|
...staticHppRows
|
||||||
|
.filter((row) => row.group_index === 1)
|
||||||
|
.map((staticRow) => {
|
||||||
|
const apiData = isResponseSuccess(finance)
|
||||||
|
? finance.data.hpp_purchases.hpp
|
||||||
|
.find((g) => g.group_name === staticRow.group_name)
|
||||||
|
?.data.find((d) => d.type === staticRow.type)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
group_name: staticRow.group_name,
|
||||||
|
group_index: staticRow.group_index,
|
||||||
|
type: staticRow.type,
|
||||||
|
budgeting: apiData?.budgeting || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
|
realization: apiData?.realization || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
|
isGroupHeader: false as const,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
group_name: 'HPP',
|
||||||
|
group_index: 2,
|
||||||
|
isGroupHeader: true as const,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const profitLossTableData: ProfitLossTableRow[] = isResponseSuccess(finance)
|
const profitLossTableData: ProfitLossTableRow[] = isResponseSuccess(finance)
|
||||||
? [
|
? [
|
||||||
|
|||||||
Reference in New Issue
Block a user