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
+9 -9
View File
@@ -15,7 +15,7 @@ export type MarketingFormValues = {
total_price?: string | number;
marketing_type?: { value: string; label: string } | null;
convertion_unit?: { value: string; label: string } | null;
weeks?: { value: number; label: string } | null;
week?: { value?: number; label?: string } | null;
weight_per_convertion?: number | null;
price_per_convertion?: number | null;
total_peti?: number | null;
@@ -100,7 +100,7 @@ export const calculateAyamPullet = (
): void => {
const { values, setFieldValue } = ctx;
const unitPrice = Number(values.unit_price || 0);
const weeks = Number(values.weeks?.value || 0);
const week = Number(values.week?.value || 0);
const qty = Number(values.qty || 0);
const avgWeight = Number(values.avg_weight || 0);
const totalWeight = Number(values.total_weight || 0);
@@ -108,11 +108,11 @@ export const calculateAyamPullet = (
switch (field) {
case 'unit_price':
case 'weeks':
case 'week':
case 'qty': {
// total_price = unit_price × weeks × qty
if (unitPrice > 0 && weeks > 0 && qty > 0) {
setFieldValue('total_price', roundPrice(unitPrice * weeks * qty));
// total_price = unit_price × week × qty
if (unitPrice > 0 && week > 0 && qty > 0) {
setFieldValue('total_price', roundPrice(unitPrice * week * qty));
}
// total_weight = avg_weight × qty
if (avgWeight > 0 && qty > 0) {
@@ -133,9 +133,9 @@ export const calculateAyamPullet = (
break;
}
case 'total_price': {
// Reverse: unit_price = total_price / (weeks × qty)
if (totalPrice > 0 && weeks > 0 && qty > 0) {
setFieldValue('unit_price', roundPrice(totalPrice / (weeks * qty)));
// Reverse: unit_price = total_price / (week × qty)
if (totalPrice > 0 && week > 0 && qty > 0) {
setFieldValue('unit_price', roundPrice(totalPrice / (week * qty)));
}
break;
}