fix: inaccurate .01 price

This commit is contained in:
Methapon2001 2025-01-23 10:20:46 +07:00
parent ec61c73342
commit e12a87f496
3 changed files with 73 additions and 42 deletions

View file

@ -242,11 +242,19 @@ function getPrice(
return a;
}
const price = c.pricePerUnit * c.amount;
const originalPrice = c.pricePerUnit;
const finalPriceWithVat = precisionRound(
originalPrice +
(c.product.vatIncluded
? 0
: originalPrice * (config.value?.vat || 0.07)),
);
const finalPriceNoVat =
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
const price = finalPriceNoVat * c.amount;
const vat =
(c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) *
(config.value?.vat || 0.07) *
(!c.discount ? c.amount : 1);
(finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07);
a.totalPrice = precisionRound(a.totalPrice + price);
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
@ -704,12 +712,12 @@ function handleUpdateProductTable(
const pricePerUnit = c.pricePerUnit || 0;
const discount = c.discount || 0;
return precisionRound(
return (
pricePerUnit * c.amount -
discount +
(c.product.calcVat
? (pricePerUnit * c.amount - discount) * (config.value?.vat || 0.07)
: 0),
discount +
(c.product.calcVat
? (pricePerUnit * c.amount - discount) * (config.value?.vat || 0.07)
: 0)
);
};
@ -767,17 +775,15 @@ function toggleDeleteProduct(index: number) {
? currProduct.product.agentPrice
: currProduct.product.price;
const pricePerUnit = currProduct.product.vatIncluded
? precisionRound(price / (1 + (config.value?.vat || 0.07)))
? price / (1 + (config.value?.vat || 0.07))
: price;
const vat = precisionRound(
const vat =
(pricePerUnit * currProduct.amount - currProduct.discount) *
(config.value?.vat || 0.07),
);
const finalPrice = precisionRound(
(config.value?.vat || 0.07);
const finalPrice =
pricePerUnit * currProduct.amount +
vat -
Number(currProduct.discount || 0),
);
vat -
Number(currProduct.discount || 0);
currTempPaySplit.amount = currPaySplit.amount - finalPrice;
currPaySplit.amount = currTempPaySplit.amount;