From d0abc0e9ff1df5235c147691f7c48d653cb47506 Mon Sep 17 00:00:00 2001 From: randy-ar Date: Thu, 11 Dec 2025 14:35:27 +0700 Subject: [PATCH] fix(FE): adjust inventory adjustment and inventory product table --- .../adjustment/InventoryAdjustmentTable.tsx | 46 ++++++++----------- .../form/InventoryAdjustmentForm.tsx | 30 +----------- .../product/detail/InventoryProductDetail.tsx | 8 +++- .../product/detail/StockLogTable.tsx | 10 +++- src/types/api/inventory/adjustment.d.ts | 6 +-- 5 files changed, 38 insertions(+), 62 deletions(-) diff --git a/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx b/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx index 30807d1c..a3de8a34 100644 --- a/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx +++ b/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx @@ -1,5 +1,6 @@ 'use client'; +import Badge from '@/components/Badge'; import Button from '@/components/Button'; import SelectInput, { OptionType } from '@/components/input/SelectInput'; import Table from '@/components/Table'; @@ -77,46 +78,39 @@ const InventoryAdjustmentTable = () => { year: 'numeric', }), }, - { - id: 'before_quantity', - header: 'Stok Sebelum', - accessorFn: (row) => formatNumber(String(row.before_quantity)), - }, - { - id: 'after_quantity', - header: 'Stok Sesudah', - accessorFn: (row) => formatNumber(String(row.after_quantity)), - }, + // { + // id: 'before_quantity', + // header: 'Stok Sebelum', + // accessorFn: (row) => + // formatNumber(String(row.product_warehouse?.quantity)), + // }, + // { + // id: 'after_quantity', + // header: 'Stok Sesudah', + // accessorFn: (row) => + // formatNumber(String(row.product_warehouse?.quantity)), + // }, { id: 'quantity', header: 'Kuantitas', - accessorFn: (row) => formatNumber(String(row.quantity)), + accessorFn: (row) => formatNumber(String(row.increase + row.decrease)), }, { id: 'transaction_type', header: 'Tipe Transaksi', accessorFn: (row) => { - if (row.transaction_type === 'INCREASE') return 'Peningkatan'; - if (row.transaction_type === 'DECREASE') return 'Penurunan'; + if (row.increase > 0) return 'Peningkatan'; + if (row.decrease > 0) return 'Penurunan'; return '-'; }, cell: (props) => { - const type = props.row.original.transaction_type; - const label = - type === 'INCREASE' - ? 'Peningkatan' - : type === 'DECREASE' - ? 'Penurunan' - : '-'; + const type = props.row.original.increase; + const label = type > 0 ? 'Peningkatan' : type <= 0 ? 'Penurunan' : '-'; return ( -
+ 0 ? 'success' : 'error'}> {label} -
+ ); }, }, diff --git a/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx b/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx index 2c6c463c..f134369e 100644 --- a/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx +++ b/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx @@ -76,7 +76,7 @@ const InventoryAdjustmentForm = ({ product_category: undefined, product: undefined, warehouse: undefined, - quantity: initialValues?.quantity ?? 0, + quantity: initialValues?.increase ?? initialValues?.decrease ?? 0, transaction_type: undefined, note: initialValues?.note ?? '', }; @@ -214,16 +214,8 @@ const InventoryAdjustmentForm = ({ 'quantity', initialValues.product_warehouse.quantity ); - formik.setFieldValue( - 'transaction_type', - initialValues.transaction_type.toLowerCase() - ); formik.setFieldValue('note', initialValues.note); } - if (initialValues?.transaction_type) { - const type = initialValues.transaction_type.toLowerCase(); - setQuantityLabel(type === 'increase' ? 'Tambah Stok' : 'Kurangi Stok'); - } }, [ formik, initialValues, @@ -278,26 +270,6 @@ const InventoryAdjustmentForm = ({ className='w-full mt-8 flex flex-col gap-6' >
- {/* Text Input Before Quantity */} - {type === 'detail' && initialValues && ( - <> - - - - )} - {/* Select Input Product Category */} { const stockLogs = useMemo(() => { return ( - inventoryProduct?.product_warehouses?.flatMap( - (warehouse) => warehouse.stock_logs || [] + inventoryProduct?.product_warehouses?.flatMap((warehouse) => + warehouse.stock_logs.map((log) => ({ + ...log, + warehouse_name: warehouse.warehouse_name, + warehouse_id: warehouse.warehouse_id, + })) ) || [] ); }, [inventoryProduct]); diff --git a/src/components/pages/inventory/product/detail/StockLogTable.tsx b/src/components/pages/inventory/product/detail/StockLogTable.tsx index 42f7bc29..96d3dda6 100644 --- a/src/components/pages/inventory/product/detail/StockLogTable.tsx +++ b/src/components/pages/inventory/product/detail/StockLogTable.tsx @@ -3,7 +3,11 @@ import Table from '@/components/Table'; import { formatDate, formatNumber, formatTitleCase } from '@/lib/helper'; import { StockLog } from '@/types/api/inventory/product'; -const StockLogTable = ({ stockLogs }: { stockLogs: StockLog[] }) => { +const StockLogTable = ({ + stockLogs, +}: { + stockLogs: (StockLog & { warehouse_name: string; warehouse_id: number })[]; +}) => { return ( { return formatDate(props.row.original.created_at, 'DD-MMM-yyyy'); }, }, + { + header: 'Gudang', + accessorKey: 'warehouse_name', + }, { header: 'Peningkatan', accessorKey: 'increase', diff --git a/src/types/api/inventory/adjustment.d.ts b/src/types/api/inventory/adjustment.d.ts index d6c0e078..90ef8ff8 100644 --- a/src/types/api/inventory/adjustment.d.ts +++ b/src/types/api/inventory/adjustment.d.ts @@ -4,10 +4,8 @@ import { BaseMetadata } from '@/types/api/api-general'; export type BaseInventoryAdjustment = { id: number; - transaction_type: string; - quantity: number; - before_quantity: number; - after_quantity: number; + increase: number; + decrease: number; note: string; product_warehouse_id: number; product_warehouse: {