search salary

This commit is contained in:
mamoss 2025-10-25 02:00:35 +07:00
parent 783bb95e16
commit 31b20bc98e

View file

@ -148,6 +148,7 @@ export class ProfileGovernmentHistoryController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER");
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const orgRevision = await this.orgRevisionRepository.findOne({ const orgRevision = await this.orgRevisionRepository.findOne({
select: ["id"], select: ["id"],
where: { where: {
@ -155,7 +156,19 @@ export class ProfileGovernmentHistoryController extends Controller {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
}, },
}); });
// ค้นหา profile ก่อน
const record = await this.profileRepo.findOne({ const record = await this.profileRepo.findOne({
where: { id: profileId },
relations: ["posType", "posLevel"],
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล profile");
}
// ค้นหา profileSalary แยกต่างหาก
const profileWithSalary = await this.profileRepo.findOne({
where: { where: {
id: profileId, id: profileId,
profileSalary: { profileSalary: {
@ -175,16 +188,19 @@ export class ProfileGovernmentHistoryController extends Controller {
"15", "15",
"16", "16",
]), ]),
}
}, },
relations: ["posType", "posLevel", "profileSalary"], },
relations: ["profileSalary"],
order: { order: {
profileSalary: { profileSalary: {
order: "DESC", order: "DESC",
createdAt: "DESC" createdAt: "DESC",
} },
} },
}); });
// ใช้ profileSalary จาก query ที่สอง หรือ [] ถ้าไม่เจอ
record.profileSalary = profileWithSalary?.profileSalary || [];
const posMaster = await this.posMasterRepo.findOne({ const posMaster = await this.posMasterRepo.findOne({
where: { where: {
orgRevisionId: orgRevision?.id, orgRevisionId: orgRevision?.id,
@ -236,7 +252,7 @@ export class ProfileGovernmentHistoryController extends Controller {
orgShortName = posMaster.orgChild4?.orgChild4ShortName ?? ""; orgShortName = posMaster.orgChild4?.orgChild4ShortName ?? "";
} }
} }
let _OrgLeave:any = [] let _OrgLeave: any = [];
let _profileSalary: any = null; let _profileSalary: any = null;
if (record?.isLeave && record?.profileSalary.length > 0) { if (record?.isLeave && record?.profileSalary.length > 0) {
// _OrgLeave = [ // _OrgLeave = [
@ -247,15 +263,14 @@ export class ProfileGovernmentHistoryController extends Controller {
// record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null, // record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null,
// ]; // ];
if (record.leaveType == "RETIRE") { if (record.leaveType == "RETIRE") {
_profileSalary = record?.profileSalary.length > 1 _profileSalary =
record?.profileSalary.length > 1
? record?.profileSalary[1] ? record?.profileSalary[1]
: record?.profileSalary.length > 0 : record?.profileSalary.length > 0
? record?.profileSalary[0] ? record?.profileSalary[0]
: null; : null;
} else { } else {
_profileSalary = record?.profileSalary.length > 0 _profileSalary = record?.profileSalary.length > 0 ? record?.profileSalary[0] : null;
? record?.profileSalary[0]
: null;
} }
if (_profileSalary) { if (_profileSalary) {
_OrgLeave = [ _OrgLeave = [
@ -275,8 +290,11 @@ export class ProfileGovernmentHistoryController extends Controller {
positionField: position == null ? null : position.positionField, //สายงาน positionField: position == null ? null : position.positionField, //สายงาน
position: record?.position, //ตำแหน่ง position: record?.position, //ตำแหน่ง
posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ
posMasterNo: record?.isLeave == false posMasterNo:
? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` record?.isLeave == false
? posMaster == null
? null
: `${orgShortName} ${posMaster.posMasterNo}`
: _profileSalary != null : _profileSalary != null
? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}`
: null, //เลขที่ตำแหน่ง : null, //เลขที่ตำแหน่ง
@ -310,7 +328,19 @@ export class ProfileGovernmentHistoryController extends Controller {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
}, },
}); });
// ค้นหา profile ก่อน
const record = await this.profileRepo.findOne({ const record = await this.profileRepo.findOne({
where: { id: profileId },
relations: ["posType", "posLevel"],
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล profile");
}
// ค้นหา profileSalary แยกต่างหาก
const profileWithSalary = await this.profileRepo.findOne({
where: { where: {
id: profileId, id: profileId,
profileSalary: { profileSalary: {
@ -330,20 +360,19 @@ export class ProfileGovernmentHistoryController extends Controller {
"15", "15",
"16", "16",
]), ]),
}
}, },
relations: {
posType: true,
posLevel: true,
profileSalary: true
}, },
relations: ["profileSalary"],
order: { order: {
profileSalary: { profileSalary: {
order: "DESC", order: "DESC",
createdAt: "DESC" createdAt: "DESC",
} },
} },
}); });
// ใช้ profileSalary จาก query ที่สอง หรือ [] ถ้าไม่เจอ
record.profileSalary = profileWithSalary?.profileSalary || [];
const posMaster = await this.posMasterRepo.findOne({ const posMaster = await this.posMasterRepo.findOne({
where: { where: {
orgRevisionId: orgRevision?.id, orgRevisionId: orgRevision?.id,
@ -395,7 +424,7 @@ export class ProfileGovernmentHistoryController extends Controller {
orgShortName = posMaster.orgChild4?.orgChild4ShortName; orgShortName = posMaster.orgChild4?.orgChild4ShortName;
} }
} }
let _OrgLeave:any = [] let _OrgLeave: any = [];
let _profileSalary: any = null; let _profileSalary: any = null;
if (record?.isLeave && record?.profileSalary.length > 0) { if (record?.isLeave && record?.profileSalary.length > 0) {
// _OrgLeave = [ // _OrgLeave = [
@ -406,15 +435,14 @@ export class ProfileGovernmentHistoryController extends Controller {
// record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null, // record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null,
// ]; // ];
if (record.leaveType == "RETIRE") { if (record.leaveType == "RETIRE") {
_profileSalary = record?.profileSalary.length > 1 _profileSalary =
record?.profileSalary.length > 1
? record?.profileSalary[1] ? record?.profileSalary[1]
: record?.profileSalary.length > 0 : record?.profileSalary.length > 0
? record?.profileSalary[0] ? record?.profileSalary[0]
: null; : null;
} else { } else {
_profileSalary = record?.profileSalary.length > 0 _profileSalary = record?.profileSalary.length > 0 ? record?.profileSalary[0] : null;
? record?.profileSalary[0]
: null;
} }
if (_profileSalary) { if (_profileSalary) {
_OrgLeave = [ _OrgLeave = [
@ -458,7 +486,7 @@ export class ProfileGovernmentHistoryController extends Controller {
govAgeAbsent: record?.govAgeAbsent, govAgeAbsent: record?.govAgeAbsent,
govAgePlus: record?.govAgePlus, govAgePlus: record?.govAgePlus,
reasonSameDate: record?.reasonSameDate, reasonSameDate: record?.reasonSameDate,
isLeave: record?.isLeave isLeave: record?.isLeave,
}; };
return new HttpSuccess(data); return new HttpSuccess(data);