Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
kittapath 2024-11-07 13:48:43 +07:00
commit e701287969
2 changed files with 636 additions and 289 deletions

View file

@ -2313,7 +2313,7 @@ export class CommandController extends Controller {
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posLevel","posType","current_holders"],
where: { id: item.profileId }, where: { id: item.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2324,7 +2324,38 @@ export class CommandController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
// ประวัติตำแหน่ง // ประวัติตำแหน่ง
const data = new ProfileSalary(); const data = new ProfileSalary();
const meta = { const meta = {
@ -2333,18 +2364,13 @@ export class CommandController extends Controller {
date: item.date, date: item.date,
refCommandNo: item.refCommandNo, refCommandNo: item.refCommandNo,
templateDoc: item.salaryRef, templateDoc: item.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: positionType: profile.posType.posTypeName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionLevel: profile.posLevel.posLevelName,
positionLevel: posNo: shortName?shortName:"-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, positionLine: position?.positionField ?? "-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionPathSide: position?.positionArea ?? "-",
positionLine: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null,
positionPathSide:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null,
positionExecutive:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null,
amount: item.amount ? item.amount : null, amount: item.amount ? item.amount : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
@ -2449,7 +2475,7 @@ export class CommandController extends Controller {
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: item.profileId }, where: { id: item.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2461,6 +2487,39 @@ export class CommandController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
// ประวัติตำแหน่ง // ประวัติตำแหน่ง
const data = new ProfileSalary(); const data = new ProfileSalary();
const meta = { const meta = {
@ -2469,18 +2528,13 @@ export class CommandController extends Controller {
refCommandNo: item.refCommandNo, refCommandNo: item.refCommandNo,
templateDoc: item.salaryRef, templateDoc: item.salaryRef,
commandId: item.commandId, commandId: item.commandId,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: positionType: profile.posType.posTypeName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionLevel: profile.posLevel.posLevelName,
positionLevel: posNo: shortName?shortName:"-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, positionLine: position?.positionField ?? "-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionPathSide: position?.positionArea ?? "-",
positionLine: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null,
positionPathSide:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null,
positionExecutive:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null,
amount: item.amount ? item.amount : null, amount: item.amount ? item.amount : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
@ -2497,7 +2551,6 @@ export class CommandController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}; };
Object.assign(data, meta); Object.assign(data, meta);
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
@ -2543,7 +2596,7 @@ export class CommandController extends Controller {
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel",'current_holders','current_holders.positions','current_holders.positions.posExecutive'],
where: { id: item.profileId }, where: { id: item.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2561,7 +2614,6 @@ export class CommandController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
} }
let dateLeave_: any = item.date; let dateLeave_: any = item.date;
await removeProfileInOrganize(profile.id, "OFFICER");
_profile.isLeave = true; _profile.isLeave = true;
_profile.leaveReason = _profile.leaveReason =
"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
@ -2569,24 +2621,52 @@ export class CommandController extends Controller {
_profile.lastUpdateUserId = req.user.sub; _profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name; _profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date(); _profile.lastUpdatedAt = new Date();
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: item.profileId, profileId: item.profileId,
date: item.date, date: item.date,
refCommandNo: item.refCommandNo, refCommandNo: item.refCommandNo,
templateDoc: item.salaryRef, templateDoc: item.salaryRef,
commandId: item.commandId, commandId: item.commandId,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: positionType: profile.posType.posTypeName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionLevel: profile.posLevel.posLevelName,
positionLevel: posNo: shortName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, positionLine: position?.positionField ?? "-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionPathSide: position?.positionArea ?? "-",
positionLine: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null,
positionPathSide:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null,
positionExecutive:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null,
amount: item.amount ? item.amount : null, amount: item.amount ? item.amount : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
@ -2605,25 +2685,26 @@ export class CommandController extends Controller {
dateGovernment: new Date(), dateGovernment: new Date(),
isGovernment: item.isGovernment, isGovernment: item.isGovernment,
}); });
await removeProfileInOrganize(profile.id, "OFFICER");
const clearProfile = await checkCommandType(String(item.commandId)); const clearProfile = await checkCommandType(String(item.commandId));
const _null: any = null; const _null: any = null;
if (clearProfile) { if (clearProfile) {
if (_profile.keycloak != null) { if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak); const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) _profile.keycloak = _null; if (delUserKeycloak) _profile.keycloak = _null;
} }
_profile.position = _null; _profile.position = _null;
_profile.posTypeId = _null; _profile.posTypeId = _null;
_profile.posLevelId = _null; _profile.posLevelId = _null;
} }
await Promise.all([ await Promise.all([
this.profileRepository.save(_profile), this.profileRepository.save(_profile),
this.salaryRepo.save(profileSalary), this.salaryRepo.save(profileSalary),
]); ]);
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...profileSalary, id: undefined }); Object.assign(history, { ...profileSalary, id: undefined });
history.profileSalaryId = profileSalary.id; history.profileSalaryId = profileSalary.id;
await this.salaryHistoryRepo.save(history); await this.salaryHistoryRepo.save(history);
}), }),
); );

