diff --git a/src/pages/09_task-order/document_view/MainPage.vue b/src/pages/09_task-order/document_view/MainPage.vue index e36e586c..4bf4511c 100644 --- a/src/pages/09_task-order/document_view/MainPage.vue +++ b/src/pages/09_task-order/document_view/MainPage.vue @@ -178,31 +178,30 @@ onMounted(async () => { })) .reduce( (a, c) => { - const price = precisionRound(c.pricePerUnit * c.amount); - const vat = - precisionRound( - (c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) * - (config.value?.vat || 0.07), - ) * (!c.discount ? c.amount : 1); + const priceNoVat = c.product.calcVat + ? c.pricePerUnit / (1 + (config.value?.vat || 0.07)) + : c.pricePerUnit; + const priceDiscountNoVat = priceNoVat * c.amount - c.discount; + + const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07); + const rawVat = rawVatTotal / c.amount; product.value.push({ id: c.product.id, code: c.product.code, detail: c.product.name, - priceUnit: c.pricePerUnit, + priceUnit: precisionRound(priceNoVat), amount: c.amount, discount: c.discount, - vat, - value: price * c.amount + vat, + vat: precisionRound(rawVat), + value: precisionRound(priceNoVat * c.amount + rawVatTotal), }); - a.totalPrice = precisionRound(a.totalPrice + price); - a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount)); - a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat; - a.vatExcluded = c.product.calcVat - ? a.vatExcluded - : precisionRound(a.vat + vat); - a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); + a.totalPrice = a.totalPrice + priceDiscountNoVat; + a.totalDiscount = a.totalDiscount + Number(c.discount); + a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat; + a.vatExcluded = c.product.calcVat ? a.vatExcluded : a.vat + rawVatTotal; + a.finalPrice = a.totalPrice - a.totalDiscount + a.vat; return a; }, {