feat: adjust price to respect its calc vat

This commit is contained in:
Methapon2001 2025-01-28 17:56:23 +07:00
parent fba9adc5f3
commit 82793dc7a8
4 changed files with 50 additions and 25 deletions

View file

@ -195,12 +195,13 @@ function getPrice(
) {
return list.reduce(
(a, c) => {
const pricePerUnit = quotationData.value?.agentPrice
? c.product.agentPrice
: c.product.price;
const agentPrice = !!quotationData.value?.agentPrice;
const pricePerUnit = agentPrice ? c.product.agentPrice : c.product.price;
const amount = c.list.length;
const discount = 0;
const priceNoVat = c.product.vatIncluded
const priceNoVat = c.product[
agentPrice ? 'agentPriceVatIncluded' : 'vatIncluded'
]
? pricePerUnit / (1 + (config.value?.vat || 0.07))
: pricePerUnit;
const priceDiscountNoVat = priceNoVat * amount - discount;
@ -210,8 +211,12 @@ function getPrice(
a.totalPrice = a.totalPrice + priceDiscountNoVat;
a.totalDiscount = a.totalDiscount + Number(discount);
a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat;
a.vatExcluded = c.product.calcVat ? a.vatExcluded : a.vat + rawVatTotal;
a.vat = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
? a.vat + rawVatTotal
: a.vat;
a.vatExcluded = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
? a.vatExcluded
: a.vat + rawVatTotal;
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
return a;
},