From 68a3e7dffdf515333fcf9cf954fa1167e55b079d Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Mon, 7 Oct 2024 15:29:45 +0700 Subject: [PATCH] fix: calc vat after discount only --- src/controllers/05-quotation-controller.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index 17bf715..3e0ec78 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -130,7 +130,7 @@ type QuotationUpdate = { * @maximum 1 * @minimum 0 */ - discount: number; + discount?: number; workerIndex?: number[]; }[]; }; @@ -344,7 +344,7 @@ export class QuotationController extends Controller { 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 vat = precisionRound(p.vatIncluded ? price - pricePerUnit : price * VAT_DEFAULT); + const vat = precisionRound((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT); return { order: i + 1, @@ -369,7 +369,7 @@ export class QuotationController extends Controller { (a, c) => { a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount); a.totalDiscount = precisionRound(a.totalDiscount + c.discount); - a.vat = precisionRound(a.vat + c.vat * c.amount); + a.vat = precisionRound(a.vat + c.vat); a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); return a; @@ -550,7 +550,7 @@ export class QuotationController extends Controller { const p = product.find((p) => p.id === v.productId)!; const price = record.agentPrice ? p.agentPrice : p.price; const pricePerUnit = p.vatIncluded ? precisionRound(price / 1 + VAT_DEFAULT) : price; - const vat = precisionRound(p.vatIncluded ? price - pricePerUnit : price * VAT_DEFAULT); + const vat = precisionRound((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT); return { order: i + 1, @@ -576,7 +576,7 @@ export class QuotationController extends Controller { (a, c) => { a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount); a.totalDiscount = precisionRound(a.totalDiscount + c.discount); - a.vat = precisionRound(a.vat + c.vat * c.amount); + a.vat = precisionRound(a.vat + c.vat); a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); return a;