feat: adjust penjualan calculation and delivery order logic

This commit is contained in:
rstubryan
2026-02-06 10:55:38 +07:00
parent e16fa9a167
commit 9dc8f05534
8 changed files with 41 additions and 72 deletions
@@ -208,7 +208,7 @@ const SalesOrderFormModal = ({
convertion_unit: normalizedConvertionUnit, convertion_unit: normalizedConvertionUnit,
weight_per_convertion: weight_per_convertion:
product.weight_per_convertion ?? undefined, product.weight_per_convertion ?? undefined,
week: product.week?.value ?? undefined, week: product.week ?? undefined,
} as CreateSalesOrderProductPayload; } as CreateSalesOrderProductPayload;
}), }),
} as CreateSalesOrderPayload) } as CreateSalesOrderPayload)
@@ -128,12 +128,7 @@ export const SalesProductToFieldValues = (
label: formatTitleCase(product.convertion_unit), label: formatTitleCase(product.convertion_unit),
} }
: null, : null,
week: product.week week: product.week ?? null,
? {
value: product.week,
label: `Week ${product.week}`,
}
: null,
total_peti: product.total_peti, total_peti: product.total_peti,
weight_per_convertion: product.weight_per_convertion, weight_per_convertion: product.weight_per_convertion,
uom: product.product_warehouse.product.uom.name, uom: product.product_warehouse.product.uom.name,
@@ -30,13 +30,7 @@ type DeliveryOrderProductSchemaType = {
/** Harga per butir telur untuk TELUR + QTY */ /** Harga per butir telur untuk TELUR + QTY */
price_per_qty?: number | null | undefined; price_per_qty?: number | null | undefined;
/** Week untuk ayam pullet */ /** Week untuk ayam pullet */
week?: week?: number | null | undefined;
| {
value?: number;
label?: string;
}
| null
| undefined;
}; };
export const DeliveryOrderProductSchema: Yup.ObjectSchema<DeliveryOrderProductSchemaType> = export const DeliveryOrderProductSchema: Yup.ObjectSchema<DeliveryOrderProductSchemaType> =
@@ -79,26 +73,18 @@ export const DeliveryOrderProductSchema: Yup.ObjectSchema<DeliveryOrderProductSc
sisa_berat: Yup.number().nullable().optional().notRequired(), sisa_berat: Yup.number().nullable().optional().notRequired(),
price_sisa_berat: Yup.number().nullable().optional().notRequired(), price_sisa_berat: Yup.number().nullable().optional().notRequired(),
price_per_qty: Yup.number().nullable().optional().notRequired(), price_per_qty: Yup.number().nullable().optional().notRequired(),
week: Yup.object({ week: Yup.number()
value: Yup.number(),
label: Yup.string(),
})
.nullable() .nullable()
.default(null) .optional()
.notRequired()
.when('marketing_type', { .when('marketing_type', {
is: (marketingType: { value: string } | null | undefined) => is: (marketingType: { value: string } | null | undefined) =>
marketingType?.value?.toLowerCase() === 'ayam_pullet', marketingType?.value?.toLowerCase() === 'ayam_pullet',
then: (schema) => then: (schema) =>
schema schema
.shape({ .min(1, 'Week wajib diisi untuk Ayam Pullet!')
value: Yup.number().required( .required('Week wajib diisi untuk Ayam Pullet!')
'Week wajib diisi untuk Ayam Pullet!' .typeError('Week harus berupa angka!'),
),
label: Yup.string().required(
'Week wajib diisi untuk Ayam Pullet!'
),
})
.required('Week wajib diisi untuk Ayam Pullet!'),
otherwise: (schema) => schema.optional().notRequired(), otherwise: (schema) => schema.optional().notRequired(),
}), }),
}); });
@@ -511,19 +511,20 @@ const DeliveryOrderProductForm = ({
{/* Konversi Satuan Week Pullet */} {/* Konversi Satuan Week Pullet */}
{formik.values.marketing_type?.value.toLowerCase() === {formik.values.marketing_type?.value.toLowerCase() ===
'ayam_pullet' && ( 'ayam_pullet' && (
<SelectInputRadio <NumberInput
required required
label='Minggu' label='Minggu'
options={optionsWeek} name='week'
value={ value={formik.values.week ?? undefined}
formik.values.week?.value onChange={(e) => {
? (formik.values.week as { value: number; label: string }) formik.setFieldValue('week', Number(e.target.value));
: null setCurrentInput(e.target.name);
}
onChange={(val) => {
formik.setFieldValue('week', val);
}} }}
placeholder='Pilih Week' onBlur={() => handleBlurField('week')}
isError={formik.touched.week && Boolean(formik.errors.week)}
errorMessage={formik.errors.week as string}
placeholder='Masukan Minggu'
decimalScale={0}
/> />
)} )}
@@ -37,13 +37,7 @@ type SalesOrderProductSchemaType = {
/** Harga per butir telur untuk TELUR + QTY */ /** Harga per butir telur untuk TELUR + QTY */
price_per_qty?: number | null | undefined; price_per_qty?: number | null | undefined;
/** Week untuk ayam pullet */ /** Week untuk ayam pullet */
week?: week?: number | null | undefined;
| {
value?: number;
label?: string;
}
| null
| undefined;
}; };
export const SalesOrderProductSchema: Yup.ObjectSchema<SalesOrderProductSchemaType> = export const SalesOrderProductSchema: Yup.ObjectSchema<SalesOrderProductSchemaType> =
@@ -102,26 +96,18 @@ export const SalesOrderProductSchema: Yup.ObjectSchema<SalesOrderProductSchemaTy
sisa_berat: Yup.number().nullable().optional().notRequired(), sisa_berat: Yup.number().nullable().optional().notRequired(),
price_sisa_berat: Yup.number().nullable().optional().notRequired(), price_sisa_berat: Yup.number().nullable().optional().notRequired(),
price_per_qty: Yup.number().nullable().optional().notRequired(), price_per_qty: Yup.number().nullable().optional().notRequired(),
week: Yup.object({ week: Yup.number()
value: Yup.number(),
label: Yup.string(),
})
.nullable() .nullable()
.default(null) .optional()
.notRequired()
.when('marketing_type', { .when('marketing_type', {
is: (marketingType: { value: string } | null | undefined) => is: (marketingType: { value: string } | null | undefined) =>
marketingType?.value?.toLowerCase() === 'ayam_pullet', marketingType?.value?.toLowerCase() === 'ayam_pullet',
then: (schema) => then: (schema) =>
schema schema
.shape({ .min(1, 'Week wajib diisi untuk Ayam Pullet!')
value: Yup.number().required( .required('Week wajib diisi untuk Ayam Pullet!')
'Week wajib diisi untuk Ayam Pullet!' .typeError('Week harus berupa angka!'),
),
label: Yup.string().required(
'Week wajib diisi untuk Ayam Pullet!'
),
})
.required('Week wajib diisi untuk Ayam Pullet!'),
otherwise: (schema) => schema.optional().notRequired(), otherwise: (schema) => schema.optional().notRequired(),
}), }),
}); });
@@ -467,19 +467,20 @@ const SalesOrderProductForm = ({
{/* Konversi Satuan Week Pullet */} {/* Konversi Satuan Week Pullet */}
{formik.values.marketing_type?.value.toLowerCase() === {formik.values.marketing_type?.value.toLowerCase() ===
'ayam_pullet' && ( 'ayam_pullet' && (
<SelectInputRadio <NumberInput
required required
label='Minggu' label='Minggu'
options={optionsWeek} name='week'
value={ value={formik.values.week ?? undefined}
formik.values.week?.value onChange={(e) => {
? (formik.values.week as { value: number; label: string }) formik.setFieldValue('week', Number(e.target.value));
: null setCurrentInput(e.target.name);
}
onChange={(val) => {
formik.setFieldValue('week', val);
}} }}
placeholder='Pilih Week' onBlur={() => handleBlurField('week')}
isError={formik.touched.week && Boolean(formik.errors.week)}
errorMessage={formik.errors.week as string}
placeholder='Masukan Minggu'
decimalScale={0}
/> />
)} )}
@@ -234,7 +234,7 @@ const SalesOrderProductTable = ({
'ayam_pullet' && ( 'ayam_pullet' && (
<tr> <tr>
<td className='text-sm px-4 py-3'>Tipe Konversi</td> <td className='text-sm px-4 py-3'>Tipe Konversi</td>
<td className='text-sm px-4 py-3'>{item.week?.label}</td> <td className='text-sm px-4 py-3'>Week {item.week}</td>
</tr> </tr>
)} )}
{item.convertion_unit?.value.toLowerCase() === 'peti' && ( {item.convertion_unit?.value.toLowerCase() === 'peti' && (
+2 -2
View File
@@ -15,7 +15,7 @@ export type MarketingFormValues = {
total_price?: string | number; total_price?: string | number;
marketing_type?: { value: string; label: string } | null; marketing_type?: { value: string; label: string } | null;
convertion_unit?: { value: string; label: string } | null; convertion_unit?: { value: string; label: string } | null;
week?: { value?: number; label?: string } | null; week?: number | null;
weight_per_convertion?: number | null; weight_per_convertion?: number | null;
price_per_convertion?: number | null; price_per_convertion?: number | null;
total_peti?: number | null; total_peti?: number | null;
@@ -100,7 +100,7 @@ export const calculateAyamPullet = (
): void => { ): void => {
const { values, setFieldValue } = ctx; const { values, setFieldValue } = ctx;
const unitPrice = Number(values.unit_price || 0); const unitPrice = Number(values.unit_price || 0);
const week = Number(values.week?.value || 0); const week = Number(values.week || 0);
const qty = Number(values.qty || 0); const qty = Number(values.qty || 0);
const avgWeight = Number(values.avg_weight || 0); const avgWeight = Number(values.avg_weight || 0);
const totalWeight = Number(values.total_weight || 0); const totalWeight = Number(values.total_weight || 0);