feat: add vat exclude feature

This commit is contained in:
Methapon Metanipat 2024-10-17 15:52:29 +07:00
parent 0af6dbaae1
commit eb91715ca7

View file

@ -370,7 +370,9 @@ 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((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT);
const vat = p.calcVat
? precisionRound((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT)
: 0;
return {
order: i + 1,
@ -394,6 +396,12 @@ export class QuotationController extends Controller {
a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount);
a.totalDiscount = precisionRound(a.totalDiscount + c.discount);
a.vat = precisionRound(a.vat + c.vat);
a.vatExcluded =
c.vat === 0
? precisionRound(
a.vatExcluded + (c.pricePerUnit * c.amount - (c.discount || 0)) * VAT_DEFAULT,
)
: 0;
a.finalPrice = precisionRound(
Math.max(a.totalPrice - a.totalDiscount + a.vat - (body.discount || 0), 0),
);
@ -404,6 +412,7 @@ export class QuotationController extends Controller {
totalPrice: 0,
totalDiscount: 0,
vat: 0,
vatExcluded: 0,
discount: body.discount,
finalPrice: 0,
},
@ -613,7 +622,9 @@ 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((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT);
const vat = p.calcVat
? precisionRound((pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT)
: 0;
return {
order: i + 1,
@ -637,6 +648,12 @@ export class QuotationController extends Controller {
a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount);
a.totalDiscount = precisionRound(a.totalDiscount + c.discount);
a.vat = precisionRound(a.vat + c.vat);
a.vatExcluded =
c.vat === 0
? precisionRound(
a.vatExcluded + (c.pricePerUnit * c.amount - (c.discount || 0)) * VAT_DEFAULT,
)
: 0;
a.finalPrice = precisionRound(
Math.max(a.totalPrice - a.totalDiscount + a.vat - (body.discount || 0), 0),
);
@ -647,6 +664,7 @@ export class QuotationController extends Controller {
totalPrice: 0,
totalDiscount: 0,
vat: 0,
vatExcluded: 0,
discount: body.discount,
finalPrice: 0,
},