diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 39876e62..278f92ed 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -5626,7 +5626,7 @@ export class ProfileEmployeeController extends Controller { ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; const dest_item = await this.salaryRepo.findOne({ - where: { profileId: id }, + where: { profileEmployeeId: id }, order: { order: "DESC" }, }); const data: any = { @@ -5638,7 +5638,9 @@ export class ProfileEmployeeController extends Controller { posNo: orgRevisionRef?.posMasterNo, positionExecutive: "", positionType: profile.posType?.posTypeName, - positionLevel: profile.posLevel?.posLevelName, + positionLevel: profile.posType && profile.posLevel + ? `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}` + : "", amountSpecial: profile.amountSpecial, orgRoot: orgRootRef?.orgRootName, orgChild1: orgChild1Ref?.orgChild1Name, diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index af81df62..8766017f 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -3297,7 +3297,7 @@ export class ProfileEmployeeTempController extends Controller { ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; const dest_item = await this.salaryRepo.findOne({ - where: { profileId: id }, + where: { profileEmployeeId: id }, order: { order: "DESC" }, }); const data: any = { @@ -3309,7 +3309,9 @@ export class ProfileEmployeeTempController extends Controller { posNo: orgRevisionRef?.posMasterNo, positionExecutive: "", positionType: profile.posType?.posTypeName, - positionLevel: profile.posLevel?.posLevelName, + positionLevel: profile.posType && profile.posLevel + ? `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}` + : "", amountSpecial: profile.amountSpecial, orgRoot: orgRootRef?.orgRootName, orgChild1: orgChild1Ref?.orgChild1Name, diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 28b6690e..b1e313be 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -156,17 +156,16 @@ export class ProfileGovernmentHistoryController extends Controller { }); const record = await this.profileRepo.findOne({ where: { id: profileId }, - relations: { - posType: true, - posLevel: true, - }, + relations: ["posType", "posLevel", "profileSalary"], + order: { + profileSalary: { + order: "DESC", + createdAt: "DESC" + } + } }); const posMaster = await this.posMasterRepo.findOne({ where: { - // orgRevision: { - // orgRevisionIsCurrent: true, - // orgRevisionIsDraft: false, - // }, orgRevisionId: orgRevision?.id, current_holderId: profileId, }, @@ -183,10 +182,6 @@ export class ProfileGovernmentHistoryController extends Controller { where: { positionIsSelected: true, posMaster: { - // orgRevision: { - // orgRevisionIsCurrent: true, - // orgRevisionIsDraft: false, - // }, orgRevisionId: orgRevision?.id, current_holderId: profileId, }, @@ -220,12 +215,24 @@ export class ProfileGovernmentHistoryController extends Controller { orgShortName = posMaster.orgChild4?.orgChild4ShortName; } } + const _OrgLeave = [ + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild4 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild3 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild2 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild1 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgRoot : null, + ]; + const orgLeave = _OrgLeave.filter((x) => x !== undefined && x !== null).join("\n"); const data = { - org: org, //สังกัด + org: record.isLeave == false ? org : orgLeave, //สังกัด positionField: position == null ? null : position.positionField, //สายงาน position: record.position, //ตำแหน่ง posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ - posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posMasterNo: record.isLeave == false + ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` + : record.profileSalary.length > 0 + ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : null, //เลขที่ตำแหน่ง posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท posExecutive: position == null || position.posExecutive == null diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index d30e9e99..bae4a59b 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -148,17 +148,16 @@ export class ProfileGovernmentEmployeeController extends Controller { }); const record = await this.profileEmployeeRepo.findOne({ where: { id: profileEmployeeId }, - relations: { - posType: true, - posLevel: true, - }, + relations: ["posType", "posLevel", "profileSalary"], + order: { + profileSalary: { + order: "DESC", + createdAt: "DESC" + } + } }); const posMaster = await this.posMasterRepo.findOne({ where: { - // orgRevision: { - // orgRevisionIsCurrent: true, - // orgRevisionIsDraft: false, - // }, orgRevisionId: orgRevision?.id, current_holderId: profileEmployeeId, }, @@ -171,20 +170,6 @@ export class ProfileGovernmentEmployeeController extends Controller { orgChild4: true, }, }); - const position = await this.positionRepo.findOne({ - where: { - positionIsSelected: true, - posMaster: { - // orgRevision: { - // orgRevisionIsCurrent: true, - // orgRevisionIsDraft: false, - // }, - orgRevisionId: orgRevision?.id, - current_holderId: profileEmployeeId, - }, - }, - order: { createdAt: "DESC" }, - }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ @@ -209,14 +194,26 @@ export class ProfileGovernmentEmployeeController extends Controller { orgShortName = posMaster.orgChild4?.orgChild4ShortName; } } + const _OrgLeave = [ + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild4 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild3 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild2 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild1 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgRoot : null, + ]; + const orgLeave = _OrgLeave.filter((x) => x !== undefined && x !== null).join("\n"); const data = { - org: org, //สังกัด + org: record.isLeave == false ? org : orgLeave, //สังกัด position: record.position, //ตำแหน่ง posLevel: record.posLevel == null ? null : `${record?.posType?.posTypeShortName ?? ""} ${record?.posLevel?.posLevelName ?? ""}`, //ระดับ - posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posMasterNo: record.isLeave == false + ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` + : record.profileSalary.length > 0 + ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : null, //เลขที่ตำแหน่ง posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ dateAppoint: record.dateAppoint, //วันที่สั่งบรรจุ diff --git a/src/controllers/ProfileGovernmentEmployeeTempController.ts b/src/controllers/ProfileGovernmentEmployeeTempController.ts index f5a68186..98145dc9 100644 --- a/src/controllers/ProfileGovernmentEmployeeTempController.ts +++ b/src/controllers/ProfileGovernmentEmployeeTempController.ts @@ -40,17 +40,16 @@ export class ProfileGovernmentEmployeeTempController extends Controller { } const record = await this.profileEmployeeRepo.findOne({ where: { id: profile.id }, - relations: { - posType: true, - posLevel: true, - }, + relations: ["posType", "posLevel", "profileSalary"], + order: { + profileSalary: { + order: "DESC", + createdAt: "DESC" + } + } }); const posMaster = await this.posMasterRepo.findOne({ where: { - // orgRevision: { - // orgRevisionIsCurrent: true, - // orgRevisionIsDraft: false, - // }, orgRevisionId: orgRevision?.id, current_holderId: profile.id, }, @@ -63,19 +62,6 @@ export class ProfileGovernmentEmployeeTempController extends Controller { orgChild4: true, }, }); - // const position = await this.positionRepo.findOne({ - // where: { - // positionIsSelected: true, - // posMaster: { - // orgRevision: { - // orgRevisionIsCurrent: true, - // orgRevisionIsDraft: false, - // }, - // current_holderId: profile.id, - // }, - // }, - // order: { createdAt: "DESC" }, - // }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ @@ -100,11 +86,23 @@ export class ProfileGovernmentEmployeeTempController extends Controller { orgShortName = posMaster.orgChild4?.orgChild4ShortName; } } + const _OrgLeave = [ + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild4 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild3 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild2 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgChild1 : null, + record.profileSalary.length > 0 ? record.profileSalary[0].orgRoot : null, + ]; + const orgLeave = _OrgLeave.filter((x) => x !== undefined && x !== null).join("\n"); const data = { - org: org, //สังกัด + org: record.isLeave == false ? org : orgLeave, //สังกัด position: record.position, //ตำแหน่ง posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ - posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posMasterNo: record.isLeave == false + ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` + : record.profileSalary.length > 0 + ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : null, //เลขที่ตำแหน่ง posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), dateRetireLaw: record.dateRetireLaw ?? null,