[] = [
+ {
+ header: 'No',
+ accessorKey: 'no',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) {
+ return (
+
+ {props.row.original.no}
+
+ );
+ }
+ return props.row.index + 1;
+ },
+ },
+ {
+ header: 'Tanggal Terima',
+ accessorKey: 'received_date',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) {
+ return (
+
+ {props.row.original.received_date}
+
+ );
+ }
+ return formatDate(props.row.original.received_date, 'DD MMM YYYY');
+ },
+ },
+ {
+ header: 'Tanggal PO',
+ accessorKey: 'po_date',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) return null;
+ return formatDate(props.row.original.po_date, 'DD MMM YYYY');
+ },
+ },
+ {
+ header: 'No. Referensi',
+ accessorKey: 'po_number',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) return null;
+ return props.row.original.po_number;
+ },
+ },
+ {
+ header: 'Nama Produk',
+ accessorKey: 'product_name',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) return null;
+ return props.row.original.product_name;
+ },
+ },
+ {
+ header: 'Tujuan',
+ accessorKey: 'destination_warehouse',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) return null;
+ return props.row.original.destination_warehouse;
+ },
+ },
+ {
+ header: 'QTY',
+ accessorKey: 'qty',
+ cell: (props) => {
+ const value = props.getValue() as number;
+ const isFooter = '_isFooter' in props.row.original;
+ return (
+
+ {value.toLocaleString()}
+
+ );
+ },
+ },
+ {
+ header: 'Harga Beli (Rp)',
+ accessorKey: 'price',
+ cell: (props) => {
+ const value = props.getValue() as number;
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) {
+ return (
+
+ {formatCurrency(value)}
+
+ );
+ }
+ return (
+
+ {formatCurrency(props.row.original.price)}
+
+ );
+ },
+ },
+ {
+ header: 'Value Harga Beli (Rp)',
+ accessorKey: 'purchase_amount',
+ cell: (props) => {
+ const value = props.getValue() as number;
+ const isFooter = '_isFooter' in props.row.original;
+ return (
+
+ {formatCurrency(value)}
+
+ );
+ },
+ },
+ {
+ header: 'Transport (Rp)',
+ accessorKey: 'transport',
+ cell: (props) => {
+ const value = props.getValue() as number;
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) {
+ return (
+
+ {formatCurrency(value)}
+
+ );
+ }
+ return (
+
+ {formatCurrency(props.row.original.transport)}
+
+ );
+ },
+ },
+ {
+ header: 'Value Transport (Rp)',
+ accessorKey: 'value_transport',
+ cell: (props) => {
+ const value = props.getValue() as number;
+ const isFooter = '_isFooter' in props.row.original;
+ return (
+
+ {formatCurrency(value)}
+
+ );
+ },
+ },
+ {
+ header: 'Jumlah (Rp)',
+ accessorKey: 'total',
+ cell: (props) => {
+ const value = props.getValue() as number;
+ const isFooter = '_isFooter' in props.row.original;
+ return (
+
+ {formatCurrency(value)}
+
+ );
+ },
+ },
+ {
+ header: 'Ekspedisi',
+ accessorKey: 'expedition_vendor_name',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) return null;
+ return props.row.original.expedition_vendor_name;
+ },
+ },
+ {
+ header: 'Surat Jalan',
+ accessorKey: 'travel_number',
+ cell: (props) => {
+ const isFooter = '_isFooter' in props.row.original;
+ if (isFooter) return null;
+ return props.row.original.travel_number;
+ },
+ },
+ ];
+
+ return (
+ <>
+
+
+ {/* TODO START */}
+ option.value === selectedArea) ||
+ null
+ }
+ // @ts-expect-error TS2345
+ onChange={(val) => setSelectedArea(val?.value || null)}
+ isLoading={isLoadingAreas}
+ isClearable
+ />
+ option.value === selectedSupplier
+ ) || null
+ }
+ // @ts-expect-error TS2345
+ onChange={(val) => setSelectedSupplier(val?.value || null)}
+ isLoading={isLoadingSuppliers}
+ isClearable
+ />
+ option.value === selectedProduct
+ ) || null
+ }
+ // @ts-expect-error TS2345
+ onChange={(val) => setSelectedProduct(val?.value || null)}
+ isLoading={isLoadingProducts}
+ isClearable
+ />
+ {/* TODO END */}
+
+
+ {data.length === 0 ? (
+
+ Tidak ada data untuk ditampilkan.
+
+ ) : (
+ data.map((supplier) => {
+ const totalQty = supplier.items.reduce(
+ (sum, item) => sum + (item.qty || 0),
+ 0
+ );
+ const totalPrice = supplier.items.reduce(
+ (sum, item) => sum + (item.price || 0),
+ 0
+ );
+ const totalPurchaseAmount = supplier.items.reduce(
+ (sum, item) => sum + (item.purchase_amount || 0),
+ 0
+ );
+ const totalTransport = supplier.items.reduce(
+ (sum, item) => sum + (item.transport || 0),
+ 0
+ );
+ const totalValueTransport = supplier.items.reduce(
+ (sum, item) => sum + (item.value_transport || 0),
+ 0
+ );
+ const totalJumlah = supplier.items.reduce(
+ (sum, item) => sum + (item.total || 0),
+ 0
+ );
+
+ const totals = {
+ totalQty,
+ totalPrice,
+ totalPurchaseAmount,
+ totalTransport,
+ totalValueTransport,
+ totalJumlah,
+ };
+
+ const footerData =
+ supplier.items.length > 0
+ ? [
+ {
+ id: -999,
+ no: 'Total',
+ received_date: '',
+ po_date: null,
+ po_number: null,
+ product_name: null,
+ destination_warehouse: null,
+ qty: totals.totalQty,
+ price: totals.totalPrice,
+ purchase_amount: totals.totalPurchaseAmount,
+ transport: totals.totalTransport,
+ value_transport: totals.totalValueTransport,
+ total: totals.totalJumlah,
+ expedition_vendor_name: null,
+ travel_number: null,
+ _isFooter: true,
+ },
+ ]
+ : [];
+
+ const totalPurchase = totals.totalJumlah;
+
+ return (
+
+ 0}
+ className={{
+ tableWrapperClassName: 'overflow-x-auto mt-4',
+ tableClassName: 'w-full table-auto text-sm',
+ headerRowClassName: 'border-b border-b-gray-200 bg-gray-50',
+ headerColumnClassName:
+ 'px-4 py-3 text-xs font-semibold text-gray-700 text-left border border-gray-200',
+ bodyRowClassName:
+ 'hover:bg-gray-50 transition-colors border-b border-l border-r border-b-gray-200 border-l-gray-200 border-r-gray-200',
+ bodyColumnClassName:
+ 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap',
+ tableFooterClassName:
+ 'bg-gray-100 font-semibold border border-gray-200',
+ footerRowClassName: 'border-t-2 border-gray-300',
+ footerColumnClassName:
+ 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap',
+ paginationClassName: 'hidden',
+ }}
+ />
+
+ );
+ })
+ )}
+
+ >
+ );
+};
+
+export default PurchasesPerSupplierTab;