fix(FE): adjust ui closing overhead kandang

This commit is contained in:
randy-ar
2026-01-15 21:14:55 +07:00
parent 40e8f52fe4
commit 01b8841e3c
@@ -32,17 +32,11 @@ const ClosingOverheadTable = ({
); );
// Helper function to create columns with footer support // Helper function to create columns with footer support
const createColumns = (total?: OverheadTotal): ColumnDef<Overhead>[] => [ const createColumns = (
// Group untuk kolom tanpa footer total?: OverheadTotal,
{ kandangId?: number
header: 'Nama Item', ): ColumnDef<Overhead>[] => {
accessorFn: (props) => props.item_name, const flockColumn: ColumnDef<Overhead>[] = [
footer: 'Total Pengeluaran Overhead',
},
{
header: 'Satuan',
accessorFn: (props) => props.uom_name,
},
{ {
header: 'Budget Pengajuan', header: 'Budget Pengajuan',
footer: '', footer: '',
@@ -70,7 +64,9 @@ const ClosingOverheadTable = ({
props.budget_total_amount props.budget_total_amount
? formatCurrency(props.budget_total_amount) ? formatCurrency(props.budget_total_amount)
: '-', : '-',
footer: total ? () => formatCurrency(total.budget_total_amount) : '', footer: total
? () => formatCurrency(total.budget_total_amount)
: '',
}, },
], ],
}, },
@@ -110,10 +106,68 @@ const ClosingOverheadTable = ({
props.actual_total_amount props.actual_total_amount
? formatCurrency(props.actual_total_amount) ? formatCurrency(props.actual_total_amount)
: '-', : '-',
footer: total ? () => formatCurrency(total.actual_total_amount) : '', footer: total
? () => formatCurrency(total.actual_total_amount)
: '',
}, },
], ],
}, },
];
const kandangColumn: ColumnDef<Overhead>[] = [
{
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<Overhead>[] = [
// 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', id: 'cost_per_bird',
header: 'Rp/Ekor', header: 'Rp/Ekor',
@@ -122,11 +176,16 @@ const ClosingOverheadTable = ({
footer: total ? () => formatCurrency(total.cost_per_bird) : '', footer: total ? () => formatCurrency(total.cost_per_bird) : '',
}, },
]; ];
return finalColumns;
};
const columns = useMemo( const columns = useMemo(
() => () =>
isResponseSuccess(overhead) isResponseSuccess(overhead)
? createColumns(overhead.data?.total) ? createColumns(
overhead.data?.total,
kandangId ? Number(kandangId) : undefined
)
: createColumns(), : createColumns(),
[overhead] [overhead]
); );