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;
workerCount: number;
workerCount?: number;
// EmployeeId or Create new employee
worker?: (
| string
@ -503,10 +503,10 @@ export class QuotationController extends Controller {
const [customer, customerBranch, employee, service, product] = await prisma.$transaction(
async (tx) =>
await Promise.all([
tx.customer.findUnique({
tx.customer.findFirst({
where: { id: body.customerId },
}),
tx.customerBranch.findUnique({
tx.customerBranch.findFirst({
include: { customer: true },
where: { id: body.customerBranchId },
}),
@ -638,11 +638,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;
@ -704,7 +706,7 @@ export class QuotationController extends Controller {
},
});
if (restructureService)
if (restructureService) {
await Promise.all(
restructureService.map(async (a) => {
const { id: _currentServiceId } = await tx.quotationService.create({
@ -744,6 +746,7 @@ export class QuotationController extends Controller {
);
}),
);
}
return await tx.quotation.findUnique({
include: {