From 9bfa2dd8c591fadf97e485a1eb1b307ef9f8c899 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 29 Mar 2024 17:09:40 +0700 Subject: [PATCH] emp2-25 --- src/controllers/TumReportController.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/controllers/TumReportController.ts b/src/controllers/TumReportController.ts index 27f3fad..386867b 100644 --- a/src/controllers/TumReportController.ts +++ b/src/controllers/TumReportController.ts @@ -35,6 +35,7 @@ import { import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee"; import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee"; +import { log } from "console"; @Route("api/v1/salary/report/tum") @Tags("Tum") @Security("bearerAuth") @@ -407,10 +408,25 @@ import { if (!salaryProfileCurrentOCT) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - - const agency = salaryProfileCurrentOCT[0] == null ? "" : salaryProfileCurrentOCT[0].root; + const agency = salaryProfileCurrentOCT[0] == null ? "" : salaryProfileCurrentOCT[0].root; + const formattedData = salaryProfileCurrentOCT.map((profile, index) => { + //งวดปีก่อนหน้า + const matchedAPRProfileOld = salaryProfilePerviousAPR.find(aprProfile_old => aprProfile_old.citizenId === profile.citizenId); + const matchedOCTProfileOld = salaryProfilePerviousOCT.find(octProfile_old => octProfile_old.citizenId === profile.citizenId); + const amountUseAPR_Old = matchedAPRProfileOld ? matchedAPRProfileOld.amountUse : 0; + const amountUseOCT_Old = matchedOCTProfileOld ? matchedOCTProfileOld.amountUse : 0; + const amountUseOld = amountUseAPR_Old + amountUseOCT_Old; + + //งวดปีปัจจุบัน + const matchedAPRProfile = salaryProfileCurrentAPR.find(aprProfile => aprProfile.citizenId === profile.citizenId); + const matchedOCTProfile = salaryProfileCurrentOCT.find(octProfile => octProfile.citizenId === profile.citizenId); + const amountUseAPR = matchedAPRProfile ? matchedAPRProfile.amountUse : 0; + const amountUseOCT = matchedOCTProfile ? matchedOCTProfile.amountUse : 0; + const amountUse = amountUseAPR + amountUseOCT; + + const fullNameParts = [ profile.child4, profile.child3, @@ -433,8 +449,8 @@ import { profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : null, - amountUseOld: null, - amountUse: null, + amountUseOld: amountUseOld ? Extension.ToThaiNumber(amountUseOld.toLocaleString()) : null, + amountUse: amountUse ? Extension.ToThaiNumber(amountUse.toLocaleString()) : null, reason: null, }; });