diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 33d33227..636a4e48 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5888,7 +5888,7 @@ export class ProfileController extends Controller { ) // .andWhere("profile.leaveCommandId Is NOT NULL") .andWhere( - "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id)", + "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and profileSalary.positionName != 'เกษียณอายุราชการ')", ) .andWhere( diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 04b43f87..4bc85898 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2786,7 +2786,7 @@ export class ProfileEmployeeController extends Controller { ) // .andWhere("profileEmployee.leaveCommandId Is NOT NULL") .andWhere( - "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id)", + "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id and profileSalary.positionName != 'เกษียณอายุราชการ')", ) // .andWhere( diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 6f63bd0e..8abe6617 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -237,14 +237,33 @@ export class ProfileGovernmentHistoryController extends Controller { } } let _OrgLeave:any = [] + let _profileSalary:any = null; if (record?.isLeave && record?.profileSalary.length > 0) { - _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, - ]; + // _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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { @@ -254,8 +273,8 @@ export class ProfileGovernmentHistoryController extends Controller { posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ posMasterNo: record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record && record?.profileSalary.length > 0 - ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` + : _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : null, //เลขที่ตำแหน่ง posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: @@ -373,14 +392,33 @@ export class ProfileGovernmentHistoryController extends Controller { } } let _OrgLeave:any = [] + let _profileSalary:any = null; if (record?.isLeave && record?.profileSalary.length > 0) { - _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, - ]; + // _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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { @@ -393,8 +431,8 @@ export class ProfileGovernmentHistoryController extends Controller { ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record && record.profileSalary.length > 0 - ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` + : _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : null, //เลขที่ตำแหน่ง posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 0cfd43e3..9191eb2e 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -220,6 +220,7 @@ export class ProfileGovernmentEmployeeController extends Controller { let _OrgLeave:any = [] let orgLeave:string = "" let posNoLeave:string = "" + let _profileSalary:any = null; if (record?.isLeave /*&& record?.profileSalary.length > 0*/) { const profileSalary = await this.salaryRepo.find({ select: [ @@ -255,16 +256,34 @@ export class ProfileGovernmentEmployeeController extends Controller { createdAt: "DESC" } }); - _OrgLeave = [ - 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 = [ + // 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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); - posNoLeave = profileSalary.length > 0 - ? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}` + posNoLeave = _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : "" } const data = { @@ -372,6 +391,7 @@ export class ProfileGovernmentEmployeeController extends Controller { let _OrgLeave:any = [] let orgLeave:string = "" let posNoLeave:string = "" + let _profileSalary:any = null; if (record?.isLeave /*&& record?.profileSalary.length > 0*/) { const profileSalary = await this.salaryRepo.find({ select: [ @@ -407,16 +427,34 @@ export class ProfileGovernmentEmployeeController extends Controller { createdAt: "DESC" } }); - _OrgLeave = [ - 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 = [ + // 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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); - posNoLeave = profileSalary.length > 0 - ? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}` + posNoLeave = _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : "" } const data = {