diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 17a1d020..7365c6ca 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -156,39 +156,39 @@ const productionStandardColumns: ColumnDef[] = [ }, { accessorKey: 'egg_production_standard_detail.target_hen_house_production', - header: 'Target Hen House (%)', + header: 'Target Hen House (btr)', cell: (props) => - `${ + formatNumber( (props.row.original.egg_production_standard_detail ?.target_hen_house_production as number) || 0 - }%`, + ), }, { accessorKey: 'egg_production_standard_detail.target_egg_weight', - header: 'Target Egg Weight (gram)', + header: 'Target Egg Weight (g)', cell: (props) => - formatNumber( + `${ (props.row.original.egg_production_standard_detail ?.target_egg_weight as number) || 0 - ), + } g`, }, { accessorKey: 'egg_production_standard_detail.target_egg_mass', - header: 'Target Egg Mass (gram)', + header: 'Target Egg Mass (kg)', cell: (props) => - formatNumber( + `${ (props.row.original.egg_production_standard_detail ?.target_egg_mass as number) || 0 - ), + } kg`, }, { accessorKey: 'egg_production_standard_detail.standard_fcr', - header: 'Standard FCR', + header: 'Standard FCR (g)', cell: (props) => - formatNumber( + `${ (props.row.original.egg_production_standard_detail ?.standard_fcr as number) || 0 - ), + } g`, }, ]; @@ -552,23 +552,17 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { ); const nextDayRecordingUrl = useMemo(() => { - if (!selectedProjectFlock) return null; - const projectFlockId = - typeof selectedProjectFlock.value === 'string' - ? parseInt(selectedProjectFlock.value, 10) - : selectedProjectFlock.value; - return `${RecordingApi.basePath}/next-day?project_flock_id=${projectFlockId}`; - }, [selectedProjectFlock]); + if (!projectFlockKandangLookup) return null; + const projectFlockKandangId = projectFlockKandangLookup.id; + return `${RecordingApi.basePath}/next-day?project_flock_kandang_id=${projectFlockKandangId}`; + }, [projectFlockKandangLookup]); const { data: nextDayRecordingData } = useSWR( nextDayRecordingUrl, nextDayRecordingUrl ? () => { - const projectFlockId = - typeof selectedProjectFlock!.value === 'string' - ? parseInt(selectedProjectFlock!.value, 10) - : selectedProjectFlock!.value; - return RecordingApi.nextDayRecording(projectFlockId); + const projectFlockKandangId = projectFlockKandangLookup!.id; + return RecordingApi.nextDayRecording(projectFlockKandangId); } : null ); @@ -1180,6 +1174,47 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { [stockProducts] ); + const getProductUomSuffix = useCallback( + (productWarehouseId: number, dataSource: 'stock' | 'depletion' | 'egg') => { + if (type !== 'add' && initialValues) { + let items; + if (dataSource === 'stock') { + items = initialValues.stocks; + } else if (dataSource === 'depletion') { + items = initialValues.depletions; + } else if (dataSource === 'egg') { + items = initialValues.eggs; + } + + if (items) { + const item = items.find( + (i) => i.product_warehouse_id === productWarehouseId + ); + if (item?.product_warehouse?.product?.uom?.name) { + return item.product_warehouse.product.uom.name; + } + } + } + + let rawData; + if (dataSource === 'stock') { + rawData = stockProducts; + } else if (dataSource === 'depletion') { + rawData = depletionProductsData; + } else if (dataSource === 'egg') { + rawData = eggProductsData; + } + + if (!isResponseSuccess(rawData)) return null; + + const data = rawData.data as unknown as ProductWarehouse[]; + const productWarehouse = data.find((pw) => pw.id === productWarehouseId); + + return productWarehouse?.product.uom.name || null; + }, + [stockProducts, depletionProductsData, eggProductsData, initialValues, type] + ); + const hasExceededStock = useMemo(() => { if ((type as 'add' | 'edit' | 'detail') === 'detail') return false; return ( @@ -2113,38 +2148,33 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { - FCR + FCR (g) {initialValues.fcr_value != null - ? formatNumber(initialValues.fcr_value) + ? `${formatNumber(initialValues.fcr_value)} g` : '-'} {initialValues.project_flock?.fcr?.fcr_std != null - ? formatNumber( - initialValues.project_flock?.fcr?.fcr_std - ) + ? `${formatNumber(initialValues.project_flock?.fcr?.fcr_std)} g` : '-'} - Feed Intake (KG) + Feed Intake (g) {initialValues.feed_intake != null - ? formatNumber(initialValues.feed_intake) + ? `${formatNumber(initialValues.feed_intake)} g` : '-'} {initialValues.project_flock?.production_standart ?.feed_intake_std != null - ? formatNumber( - initialValues.project_flock?.production_standart - ?.feed_intake_std - ) + ? `${formatNumber(initialValues.project_flock?.production_standart?.feed_intake_std)} g` : '-'} @@ -2224,51 +2254,43 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { - Egg Mass + Egg Mass (kg) {initialValues.egg_mass != null - ? formatNumber(initialValues.egg_mass) + ? `${formatNumber(initialValues.egg_mass)} kg` : '-'} {initialValues.project_flock?.production_standart ?.egg_mass_std != null - ? formatNumber( - initialValues.project_flock - ?.production_standart?.egg_mass_std - ) + ? `${formatNumber(initialValues.project_flock?.production_standart?.egg_mass_std)} kg` : '-'} - - Egg Weight (KG) - + Egg Weight (g) {initialValues.egg_weight != null - ? formatNumber(initialValues.egg_weight) + ? `${formatNumber(initialValues.egg_weight)} g` : '-'} {initialValues.project_flock?.production_standart ?.egg_weight_std != null - ? formatNumber( - initialValues.project_flock - ?.production_standart?.egg_weight_std - ) + ? `${formatNumber(initialValues.project_flock?.production_standart?.egg_weight_std)} g` : '-'} - Hen Day + Hen Day (%) {initialValues.hen_day != null - ? formatNumber(initialValues.hen_day) + ? `${formatNumber(initialValues.hen_day)}%` : '-'} @@ -2280,18 +2302,20 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { - Hen House + + Hen House (btr) + {initialValues.hen_house != null - ? formatNumber(initialValues.hen_house) + ? `${formatNumber(initialValues.hen_house)} btr` : '-'} {initialValues.project_flock?.production_standart ?.hen_house_std != null - ? `${initialValues.project_flock?.production_standart?.hen_house_std}%` + ? `${formatNumber(initialValues.project_flock?.production_standart?.hen_house_std)} btr` : '-'} @@ -2468,6 +2492,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { wrapper: 'w-full min-w-24', }} placeholder='Masukkan jumlah pakai' + inputSuffix={ + stock.product_warehouse_id + ? getProductUomSuffix( + stock.product_warehouse_id, + 'stock' + ) + : null + } /> {(type as 'add' | 'edit' | 'detail') !== 'detail' && getStockUsageAdornment(idx)} @@ -2663,6 +2695,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { wrapper: 'w-full min-w-24', }} placeholder='Masukkan jumlah deplesi' + inputSuffix={ + depletion.product_warehouse_id + ? getProductUomSuffix( + depletion.product_warehouse_id, + 'depletion' + ) + : null + } /> {(type as 'add' | 'edit' | 'detail') !== 'detail' && ( @@ -2759,7 +2799,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { )} Kondisi Telur Jumlah - Berat (gram) + Total Berat (Kilogram) {(type as 'add' | 'edit' | 'detail') !== 'detail' && ( Action )} @@ -2856,6 +2896,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { wrapper: 'w-full min-w-24', }} placeholder='Masukkan jumlah telur' + inputSuffix={'Butir'} /> @@ -2880,7 +2921,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { className={{ wrapper: 'w-full min-w-24', }} - placeholder='Masukkan berat telur (gram)...' + placeholder='Masukkan total berat telur (Kilogram)...' + inputSuffix='Kilogram' /> {(type as 'add' | 'edit' | 'detail') !== 'detail' && ( diff --git a/src/types/api/inventory/product-warehouse.d.ts b/src/types/api/inventory/product-warehouse.d.ts index eda8d1b8..8bed1aba 100644 --- a/src/types/api/inventory/product-warehouse.d.ts +++ b/src/types/api/inventory/product-warehouse.d.ts @@ -1,11 +1,13 @@ import { BaseMetadata } from '@/types/api/api-general'; import { Warehouse } from '@/types/api/master-data/warehouse'; import { Product } from '@/types/api/master-data/product'; +import { Uom } from '@/types/api/master-data/uom'; export type BaseProductWarehouse = { id: number; product_id: number; warehouse_id: number; + uom: Uom; quantity: number; product: Product; warehouse: Warehouse;