fix: calc vat after discount only

This commit is contained in:
Methapon Metanipat 2024-10-07 15:29:45 +07:00
parent 66444bfdc5
commit 68a3e7dffd

View file

@ -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;