feat(FE): adding 4 input scenario marketing type

This commit is contained in:
randy-ar
2026-02-05 05:38:02 +07:00
parent cb22fd1037
commit 43dcbf73ee
7 changed files with 123 additions and 65 deletions
@@ -208,6 +208,7 @@ const SalesOrderFormModal = ({
convertion_unit: normalizedConvertionUnit,
weight_per_convertion:
product.weight_per_convertion ?? undefined,
week: product.week?.value ?? undefined,
} as CreateSalesOrderProductPayload;
}),
} as CreateSalesOrderPayload)
@@ -115,14 +115,24 @@ export const SalesProductToFieldValues = (
qty: product.qty,
avg_weight: product.avg_weight,
total_price: product.total_price,
marketing_type: {
value: product.marketing_type,
label: formatTitleCase(product.marketing_type),
},
convertion_unit: {
value: product.convertion_unit,
label: formatTitleCase(product.convertion_unit),
},
marketing_type: product.marketing_type
? {
value: product.marketing_type,
label: formatTitleCase(product.marketing_type),
}
: null,
convertion_unit: product.convertion_unit
? {
value: product.convertion_unit,
label: formatTitleCase(product.convertion_unit),
}
: null,
week: product.week
? {
value: product.week,
label: `Week ${product.week}`,
}
: null,
total_peti: product.total_peti,
weight_per_convertion: product.weight_per_convertion,
};
@@ -34,6 +34,14 @@ type SalesOrderProductSchemaType = {
price_sisa_berat?: number | null | undefined;
/** Harga per butir telur untuk TELUR + QTY */
price_per_qty?: number | null | undefined;
/** Week untuk ayam pullet */
week?:
| {
value?: number;
label?: string;
}
| null
| undefined;
};
export const SalesOrderProductSchema: Yup.ObjectSchema<SalesOrderProductSchemaType> =
@@ -88,6 +96,28 @@ export const SalesOrderProductSchema: Yup.ObjectSchema<SalesOrderProductSchemaTy
sisa_berat: Yup.number().nullable().optional().notRequired(),
price_sisa_berat: Yup.number().nullable().optional().notRequired(),
price_per_qty: Yup.number().nullable().optional().notRequired(),
week: Yup.object({
value: Yup.number(),
label: Yup.string(),
})
.nullable()
.default(null)
.when('marketing_type', {
is: (marketingType: { value: string } | null | undefined) =>
marketingType?.value?.toLowerCase() === 'ayam_pullet',
then: (schema) =>
schema
.shape({
value: Yup.number().required(
'Week wajib diisi untuk Ayam Pullet!'
),
label: Yup.string().required(
'Week wajib diisi untuk Ayam Pullet!'
),
})
.required('Week wajib diisi untuk Ayam Pullet!'),
otherwise: (schema) => schema.optional().notRequired(),
}),
});
export type SalesOrderProductFormValues = Yup.InferType<
@@ -70,8 +70,10 @@ const SalesOrderProductForm = ({
: 0;
const initialPriceSisaBerat =
Number(initialValues?.total_price) -
initialPricePerConvertion * Number(initialValues?.total_peti);
initialValues?.total_price && initialValues?.total_peti
? Number(initialValues.total_price) -
initialPricePerConvertion * Number(initialValues.total_peti)
: 0;
const [hasSisaBerat, setHasSisaBerat] = useState<boolean>(
initialSisaBerat > 0
@@ -103,6 +105,7 @@ const SalesOrderProductForm = ({
price_per_qty: initialValues?.price_per_qty ?? null,
sisa_berat: initialSisaBerat,
price_sisa_berat: initialPriceSisaBerat,
week: initialValues?.week ?? null,
},
validationSchema: SalesOrderProductSchema,
onSubmit: async (values) => {
@@ -122,11 +125,11 @@ const SalesOrderProductForm = ({
loadMore: loadMoreKandang,
} = useSelect<Kandang>(WarehouseApi.basePath, 'id', 'name');
// Options Weeks dari minggu 1 - 22
const optionsWeeks = useMemo(() => {
// Options Week dari minggu 1 - 22
const optionsWeek = useMemo(() => {
return Array.from({ length: 22 }, (_, i) => ({
value: i + 1,
label: `Weeks ${i + 1}`,
label: `Week ${i + 1}`,
}));
}, []);
@@ -205,6 +208,7 @@ const SalesOrderProductForm = ({
weight_per_convertion: null,
price_per_convertion: null,
uom: '',
week: null,
},
});
};
@@ -256,6 +260,10 @@ const SalesOrderProductForm = ({
}
);
useEffect(() => {
handleBlurField('week');
}, [formik.values.week]);
return (
<>
<form
@@ -452,20 +460,24 @@ const SalesOrderProductForm = ({
</div>
)}
{/* Konversi Satuan Weeks Pullet */}
{/* {formik.values.marketing_type?.value.toLowerCase() ===
{/* Konversi Satuan Week Pullet */}
{formik.values.marketing_type?.value.toLowerCase() ===
'ayam_pullet' && (
<SelectInputRadio
required
label='Minggu'
options={optionsWeeks}
value={formik.values.weeks || undefined}
options={optionsWeek}
value={
formik.values.week?.value
? (formik.values.week as { value: number; label: string })
: null
}
onChange={(val) => {
formik.setFieldValue('weeks', val);
formik.setFieldValue('week', val);
}}
placeholder='Pilih Weeks'
placeholder='Pilih Week'
/>
)} */}
)}
{/* Total Peti */}
{formik.values.convertion_unit?.value.toLowerCase() === 'peti' && (
@@ -222,12 +222,21 @@ const SalesOrderProductTable = ({
{item.product_warehouse?.label}
</td>
</tr>
<tr>
<td className='text-sm px-4 py-3'>Tipe Konversi</td>
<td className='text-sm px-4 py-3'>
{item.convertion_unit?.label}
</td>
</tr>
{item.marketing_type?.value.toLowerCase() === 'telur' && (
<tr>
<td className='text-sm px-4 py-3'>Tipe Konversi</td>
<td className='text-sm px-4 py-3'>
{item.convertion_unit?.label}
</td>
</tr>
)}
{item.marketing_type?.value.toLowerCase() ===
'ayam_pullet' && (
<tr>
<td className='text-sm px-4 py-3'>Tipe Konversi</td>
<td className='text-sm px-4 py-3'>{item.week?.label}</td>
</tr>
)}
{item.convertion_unit?.value.toLowerCase() === 'peti' && (
<tr>
<td className='text-sm px-4 py-3'>Total Peti</td>
@@ -236,25 +245,30 @@ const SalesOrderProductTable = ({
</td>
</tr>
)}
<tr>
<td className='text-sm px-4 py-3'>Total Bobot</td>
<td className='text-sm px-4 py-3'>
{item.total_weight
? formatNumber(
parseFloat(item.total_weight as string)
) + ' Kg'
: '-'}
</td>
</tr>
<tr>
<td className='text-sm px-4 py-3'>Avg Bobot</td>
<td className='text-sm px-4 py-3'>
{item.avg_weight
? formatNumber(parseFloat(item.avg_weight as string)) +
' Kg'
: '-'}
</td>
</tr>
{item.marketing_type?.value.toLowerCase() !== 'trading' && (
<>
<tr>
<td className='text-sm px-4 py-3'>Total Bobot</td>
<td className='text-sm px-4 py-3'>
{item.total_weight
? formatNumber(
parseFloat(item.total_weight as string)
) + ' Kg'
: '0 Kg'}
</td>
</tr>
<tr>
<td className='text-sm px-4 py-3'>Avg Bobot</td>
<td className='text-sm px-4 py-3'>
{item.avg_weight
? formatNumber(
parseFloat(item.avg_weight as string)
) + ' Kg'
: '0 Kg'}
</td>
</tr>
</>
)}
<tr>
<td className='text-sm px-4 py-3'>
{item.marketing_type?.value === 'telur'