fix: discount not have effect

This commit is contained in:
Methapon Metanipat 2024-10-09 09:18:37 +07:00
parent f44746978a
commit 8172bd4ab6

View file

@ -390,7 +390,9 @@ export class QuotationController extends Controller {
a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount); a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount);
a.totalDiscount = precisionRound(a.totalDiscount + c.discount); a.totalDiscount = precisionRound(a.totalDiscount + c.discount);
a.vat = precisionRound(a.vat + c.vat); a.vat = precisionRound(a.vat + c.vat);
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); a.finalPrice = precisionRound(
Math.max(a.totalPrice - a.totalDiscount + a.vat - (body.discount || 0), 0),
);
return a; return a;
}, },
@ -399,7 +401,7 @@ export class QuotationController extends Controller {
totalDiscount: 0, totalDiscount: 0,
vat: 0, vat: 0,
discount: body.discount, discount: body.discount,
finalPrice: -(body.discount || 0), finalPrice: 0,
}, },
); );
@ -611,7 +613,9 @@ export class QuotationController extends Controller {
a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount); a.totalPrice = precisionRound(a.totalPrice + c.pricePerUnit * c.amount);
a.totalDiscount = precisionRound(a.totalDiscount + c.discount); a.totalDiscount = precisionRound(a.totalDiscount + c.discount);
a.vat = precisionRound(a.vat + c.vat); a.vat = precisionRound(a.vat + c.vat);
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); a.finalPrice = precisionRound(
Math.max(a.totalPrice - a.totalDiscount + a.vat - (body.discount || 0), 0),
);
return a; return a;
}, },
@ -620,7 +624,7 @@ export class QuotationController extends Controller {
totalDiscount: 0, totalDiscount: 0,
vat: 0, vat: 0,
discount: body.discount, discount: body.discount,
finalPrice: -(body.discount || 0), finalPrice: 0,
}, },
); );