diff --git a/src/components/pages/purchase/PurchaseTable.tsx b/src/components/pages/purchase/PurchaseTable.tsx index 31ed1abc..6a74af0c 100644 --- a/src/components/pages/purchase/PurchaseTable.tsx +++ b/src/components/pages/purchase/PurchaseTable.tsx @@ -91,7 +91,6 @@ const PurchaseTable = () => { null ); const [sorting, setSorting] = useState([]); - const [rowSelection, setRowSelection] = useState>({}); // ===== TABLE FILTER STATE ===== const { @@ -134,104 +133,94 @@ const PurchaseTable = () => { PurchaseRequestApi.getAllFetcher ); - // ===== COMPUTED VALUES ===== - const selectedRowIds = useMemo( - () => Object.keys(rowSelection).map((item) => parseInt(item)), - [rowSelection] - ); - // ===== TABLE COLUMNS DEFINITION ===== - const purchaseColumns: ColumnDef[] = useMemo( - () => [ - { - header: 'No. PR/PO', - cell: (props) => { - const { pr_number, po_number } = props.row.original; - return po_number ? po_number : pr_number; - }, + const purchaseColumns: ColumnDef[] = [ + { + header: 'No. PR/PO', + cell: (props) => { + const { pr_number, po_number } = props.row.original; + return po_number ? po_number : pr_number; }, - { - accessorKey: 'supplier', - header: 'Vendor', - cell: (props) => props.row.original.supplier.name, + }, + { + accessorKey: 'supplier', + header: 'Vendor', + cell: (props) => props.row.original.supplier.name, + }, + { + accessorKey: 'po_date', + header: 'Tgl. PO', + cell: (props) => + props.row.original.po_date + ? formatDate(props.row.original.po_date, 'DD MMM YYYY') + : '-', + }, + { + accessorKey: 'due_date', + header: 'Jatuh Tempo', + cell: (props) => + props.row.original.due_date + ? formatDate(props.row.original.due_date, 'DD MMM YYYY') + : '-', + }, + { + header: 'Aging', + cell: (props) => { + const purchase = props.row.original; + if (!purchase.po_date) return '-'; + const poDate = new Date(purchase.po_date); + const today = new Date(); + const diffTime = Math.abs(today.getTime() - poDate.getTime()); + const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); + return `${diffDays} hari`; }, - { - accessorKey: 'po_date', - header: 'Tgl. PO', - cell: (props) => - props.row.original.po_date - ? formatDate(props.row.original.po_date, 'DD MMM YYYY') - : '-', - }, - { - accessorKey: 'due_date', - header: 'Jatuh Tempo', - cell: (props) => - props.row.original.due_date - ? formatDate(props.row.original.due_date, 'DD MMM YYYY') - : '-', - }, - { - header: 'Aging', - cell: (props) => { - const purchase = props.row.original; - if (!purchase.po_date) return '-'; - const poDate = new Date(purchase.po_date); - const today = new Date(); - const diffTime = Math.abs(today.getTime() - poDate.getTime()); - const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); - return `${diffDays} hari`; - }, - }, - { - accessorKey: 'grand_total', - header: 'Total (Rp.)', - cell: (props) => formatCurrency(props.row.original.grand_total), - }, - { - header: 'Aksi', - cell: (props) => { - const currentPageSize = - props.table.getPaginationRowModel().rows.length; - const currentPageRows = props.table.getPaginationRowModel().flatRows; - const currentRowRelativeIndex = - currentPageRows.findIndex((r) => r.id === props.row.id) + 1; + }, + { + accessorKey: 'grand_total', + header: 'Total (Rp.)', + cell: (props) => formatCurrency(props.row.original.grand_total), + }, + { + header: 'Aksi', + cell: (props) => { + const currentPageSize = props.table.getPaginationRowModel().rows.length; + const currentPageRows = props.table.getPaginationRowModel().flatRows; + const currentRowRelativeIndex = + currentPageRows.findIndex((r) => r.id === props.row.id) + 1; - const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2; + const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2; - const deleteClickHandler = () => { - setSelectedPurchase(props.row.original); - deleteModal.openModal(); - }; + const deleteClickHandler = () => { + setSelectedPurchase(props.row.original); + deleteModal.openModal(); + }; - return ( - <> - {currentPageSize > 2 && ( - - - - )} + return ( + <> + {currentPageSize > 2 && ( + + + + )} - {currentPageSize <= 2 && ( - - - - )} - - ); - }, + {currentPageSize <= 2 && ( + + + + )} + + ); }, - ], - [] - ); + }, + ]; // ===== EVENT HANDLERS ===== const confirmationModalDeleteClickHandler = useCallback(async () => { @@ -287,7 +276,7 @@ const PurchaseTable = () => {
-
+
- - {selectedRowIds.length > 0 && ( - - )}
{ isLoading={isLoading} sorting={sorting} setSorting={setSorting} - rowSelection={rowSelection} - setRowSelection={setRowSelection} className={{ containerClassName: cn({ 'mb-20': diff --git a/src/components/pages/purchase/form/order/PurchaseOrderStaffApprovalForm.tsx b/src/components/pages/purchase/form/order/PurchaseOrderStaffApprovalForm.tsx index 2517b337..f3c2ce36 100644 --- a/src/components/pages/purchase/form/order/PurchaseOrderStaffApprovalForm.tsx +++ b/src/components/pages/purchase/form/order/PurchaseOrderStaffApprovalForm.tsx @@ -170,7 +170,7 @@ const PurchaseOrderStaffApprovalForm = ({ if (initialValues?.items) { return initialValues.items.map((item) => ({ value: item.id, - label: `${item.product.name} (${item.quantity} ${item.product.uom?.name || 'unit'})`, + label: `${item.product.name} ${item.quantity}`, id: item.id, quantity: item.quantity, product: { @@ -184,57 +184,8 @@ const PurchaseOrderStaffApprovalForm = ({ })); } - return [ - { - value: 1, - label: 'SEALYTE SPARK 1 x 87 gr (14 SACHET)', - id: 1, - quantity: 14, - product: { - name: 'SEALYTE SPARK 1 x 87 gr', - product_category: 'Bahan Baku', - uom: { - name: 'SACHET', - }, - }, - warehouse: { - name: 'GUDANG CIANGSANA 1 (ARCA P15)', - }, - }, - { - value: 2, - label: 'CID-2000 @ 5 KG (2 KILOGRAM)', - id: 2, - quantity: 2, - product: { - name: 'CID-2000 @ 5 KG', - product_category: 'Bahan Baku', - uom: { - name: 'Kilogram', - }, - }, - warehouse: { - name: 'GUDANG CIANGSANA 2 (ARCA P15)', - }, - }, - { - value: 3, - label: 'VITAMIN AYAM (10 DOSIS)', - id: 3, - quantity: 10, - product: { - name: 'VITAMIN AYAM', - product_category: 'Bahan Baku', - uom: { - name: 'DOSIS', - }, - }, - warehouse: { - name: 'GUDANG CIANGSANA 3 (ARCA P15)', - }, - }, - ]; - }, [initialValues?.items, searchParams]); + return []; + }, [initialValues?.items]); const getPurchaseItemOptions = useCallback(() => { return purchaseItems; diff --git a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx index 0c4337b1..8de2f322 100644 --- a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx +++ b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx @@ -758,6 +758,7 @@ const PurchaseOrderDetail = ({ >