refactor(FE): Simplify table cells and render initial balance row

This commit is contained in:
rstubryan
2026-01-14 15:46:03 +07:00
parent 08c28f4077
commit ab2175d903
@@ -302,49 +302,35 @@ const CustomerPaymentTab = () => {
{ {
id: 'no', id: 'no',
header: 'No', header: 'No',
cell: (props) => { cell: (props) => props.row.index,
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
return isInitialBalanceRow ? 'Saldo Awal' : props.row.index;
},
footer: () => <div className='font-semibold text-gray-900'>Total</div>, footer: () => <div className='font-semibold text-gray-900'>Total</div>,
}, },
{ {
id: 'do_date_or_payment_date', id: 'do_date_or_payment_date',
header: 'Tanggal DO/Bayar', header: 'Tanggal DO/Bayar',
accessorKey: 'trans_date', accessorKey: 'trans_date',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.trans_date; const value = props.row.original.trans_date;
return formatDate(value, 'DD MMM YYYY'); return value ? formatDate(value, 'DD MMM YYYY') : '-';
}, },
}, },
{ {
id: 'realization_date', id: 'realization_date',
header: 'Tanggal Realisasi', header: 'Tanggal Realisasi',
accessorKey: 'delivery_date', accessorKey: 'delivery_date',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.delivery_date; const value = props.row.original.delivery_date;
return formatDate(value, 'DD MMM YYYY'); return value ? formatDate(value, 'DD MMM YYYY') : '-';
}, },
}, },
{ {
id: 'aging', id: 'aging',
header: 'Aging', header: 'Aging',
accessorKey: 'aging_day', accessorKey: 'aging_day',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.aging_day; const value = props.row.original.aging_day;
return ( return (
<div className='text-center'> <div className='text-center'>
@@ -357,11 +343,8 @@ const CustomerPaymentTab = () => {
id: 'reference', id: 'reference',
header: 'Referensi', header: 'Referensi',
accessorKey: 'reference', accessorKey: 'reference',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.reference; const value = props.row.original.reference;
return value || '-'; return value || '-';
}, },
@@ -370,11 +353,8 @@ const CustomerPaymentTab = () => {
id: 'vehicle_plate', id: 'vehicle_plate',
header: 'Nomor Polisi', header: 'Nomor Polisi',
accessorKey: 'vehicle_numbers', accessorKey: 'vehicle_numbers',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.vehicle_numbers; const value = props.row.original.vehicle_numbers;
return value || '-'; return value || '-';
}, },
@@ -383,11 +363,8 @@ const CustomerPaymentTab = () => {
id: 'qty', id: 'qty',
header: 'Ekor/Qty', header: 'Ekor/Qty',
accessorKey: 'qty', accessorKey: 'qty',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.qty; const value = props.row.original.qty;
return <div className='text-right'>{formatNumber(value)}</div>; return <div className='text-right'>{formatNumber(value)}</div>;
}, },
@@ -401,11 +378,8 @@ const CustomerPaymentTab = () => {
id: 'weight', id: 'weight',
header: 'Berat (Kg)', header: 'Berat (Kg)',
accessorKey: 'weight', accessorKey: 'weight',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.weight; const value = props.row.original.weight;
return <div className='text-right'>{formatNumber(value)}</div>; return <div className='text-right'>{formatNumber(value)}</div>;
}, },
@@ -419,11 +393,8 @@ const CustomerPaymentTab = () => {
id: 'average_weight', id: 'average_weight',
header: 'AVG', header: 'AVG',
accessorKey: 'average_weight', accessorKey: 'average_weight',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.average_weight; const value = props.row.original.average_weight;
return <div className='text-right'>{formatNumber(value)}</div>; return <div className='text-right'>{formatNumber(value)}</div>;
}, },
@@ -435,11 +406,8 @@ const CustomerPaymentTab = () => {
id: 'price', id: 'price',
header: 'Harga Awal', header: 'Harga Awal',
accessorKey: 'price', accessorKey: 'price',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.price; const value = props.row.original.price;
return <div className='text-right'>{formatCurrency(value)}</div>; return <div className='text-right'>{formatCurrency(value)}</div>;
}, },
@@ -453,11 +421,8 @@ const CustomerPaymentTab = () => {
id: 'credit_note', id: 'credit_note',
header: 'CN', header: 'CN',
accessorKey: 'credit_note', accessorKey: 'credit_note',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.credit_note; const value = props.row.original.credit_note;
return <div className='text-right'>{formatCurrency(value)}</div>; return <div className='text-right'>{formatCurrency(value)}</div>;
}, },
@@ -471,11 +436,8 @@ const CustomerPaymentTab = () => {
id: 'final_price', id: 'final_price',
header: 'Harga Akhir', header: 'Harga Akhir',
accessorKey: 'final_price', accessorKey: 'final_price',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.final_price; const value = props.row.original.final_price;
return <div className='text-right'>{formatCurrency(value)}</div>; return <div className='text-right'>{formatCurrency(value)}</div>;
}, },
@@ -489,11 +451,8 @@ const CustomerPaymentTab = () => {
id: 'ppn', id: 'ppn',
header: 'PPN (%)', header: 'PPN (%)',
accessorKey: 'ppn', accessorKey: 'ppn',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.ppn; const value = props.row.original.ppn;
return <div className='text-right'>{formatNumber(value)}%</div>; return <div className='text-right'>{formatNumber(value)}%</div>;
}, },
@@ -505,11 +464,8 @@ const CustomerPaymentTab = () => {
id: 'total', id: 'total',
header: 'Total', header: 'Total',
accessorKey: 'total_price', accessorKey: 'total_price',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.total_price; const value = props.row.original.total_price;
return <div className='text-right'>{formatCurrency(value)}</div>; return <div className='text-right'>{formatCurrency(value)}</div>;
}, },
@@ -523,11 +479,8 @@ const CustomerPaymentTab = () => {
id: 'payment', id: 'payment',
header: 'Pembayaran', header: 'Pembayaran',
accessorKey: 'payment_amount', accessorKey: 'payment_amount',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return <div className='text-right'>-</div>;
const value = props.row.original.payment_amount; const value = props.row.original.payment_amount;
return <div className='text-right'>{formatCurrency(value)}</div>; return <div className='text-right'>{formatCurrency(value)}</div>;
}, },
@@ -541,6 +494,7 @@ const CustomerPaymentTab = () => {
id: 'accounts_receivable', id: 'accounts_receivable',
header: 'Saldo Piutang', header: 'Saldo Piutang',
accessorKey: 'accounts_receivable', accessorKey: 'accounts_receivable',
enableSorting: false,
cell: (props) => { cell: (props) => {
const value = props.row.original.accounts_receivable; const value = props.row.original.accounts_receivable;
return ( return (
@@ -557,11 +511,8 @@ const CustomerPaymentTab = () => {
id: 'notes', id: 'notes',
header: 'Keterangan', header: 'Keterangan',
accessorKey: 'status', accessorKey: 'status',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.status; const value = props.row.original.status;
if (!value) { if (!value) {
@@ -586,11 +537,8 @@ const CustomerPaymentTab = () => {
id: 'pickup_info', id: 'pickup_info',
header: 'Pengambilan', header: 'Pengambilan',
accessorKey: 'pickup_info', accessorKey: 'pickup_info',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.pickup_info; const value = props.row.original.pickup_info;
return value || '-'; return value || '-';
}, },
@@ -599,11 +547,8 @@ const CustomerPaymentTab = () => {
id: 'sales_marketing', id: 'sales_marketing',
header: 'Sales/Marketing', header: 'Sales/Marketing',
accessorKey: 'sales_person', accessorKey: 'sales_person',
enableSorting: false,
cell: (props) => { cell: (props) => {
const isInitialBalanceRow =
Object.keys(props.row.original).length === 1 &&
'accounts_receivable' in props.row.original;
if (isInitialBalanceRow) return '-';
const value = props.row.original.sales_person; const value = props.row.original.sales_person;
return value || '-'; return value || '-';
}, },
@@ -854,6 +799,30 @@ const CustomerPaymentTab = () => {
'px-4 py-3 text-xs text-gray-900 whitespace-nowrap', 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap',
paginationClassName: 'hidden', paginationClassName: 'hidden',
}} }}
renderCustomRow={(row) => {
if (row.index === 0) {
return (
<tr
className='hover:bg-gray-50 transition-colors border-b border-l border-r border-b-gray-200 border-l-gray-200 border-r-gray-200'
key={row.index}
>
<td
className='px-4 py-3 text-xs text-gray-900 whitespace-nowrap'
colSpan={15}
></td>
<td className='px-4 py-3 text-xs text-gray-900 whitespace-nowrap'>
<div className='text-right text-error'>
{formatCurrency(row.original.accounts_receivable)}
</div>
</td>
<td
className='px-4 py-3 text-xs text-gray-900 whitespace-nowrap'
colSpan={4}
></td>
</tr>
);
}
}}
/> />
</Card> </Card>
); );