fix: calculation

This commit is contained in:
Methapon2001 2024-07-24 09:26:17 +07:00
parent c13eeb9b14
commit 67c3ead7ec

View file

@ -340,7 +340,7 @@ export class QuotationController extends Controller {
const currentWork = currentService.work.find((d) => d.id === c.id);
if (!currentWork) return []; // should not possible
if (!currentWork) return []; // additional will get stripped
return {
id: currentWork.id,
@ -352,11 +352,13 @@ export class QuotationController extends Controller {
if (!currentProduct) return []; // should not possible
price.totalPrice += currentProduct.price;
price.totalDiscount += Math.round(currentProduct.price * e.discount * 100) / 100;
price.totalPrice += currentProduct.price * e.amount;
price.totalDiscount +=
Math.round(currentProduct.price * e.amount * e.discount * 100) / 100;
price.totalVat +=
Math.round(
(currentProduct.price - currentProduct.price * e.discount) *
(currentProduct.price * e.amount -
currentProduct.price * e.amount * e.discount) *
(e.vat === undefined ? 0.07 : e.vat) *
100,
) / 100;
@ -373,9 +375,6 @@ export class QuotationController extends Controller {
});
const quotation = await tx.quotation.create({
include: {
service: true,
},
data: {
...rest,
statusOrder: +(rest.status === "INACTIVE"),