From 1486ce79abf710101ea8a8783856c50da42e5381 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:50:40 +0700 Subject: [PATCH] fix: calculate credit note price --- src/controllers/08-credit-note-controller.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/controllers/08-credit-note-controller.ts b/src/controllers/08-credit-note-controller.ts index 48ee2ab..1b3c75d 100644 --- a/src/controllers/08-credit-note-controller.ts +++ b/src/controllers/08-credit-note-controller.ts @@ -13,6 +13,7 @@ import { Security, Tags, } from "tsoa"; +import config from "../config.json"; import prisma from "../db"; @@ -53,6 +54,7 @@ function globalAllow(user: RequestWithUser["user"]) { const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"]; return user.roles?.some((v) => listAllowed.includes(v)) || false; } +const VAT_DEFAULT = config.vat; const permissionCond = createPermCondition(globalAllow); const permissionCheck = createPermCheck(globalAllow); @@ -346,9 +348,9 @@ export class CreditNoteController extends Controller { ).length; const price = - c.productService.pricePerUnit - - c.productService.discount / c.productService.amount + - c.productService.vat / c.productService.amount; + c.productService.pricePerUnit * + (1 + (c.productService.product.serviceChargeCalcVat ? VAT_DEFAULT : 0)) - + c.productService.discount; if (serviceChargeStepCount && successCount) { return a + price - c.productService.product.serviceCharge * successCount; @@ -424,7 +426,6 @@ export class CreditNoteController extends Controller { let textData = ""; let dataCustomerId: string[] = []; - let textWorkList: string[] = []; let dataUserId: string[] = []; if (res) { @@ -541,9 +542,9 @@ export class CreditNoteController extends Controller { ).length; const price = - c.productService.pricePerUnit - - c.productService.discount / c.productService.amount + - c.productService.vat / c.productService.amount; + c.productService.pricePerUnit * + (1 + (c.productService.product.serviceChargeCalcVat ? VAT_DEFAULT : 0)) - + c.productService.discount; if (serviceChargeStepCount && successCount) { return a + price - c.productService.product.serviceCharge * successCount;