fix: price not match with original price by .01

This will calculate quantity later when no discount is set.
However when discount is set there may be some number that can introduce
+-0.01
This commit is contained in:
Methapon2001 2024-12-10 17:04:59 +07:00
parent 5afe625290
commit e0d24b49cb
2 changed files with 12 additions and 6 deletions

View file

@ -54,9 +54,13 @@ function calcPrice(c: (typeof rows.value)[number]) {
return precisionRound(
c.pricePerUnit * c.amount -
c.discount +
(c.product.calcVat
? (c.pricePerUnit * c.amount - c.discount) * (config.value?.vat || 0.07)
: 0),
precisionRound(
c.product.calcVat
? (c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) *
(config.value?.vat || 0.07)
: 0,
) *
(!c.discount ? c.amount : 1),
);
}

View file

@ -214,9 +214,11 @@ function getPrice(
}
const price = precisionRound(c.pricePerUnit * c.amount);
const vat = precisionRound(
(c.pricePerUnit * c.amount - c.discount) * (config.value?.vat || 0.07),
);
const vat =
precisionRound(
(c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) *
(config.value?.vat || 0.07),
) * (!c.discount ? c.amount : 1);
a.totalPrice = precisionRound(a.totalPrice + price);
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));