View file

@ -252,9 +252,8 @@ export class ProfileController extends Controller {
profile.dateRetire != null profile.dateRetire != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateRetire)) ? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateRetire))
: "-", : "-",
salaryAmount: salaryAmount: profile.amount != null
profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null ? Extension.ToThaiNumber(profile.amount.toLocaleString())
? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString())
: "-", : "-",
registrationAddress: Extension.ToThaiNumber( registrationAddress: Extension.ToThaiNumber(
`${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
@ -1911,7 +1910,38 @@ export class ProfileController extends Controller {
} }
// const posType = await this.posTypeRepo.findOneBy({ id: String(profile.posTypeId) }) // const posType = await this.posTypeRepo.findOneBy({ id: String(profile.posTypeId) })
// const posLevel = await this.posLevelRepo.findOneBy({ id: String(profile.posLevelId) }) // const posLevel = await this.posLevelRepo.findOneBy({ id: String(profile.posLevelId) })
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
if (profile.isProbation != false) { if (profile.isProbation != false) {
profile.isProbation = false; profile.isProbation = false;
profile.lastUpdateUserId = req.user.sub; profile.lastUpdateUserId = req.user.sub;
@ -1923,23 +1953,16 @@ export class ProfileController extends Controller {
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
//profile.position, //profile.position,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: positionType: profile.posType.posTypeName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionLevel: profile.posLevel.posLevelName,
positionLevel: posNo: shortName?shortName:"-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, positionLine: position?.positionField ?? "-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionPathSide: position?.positionArea ?? "-",
positionLine: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, amount: profile.amount,
positionPathSide: positionSalaryAmount:profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, mouthSalaryAmount: profile.mouthSalaryAmount,
positionExecutive:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -1976,7 +1999,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -1994,7 +2017,6 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
} }
let dateLeave_: any = body.date; let dateLeave_: any = body.date;
await removeProfileInOrganize(profile.id, "OFFICER");
_profile.isLeave = true; _profile.isLeave = true;
_profile.leaveReason = _profile.leaveReason =
"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
@ -2002,26 +2024,54 @@ export class ProfileController extends Controller {
_profile.lastUpdateUserId = req.user.sub; _profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name; _profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date(); _profile.lastUpdatedAt = new Date();
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2035,6 +2085,7 @@ export class ProfileController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}); });
await removeProfileInOrganize(profile.id, "OFFICER");
await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess(); return new HttpSuccess();
@ -2058,7 +2109,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2076,33 +2127,60 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
} }
let dateLeave_: any = body.date; let dateLeave_: any = body.date;
await removeProfileInOrganize(profile.id, "OFFICER");
_profile.isLeave = true; _profile.isLeave = true;
_profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; _profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ";
_profile.dateLeave = dateLeave_; _profile.dateLeave = dateLeave_;
_profile.lastUpdateUserId = req.user.sub; _profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name; _profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date(); _profile.lastUpdatedAt = new Date();
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2116,6 +2194,7 @@ export class ProfileController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}); });
await removeProfileInOrganize(profile.id, "OFFICER");
await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess(); return new HttpSuccess();
@ -2139,7 +2218,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2157,33 +2236,60 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
} }
let dateLeave_: any = body.date; let dateLeave_: any = body.date;
await removeProfileInOrganize(profile.id, "OFFICER");
_profile.isLeave = true; _profile.isLeave = true;
_profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; _profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ";
_profile.dateLeave = dateLeave_; _profile.dateLeave = dateLeave_;
_profile.lastUpdateUserId = req.user.sub; _profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name; _profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date(); _profile.lastUpdatedAt = new Date();
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2209,6 +2315,7 @@ export class ProfileController extends Controller {
// createdAt: new Date(), // createdAt: new Date(),
// lastUpdatedAt: new Date(), // lastUpdatedAt: new Date(),
// }); // });
await removeProfileInOrganize(profile.id, "OFFICER");
await Promise.all([ await Promise.all([
this.profileRepo.save(_profile), this.profileRepo.save(_profile),
this.salaryRepository.save(profileSalary), this.salaryRepository.save(profileSalary),
@ -2236,7 +2343,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2254,33 +2361,60 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
} }
let dateLeave_: any = body.date; let dateLeave_: any = body.date;
await removeProfileInOrganize(profile.id, "OFFICER");
_profile.isLeave = true; _profile.isLeave = true;
_profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ"; _profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ";
_profile.dateLeave = dateLeave_; _profile.dateLeave = dateLeave_;
_profile.lastUpdateUserId = req.user.sub; _profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name; _profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date(); _profile.lastUpdatedAt = new Date();
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2294,6 +2428,7 @@ export class ProfileController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}); });
await removeProfileInOrganize(profile.id, "OFFICER");
await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess(); return new HttpSuccess();
@ -2317,7 +2452,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2335,32 +2470,59 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
} }
let dateLeave_: any = body.date; let dateLeave_: any = body.date;
await removeProfileInOrganize(profile.id, "OFFICER");
_profile.isLeave = true; _profile.isLeave = true;
_profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน"; _profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน";
_profile.dateLeave = dateLeave_; _profile.dateLeave = dateLeave_;
_profile.lastUpdateUserId = req.user.sub; _profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name; _profile.lastUpdateFullName = req.user.name;
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2374,6 +2536,7 @@ export class ProfileController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}); });
await removeProfileInOrganize(profile.id, "OFFICER");
await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess(); return new HttpSuccess();
@ -2397,7 +2560,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2414,26 +2577,54 @@ export class ProfileController extends Controller {
// profile.dateLeave = dateLeave_; // profile.dateLeave = dateLeave_;
// profile.lastUpdateUserId = req.user.sub; // profile.lastUpdateUserId = req.user.sub;
// profile.lastUpdateFullName = req.user.name; // profile.lastUpdateFullName = req.user.name;
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2470,7 +2661,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2487,26 +2678,54 @@ export class ProfileController extends Controller {
// profile.dateLeave = dateLeave_; // profile.dateLeave = dateLeave_;
// profile.lastUpdateUserId = req.user.sub; // profile.lastUpdateUserId = req.user.sub;
// profile.lastUpdateFullName = req.user.name; // profile.lastUpdateFullName = req.user.name;
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2543,7 +2762,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2560,26 +2779,55 @@ export class ProfileController extends Controller {
// profile.dateLeave = dateLeave_; // profile.dateLeave = dateLeave_;
// profile.lastUpdateUserId = req.user.sub; // profile.lastUpdateUserId = req.user.sub;
// profile.lastUpdateFullName = req.user.name; // profile.lastUpdateFullName = req.user.name;
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2616,7 +2864,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2633,26 +2881,54 @@ export class ProfileController extends Controller {
// profile.dateLeave = dateLeave_; // profile.dateLeave = dateLeave_;
// profile.lastUpdateUserId = req.user.sub; // profile.lastUpdateUserId = req.user.sub;
// profile.lastUpdateFullName = req.user.name; // profile.lastUpdateFullName = req.user.name;
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2689,7 +2965,7 @@ export class ProfileController extends Controller {
}, },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: ["profileSalary"], relations: ["profileSalary","posType","posLevel"],
where: { id: body.profileId }, where: { id: body.profileId },
order: { order: {
profileSalary: { profileSalary: {
@ -2706,26 +2982,55 @@ export class ProfileController extends Controller {
// profile.dateLeave = dateLeave_; // profile.dateLeave = dateLeave_;
// profile.lastUpdateUserId = req.user.sub; // profile.lastUpdateUserId = req.user.sub;
// profile.lastUpdateFullName = req.user.name; // profile.lastUpdateFullName = req.user.name;
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
: null;
let position = profile.current_holders.filter((x) => x.orgRevisionId == orgRevision?.id)[0]?.positions?.filter((pos) => pos.positionIsSelected === true)[0]?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId, profileId: body.profileId,
date: body.date, date: body.date,
refCommandNo: body.refCommandNo, refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef, templateDoc: body.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, position: profile.position,
positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, positionType: profile.posType.posTypeName,
positionLevel: positionLevel: profile.posLevel.posLevelName,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, posNo: shortName?shortName:"-",
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, positionLine: position?.positionField ?? "-",
positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, positionPathSide: position?.positionArea ?? "-",
positionPathSide: positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, amount: profile.amount,
positionExecutive: positionSalaryAmount: profile.positionSalaryAmount,
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, mouthSalaryAmount: profile.mouthSalaryAmount,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order: order:
profile.profileSalary.length >= 0 profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary.length > 0
@ -2780,39 +3085,7 @@ export class ProfileController extends Controller {
profile.lastUpdateUserId = req.user.sub; profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name; profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date(); profile.lastUpdatedAt = new Date();
// const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
// profileId: body.profileId,
// date: body.date,
// refCommandNo: body.refCommandNo,
// templateDoc: body.salaryRef,
// position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null,
// positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null,
// positionLevel:
// profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null,
// posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null,
// positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null,
// positionPathSide:
// profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null,
// positionExecutive:
// profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null,
// amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
// positionSalaryAmount:
// profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
// mouthSalaryAmount:
// profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
// order:
// profile.profileSalary.length >= 0
// ? profile.profileSalary.length > 0
// ? profile.profileSalary[0].order + 1
// : 1
// : null,
// createdUserId: req.user.sub,
// createdFullName: req.user.name,
// lastUpdateUserId: req.user.sub,
// lastUpdateFullName: req.user.name,
// createdAt: new Date(),
// lastUpdatedAt: new Date(),
// });
await Promise.all([this.profileRepo.save(profile)]); await Promise.all([this.profileRepo.save(profile)]);
return new HttpSuccess(); return new HttpSuccess();
@ -4406,8 +4679,7 @@ export class ProfileController extends Controller {
child4ShortName: child4 == null ? null : child4.orgChild4ShortName, child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null, node: null,
nodeId: null, nodeId: null,
type: "OFFICER", salary: profile ? profile.amount: null,
salary: profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
}; };
if (_profile.child4Id != null) { if (_profile.child4Id != null) {
@ -5152,7 +5424,7 @@ export class ProfileController extends Controller {
posNo: shortName, posNo: shortName,
isPosmasterAct: data.length > 0, isPosmasterAct: data.length > 0,
posmasterAct: data, posmasterAct: data,
salary: profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null, salary: profile ? profile.amount: null,
}; };
if (_profile.child4Id != null) { if (_profile.child4Id != null) {
@ -5306,15 +5578,9 @@ export class ProfileController extends Controller {
child4ShortName: child4 == null ? null : child4.orgChild4ShortName, child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null, node: null,
nodeId: null, nodeId: null,
amount: profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null, amount: profile ? profile.amount : null,
positionSalaryAmount: positionSalaryAmount: profile ? profile.positionSalaryAmount : null,
profile && profile.profileSalary.length > 0 mouthSalaryAmount: profile ? profile.mouthSalaryAmount : null,
? profile.profileSalary[0].positionSalaryAmount
: null,
mouthSalaryAmount:
profile && profile.profileSalary.length > 0
? profile.profileSalary[0].mouthSalaryAmount
: null,
}; };
if (_profile.child4Id != null) { if (_profile.child4Id != null) {