From 01b8841e3cbbe94c1b5b4fdeb4fd41b8fb9ac278 Mon Sep 17 00:00:00 2001 From: randy-ar Date: Thu, 15 Jan 2026 21:14:55 +0700 Subject: [PATCH] fix(FE): adjust ui closing overhead kandang --- .../pages/closing/ClosingOverheadTable.tsx | 241 +++++++++++------- 1 file changed, 150 insertions(+), 91 deletions(-) diff --git a/src/components/pages/closing/ClosingOverheadTable.tsx b/src/components/pages/closing/ClosingOverheadTable.tsx index ed74ca66..9ef6694f 100644 --- a/src/components/pages/closing/ClosingOverheadTable.tsx +++ b/src/components/pages/closing/ClosingOverheadTable.tsx @@ -32,101 +32,160 @@ const ClosingOverheadTable = ({ ); // Helper function to create columns with footer support - const createColumns = (total?: OverheadTotal): ColumnDef[] => [ - // Group untuk kolom tanpa footer - { - header: 'Nama Item', - accessorFn: (props) => props.item_name, - footer: 'Total Pengeluaran Overhead', - }, - { - header: 'Satuan', - accessorFn: (props) => props.uom_name, - }, - { - header: 'Budget Pengajuan', - footer: '', - columns: [ - { - id: 'budget_quantity', - header: 'Jumlah', - accessorFn: (props) => - props.budget_quantity ? formatNumber(props.budget_quantity) : '-', - footer: total ? () => formatNumber(total.budget_quantity) : '', - }, - { - id: 'budget_unit_price', - header: 'Harga Satuan', - accessorFn: (props) => - props.budget_unit_price - ? formatCurrency(props.budget_unit_price) - : '-', - footer: '', - }, - { - id: 'budget_total_amount', - header: 'Total', - accessorFn: (props) => - props.budget_total_amount - ? formatCurrency(props.budget_total_amount) - : '-', - footer: total ? () => formatCurrency(total.budget_total_amount) : '', - }, - ], - }, - { - header: 'Realisasi', - footer: '', - columns: [ - { - id: 'actual_date', - header: 'Tanggal', - accessorFn: (props) => - props.actual_date - ? formatDate(props.actual_date, 'DD MMM, YYYY') - : '-', - footer: '', - }, - { - id: 'actual_quantity', - header: 'Jumlah', - accessorFn: (props) => - props.actual_quantity ? formatNumber(props.actual_quantity) : '-', - footer: total ? () => formatNumber(total.actual_quantity) : '', - }, - { - id: 'actual_unit_price', - header: 'Harga Satuan', - accessorFn: (props) => - props.actual_unit_price - ? formatCurrency(props.actual_unit_price) - : '-', - footer: '', - }, - { - id: 'actual_total_amount', - header: 'Total', - accessorFn: (props) => - props.actual_total_amount - ? formatCurrency(props.actual_total_amount) - : '-', - footer: total ? () => formatCurrency(total.actual_total_amount) : '', - }, - ], - }, - { - id: 'cost_per_bird', - header: 'Rp/Ekor', - accessorFn: (props) => - props.cost_per_bird ? formatCurrency(props.cost_per_bird) : '-', - footer: total ? () => formatCurrency(total.cost_per_bird) : '', - }, - ]; + const createColumns = ( + total?: OverheadTotal, + kandangId?: number + ): ColumnDef[] => { + const flockColumn: ColumnDef[] = [ + { + header: 'Budget Pengajuan', + footer: '', + columns: [ + { + id: 'budget_quantity', + header: 'Jumlah', + accessorFn: (props) => + props.budget_quantity ? formatNumber(props.budget_quantity) : '-', + footer: total ? () => formatNumber(total.budget_quantity) : '', + }, + { + id: 'budget_unit_price', + header: 'Harga Satuan', + accessorFn: (props) => + props.budget_unit_price + ? formatCurrency(props.budget_unit_price) + : '-', + footer: '', + }, + { + id: 'budget_total_amount', + header: 'Total', + accessorFn: (props) => + props.budget_total_amount + ? formatCurrency(props.budget_total_amount) + : '-', + footer: total + ? () => formatCurrency(total.budget_total_amount) + : '', + }, + ], + }, + { + header: 'Realisasi', + footer: '', + columns: [ + { + id: 'actual_date', + header: 'Tanggal', + accessorFn: (props) => + props.actual_date + ? formatDate(props.actual_date, 'DD MMM, YYYY') + : '-', + footer: '', + }, + { + id: 'actual_quantity', + header: 'Jumlah', + accessorFn: (props) => + props.actual_quantity ? formatNumber(props.actual_quantity) : '-', + footer: total ? () => formatNumber(total.actual_quantity) : '', + }, + { + id: 'actual_unit_price', + header: 'Harga Satuan', + accessorFn: (props) => + props.actual_unit_price + ? formatCurrency(props.actual_unit_price) + : '-', + footer: '', + }, + { + id: 'actual_total_amount', + header: 'Total', + accessorFn: (props) => + props.actual_total_amount + ? formatCurrency(props.actual_total_amount) + : '-', + footer: total + ? () => formatCurrency(total.actual_total_amount) + : '', + }, + ], + }, + ]; + + const kandangColumn: ColumnDef[] = [ + { + id: 'actual_date', + header: 'Tanggal', + accessorFn: (props) => + props.actual_date + ? formatDate(props.actual_date, 'DD MMM, YYYY') + : '-', + footer: '', + }, + { + id: 'actual_quantity', + header: 'Jumlah', + accessorFn: (props) => + props.actual_quantity ? formatNumber(props.actual_quantity) : '-', + footer: total ? () => formatNumber(total.actual_quantity) : '', + }, + { + id: 'actual_unit_price', + header: 'Harga Satuan', + accessorFn: (props) => + props.actual_unit_price + ? formatCurrency(props.actual_unit_price) + : '-', + footer: '', + }, + { + id: 'actual_total_amount', + header: 'Total', + accessorFn: (props) => + props.actual_total_amount + ? formatCurrency(props.actual_total_amount) + : '-', + footer: total ? () => formatCurrency(total.actual_total_amount) : '', + }, + ]; + + const finalColumns: ColumnDef[] = [ + // Group untuk kolom tanpa footer + { + header: 'No', + accessorFn: (_, index) => index, + cell: (props) => props.row.index + 1, + }, + { + header: 'Nama Item', + accessorFn: (props) => props.item_name, + footer: 'Total Pengeluaran Overhead', + }, + { + header: 'Satuan', + accessorFn: (props) => props.uom_name, + }, + ...(kandangId ? kandangColumn : flockColumn), + { + id: 'cost_per_bird', + header: 'Rp/Ekor', + accessorFn: (props) => + props.cost_per_bird ? formatCurrency(props.cost_per_bird) : '-', + footer: total ? () => formatCurrency(total.cost_per_bird) : '', + }, + ]; + return finalColumns; + }; const columns = useMemo( () => isResponseSuccess(overhead) - ? createColumns(overhead.data?.total) + ? createColumns( + overhead.data?.total, + kandangId ? Number(kandangId) : undefined + ) : createColumns(), [overhead] );