From 77dbdac012ac1a16d8def93f54e18d0acfd653ed Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:02:41 +0700 Subject: [PATCH] feat: detect if agent price --- src/controllers/08-credit-note-controller.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/controllers/08-credit-note-controller.ts b/src/controllers/08-credit-note-controller.ts index 1f87dd1..56d892f 100644 --- a/src/controllers/08-credit-note-controller.ts +++ b/src/controllers/08-credit-note-controller.ts @@ -273,11 +273,17 @@ export class CreditNoteController extends Controller { (v) => v.productId === c.productService.productId, )?.stepCount; - const successCount = c.stepStatus.filter((v) => v.workStatus === "Completed").length; + const successCount = c.stepStatus.filter( + (v) => v.workStatus === RequestWorkStatus.Completed, + ).length; + + const price = c.request.quotation.agentPrice ? "price" : "agentPrice"; if (serviceChargeStepCount && successCount) { return ( - a + c.productService.product.price - c.productService.product.serviceCharge * successCount + a + + c.productService.product[price] - + c.productService.product.serviceCharge * successCount ); } return a + c.productService.product.price; @@ -400,11 +406,17 @@ export class CreditNoteController extends Controller { (v) => v.productId === c.productService.productId, )?.stepCount; - const successCount = c.stepStatus.filter((v) => v.workStatus === "Completed").length; + const successCount = c.stepStatus.filter( + (v) => v.workStatus === RequestWorkStatus.Completed, + ).length; + + const price = c.request.quotation.agentPrice ? "price" : "agentPrice"; if (serviceChargeStepCount && successCount) { return ( - a + c.productService.product.price - c.productService.product.serviceCharge * successCount + a + + c.productService.product[price] - + c.productService.product.serviceCharge * successCount ); } return a + c.productService.product.price;