fix: error and price calc

This commit is contained in:
Methapon2001 2024-07-24 14:26:06 +07:00
parent 126a44cb7f
commit 2c99b92aa5

View file

@ -96,7 +96,7 @@ type QuotationUpdate = {
payBillDate?: Date; payBillDate?: Date;
workerCount: number; workerCount?: number;
// EmployeeId or Create new employee // EmployeeId or Create new employee
worker?: ( worker?: (
| string | string
@ -503,10 +503,10 @@ export class QuotationController extends Controller {
const [customer, customerBranch, employee, service, product] = await prisma.$transaction( const [customer, customerBranch, employee, service, product] = await prisma.$transaction(
async (tx) => async (tx) =>
await Promise.all([ await Promise.all([
tx.customer.findUnique({ tx.customer.findFirst({
where: { id: body.customerId }, where: { id: body.customerId },
}), }),
tx.customerBranch.findUnique({ tx.customerBranch.findFirst({
include: { customer: true }, include: { customer: true },
where: { id: body.customerBranchId }, where: { id: body.customerBranchId },
}), }),
@ -638,11 +638,13 @@ export class QuotationController extends Controller {
if (!currentProduct) return []; // should not possible if (!currentProduct) return []; // should not possible
price.totalPrice += currentProduct.price; price.totalPrice += currentProduct.price * e.amount;
price.totalDiscount += Math.round(currentProduct.price * e.discount * 100) / 100; price.totalDiscount +=
Math.round(currentProduct.price * e.amount * e.discount * 100) / 100;
price.totalVat += price.totalVat +=
Math.round( 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) * (e.vat === undefined ? 0.07 : e.vat) *
100, 100,
) / 100; ) / 100;
@ -704,7 +706,7 @@ export class QuotationController extends Controller {
}, },
}); });
if (restructureService) if (restructureService) {
await Promise.all( await Promise.all(
restructureService.map(async (a) => { restructureService.map(async (a) => {
const { id: _currentServiceId } = await tx.quotationService.create({ const { id: _currentServiceId } = await tx.quotationService.create({
@ -744,6 +746,7 @@ export class QuotationController extends Controller {
); );
}), }),
); );
}
return await tx.quotation.findUnique({ return await tx.quotation.findUnique({
include: { include: {