From 524a493149a86615357ca3d2d2d73437b66af167 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 29 Jan 2025 09:52:53 +0700 Subject: [PATCH 1/5] fix: get actual price from final price instead --- src/controllers/08-credit-note-controller.ts | 26 +++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) 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({ From d5678c537f62cfd39f889d9ca34389932aad0254 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:47:18 +0700 Subject: [PATCH 2/5] feat: conditional include step status --- src/controllers/06-request-list-controller.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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: { From 11a6918e9643ac366c22073307d6f46b0bdff043 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:50:13 +0700 Subject: [PATCH 3/5] fix: error --- src/controllers/05-quotation-controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index e653883..cc6fe6b 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -1047,7 +1047,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, }, }); From 717966796ee82453bcdc260cf7683452d48fdd2f Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:51:03 +0700 Subject: [PATCH 4/5] fix: ordering --- src/controllers/01-branch-controller.ts | 2 ++ 1 file changed, 2 insertions(+) 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, From 891d9a86d2d029fd6a6792b98b64d75f0bfa4733 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:51:48 +0700 Subject: [PATCH 5/5] fix: wrong vat --- src/controllers/05-quotation-controller.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index cc6fe6b..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,