mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 06:45:46 +00:00
hotfix: fix sales calculation
This commit is contained in:
+60
-27
@@ -163,6 +163,11 @@ const SalesOrderProductForm = ({
|
|||||||
|
|
||||||
if (qty <= 0) return;
|
if (qty <= 0) return;
|
||||||
|
|
||||||
|
// Cek apakah produk memiliki flag OVK atau PAKAN
|
||||||
|
const productFlags = selectedProductWarehouse?.product?.flags || [];
|
||||||
|
const isOvkOrPakan =
|
||||||
|
productFlags.includes('OVK') || productFlags.includes('PAKAN');
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
// ===== SOURCE FIELDS =====
|
// ===== SOURCE FIELDS =====
|
||||||
case 'qty': {
|
case 'qty': {
|
||||||
@@ -170,9 +175,15 @@ const SalesOrderProductForm = ({
|
|||||||
const tw = roundWeight(qty * avgWeight);
|
const tw = roundWeight(qty * avgWeight);
|
||||||
formik.setFieldValue('total_weight', tw);
|
formik.setFieldValue('total_weight', tw);
|
||||||
|
|
||||||
// Hitung total_price berdasarkan unit_price × total_weight
|
// Hitung total_price berdasarkan flag produk
|
||||||
if (unitPrice > 0) {
|
if (unitPrice > 0) {
|
||||||
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
|
if (isOvkOrPakan) {
|
||||||
|
// Untuk OVK/PAKAN: total_price = qty × unit_price
|
||||||
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
|
} else {
|
||||||
|
// Untuk produk lain: total_price = unit_price × total_weight
|
||||||
|
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -183,32 +194,27 @@ const SalesOrderProductForm = ({
|
|||||||
const tw = roundWeight(qty * avgWeight);
|
const tw = roundWeight(qty * avgWeight);
|
||||||
formik.setFieldValue('total_weight', tw);
|
formik.setFieldValue('total_weight', tw);
|
||||||
|
|
||||||
// Hitung total_price berdasarkan unit_price × total_weight
|
// Hitung total_price berdasarkan flag produk
|
||||||
if (unitPrice > 0) {
|
if (unitPrice > 0) {
|
||||||
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
|
if (isOvkOrPakan) {
|
||||||
|
// Untuk OVK/PAKAN: total_price = qty × unit_price
|
||||||
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
|
} else {
|
||||||
|
// Untuk produk lain: total_price = unit_price × total_weight
|
||||||
|
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'unit_price': {
|
case 'unit_price': {
|
||||||
if (unitPrice > 0 && totalWeight > 0) {
|
if (unitPrice > 0) {
|
||||||
// Hitung total_price berdasarkan unit_price × total_weight
|
if (isOvkOrPakan) {
|
||||||
formik.setFieldValue(
|
// Untuk OVK/PAKAN: total_price = qty × unit_price
|
||||||
'total_price',
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
roundPrice(unitPrice * totalWeight)
|
} else if (totalWeight > 0) {
|
||||||
);
|
// Untuk produk lain: total_price = unit_price × total_weight
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===== TOTAL EDITABLE =====
|
|
||||||
case 'total_weight': {
|
|
||||||
if (totalWeight > 0) {
|
|
||||||
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
|
|
||||||
|
|
||||||
// Hitung ulang total_price berdasarkan unit_price × total_weight
|
|
||||||
if (unitPrice > 0) {
|
|
||||||
formik.setFieldValue(
|
formik.setFieldValue(
|
||||||
'total_price',
|
'total_price',
|
||||||
roundPrice(unitPrice * totalWeight)
|
roundPrice(unitPrice * totalWeight)
|
||||||
@@ -218,13 +224,40 @@ const SalesOrderProductForm = ({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== TOTAL EDITABLE =====
|
||||||
|
case 'total_weight': {
|
||||||
|
if (totalWeight > 0) {
|
||||||
|
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
|
||||||
|
|
||||||
|
// Hitung ulang total_price berdasarkan flag produk
|
||||||
|
if (unitPrice > 0) {
|
||||||
|
if (isOvkOrPakan) {
|
||||||
|
// Untuk OVK/PAKAN: total_price = qty × unit_price
|
||||||
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
|
} else {
|
||||||
|
// Untuk produk lain: total_price = unit_price × total_weight
|
||||||
|
formik.setFieldValue(
|
||||||
|
'total_price',
|
||||||
|
roundPrice(unitPrice * totalWeight)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'total_price': {
|
case 'total_price': {
|
||||||
if (totalPrice > 0 && totalWeight > 0) {
|
if (totalPrice > 0) {
|
||||||
// Hitung unit_price berdasarkan total_price / total_weight
|
if (isOvkOrPakan && qty > 0) {
|
||||||
formik.setFieldValue(
|
// Untuk OVK/PAKAN: unit_price = total_price / qty
|
||||||
'unit_price',
|
formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
|
||||||
roundPrice(totalPrice / totalWeight)
|
} else if (totalWeight > 0) {
|
||||||
);
|
// Untuk produk lain: unit_price = total_price / total_weight
|
||||||
|
formik.setFieldValue(
|
||||||
|
'unit_price',
|
||||||
|
roundPrice(totalPrice / totalWeight)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user