From 70556d04ba700af8382c4645524523367546f6fa Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Fri, 10 Apr 2026 15:07:39 +0700 Subject: [PATCH] fix: calculate unit price by weight --- src/lib/marketing-calculation.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/marketing-calculation.ts b/src/lib/marketing-calculation.ts index 3d4930c5..e957d64f 100644 --- a/src/lib/marketing-calculation.ts +++ b/src/lib/marketing-calculation.ts @@ -235,10 +235,8 @@ export const calculateTelurPeti = ( const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat; setFieldValue('total_price', totalPrice); // Recalculate unit_price = total_price / total_weight - - // TODO: consider sisa berat later const totalWeight = weightPerConvertion * totalPeti + sisaBerat; - updateUnitPrice(totalPrice, totalPeti); + updateUnitPrice(totalPrice, totalWeight); } break; } @@ -257,8 +255,8 @@ export const calculateTelurPeti = ( if (pricePerConvertion > 0 && totalPeti > 0) { const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat; setFieldValue('total_price', totalPrice); - // Recalculate unit_price = total_price / total_peti - updateUnitPrice(totalPrice, totalPeti); + // Recalculate unit_price = total_price / totalWeight + updateUnitPrice(totalPrice, totalWeight); } break; } @@ -317,6 +315,15 @@ export const calculateTelurPeti = ( updateUnitPrice(totalPrice, totalWeight); break; } + case 'qty': + // Recalculate avg_weight = total_weight / qty + if (qty > 0 && values.total_weight) { + setFieldValue( + 'avg_weight', + preciseWeight(Number(values.total_weight) / qty) + ); + } + break; } };