diff --git a/src/controllers/01-branch-controller.ts b/src/controllers/01-branch-controller.ts index 746f3bf..acb204f 100644 --- a/src/controllers/01-branch-controller.ts +++ b/src/controllers/01-branch-controller.ts @@ -321,6 +321,7 @@ export class BranchController extends Controller { district: true, subDistrict: true, }, + orderBy: { code: "asc" }, } : false, bank: true, @@ -364,6 +365,7 @@ export class BranchController extends Controller { bank: true, contact: includeContact, }, + orderBy: { code: "asc" }, }, bank: true, contact: includeContact, diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index e653883..096864e 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -487,7 +487,9 @@ export class QuotationController extends Controller { const price = finalPriceWithVat; const pricePerUnit = price / (1 + VAT_DEFAULT); - const vat = p.calcVat ? (pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT : 0; + const vat = (body.agentPrice ? p.agentPriceCalcVat : p.calcVat) + ? (pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT + : 0; return { order: i + 1, @@ -754,7 +756,9 @@ export class QuotationController extends Controller { const price = finalPriceWithVat; const pricePerUnit = price / (1 + VAT_DEFAULT); - const vat = p.calcVat ? (pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT : 0; + const vat = (record.agentPrice ? p.agentPriceCalcVat : p.calcVat) + ? (pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT + : 0; return { order: i + 1, @@ -1047,7 +1051,7 @@ export class QuotationActionController extends Controller { const data = await tx.employee.create({ data: { ...v.workerData, - code: `${customerBranch.code}-${`${new Date().getFullYear()}`.slice(-2).padStart(2, "0")}${`${lastEmployee.value - nonExistEmployee.length + i + 1}`.padStart(7, "0")}`, + code: `${customerBranch.code}-${`${new Date().getFullYear()}`.slice(-2).padStart(2, "0")}${`${lastEmployee.value - newEmployee.length + i + 1}`.padStart(7, "0")}`, customerBranchId: customerBranch.id, }, }); diff --git a/src/controllers/06-request-list-controller.ts b/src/controllers/06-request-list-controller.ts index 145f01c..b92a3f1 100644 --- a/src/controllers/06-request-list-controller.ts +++ b/src/controllers/06-request-list-controller.ts @@ -369,11 +369,13 @@ export class RequestListController extends Controller { employee: true, }, }, - stepStatus: { - include: { - task: { where: { taskStatus: TaskStatus.Complete } }, - }, - }, + stepStatus: cancelOnly + ? true + : { + include: { + task: { where: { taskStatus: TaskStatus.Complete } }, + }, + }, productService: { include: { service: { diff --git a/src/controllers/08-credit-note-controller.ts b/src/controllers/08-credit-note-controller.ts index ad29da1..8c66ac2 100644 --- a/src/controllers/08-credit-note-controller.ts +++ b/src/controllers/08-credit-note-controller.ts @@ -323,16 +323,15 @@ export class CreditNoteController extends Controller { (v) => v.workStatus === RequestWorkStatus.Completed, ).length; - const price = c.request.quotation.agentPrice ? "price" : "agentPrice"; + const price = + c.productService.pricePerUnit - + c.productService.discount / c.productService.amount + + c.productService.vat / c.productService.amount; if (serviceChargeStepCount && successCount) { - return ( - a + - c.productService.product[price] - - c.productService.product.serviceCharge * successCount - ); + return a + price - c.productService.product.serviceCharge * successCount; } - return a + c.productService.product.price; + return a + price; }, 0); this.setStatus(HttpStatus.CREATED); @@ -457,16 +456,15 @@ export class CreditNoteController extends Controller { (v) => v.workStatus === RequestWorkStatus.Completed, ).length; - const price = c.request.quotation.agentPrice ? "price" : "agentPrice"; + const price = + c.productService.pricePerUnit - + c.productService.discount / c.productService.amount + + c.productService.vat / c.productService.amount; if (serviceChargeStepCount && successCount) { - return ( - a + - c.productService.product[price] - - c.productService.product.serviceCharge * successCount - ); + return a + price - c.productService.product.serviceCharge * successCount; } - return a + c.productService.product.price; + return a + price; }, 0); const record = await prisma.creditNote.update({