From 77678b1e4020dc30bb4ce22e716854056d988dc7 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 25 Feb 2025 14:59:02 +0700 Subject: [PATCH 1/3] fix command salary and query gov1-03 --- src/controllers/ReportController.ts | 255 +++++++++++++++++++++------- 1 file changed, 191 insertions(+), 64 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 536c623..4e38f6f 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1090,64 +1090,13 @@ export class ReportController extends Controller { }, }); } - const rootName = await this.salaryOrgRepository.findOne({ - where: { - rootId: rootId, - }, - select: ["root"], - }); - //รอบปีก่อนๆ - const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({ - where: { - period: "APR", - year: salaryPeriod.year - 2, - isActive: true, - }, - }); - const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({ - where: { - period: "OCT", - year: salaryPeriod.year - 2, - isActive: true, - }, - }); - // console.log(">>>>1",salaryPeriodIncrease1_APR); - - let salaryOrg1_APR = null; - if (salaryPeriodIncrease1_APR) { - salaryOrg1_APR = await this.salaryOrgRepository.findOne({ - where: { - salaryPeriodId: salaryPeriodIncrease1_APR?.id, - // rootId: rootId, - root: rootName?.root, - snapshot: "SNAP1", - group: convertGroup, - }, - }); - } - // console.log(">>>>2",salaryOrg1_APR); - - let salaryOrg1_OCT = null; - if (salaryPeriodIncrease1_OCT) { - salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ - where: { - salaryPeriodId: salaryPeriodIncrease1_OCT?.id, - // rootId: rootId, - root: rootName?.root, - snapshot: "SNAP1", - group: convertGroup, - }, - }); - } - - const salaryProfile1 = await this.salaryProfileRepository.find({ - where: { - salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), - type: Not(In(["NONE", "PENDING"])), - }, - }); - // console.log(">>>>3",salaryProfile1); - + // const rootName = await this.salaryOrgRepository.findOne({ + // where: { + // rootId: rootId, + // }, + // select: ["root"], + // }); + //รอบปีก่อนหน้า const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -1170,7 +1119,8 @@ export class ReportController extends Controller { where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, // rootId: rootId, - root: rootName?.root, + // root: rootName?.root, + rootId:salaryOrg?.rootDnaId, snapshot: "SNAP1", group: convertGroup, }, @@ -1183,7 +1133,8 @@ export class ReportController extends Controller { where: { salaryPeriodId: salaryPeriodIncrease2_OCT?.id, // rootId: rootId, - root: rootName?.root, + // root: rootName?.root, + rootId:salaryOrg?.rootDnaId, snapshot: "SNAP1", group: convertGroup, }, @@ -1197,6 +1148,56 @@ export class ReportController extends Controller { }, }); + //รอบปีก่อนๆ + const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({ + where: { + period: "APR", + year: salaryPeriod.year - 2, + isActive: true, + }, + }); + const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({ + where: { + period: "OCT", + year: salaryPeriod.year - 2, + isActive: true, + }, + }); + + let salaryOrg1_APR = null; + if (salaryPeriodIncrease1_APR) { + salaryOrg1_APR = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease1_APR?.id, + // rootId: rootId, + // root: rootName?.root, + rootId:salaryOrg2_APR?.rootDnaId, + snapshot: "SNAP1", + group: convertGroup, + }, + }); + } + + let salaryOrg1_OCT = null; + if (salaryPeriodIncrease1_OCT) { + salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease1_OCT?.id, + // rootId: rootId, + // root: rootName?.root, + rootId:salaryOrg2_APR?.rootDnaId, + snapshot: "SNAP1", + group: convertGroup, + }, + }); + } + + const salaryProfile1 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), + type: Not(In(["NONE", "PENDING"])), + }, + }); const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))); const yearIncrease1 = Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 2)), @@ -2504,12 +2505,132 @@ export class ReportController extends Controller { @Path() group: string, ) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + // period: "OCT",?? + isActive: true, + }, + }); + + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } + + //ปีก่อนหน้า + const salaryOldPeriod = await this.salaryPeriodRepository.findOne({ + where: { + year: salaryPeriod?.year - 1, + period: "OCT", + }, + }); + + const convertGroup = group.toUpperCase(); + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodId, + rootId: rootId, + snapshot: "SNAP2", + group: convertGroup, + }, + relations: ["salaryProfiles"], + }); + + //ปีก่อนหน้า + let salaryOrgPrevious = null; + if (salaryOldPeriod) { + salaryOrgPrevious = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryOldPeriod?.id, + rootDnaId: salaryOrg?.rootDnaId, + snapshot: "SNAP1", + group: convertGroup, + }, + }); + } + + const salaryProfile = await this.salaryProfileRepository.find({ + relations: ["salaryOrg"], + where: { + salaryOrgId: In([salaryOrg?.id]), + // amountSpecial: MoreThan(0), + }, + order: { + salaryOrg: { + group: "ASC", + }, + posMasterNo: "ASC", + }, + }); + const salaryProfilePrevious = await this.salaryProfileRepository.find({ + relations: ["salaryOrg"], + where: { + salaryOrgId: In([salaryOrgPrevious?.id]), + }, + order: { + salaryOrg: { + group: "ASC", + }, + posMasterNo: "ASC", + }, + }); + + const formattedData = salaryProfile.map((item, index) => ({ + no: Extension.ToThaiNumber(String(index + 1)), + fullname: item.prefix + item.firstName + " " + item.lastName, + root: item.root??"-", + position: item.position??"-", + posMasterNo: + Extension.ToThaiNumber(item.orgShortName) + Extension.ToThaiNumber(String(item.posMasterNo)), + posTypeCurrent: item.posType??"-", + posLevelCurrent: item.posLevel??"-", + amountCurrent: item.amount? Extension.ToThaiNumber(item.amount.toLocaleString()):"-", + posTypePrevious: salaryProfilePrevious.length > 0 + ? (() => { + const filteredType = salaryProfilePrevious + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.posType); + const posType = filteredType[0]; + return posType + ? posType : "-"; + })() + : "-", + posLevelPrevious: salaryProfilePrevious.length > 0 + ? (() => { + const filteredLevel = salaryProfilePrevious + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.posLevel); + const posLevel = filteredLevel[0]; + return posLevel + ? posLevel : "-"; + })() + : "-", + amountPrevious: salaryProfilePrevious.length > 0 + ? (() => { + const filteredAmount = salaryProfilePrevious + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.amount); + const amount = filteredAmount[0]; + return amount + ? Extension.ToThaiNumber(amount.toLocaleString()):"-" + })() + : "-", + deduction: "-", //เงินปรับลด + promote: item.amountUse?Extension.ToThaiNumber(item.amountUse.toLocaleString()):"-", //เงินเลื่อนขั้น + qualification: "-", //เงินปรับวุฒิ + adjustRate: "-", //เงินปรับอัตรา + newRate: "-", //อัตราตั้งใหม่ + specialPromote: "-", //ลำดับการเลื่อนกรณีพิเศษ + remark: item.remark??"-", + temporaryPayment: "-", //ถือจ่ายชั่วคราวขั้น + })) + return new HttpSuccess({ template: "gov2-10", reportName: "gov2-10", data: { - + data: formattedData, }, }); } @@ -7820,7 +7941,8 @@ export class ReportController extends Controller { body: { refIds: { refId: string; - commandAffectDate: Date | null; + // commandAffectDate: Date | null;//เก่า + commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG) commandNo: string | null; commandId?: string | null; commandYear: number; @@ -7894,11 +8016,15 @@ export class ReportController extends Controller { body: { refIds: { refId: string; - commandAffectDate: Date | null; + // commandAffectDate: Date | null;//เก่า + commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG) + commandDateSign?: Date | null commandNo: string | null; commandId: string | null; commandYear: number; - templateDoc: string | null; + commandCode?: string | null; + commandName?: string | null; + templateDoc?: string | null; amount: Double | null; amountSpecial: Double | null; positionSalaryAmount: Double | null; @@ -7906,6 +8032,7 @@ export class ReportController extends Controller { mpCee?: string | null; refCommandCode?: string | null; refCommandName?: string | null; + remark?: string | null; }[]; }, @Request() request: RequestWithUser, From 11c838f57aa3e384b4a885715c738813d442149f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 25 Feb 2025 17:07:55 +0700 Subject: [PATCH 2/3] fix bug --- src/controllers/ReportController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 2868b20..bef8747 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -8050,6 +8050,7 @@ export class ReportController extends Controller { id: v.refId, }, }); + if (salary != null) { await new CallAPI() .PostData(request, "/org/profile-employee/salary/update", { @@ -8060,12 +8061,11 @@ export class ReportController extends Controller { amountSpecial: v.amountSpecial, positionSalaryAmount: v.positionSalaryAmount, mouthSalaryAmount: v.mouthSalaryAmount, - posNo: salary.posMasterNo.toString(), + posNo: salary.posMasterNo != null?salary.posMasterNo.toString():null, posNoAbb: salary.orgShortName, positionName: salary.position, positionType: salary.posType, - positionLevel: salary.posLevel, - commandId: v.commandId, + positionLevel: salary.posLevel != null?salary.posLevel.toString():null, remark: v.remark, orgRoot: salary.root, orgChild1: salary.child1, From ee685f0dab225b54514bff84b6324d403e407841 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 26 Feb 2025 11:02:33 +0700 Subject: [PATCH 3/3] fix --- src/controllers/ReportController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index bef8747..5b95cc5 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -8076,6 +8076,7 @@ export class ReportController extends Controller { commandName: v.commandName, commandNo: v.commandNo, commandYear: v.commandYear, + commandId: v.commandId, }) .then(async () => { const before = null;