diff --git a/src/components/pages/expense/ExpenseRealizationContent.tsx b/src/components/pages/expense/ExpenseRealizationContent.tsx index abe00912..7057ba19 100644 --- a/src/components/pages/expense/ExpenseRealizationContent.tsx +++ b/src/components/pages/expense/ExpenseRealizationContent.tsx @@ -261,7 +261,7 @@ const ExpenseRealizationContent = ({ {pengajuanItem.qty} {formatCurrency(pengajuanItem.price)} - {pengajuanItem.note ?? '-'} + {pengajuanItem.notes ?? '-'} ) @@ -329,7 +329,7 @@ const ExpenseRealizationContent = ({ {realisasiItem.qty} {formatCurrency(realisasiItem.price)} - {realisasiItem.note ?? '-'} + {realisasiItem.notes ?? '-'} ) diff --git a/src/components/pages/expense/ExpenseRequestContent.tsx b/src/components/pages/expense/ExpenseRequestContent.tsx index ed39ea32..ac814bcf 100644 --- a/src/components/pages/expense/ExpenseRequestContent.tsx +++ b/src/components/pages/expense/ExpenseRequestContent.tsx @@ -654,7 +654,7 @@ const ExpenseRequestContent = ({ {pengajuanItem.qty} {formatCurrency(pengajuanItem.price)} - {pengajuanItem.note ?? '-'} + {pengajuanItem.notes ?? '-'} ) diff --git a/src/components/pages/expense/form/ExpenseKandangsTable.tsx b/src/components/pages/expense/form/ExpenseKandangsTable.tsx index e4db88aa..5c60ae1e 100644 --- a/src/components/pages/expense/form/ExpenseKandangsTable.tsx +++ b/src/components/pages/expense/form/ExpenseKandangsTable.tsx @@ -174,9 +174,16 @@ const ExpenseKandangsTable = ({ updateSortingFilter('picSort', picSortFilter); }, [sorting, updateSortingFilter]); + // Tampilkan tabel jika: + // 1. Mode request pertama kali (type='add' dan formType='request') + // 2. Atau sudah ada kandang yang dipilih + const shouldShowTable = + (type === 'add' && formType === 'request') || + (selectedKandangs.length > 0 && selectedKandangs.some((k) => k.id)); + return ( <> - {selectedKandangs.length > 0 && selectedKandangs.some((k) => k.id) && ( + {shouldShowTable && ( { ]} > - {pengajuan.note} + {pengajuan.notes} @@ -607,7 +607,7 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => { ]} > - {realisasi.note} + {realisasi.notes} diff --git a/src/components/pages/production/recording/RecordingTable.tsx b/src/components/pages/production/recording/RecordingTable.tsx index c30156ed..7808c5bf 100644 --- a/src/components/pages/production/recording/RecordingTable.tsx +++ b/src/components/pages/production/recording/RecordingTable.tsx @@ -729,10 +729,6 @@ const RecordingTable = () => { ); }, }, - { - header: 'Gudang', - cell: (props) => props.row.original.warehouse?.name, - }, { header: 'Waktu Recording', cell: (props) => diff --git a/src/components/pages/production/recording/form/RecordingForm.schema.ts b/src/components/pages/production/recording/form/RecordingForm.schema.ts index 82b59036..063c2cc0 100644 --- a/src/components/pages/production/recording/form/RecordingForm.schema.ts +++ b/src/components/pages/production/recording/form/RecordingForm.schema.ts @@ -33,16 +33,16 @@ type RecordingGrowingFormSchemaType = { qty: number | string; }[]; depletions: { - product_warehouse_id: number; - qty: number | string; + product_warehouse_id?: number; + qty?: number | string; }[]; }; type RecordingLayingFormSchemaType = RecordingGrowingFormSchemaType & { eggs: { - product_warehouse_id: number; - qty: number | string; - weight: number | string; + product_warehouse_id?: number; + qty?: number | string; + weight?: number | string; }[]; }; @@ -52,14 +52,14 @@ export type StockSchema = { }; export type DepletionSchema = { - product_warehouse_id: number; - qty: number | string; + product_warehouse_id?: number; + qty?: number | string; }; export type EggSchema = { - product_warehouse_id: number; - qty: number | string; - weight: number | string; + product_warehouse_id?: number; + qty?: number | string; + weight?: number | string; }; const StockObjectSchema: Yup.ObjectSchema = Yup.object({ @@ -75,28 +75,19 @@ const StockObjectSchema: Yup.ObjectSchema = Yup.object({ const DepletionObjectSchema: Yup.ObjectSchema = Yup.object({ product_warehouse_id: Yup.number() - .required('Produk depletions wajib diisi!') - .min(1, 'Produk depletions wajib diisi!') - .typeError('Produk depletions harus berupa angka!'), + .optional() + .typeError('Depletions harus berupa angka!'), qty: Yup.number() - .required('Jumlah depletions wajib diisi!') - .min(1, 'Jumlah depletions minimal 1!') + .optional() .typeError('Jumlah depletions harus berupa angka!'), }); const EggObjectSchema: Yup.ObjectSchema = Yup.object({ product_warehouse_id: Yup.number() - .required('Kondisi telur wajib diisi!') - .min(1, 'Kondisi telur wajib diisi!') + .optional() .typeError('Kondisi telur harus berupa angka!'), - qty: Yup.number() - .required('Jumlah telur wajib diisi!') - .min(1, 'Jumlah telur tidak boleh 0!') - .typeError('Jumlah telur harus berupa angka!'), - weight: Yup.number() - .required('Berat telur wajib diisi!') - .min(1, 'Berat telur minimal 1 gram!') - .typeError('Berat telur harus berupa angka!'), + qty: Yup.number().optional().typeError('Jumlah telur harus berupa angka!'), + weight: Yup.number().optional().typeError('Berat telur harus berupa angka!'), }); export const RecordingGrowingFormSchema: Yup.ObjectSchema = @@ -163,18 +154,12 @@ export const RecordingGrowingFormSchema: Yup.ObjectSchema = RecordingGrowingFormSchema.shape({ - eggs: Yup.array() - .of(EggObjectSchema) - .min(1, 'Minimal harus ada 1 data telur!') - .required('Data telur wajib diisi!'), + eggs: Yup.array().of(EggObjectSchema).default([]), }); export const UpdateRecordingGrowingFormSchema = diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 5044dec5..17a1d020 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -309,6 +309,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { // ===== PAYLOAD CREATION HELPERS ===== const createGrowingPayload = useCallback( (values: RecordingGrowingFormValues) => { + const depletions = values.depletions + ?.filter((d) => d.product_warehouse_id && d.qty) + .map((depletion) => ({ + product_warehouse_id: depletion.product_warehouse_id!, + qty: Number(depletion.qty) || 0, + })); + return { project_flock_kandang_id: values.project_flock_kandang_id, record_date: values.record_date, @@ -316,10 +323,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { product_warehouse_id: stock.product_warehouse_id, qty: Number(stock.qty) || 0, })), - depletions: (values.depletions ?? []).map((depletion) => ({ - product_warehouse_id: depletion.product_warehouse_id, - qty: Number(depletion.qty) || 0, - })), + ...(depletions && depletions.length > 0 && { depletions }), }; }, [] @@ -327,25 +331,33 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { const createLayingPayload = useCallback( (values: RecordingLayingFormValues) => { - return { - project_flock_kandang_id: values.project_flock_kandang_id, - record_date: values.record_date, - stocks: (values.stocks ?? []).map((stock) => ({ - product_warehouse_id: stock.product_warehouse_id, - qty: Number(stock.qty) || 0, - })), - depletions: (values.depletions ?? []).map((depletion) => ({ - product_warehouse_id: depletion.product_warehouse_id, + const depletions = values.depletions + ?.filter((d) => d.product_warehouse_id && d.qty) + .map((depletion) => ({ + product_warehouse_id: depletion.product_warehouse_id!, qty: Number(depletion.qty) || 0, - })), - eggs: (values.eggs ?? []).map((egg) => ({ - product_warehouse_id: egg.product_warehouse_id, + })); + + const eggs = values.eggs + ?.filter((e) => e.product_warehouse_id && e.qty && e.weight) + .map((egg) => ({ + product_warehouse_id: egg.product_warehouse_id!, qty: Number(egg.qty) || 0, weight: typeof egg.weight === 'number' ? egg.weight : parseFloat(String(egg.weight)) || 0, + })); + + return { + project_flock_kandang_id: values.project_flock_kandang_id, + record_date: values.record_date, + stocks: values.stocks.map((stock) => ({ + product_warehouse_id: stock.product_warehouse_id, + qty: Number(stock.qty) || 0, })), + ...(depletions && depletions.length > 0 && { depletions }), + ...(eggs && eggs.length > 0 && { eggs }), }; }, [] @@ -1692,12 +1704,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { )} -
- {JSON.stringify(formik.errors)} -
-
- {JSON.stringify(formik.values)} -
{/* Basic Info Card */} {(type === 'add' || type === 'edit') && ( { /> )} - - Kondisi - - * - - - - Jumlah - - * - - + Kondisi + Jumlah {(type as 'add' | 'edit' | 'detail') !== 'detail' && ( Action )} @@ -2652,7 +2642,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { { /> )} - - Kondisi Telur - - * - - - - Jumlah - - * - - - - Berat (gram) - - * - - + Kondisi Telur + Jumlah + Berat (gram) {(type as 'add' | 'edit' | 'detail') !== 'detail' && ( Action )} @@ -2829,7 +2794,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { )} @@ -2872,7 +2836,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { { { options: kandangOptions, isLoadingOptions: isLoadingKandangs, loadMore: loadMoreKandangs, - } = useSelect(KandangApi.basePath, 'id', 'name', 'search'); + } = useSelect( + ProjectFlockKandangApi.basePath, + 'id', + 'name_with_period', + 'search' + ); const showUnrecordedOptions: OptionType[] = [ { value: 'false', label: 'Sembunyikan' }, @@ -557,8 +562,8 @@ const HppPerKandangTab = () => { header: 'Kandang', accessorKey: 'kandang.name', cell: (props) => { - const kandang = props.row.original.kandang; - return kandang?.name || '-'; + const row = props.row.original; + return row.name_with_periode || row.kandang?.name || '-'; }, footer: () =>
ALL
, }, diff --git a/src/types/api/expense.d.ts b/src/types/api/expense.d.ts index 12455cc8..3ca57dd0 100644 --- a/src/types/api/expense.d.ts +++ b/src/types/api/expense.d.ts @@ -34,7 +34,7 @@ export type BaseExpense = { nonstock_id: number; qty: number; price: number; - note?: string; + notes?: string; nonstock: Pick; created_at: string; }[]; @@ -43,7 +43,7 @@ export type BaseExpense = { expense_nonstock_id: number; qty: number; price: number; - note?: string; + notes?: string; nonstock: Pick; created_at: string; }[]; diff --git a/src/types/api/production/project-flock-kandang.d.ts b/src/types/api/production/project-flock-kandang.d.ts index 8c8d6273..111ca98b 100644 --- a/src/types/api/production/project-flock-kandang.d.ts +++ b/src/types/api/production/project-flock-kandang.d.ts @@ -10,6 +10,7 @@ export type BaseProjectFlockKandang = { kandang_id: number; kandang: Kandang; project_flock: ProjectFlock; + name_with_period?: string; approval: BaseApproval; chickins?: Chickin[]; available_qtys?: AvailableQty[]; diff --git a/src/types/api/production/recording.d.ts b/src/types/api/production/recording.d.ts index 928afae0..eb611a3b 100644 --- a/src/types/api/production/recording.d.ts +++ b/src/types/api/production/recording.d.ts @@ -111,15 +111,15 @@ export type CreateGrowingRecordingPayload = { qty: number; }[]; depletions?: { - product_warehouse_id: number; - qty: number; + product_warehouse_id?: number; + qty?: number; }[]; }; export type CreateEggPayload = { - product_warehouse_id: number; - qty: number; - weight: number; + product_warehouse_id?: number; + qty?: number; + weight?: number; }; export type CreateLayingRecordingPayload = CreateGrowingRecordingPayload & { diff --git a/src/types/api/report/hpp-per-kandang.d.ts b/src/types/api/report/hpp-per-kandang.d.ts index 208a2cdb..0d47fc3f 100644 --- a/src/types/api/report/hpp-per-kandang.d.ts +++ b/src/types/api/report/hpp-per-kandang.d.ts @@ -5,6 +5,7 @@ import { Kandang } from '@/types/api/master-data/kandang'; export type HppPerKandangRow = { id: number; kandang: Kandang; + name_with_periode?: string; weight_range: { weight_min: number; weight_max: number;