From b999c9dd467cd90966fd80335c679528f332db93 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Fri, 4 Oct 2024 16:10:50 +0700 Subject: [PATCH] fix: calculate price --- src/controllers/05-quotation-controller.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index e4e4683..442552a 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -532,14 +532,14 @@ export class QuotationController extends Controller { const price = list?.reduce( (a, c) => { - const price = c.pricePerUnit * c.amount; - const discount = price * c.discount; - const vat = price - discount * c.vat; + const price = precisionRound(c.pricePerUnit * c.amount); + const discount = precisionRound(price - (c.discount || 0)); + const vat = precisionRound((price - discount) * c.vat); - a.totalPrice += price; - a.totalDiscount += discount; - a.vat += vat; - a.finalPrice += price - discount + vat; + a.totalPrice = precisionRound(a.totalPrice + price); + a.totalDiscount = precisionRound(a.totalDiscount + discount); + a.vat = precisionRound(a.vat + vat); + a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); return a; },