Fix ลูกจ้างเลือกเข้าตำแหน่ง #1752 && #1751

This commit is contained in:
Bright 2025-08-18 10:57:49 +07:00
parent ce2114131d
commit db51c0d7b2

View file

@ -17,6 +17,7 @@ import {
import permission from "../interfaces/permission";
import { OrgRevision } from "../entities/OrgRevision";
import { In } from "typeorm";
import { ProfileSalary } from "../entities/ProfileSalary";
@Route("api/v1/org/profile-employee/government")
@Tags("ProfileEmployeeGovernment")
@Security("bearerAuth")
@ -26,6 +27,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
private positionRepo = AppDataSource.getRepository(EmployeePosition);
private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
/**
*
* @summary
@ -150,32 +152,32 @@ export class ProfileGovernmentEmployeeController extends Controller {
const record = await this.profileEmployeeRepo.findOne({
where: {
id: profileEmployeeId,
profileSalary: {
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
]),
}
// profileSalary: {
// commandCode: In([
// "0",
// "9",
// "1",
// "2",
// "3",
// "4",
// "8",
// "10",
// "11",
// "12",
// "13",
// "14",
// "15",
// "16",
// ]),
// }
},
relations: ["posType", "posLevel", "profileSalary"],
order: {
profileSalary: {
order: "DESC",
createdAt: "DESC"
}
}
relations: ["posType", "posLevel"/*, "profileSalary"*/],
// order: {
// profileSalary: {
// order: "DESC",
// createdAt: "DESC"
// }
// }
});
const posMaster = await this.posMasterRepo.findOne({
where: {
@ -216,16 +218,55 @@ export class ProfileGovernmentEmployeeController extends Controller {
}
}
let _OrgLeave:any = []
if (record?.isLeave && record?.profileSalary.length > 0) {
let orgLeave:string = ""
let posNoLeave:string = ""
if (record?.isLeave /*&& record?.profileSalary.length > 0*/) {
const profileSalary = await this.salaryRepo.find({
select: [
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
"posNoAbb",
"posNo"
],
where: {
profileEmployeeId: profileEmployeeId,
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
]),
},
order: {
order: "DESC",
createdAt: "DESC"
}
});
_OrgLeave = [
record?.profileSalary[0].orgChild4 ? record?.profileSalary[0].orgChild4 : null,
record?.profileSalary[0].orgChild3 ? record?.profileSalary[0].orgChild3 : null,
record?.profileSalary[0].orgChild2 ? record?.profileSalary[0].orgChild2 : null,
record?.profileSalary[0].orgChild1 ? record?.profileSalary[0].orgChild1 : null,
record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null,
profileSalary.length > 0 && profileSalary[0].orgChild4 ? profileSalary[0].orgChild4 : null,
profileSalary.length > 0 && profileSalary[0].orgChild3 ? profileSalary[0].orgChild3 : null,
profileSalary.length > 0 && profileSalary[0].orgChild2 ? profileSalary[0].orgChild2 : null,
profileSalary.length > 0 && profileSalary[0].orgChild1 ? profileSalary[0].orgChild1 : null,
profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
];
orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n");
posNoLeave = profileSalary.length > 0
? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}`
: ""
}
const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n");
const data = {
org: record?.isLeave == false ? org : orgLeave, //สังกัด
position: record?.position, //ตำแหน่ง
@ -235,9 +276,9 @@ export class ProfileGovernmentEmployeeController extends Controller {
: `${record?.posType?.posTypeShortName ?? ""} ${record?.posLevel?.posLevelName ?? ""}`, //ระดับ
posMasterNo: record?.isLeave == false
? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`
: record && record?.profileSalary.length > 0
: posNoLeave/*record && record?.profileSalary.length > 0
? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}`
: null, //เลขที่ตำแหน่ง
: null*/, //
posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท
dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ
dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ
@ -265,29 +306,29 @@ export class ProfileGovernmentEmployeeController extends Controller {
const record = await this.profileEmployeeRepo.findOne({
where: {
id: profileEmployeeId,
profileSalary:{
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
]),
}
// profileSalary:{
// commandCode: In([
// "0",
// "9",
// "1",
// "2",
// "3",
// "4",
// "8",
// "10",
// "11",
// "12",
// "13",
// "14",
// "15",
// "16",
// ]),
// }
},
relations: {
posType: true,
posLevel: true,
profileSalary: true
// profileSalary: true
},
});
const posMaster = await this.posMasterRepo.findOne({
@ -329,16 +370,55 @@ export class ProfileGovernmentEmployeeController extends Controller {
}
}
let _OrgLeave:any = []
if (record?.isLeave && record?.profileSalary.length > 0) {
let orgLeave:string = ""
let posNoLeave:string = ""
if (record?.isLeave /*&& record?.profileSalary.length > 0*/) {
const profileSalary = await this.salaryRepo.find({
select: [
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
"posNoAbb",
"posNo"
],
where: {
profileEmployeeId: profileEmployeeId,
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
]),
},
order: {
order: "DESC",
createdAt: "DESC"
}
});
_OrgLeave = [
record?.profileSalary[0].orgChild4 ? record?.profileSalary[0].orgChild4 : null,
record?.profileSalary[0].orgChild3 ? record?.profileSalary[0].orgChild3 : null,
record?.profileSalary[0].orgChild2 ? record?.profileSalary[0].orgChild2 : null,
record?.profileSalary[0].orgChild1 ? record?.profileSalary[0].orgChild1 : null,
record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null,
profileSalary.length > 0 && profileSalary[0].orgChild4 ? profileSalary[0].orgChild4 : null,
profileSalary.length > 0 && profileSalary[0].orgChild3 ? profileSalary[0].orgChild3 : null,
profileSalary.length > 0 && profileSalary[0].orgChild2 ? profileSalary[0].orgChild2 : null,
profileSalary.length > 0 && profileSalary[0].orgChild1 ? profileSalary[0].orgChild1 : null,
profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
];
orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n");
posNoLeave = profileSalary.length > 0
? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}`
: ""
}
const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n");
const data = {
org: record?.isLeave == false ? org : orgLeave, //สังกัด
position: record?.position, //ตำแหน่ง
@ -350,9 +430,9 @@ export class ProfileGovernmentEmployeeController extends Controller {
? posMaster == null
? null
: `${orgShortName} ${posMaster.posMasterNo}`
: record && record.profileSalary.length > 0
: posNoLeave/*record && record.profileSalary.length > 0
? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}`
: null, //เลขที่ตำแหน่ง
: null*/, //
posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท
dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ
dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