fix: wrong price

This commit is contained in:
Methapon2001 2024-12-26 16:16:28 +07:00
parent ec7d76b6fa
commit 8a071e61a6

View file

@ -178,31 +178,30 @@ onMounted(async () => {
})) }))
.reduce( .reduce(
(a, c) => { (a, c) => {
const price = precisionRound(c.pricePerUnit * c.amount); const priceNoVat = c.product.calcVat
const vat = ? c.pricePerUnit / (1 + (config.value?.vat || 0.07))
precisionRound( : c.pricePerUnit;
(c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) * const priceDiscountNoVat = priceNoVat * c.amount - c.discount;
(config.value?.vat || 0.07),
) * (!c.discount ? c.amount : 1); const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07);
const rawVat = rawVatTotal / c.amount;
product.value.push({ product.value.push({
id: c.product.id, id: c.product.id,
code: c.product.code, code: c.product.code,
detail: c.product.name, detail: c.product.name,
priceUnit: c.pricePerUnit, priceUnit: precisionRound(priceNoVat),
amount: c.amount, amount: c.amount,
discount: c.discount, discount: c.discount,
vat, vat: precisionRound(rawVat),
value: price * c.amount + vat, value: precisionRound(priceNoVat * c.amount + rawVatTotal),
}); });
a.totalPrice = precisionRound(a.totalPrice + price); a.totalPrice = a.totalPrice + priceDiscountNoVat;
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount)); a.totalDiscount = a.totalDiscount + Number(c.discount);
a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat; a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat;
a.vatExcluded = c.product.calcVat a.vatExcluded = c.product.calcVat ? a.vatExcluded : a.vat + rawVatTotal;
? a.vatExcluded a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
: precisionRound(a.vat + vat);
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
return a; return a;
}, },
{ {