diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 77e72663..72ad4fda 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -3031,7 +3031,7 @@ export class ProfileController extends Controller { * * @param {string} id Id ทะเบียนประวัติ */ - @Put("salary/{id}") + @Post("leave/{id}") async updateLeaveUser( @Path() id: string, @Body() diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index c057a9c4..251ce0a4 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -27,7 +27,7 @@ import { CreateProfileEmployee, UpdateProfileEmployee, ProfileEmployeeHistory, - UpdatePositionTempProfileEmployee + UpdatePositionTempProfileEmployee, } from "../entities/ProfileEmployee"; import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosType } from "../entities/EmployeePosType"; @@ -505,7 +505,7 @@ export class ProfileEmployeeController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } - if(body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == ""){ + if (body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == "") { body.employeeClass = "PERM"; } if (!["PERM", "TEMP"].includes(body.employeeClass.toLocaleUpperCase())) { @@ -520,7 +520,7 @@ export class ProfileEmployeeController extends Controller { profile.dateRetire = calculateRetireDate(profile.birthDate); profile.dateRetireLaw = calculateRetireLaw(profile.birthDate); profile.citizenId = Extension.CheckCitizen(profile.citizenId); - profile.employeeClass = profile.employeeClass.toLocaleUpperCase() + profile.employeeClass = profile.employeeClass.toLocaleUpperCase(); await this.profileRepo.save(profile); return new HttpSuccess(); } @@ -570,7 +570,7 @@ export class ProfileEmployeeController extends Controller { }), ); - if(body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == ""){ + if (body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == "") { body.employeeClass = "PERM"; } if (!["PERM", "TEMP"].includes(body.employeeClass.toLocaleUpperCase())) { @@ -796,35 +796,55 @@ export class ProfileEmployeeController extends Controller { position: _data.position, posNo: shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, - govAge: Extension.CalculateGovAge(_data.dateAppoint,0,0), - age: Extension.CalculateAgeStrV2(_data.birthDate,0,0), - dateAppoint: _data.dateAppoint, + govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + dateAppoint: _data.dateAppoint, dateStart: _data.dateStart, - createdAt: _data.createdAt, + createdAt: _data.createdAt, dateRetireLaw: _data.dateRetireLaw, - draftOrganizationOrganization: - _data.nodeTemp == "0" ? _data.rootTemp : - _data.nodeTemp == "1" ? _data.child1Temp : - _data.nodeTemp == "2" ? _data.child2Temp : - _data.nodeTemp == "3" ? _data.child3Temp : - _data.nodeTemp == "4" ? _data.child4Temp : null, + draftOrganizationOrganization: + _data.nodeTemp == "0" + ? _data.rootTemp + : _data.nodeTemp == "1" + ? _data.child1Temp + : _data.nodeTemp == "2" + ? _data.child2Temp + : _data.nodeTemp == "3" + ? _data.child3Temp + : _data.nodeTemp == "4" + ? _data.child4Temp + : null, draftPositionEmployee: _data.positionTemp, draftOrgEmployeeStatus: _data.statusTemp, node: _data.nodeTemp, nodeId: _data.nodeIdTemp, - nodeName: _data.nodeTemp == "0" ? _data.rootTemp : - _data.nodeTemp == "1" ? _data.child1Temp : - _data.nodeTemp == "2" ? _data.child2Temp : - _data.nodeTemp == "3" ? _data.child3Temp : - _data.nodeTemp == "4" ? _data.child4Temp : null, - nodeShortName: _data.nodeTemp == "0" ? _data.rootShortNameTemp : - _data.nodeTemp == "1" ? _data.child1ShortNameTemp : - _data.nodeTemp == "2" ? _data.child1ShortNameTemp : - _data.nodeTemp == "3" ? _data.child3ShortNameTemp : - _data.nodeTemp == "4" ? _data.child4ShortNameTemp: null, + nodeName: + _data.nodeTemp == "0" + ? _data.rootTemp + : _data.nodeTemp == "1" + ? _data.child1Temp + : _data.nodeTemp == "2" + ? _data.child2Temp + : _data.nodeTemp == "3" + ? _data.child3Temp + : _data.nodeTemp == "4" + ? _data.child4Temp + : null, + nodeShortName: + _data.nodeTemp == "0" + ? _data.rootShortNameTemp + : _data.nodeTemp == "1" + ? _data.child1ShortNameTemp + : _data.nodeTemp == "2" + ? _data.child1ShortNameTemp + : _data.nodeTemp == "3" + ? _data.child3ShortNameTemp + : _data.nodeTemp == "4" + ? _data.child4ShortNameTemp + : null, root: _data.rootTemp ? _data.rootTemp : null, rootId: _data.rootIdTemp ? _data.rootIdTemp : null, - rootShortName: _data.rootShortNameTemp ?_data.rootShortNameTemp : null, + rootShortName: _data.rootShortNameTemp ? _data.rootShortNameTemp : null, child1: _data.child1Temp ? _data.child1Temp : null, child1Id: _data.child1IdTemp ? _data.child1IdTemp : null, child1ShortName: _data.child1ShortNameTemp ? _data.child1ShortNameTemp : null, @@ -837,7 +857,6 @@ export class ProfileEmployeeController extends Controller { child4: _data.child4Temp ? _data.child4Temp : null, child4Id: _data.child4IdTemp ? _data.child4IdTemp : null, child4ShortName: _data.child4ShortNameTemp ? _data.child4ShortNameTemp : null, - }; }), ); @@ -1591,7 +1610,7 @@ export class ProfileEmployeeController extends Controller { case 1: { const data = await this.child1Repository.findOne({ where: { id: body.nodeId }, - relations: ["orgRoot"] + relations: ["orgRoot"], }); if (data != null) { profileEmp.rootIdTemp = data.orgRoot.id; @@ -1605,7 +1624,7 @@ export class ProfileEmployeeController extends Controller { case 2: { const data = await this.child2Repository.findOne({ where: { id: body.nodeId }, - relations: ["orgRoot", "orgChild1"] + relations: ["orgRoot", "orgChild1"], }); if (data != null) { profileEmp.rootIdTemp = data.orgRoot.id; @@ -1622,7 +1641,7 @@ export class ProfileEmployeeController extends Controller { case 3: { const data = await this.child3Repository.findOne({ where: { id: body.nodeId }, - relations: ["orgRoot", "orgChild1", "orgChild2"] + relations: ["orgRoot", "orgChild1", "orgChild2"], }); if (data != null) { profileEmp.rootIdTemp = data.orgRoot.id; @@ -1642,7 +1661,7 @@ export class ProfileEmployeeController extends Controller { case 4: { const data = await this.child4Repository.findOne({ where: { id: body.nodeId }, - relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"] + relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"], }); if (data != null) { profileEmp.rootIdTemp = data.orgRoot.id; @@ -2328,4 +2347,29 @@ export class ProfileEmployeeController extends Controller { }); return new HttpSuccess(formattedData); } + + /** + * API อัพเดทเกษียณ + * + * @summary อัพเดทเกษียณ (ADMIN) + * + * @param {string} id Id ทะเบียนประวัติ + */ + @Post("leave/{id}") + async updateLeaveUser( + @Path() id: string, + @Body() + requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date }, + ) { + const profile = await this.profileRepo.findOne({ + where: { id: id }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + profile.isLeave = requestBody.isLeave; + profile.leaveReason = requestBody.leaveReason; + profile.dateLeave = requestBody.dateLeave; + await this.profileRepo.save(profile); + return new HttpSuccess(); + } } diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 21f3855b..6bab64ca 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -181,6 +181,27 @@ export class ProfileEmployee extends EntityBase { }) isProbation: boolean; + @Column({ + comment: "เกษียณ", + default: false, + }) + isLeave: boolean; + + @Column({ + nullable: true, + comment: "เหตุผลเกษียณ", + default: null, + }) + leaveReason: string; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันพ้นราชการ", + default: null, + }) + dateLeave: Date; + @Column({ nullable: true, type: "datetime", @@ -723,16 +744,16 @@ export type UpdateProfileAddressEmployee = { }; export type UpdatePositionTempProfileEmployee = { - posmasterId: string ; - node: number ; - nodeId: string ; - orgRevisionId: string ; - positionId: string ; - posMasterNo: string ; - position: string ; - positionField: string ; + posmasterId: string; + node: number; + nodeId: string; + orgRevisionId: string; + positionId: string; + posMasterNo: string; + position: string; + positionField: string; posTypeId: string | null; - posTypeName: string ; + posTypeName: string; posLevelId: string | null; - posLevelName: string ; -}; \ No newline at end of file + posLevelName: string; +}; diff --git a/src/migration/1717688401552-update_table_salaryProfileemp_add_temp.ts b/src/migration/1717688401552-update_table_salaryProfileemp_add_temp.ts new file mode 100644 index 00000000..b5b03822 --- /dev/null +++ b/src/migration/1717688401552-update_table_salaryProfileemp_add_temp.ts @@ -0,0 +1,24 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSalaryProfileempAddTemp1717688401552 implements MigrationInterface { + name = 'UpdateTableSalaryProfileempAddTemp1717688401552' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`isLeave\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`leaveReason\` varchar(255) NULL COMMENT 'เหตุผลเกษียณ'`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`isLeave\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`leaveReason\` varchar(255) NULL COMMENT 'เหตุผลเกษียณ'`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`dateLeave\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`leaveReason\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`isLeave\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`dateLeave\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`leaveReason\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`isLeave\``); + } + +}