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,101 +32,160 @@ 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: 'Budget Pengajuan',
{ footer: '',
header: 'Satuan', columns: [
accessorFn: (props) => props.uom_name, {
}, id: 'budget_quantity',
{ header: 'Jumlah',
header: 'Budget Pengajuan', accessorFn: (props) =>
footer: '', props.budget_quantity ? formatNumber(props.budget_quantity) : '-',
columns: [ footer: total ? () => formatNumber(total.budget_quantity) : '',
{ },
id: 'budget_quantity', {
header: 'Jumlah', id: 'budget_unit_price',
accessorFn: (props) => header: 'Harga Satuan',
props.budget_quantity ? formatNumber(props.budget_quantity) : '-', accessorFn: (props) =>
footer: total ? () => formatNumber(total.budget_quantity) : '', props.budget_unit_price
}, ? formatCurrency(props.budget_unit_price)
{ : '-',
id: 'budget_unit_price', footer: '',
header: 'Harga Satuan', },
accessorFn: (props) => {
props.budget_unit_price id: 'budget_total_amount',
? formatCurrency(props.budget_unit_price) header: 'Total',
: '-', accessorFn: (props) =>
footer: '', props.budget_total_amount
}, ? formatCurrency(props.budget_total_amount)
{ : '-',
id: 'budget_total_amount', footer: total
header: 'Total', ? () => formatCurrency(total.budget_total_amount)
accessorFn: (props) => : '',
props.budget_total_amount },
? formatCurrency(props.budget_total_amount) ],
: '-', },
footer: total ? () => formatCurrency(total.budget_total_amount) : '', {
}, header: 'Realisasi',
], footer: '',
}, columns: [
{ {
header: 'Realisasi', id: 'actual_date',
footer: '', header: 'Tanggal',
columns: [ accessorFn: (props) =>
{ props.actual_date
id: 'actual_date', ? formatDate(props.actual_date, 'DD MMM, YYYY')
header: 'Tanggal', : '-',
accessorFn: (props) => footer: '',
props.actual_date },
? formatDate(props.actual_date, 'DD MMM, YYYY') {
: '-', id: 'actual_quantity',
footer: '', header: 'Jumlah',
}, accessorFn: (props) =>
{ props.actual_quantity ? formatNumber(props.actual_quantity) : '-',
id: 'actual_quantity', footer: total ? () => formatNumber(total.actual_quantity) : '',
header: 'Jumlah', },
accessorFn: (props) => {
props.actual_quantity ? formatNumber(props.actual_quantity) : '-', id: 'actual_unit_price',
footer: total ? () => formatNumber(total.actual_quantity) : '', header: 'Harga Satuan',
}, accessorFn: (props) =>
{ props.actual_unit_price
id: 'actual_unit_price', ? formatCurrency(props.actual_unit_price)
header: 'Harga Satuan', : '-',
accessorFn: (props) => footer: '',
props.actual_unit_price },
? formatCurrency(props.actual_unit_price) {
: '-', id: 'actual_total_amount',
footer: '', header: 'Total',
}, accessorFn: (props) =>
{ props.actual_total_amount
id: 'actual_total_amount', ? formatCurrency(props.actual_total_amount)
header: 'Total', : '-',
accessorFn: (props) => footer: total
props.actual_total_amount ? () => formatCurrency(total.actual_total_amount)
? formatCurrency(props.actual_total_amount) : '',
: '-', },
footer: total ? () => formatCurrency(total.actual_total_amount) : '', ],
}, },
], ];
},
{ const kandangColumn: ColumnDef<Overhead>[] = [
id: 'cost_per_bird', {
header: 'Rp/Ekor', id: 'actual_date',
accessorFn: (props) => header: 'Tanggal',
props.cost_per_bird ? formatCurrency(props.cost_per_bird) : '-', accessorFn: (props) =>
footer: total ? () => formatCurrency(total.cost_per_bird) : '', 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',
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( const columns = useMemo(
() => () =>
isResponseSuccess(overhead) isResponseSuccess(overhead)
? createColumns(overhead.data?.total) ? createColumns(
overhead.data?.total,
kandangId ? Number(kandangId) : undefined
)
: createColumns(), : createColumns(),
[overhead] [overhead]
); );