mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
fix: remove roundPrice, update unit price calculation in calculateTelurPeti
This commit is contained in:
@@ -76,13 +76,13 @@ export const calculateTrading = (
|
|||||||
case 'unit_price':
|
case 'unit_price':
|
||||||
case 'qty': {
|
case 'qty': {
|
||||||
if (unitPrice > 0 && qty > 0) {
|
if (unitPrice > 0 && qty > 0) {
|
||||||
setFieldValue('total_price', roundPrice(unitPrice * qty));
|
setFieldValue('total_price', unitPrice * qty);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'total_price': {
|
case 'total_price': {
|
||||||
if (totalPrice > 0 && qty > 0) {
|
if (totalPrice > 0 && qty > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(totalPrice / qty));
|
setFieldValue('unit_price', totalPrice / qty);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ export const calculateAyamPullet = (
|
|||||||
case 'qty': {
|
case 'qty': {
|
||||||
// total_price = unit_price × week × qty
|
// total_price = unit_price × week × qty
|
||||||
if (unitPrice > 0 && week > 0 && qty > 0) {
|
if (unitPrice > 0 && week > 0 && qty > 0) {
|
||||||
setFieldValue('total_price', roundPrice(unitPrice * week * qty));
|
setFieldValue('total_price', unitPrice * week * qty);
|
||||||
}
|
}
|
||||||
// total_weight = avg_weight × qty
|
// total_weight = avg_weight × qty
|
||||||
if (avgWeight > 0 && qty > 0) {
|
if (avgWeight > 0 && qty > 0) {
|
||||||
@@ -135,7 +135,7 @@ export const calculateAyamPullet = (
|
|||||||
case 'total_price': {
|
case 'total_price': {
|
||||||
// Reverse: unit_price = total_price / (week × qty)
|
// Reverse: unit_price = total_price / (week × qty)
|
||||||
if (totalPrice > 0 && week > 0 && qty > 0) {
|
if (totalPrice > 0 && week > 0 && qty > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(totalPrice / (week * qty)));
|
setFieldValue('unit_price', totalPrice / (week * qty));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ export const calculateAyam = (field: string, ctx: CalculationContext): void => {
|
|||||||
setFieldValue('total_weight', tw);
|
setFieldValue('total_weight', tw);
|
||||||
// total_price = total_weight × unit_price
|
// total_price = total_weight × unit_price
|
||||||
if (unitPrice > 0) {
|
if (unitPrice > 0) {
|
||||||
setFieldValue('total_price', roundPrice(tw * unitPrice));
|
setFieldValue('total_price', tw * unitPrice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -176,21 +176,21 @@ export const calculateAyam = (field: string, ctx: CalculationContext): void => {
|
|||||||
}
|
}
|
||||||
// total_price = total_weight × unit_price
|
// total_price = total_weight × unit_price
|
||||||
if (unitPrice > 0 && totalWeight > 0) {
|
if (unitPrice > 0 && totalWeight > 0) {
|
||||||
setFieldValue('total_price', roundPrice(totalWeight * unitPrice));
|
setFieldValue('total_price', totalWeight * unitPrice);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'unit_price': {
|
case 'unit_price': {
|
||||||
// total_price = total_weight × unit_price
|
// total_price = total_weight × unit_price
|
||||||
if (unitPrice > 0 && totalWeight > 0) {
|
if (unitPrice > 0 && totalWeight > 0) {
|
||||||
setFieldValue('total_price', roundPrice(totalWeight * unitPrice));
|
setFieldValue('total_price', totalWeight * unitPrice);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'total_price': {
|
case 'total_price': {
|
||||||
// unit_price = total_price / total_weight
|
// unit_price = total_price / total_weight
|
||||||
if (totalPrice > 0 && totalWeight > 0) {
|
if (totalPrice > 0 && totalWeight > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(totalPrice / totalWeight));
|
setFieldValue('unit_price', totalPrice / totalWeight);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,8 @@ export const calculateTelurPeti = (
|
|||||||
// Helper untuk menghitung dan set unit_price = total_price / total_weight
|
// Helper untuk menghitung dan set unit_price = total_price / total_weight
|
||||||
const updateUnitPrice = (tp: number, tw: number) => {
|
const updateUnitPrice = (tp: number, tw: number) => {
|
||||||
if (tw > 0 && tp > 0) {
|
if (tw > 0 && tp > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(tp / tw));
|
const unitPrice = tp / tw;
|
||||||
|
setFieldValue('unit_price', unitPrice);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -232,10 +233,12 @@ export const calculateTelurPeti = (
|
|||||||
// Recalculate total_price = (price_per_convertion × total_peti) + price_sisa_berat
|
// Recalculate total_price = (price_per_convertion × total_peti) + price_sisa_berat
|
||||||
if (pricePerConvertion > 0 && totalPeti > 0) {
|
if (pricePerConvertion > 0 && totalPeti > 0) {
|
||||||
const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat;
|
const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat;
|
||||||
setFieldValue('total_price', roundPrice(totalPrice));
|
setFieldValue('total_price', totalPrice);
|
||||||
// Recalculate unit_price = total_price / total_weight
|
// Recalculate unit_price = total_price / total_weight
|
||||||
|
|
||||||
|
// TODO: consider sisa berat later
|
||||||
const totalWeight = weightPerConvertion * totalPeti + sisaBerat;
|
const totalWeight = weightPerConvertion * totalPeti + sisaBerat;
|
||||||
updateUnitPrice(totalPrice, totalWeight);
|
updateUnitPrice(totalPrice, totalPeti);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -253,9 +256,9 @@ export const calculateTelurPeti = (
|
|||||||
// Recalculate total_price = (price_per_convertion × total_peti) + price_sisa_berat
|
// Recalculate total_price = (price_per_convertion × total_peti) + price_sisa_berat
|
||||||
if (pricePerConvertion > 0 && totalPeti > 0) {
|
if (pricePerConvertion > 0 && totalPeti > 0) {
|
||||||
const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat;
|
const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat;
|
||||||
setFieldValue('total_price', roundPrice(totalPrice));
|
setFieldValue('total_price', totalPrice);
|
||||||
// Recalculate unit_price = total_price / total_weight
|
// Recalculate unit_price = total_price / total_peti
|
||||||
updateUnitPrice(totalPrice, totalWeight);
|
updateUnitPrice(totalPrice, totalPeti);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -263,7 +266,7 @@ export const calculateTelurPeti = (
|
|||||||
// Recalculate total_price
|
// Recalculate total_price
|
||||||
if (pricePerConvertion > 0 && totalPeti > 0) {
|
if (pricePerConvertion > 0 && totalPeti > 0) {
|
||||||
const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat;
|
const totalPrice = pricePerConvertion * totalPeti + priceSisaBerat;
|
||||||
setFieldValue('total_price', roundPrice(totalPrice));
|
setFieldValue('total_price', totalPrice);
|
||||||
// Recalculate unit_price = total_price / total_weight
|
// Recalculate unit_price = total_price / total_weight
|
||||||
const totalWeight = weightPerConvertion * totalPeti + sisaBerat;
|
const totalWeight = weightPerConvertion * totalPeti + sisaBerat;
|
||||||
updateUnitPrice(totalPrice, totalWeight);
|
updateUnitPrice(totalPrice, totalWeight);
|
||||||
@@ -306,7 +309,7 @@ export const calculateTelurPeti = (
|
|||||||
if (totalPeti > 0 && totalPrice > priceSisaBerat) {
|
if (totalPeti > 0 && totalPrice > priceSisaBerat) {
|
||||||
setFieldValue(
|
setFieldValue(
|
||||||
'price_per_convertion',
|
'price_per_convertion',
|
||||||
roundPrice((totalPrice - priceSisaBerat) / totalPeti)
|
(totalPrice - priceSisaBerat) / totalPeti
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Update unit_price = total_price / total_weight
|
// Update unit_price = total_price / total_weight
|
||||||
@@ -341,10 +344,7 @@ export const calculateTelurKg = (
|
|||||||
}
|
}
|
||||||
// total_price = total_weight × unit_price
|
// total_price = total_weight × unit_price
|
||||||
if (pricePerConvertion > 0 && totalWeight > 0) {
|
if (pricePerConvertion > 0 && totalWeight > 0) {
|
||||||
setFieldValue(
|
setFieldValue('total_price', totalWeight * pricePerConvertion);
|
||||||
'total_price',
|
|
||||||
roundPrice(totalWeight * pricePerConvertion)
|
|
||||||
);
|
|
||||||
setFieldValue('unit_price', pricePerConvertion);
|
setFieldValue('unit_price', pricePerConvertion);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -352,10 +352,7 @@ export const calculateTelurKg = (
|
|||||||
case 'price_per_convertion': {
|
case 'price_per_convertion': {
|
||||||
// total_price = total_weight × price_per_convertion
|
// total_price = total_weight × price_per_convertion
|
||||||
if (pricePerConvertion > 0 && totalWeight > 0) {
|
if (pricePerConvertion > 0 && totalWeight > 0) {
|
||||||
setFieldValue(
|
setFieldValue('total_price', totalWeight * pricePerConvertion);
|
||||||
'total_price',
|
|
||||||
roundPrice(totalWeight * pricePerConvertion)
|
|
||||||
);
|
|
||||||
setFieldValue('unit_price', pricePerConvertion);
|
setFieldValue('unit_price', pricePerConvertion);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -363,11 +360,8 @@ export const calculateTelurKg = (
|
|||||||
case 'total_price': {
|
case 'total_price': {
|
||||||
// unit_price = total_price / total_weight
|
// unit_price = total_price / total_weight
|
||||||
if (totalPrice > 0 && totalWeight > 0) {
|
if (totalPrice > 0 && totalWeight > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(totalPrice / totalWeight));
|
setFieldValue('unit_price', totalPrice / totalWeight);
|
||||||
setFieldValue(
|
setFieldValue('price_per_convertion', totalPrice / totalWeight);
|
||||||
'price_per_convertion',
|
|
||||||
roundPrice(totalPrice / totalWeight)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -405,11 +399,11 @@ export const calculateTelurQty = (
|
|||||||
setFieldValue('total_weight', tw);
|
setFieldValue('total_weight', tw);
|
||||||
// total_price = qty × price_per_qty
|
// total_price = qty × price_per_qty
|
||||||
if (pricePerQty > 0) {
|
if (pricePerQty > 0) {
|
||||||
const tp = roundPrice(qty * pricePerQty);
|
const tp = qty * pricePerQty;
|
||||||
setFieldValue('total_price', tp);
|
setFieldValue('total_price', tp);
|
||||||
// unit_price = total_price / total_weight (untuk BE)
|
// unit_price = total_price / total_weight (untuk BE)
|
||||||
if (tw > 0) {
|
if (tw > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(tp / tw));
|
setFieldValue('unit_price', tp / tw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -421,7 +415,7 @@ export const calculateTelurQty = (
|
|||||||
setFieldValue('avg_weight', preciseWeight(totalWeight / qty));
|
setFieldValue('avg_weight', preciseWeight(totalWeight / qty));
|
||||||
// Recalculate total_price jika ada unit_price
|
// Recalculate total_price jika ada unit_price
|
||||||
if (unitPrice > 0) {
|
if (unitPrice > 0) {
|
||||||
setFieldValue('total_price', roundPrice(totalWeight * unitPrice));
|
setFieldValue('total_price', totalWeight * unitPrice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -429,11 +423,11 @@ export const calculateTelurQty = (
|
|||||||
case 'price_per_qty': {
|
case 'price_per_qty': {
|
||||||
// total_price = qty × price_per_qty
|
// total_price = qty × price_per_qty
|
||||||
if (pricePerQty > 0 && qty > 0) {
|
if (pricePerQty > 0 && qty > 0) {
|
||||||
const tp = roundPrice(qty * pricePerQty);
|
const tp = qty * pricePerQty;
|
||||||
setFieldValue('total_price', tp);
|
setFieldValue('total_price', tp);
|
||||||
// unit_price = total_price / total_weight (untuk BE)
|
// unit_price = total_price / total_weight (untuk BE)
|
||||||
if (totalWeight > 0) {
|
if (totalWeight > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(tp / totalWeight));
|
setFieldValue('unit_price', tp / totalWeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -441,22 +435,26 @@ export const calculateTelurQty = (
|
|||||||
case 'total_price': {
|
case 'total_price': {
|
||||||
// price_per_qty = total_price / qty
|
// price_per_qty = total_price / qty
|
||||||
if (totalPrice > 0 && qty > 0) {
|
if (totalPrice > 0 && qty > 0) {
|
||||||
setFieldValue('price_per_qty', roundPrice(totalPrice / qty));
|
setFieldValue('price_per_qty', totalPrice / qty);
|
||||||
// unit_price = total_price / total_weight (untuk BE)
|
// unit_price = total_price / total_weight (untuk BE)
|
||||||
if (totalWeight > 0) {
|
if (totalWeight > 0) {
|
||||||
setFieldValue('unit_price', roundPrice(totalPrice / totalWeight));
|
setFieldValue('unit_price', totalPrice / totalWeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'unit_price': {
|
case 'unit_price': {
|
||||||
// total_price = total_weight × unit_price
|
// total_price = total_weight × unit_price
|
||||||
|
|
||||||
|
const newTotalPrice = totalWeight * unitPrice;
|
||||||
|
|
||||||
if (unitPrice > 0 && totalWeight > 0) {
|
if (unitPrice > 0 && totalWeight > 0) {
|
||||||
setFieldValue('total_price', roundPrice(totalWeight * unitPrice));
|
setFieldValue('total_price', newTotalPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
// price_per_qty = total_price / qty
|
// price_per_qty = total_price / qty
|
||||||
if (totalPrice > 0 && qty > 0) {
|
if (newTotalPrice > 0 && qty > 0) {
|
||||||
setFieldValue('price_per_qty', roundPrice(totalPrice / qty));
|
setFieldValue('price_per_qty', newTotalPrice / qty);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user