fix(FE): adjust inventory adjustment and inventory product table

This commit is contained in:
randy-ar
2025-12-11 14:35:27 +07:00
parent 48c163c1cd
commit d0abc0e9ff
5 changed files with 38 additions and 62 deletions
@@ -1,5 +1,6 @@
'use client'; 'use client';
import Badge from '@/components/Badge';
import Button from '@/components/Button'; import Button from '@/components/Button';
import SelectInput, { OptionType } from '@/components/input/SelectInput'; import SelectInput, { OptionType } from '@/components/input/SelectInput';
import Table from '@/components/Table'; import Table from '@/components/Table';
@@ -77,46 +78,39 @@ const InventoryAdjustmentTable = () => {
year: 'numeric', year: 'numeric',
}), }),
}, },
{ // {
id: 'before_quantity', // id: 'before_quantity',
header: 'Stok Sebelum', // header: 'Stok Sebelum',
accessorFn: (row) => formatNumber(String(row.before_quantity)), // accessorFn: (row) =>
}, // formatNumber(String(row.product_warehouse?.quantity)),
{ // },
id: 'after_quantity', // {
header: 'Stok Sesudah', // id: 'after_quantity',
accessorFn: (row) => formatNumber(String(row.after_quantity)), // header: 'Stok Sesudah',
}, // accessorFn: (row) =>
// formatNumber(String(row.product_warehouse?.quantity)),
// },
{ {
id: 'quantity', id: 'quantity',
header: 'Kuantitas', header: 'Kuantitas',
accessorFn: (row) => formatNumber(String(row.quantity)), accessorFn: (row) => formatNumber(String(row.increase + row.decrease)),
}, },
{ {
id: 'transaction_type', id: 'transaction_type',
header: 'Tipe Transaksi', header: 'Tipe Transaksi',
accessorFn: (row) => { accessorFn: (row) => {
if (row.transaction_type === 'INCREASE') return 'Peningkatan'; if (row.increase > 0) return 'Peningkatan';
if (row.transaction_type === 'DECREASE') return 'Penurunan'; if (row.decrease > 0) return 'Penurunan';
return '-'; return '-';
}, },
cell: (props) => { cell: (props) => {
const type = props.row.original.transaction_type; const type = props.row.original.increase;
const label = const label = type > 0 ? 'Peningkatan' : type <= 0 ? 'Penurunan' : '-';
type === 'INCREASE'
? 'Peningkatan'
: type === 'DECREASE'
? 'Penurunan'
: '-';
return ( return (
<div <Badge variant='soft' color={type > 0 ? 'success' : 'error'}>
className={`small mx-auto badge badge-soft ${
type === 'INCREASE' ? 'badge-success' : 'badge-error'
}`}
>
{label} {label}
</div> </Badge>
); );
}, },
}, },
@@ -76,7 +76,7 @@ const InventoryAdjustmentForm = ({
product_category: undefined, product_category: undefined,
product: undefined, product: undefined,
warehouse: undefined, warehouse: undefined,
quantity: initialValues?.quantity ?? 0, quantity: initialValues?.increase ?? initialValues?.decrease ?? 0,
transaction_type: undefined, transaction_type: undefined,
note: initialValues?.note ?? '', note: initialValues?.note ?? '',
}; };
@@ -214,16 +214,8 @@ const InventoryAdjustmentForm = ({
'quantity', 'quantity',
initialValues.product_warehouse.quantity initialValues.product_warehouse.quantity
); );
formik.setFieldValue(
'transaction_type',
initialValues.transaction_type.toLowerCase()
);
formik.setFieldValue('note', initialValues.note); formik.setFieldValue('note', initialValues.note);
} }
if (initialValues?.transaction_type) {
const type = initialValues.transaction_type.toLowerCase();
setQuantityLabel(type === 'increase' ? 'Tambah Stok' : 'Kurangi Stok');
}
}, [ }, [
formik, formik,
initialValues, initialValues,
@@ -278,26 +270,6 @@ const InventoryAdjustmentForm = ({
className='w-full mt-8 flex flex-col gap-6' className='w-full mt-8 flex flex-col gap-6'
> >
<div className='flex flex-col gap-4'> <div className='flex flex-col gap-4'>
{/* Text Input Before Quantity */}
{type === 'detail' && initialValues && (
<>
<TextInput
label='Stok Sebelum'
name='before_quantity'
type='text'
value={formatNumber(String(initialValues.before_quantity))}
readOnly={true}
/>
<TextInput
label='Stok Setelah'
name='after_quantity'
type='text'
readOnly={true}
value={formatNumber(String(initialValues.after_quantity))}
/>
</>
)}
{/* Select Input Product Category */} {/* Select Input Product Category */}
<SelectInput <SelectInput
required required
@@ -13,8 +13,12 @@ const InventoryProductDetail = ({
}) => { }) => {
const stockLogs = useMemo(() => { const stockLogs = useMemo(() => {
return ( return (
inventoryProduct?.product_warehouses?.flatMap( inventoryProduct?.product_warehouses?.flatMap((warehouse) =>
(warehouse) => warehouse.stock_logs || [] warehouse.stock_logs.map((log) => ({
...log,
warehouse_name: warehouse.warehouse_name,
warehouse_id: warehouse.warehouse_id,
}))
) || [] ) || []
); );
}, [inventoryProduct]); }, [inventoryProduct]);
@@ -3,7 +3,11 @@ import Table from '@/components/Table';
import { formatDate, formatNumber, formatTitleCase } from '@/lib/helper'; import { formatDate, formatNumber, formatTitleCase } from '@/lib/helper';
import { StockLog } from '@/types/api/inventory/product'; 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 (
<Card <Card
title='Informasi Stock Produk' title='Informasi Stock Produk'
@@ -27,6 +31,10 @@ const StockLogTable = ({ stockLogs }: { stockLogs: StockLog[] }) => {
return formatDate(props.row.original.created_at, 'DD-MMM-yyyy'); return formatDate(props.row.original.created_at, 'DD-MMM-yyyy');
}, },
}, },
{
header: 'Gudang',
accessorKey: 'warehouse_name',
},
{ {
header: 'Peningkatan', header: 'Peningkatan',
accessorKey: 'increase', accessorKey: 'increase',
+2 -4
View File
@@ -4,10 +4,8 @@ import { BaseMetadata } from '@/types/api/api-general';
export type BaseInventoryAdjustment = { export type BaseInventoryAdjustment = {
id: number; id: number;
transaction_type: string; increase: number;
quantity: number; decrease: number;
before_quantity: number;
after_quantity: number;
note: string; note: string;
product_warehouse_id: number; product_warehouse_id: number;
product_warehouse: { product_warehouse: {