From 4dfa63dd12281a706ea2d7fccbc058dc60a41e00 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Mon, 7 Oct 2024 14:51:16 +0700 Subject: [PATCH] fix: vat calc --- src/controllers/05-quotation-controller.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index cd214ec..17bf715 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -343,7 +343,7 @@ export class QuotationController extends Controller { const list = body.productServiceList.map((v, i) => { const p = product.find((p) => p.id === v.productId)!; const price = body.agentPrice ? p.agentPrice : p.price; - const pricePerUnit = p.vatIncluded ? precisionRound(price / 1 + VAT_DEFAULT) : price; + const pricePerUnit = p.vatIncluded ? precisionRound(price / (1 + VAT_DEFAULT)) : price; const vat = precisionRound(p.vatIncluded ? price - pricePerUnit : price * VAT_DEFAULT); return { @@ -367,11 +367,9 @@ export class QuotationController extends Controller { const price = list.reduce( (a, c) => { - const multiply = precisionRound(c.pricePerUnit * c.amount); - - a.totalPrice = precisionRound(a.totalPrice + multiply); + a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount); a.totalDiscount = precisionRound(a.totalDiscount + c.discount); - a.vat = precisionRound(a.vat + c.vat); + a.vat = precisionRound(a.vat + c.vat * c.amount); a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); return a; @@ -576,11 +574,9 @@ export class QuotationController extends Controller { const price = list?.reduce( (a, c) => { - const multiply = precisionRound(c.pricePerUnit * c.amount); - - a.totalPrice = precisionRound(a.totalPrice + multiply); + a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount); a.totalDiscount = precisionRound(a.totalDiscount + c.discount); - a.vat = precisionRound(a.vat + c.vat); + a.vat = precisionRound(a.vat + c.vat * c.amount); a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); return a;