From 13545d3f3c7407e4d993573c479537f304bf997e Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Fri, 18 Jul 2025 14:39:22 +0700 Subject: [PATCH 1/3] import salary temp --- src/controllers/ImportDataController.ts | 137 ++++++++++++++++ src/entities/EMPLOYEETEMP.ts | 203 ++++++++++++++++++++++++ 2 files changed, 340 insertions(+) create mode 100644 src/entities/EMPLOYEETEMP.ts diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index d1fb5b20..369c9ed6 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -95,6 +95,7 @@ import { ProfileLeaves } from "../entities/ProfileLeaves"; import { ProfileSalaryTemp } from "../entities/ProfileSalaryTemp"; import { ProfileTraining } from "../entities/ProfileTraining"; import { ProfileTrainings } from "../entities/ProfileTrainings"; +import { EMPLOYEETEMP } from "../entities/EMPLOYEETEMP"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") @@ -155,6 +156,7 @@ export class ImportDataController extends Controller { private IMPORT_ORGRepo = AppDataSource.getRepository(IMPORT_ORG); private OFFICERRepo = AppDataSource.getRepository(OFFICER); private EMPLOYEERepo = AppDataSource.getRepository(EMPLOYEE); + private EMPLOYEETEMPRepo = AppDataSource.getRepository(EMPLOYEETEMP); private positionEmpRepo = AppDataSource.getRepository(EmployeePosition); private positionRepo = AppDataSource.getRepository(Position); @@ -472,6 +474,141 @@ export class ImportDataController extends Controller { return new HttpSuccess(); } + /** + * @summary ทะเบียนประวัติ ลูกจ้างชั่วคราว + */ + @Post("uploadProfile-EmployeeTemp") + async UploadFileSQLTemp(@Request() request: { user: Record }) { + // const existingProfile = await this.profileEmpRepo.find({ + // where: { employeeClass: "TEMP" }, + // select: ["citizenId"], + // }); + + const EMPLOYEE = await this.EMPLOYEETEMPRepo.find({ + // where: { CIT: Not(In(existingProfile.map((x) => x.citizenId))) }, + }); + let rowCount = 0; + let _null: any = null; + let profile: any; + for await (const item of EMPLOYEE) { + rowCount++; + let type_: any = null; + let level_: any = null; + profile = null; + profile = new ProfileEmployee(); + + if (item.CIT.toString() == "1101801164891") { + // profile.id = existingProfile.id; + continue; + } + const existingProfile = await this.profileEmpRepo.findOne({ + where: { employeeClass: "TEMP", citizenId: item.CIT.toString() }, + }); + if (existingProfile) { + profile.id = existingProfile.id; + // continue; + } else { + continue; + } + + var positionType = ""; + var positionLevel = 0; + const value2 = item.POSITION_LEVEL; + // const part1 = workLevel.split("/")[0]; // "ส 2" + // const value2 = part1.split(" ")[1]; // "2" + if (value2) { + positionLevel = parseInt(value2); + } + if (item.CATEGORY_SAL_CODE == "11") { + positionType = "บริการพื้นฐาน"; + // positionLevel = "ปฏิบัติงาน"; + } else if (item.CATEGORY_SAL_CODE == "12") { + positionType = "สนับสนุน"; + // positionLevel = "ชำนาญงาน"; + } else if (item.CATEGORY_SAL_CODE == "13") { + positionType = "ช่าง"; + // positionLevel = "อาวุโส"; + } + if (positionType) { + type_ = await this.posTypeEmpRepo.findOne({ + where: { posTypeName: positionType }, + }); + } + if (positionLevel) { + if (type_ == null) { + level_ = await this.posLevelEmpRepo.findOne({ + where: { + posLevelName: positionLevel, + }, + }); + } else { + level_ = await this.posLevelEmpRepo.findOne({ + where: { + posLevelName: positionLevel, + posTypeId: type_.id, + }, + }); + } + } + + let BORN = item.BORN; + if (item.BORN) { + // const [datePart] = item.BORN.split(" "); + // const [day, month, year] = datePart.split("/"); + // BORN = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + let BEGIN_ENTRY_DATE = item.BEGIN_ENTRY_DATE; + if (item.BEGIN_ENTRY_DATE) { + // const [datePart] = item.BEGIN_ENTRY_DATE.split(" "); + // const [day, month, year] = datePart.split("/"); + // BEGIN_ENTRY_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + + profile.citizenId = item.CIT; + profile.rank = + item.RANK_NAME == "" || + item.RANK_NAME == "นาย" || + item.RANK_NAME == "นาง" || + item.RANK_NAME == "นางสาว" + ? null + : item.RANK_NAME; + profile.prefix = item.RANK_NAME == "" ? null : item.RANK_NAME; + profile.prefixMain = + item.RANK_NAME == "" || + (item.RANK_NAME != "นาย" && item.RANK_NAME != "นาง" && item.RANK_NAME != "นางสาว") + ? null + : item.RANK_NAME; + profile.firstName = item.FNAME == "" ? null : item.FNAME; + profile.lastName = item.LNAME == "" ? null : item.LNAME; + profile.employeeClass = "TEMP"; + profile.gender = item.SEX == "1" ? "ชาย" : item.SEX == "2" ? "หญิง" : _null; + profile.birthDate = BORN == "" ? _null : new Date(BORN); + profile.dateAppoint = BEGIN_ENTRY_DATE == "" ? _null : new Date(BEGIN_ENTRY_DATE); + profile.dateStart = BEGIN_ENTRY_DATE == "" ? _null : new Date(BEGIN_ENTRY_DATE); + profile.dateRetire = BORN == "" ? _null : calculateRetireDate(new Date(BORN)); + profile.dateRetireLaw = BORN == "" ? _null : calculateRetireLaw(new Date(BORN)); + profile.position = item.WORK_LINE_NAME == "" ? null : item.WORK_LINE_NAME.split(" ")[0]; + profile.posTypeId = + type_ != null && type_.posTypeName == positionType && type_ ? type_.id : null; + profile.posLevelId = + level_ != null && level_.posLevelName == positionLevel && level_ ? level_.id : null; + + profile.amount = item.SALARY == "" ? 0 : Number(item.SALARY); + profile.salaryLevel = item.SALARY == "" ? null : Number(item.SALARY_LEVEL_CODE); + profile.createdUserId = request.user.sub; + profile.createdFullName = request.user.name; + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + profile.createdAt = new Date(); + profile.lastUpdatedAt = new Date(); + + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + + await this.profileEmpRepo.save(profile); + } + return new HttpSuccess(); + } + /** * @summary เงินเดือน ข้าราชการ */ diff --git a/src/entities/EMPLOYEETEMP.ts b/src/entities/EMPLOYEETEMP.ts new file mode 100644 index 00000000..571bc015 --- /dev/null +++ b/src/entities/EMPLOYEETEMP.ts @@ -0,0 +1,203 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("EMPLOYEETEMP") +export class EMPLOYEETEMP { + @PrimaryGeneratedColumn() + id!: number; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // RET_YEAR: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ID: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // MP_CATEGORY: string; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // MP_LEVEL: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BORN: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BEGIN_ENTRY_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SEX: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + WORK_LINE_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SALARY: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CATEGORY_SAL_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SALARY_LEVEL_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LEVEL_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + WORK_LEVEL: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POSITION_LEVEL: string; +} From 9121eebcdea938c618966c516606c35073402615 Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 18 Jul 2025 14:40:50 +0700 Subject: [PATCH 2/3] =?UTF-8?q?=E0=B8=96=E0=B8=B6=E0=B8=87=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=88=E0=B8=81=E0=B8=A3=E0=B8=A3=E0=B8=A1=E0=B8=9B?= =?UTF-8?q?=E0=B8=B1=E0=B9=8A=E0=B8=A1=E0=B8=A5=E0=B8=87=20leaveDate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 1 + src/controllers/ProfileEmployeeController.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 9bdb33ff..22abc1de 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -10297,6 +10297,7 @@ export class ProfileController extends Controller { profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; + profile.leaveDate = requestBody.dateLeave; profile.leaveType = "RETIRE_DECEASED"; // profile.position = _null; // profile.posLevelId = _null; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 9331c1a2..00a04ca2 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -5702,6 +5702,8 @@ export class ProfileEmployeeController extends Controller { profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; + profile.leaveDate = requestBody.dateLeave; + profile.leaveType = "RETIRE_DECEASED"; // profile.position = _null; // profile.posLevelId = _null; // profile.posTypeId = _null; @@ -5713,7 +5715,6 @@ export class ProfileEmployeeController extends Controller { profile.isActive = false; } } - profile.leaveType = "RETIRE_DECEASED"; await this.profileRepo.save(profile); if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); From 8d9ffda872b5f6a254eac8b07f8c390edad392cb Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 18 Jul 2025 15:23:49 +0700 Subject: [PATCH 3/3] =?UTF-8?q?=E0=B8=81=E0=B8=A3=E0=B8=93=E0=B8=B5?= =?UTF-8?q?=E0=B8=96=E0=B8=B6=E0=B8=87=E0=B9=81=E0=B8=81=E0=B9=88=E0=B8=81?= =?UTF-8?q?=E0=B8=A3=E0=B8=A3=E0=B8=A1=E0=B9=83=E0=B8=8A=E0=B9=89=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B9=80=E0=B8=AA?= =?UTF-8?q?=E0=B8=B5=E0=B8=A2=E0=B8=8A=E0=B8=B5=E0=B8=A7=E0=B8=B4=E0=B8=95?= =?UTF-8?q?=E0=B8=9B=E0=B8=B1=E0=B9=8A=E0=B8=A1=E0=B8=A5=E0=B8=87=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=84=E0=B8=B3?= =?UTF-8?q?=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A1=E0=B8=B5=E0=B8=9C?= =?UTF-8?q?=E0=B8=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 2 +- src/controllers/ProfileEmployeeController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 22abc1de..c63fc972 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -10268,7 +10268,7 @@ export class ProfileController extends Controller { orgChild4: orgChild4Ref?.orgChild4Name, commandYear: new Date().getFullYear() + 543, // commandDateSign: new Date(), - commandDateAffect: new Date(), + commandDateAffect: requestBody.dateLeave, commandCode: "16", commandName: "พ้นจากราชการ", posNoAbb: shortName, diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 00a04ca2..d6c198d9 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -5674,7 +5674,7 @@ export class ProfileEmployeeController extends Controller { orgChild4: orgChild4Ref?.orgChild4Name, commandYear: new Date().getFullYear() + 543, // commandDateSign: new Date(), - commandDateAffect: new Date(), + commandDateAffect: requestBody.dateLeave, commandCode: "16", commandName: "พ้นจากราชการ", posNoAbb: shortName,