From 58afa49fcdcae7e274564432a084208518a44764 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 28 Apr 2026 15:17:16 +0700 Subject: [PATCH] =?UTF-8?q?insert=20profileSalary=20=E0=B9=80=E0=B8=94?= =?UTF-8?q?=E0=B8=B4=E0=B8=A1=E0=B9=80=E0=B8=82=E0=B9=89=E0=B8=B2=E0=B8=A1?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=B1=E0=B8=87=20profile=20=E0=B9=83?= =?UTF-8?q?=E0=B8=AB=E0=B8=A1=E0=B9=88=20#232?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index e97abce5..ba498c1e 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -6510,6 +6510,7 @@ export class CommandController extends Controller { relations: ["roleKeycloaks", "profileInsignias", "profileAvatars"], }); let _oldInsigniaIds: string[] = []; + let _oldSalaries: any[] = []; //ลูกจ้างประจำ หรือ บุคคลภายนอก if (!profile) { //กรณีลูกจ้างประจำมาสอบเป็นข้าราชการ ต้อง update สถานะโปรไฟล์เดิม @@ -6618,6 +6619,11 @@ export class CommandController extends Controller { profile.isLeave && ["PLACEMENT_TRANSFER", "RETIRE_RESIGN"].includes(profile.leaveType) ) { + //ดึง profileSalary เดิม + _oldSalaries = await this.salaryRepo.find({ + where: { profileId: profile.id }, + order: { order: "ASC" }, + }); if (profile.profileInsignias.length > 0) { _oldInsigniaIds = profile.profileInsignias?.map((x: any) => x.id) ?? []; } @@ -6856,6 +6862,23 @@ export class CommandController extends Controller { await this.profileFamilyMotherHistoryRepo.save(motherHistory, { data: req }); } //Salary + //insert profileSalary อันเก่า กรณีพ้นราชการแล้วกลับมาบรรจุ + if (_oldSalaries.length > 0) { + await Promise.all( + _oldSalaries.map(async (oldSal) => { + const profileSal: any = new ProfileSalary(); + Object.assign(profileSal, { ...oldSal, ...meta }); + const salaryHistory = new ProfileSalaryHistory(); + Object.assign(salaryHistory, { ...profileSal, id: undefined }); + profileSal.profileId = profile.id; + await this.salaryRepo.save(profileSal, { data: req }); + setLogDataDiff(req, { before, after: profileSal }); + salaryHistory.profileSalaryId = profileSal.id; + await this.salaryHistoryRepo.save(salaryHistory, { data: req }); + }), + ); + } + //insert item.bodySalarys ต่อจากที่ insert เดิมไปแล้ว if (item.bodySalarys && item.bodySalarys != null) { const dest_item = await this.salaryRepo.findOne({ where: { profileId: profile.id },