fix ส่งรายชื่อไปยังรายการอื่น ๆ #2571
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m10s

This commit is contained in:
harid 2026-06-22 13:32:26 +07:00
parent bbc6a5e6a9
commit 00c35e8974
2 changed files with 181 additions and 78 deletions

View file

@ -8726,14 +8726,10 @@ export class ProfileController extends Controller {
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
// "profileSalary",
"profileEducations",
"profileActpositions",
],
order: {
// profileSalary: {
// order: "DESC",
// },
profileEducations: {
level: "ASC",
},
@ -8798,72 +8794,6 @@ export class ProfileController extends Controller {
});
const holder = profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id);
const numPart = holder ? [holder.posMasterNoPrefix, holder.posMasterNo, holder.posMasterNoSuffix].filter((p) => p !== null && p !== undefined && p !== '').join(' ') : '';
const shortName =
holder == null
? null
: holder.orgChild4 != null
? `${holder.orgChild4.orgChild4ShortName} ${numPart}`
: holder.orgChild3 != null
? `${holder.orgChild3.orgChild3ShortName} ${numPart}`
: holder.orgChild2 != null
? `${holder.orgChild2.orgChild2ShortName} ${numPart}`
: holder.orgChild1 != null
? `${holder.orgChild1.orgChild1ShortName} ${numPart}`
: holder.orgRoot != null
? `${holder.orgRoot.orgRootShortName} ${numPart}`
: null;
// const posMasterActs = await this.posMasterActRepository.find({
// relations: [
// "posMaster",
// "posMaster.orgRoot",
// "posMaster.orgChild1",
// "posMaster.orgChild2",
// "posMaster.orgChild3",
// "posMaster.orgChild4",
// "posMaster.current_holder",
// "posMaster.current_holder.posLevel",
// "posMaster.current_holder.posType",
// ],
// where: {
// posMaster: {
// orgRevisionId: orgRevisionPublish.id,
// },
// posMasterChild: {
// current_holderId: profile.id,
// },
// },
// });
// const data = await Promise.all(
// posMasterActs
// .sort((a, b) => a.posMaster.posMasterOrder - b.posMaster.posMasterOrder)
// .map((item) => {
// const shortName =
// item.posMaster != null && item.posMaster.orgChild4 != null
// ? `${item.posMaster.orgChild4.orgChild4ShortName} ${item.posMaster.posMasterNo}`
// : item.posMaster != null && item.posMaster?.orgChild3 != null
// ? `${item.posMaster.orgChild3.orgChild3ShortName} ${item.posMaster.posMasterNo}`
// : item.posMaster != null && item.posMaster?.orgChild2 != null
// ? `${item.posMaster.orgChild2.orgChild2ShortName} ${item.posMaster.posMasterNo}`
// : item.posMaster != null && item.posMaster?.orgChild1 != null
// ? `${item.posMaster.orgChild1.orgChild1ShortName} ${item.posMaster.posMasterNo}`
// : item.posMaster != null && item.posMaster?.orgRoot != null
// ? `${item.posMaster.orgRoot.orgRootShortName} ${item.posMaster.posMasterNo}`
// : null;
// return {
// id: item.id,
// posMasterOrder: item.posMasterOrder,
// profileId: item.posMaster?.current_holder?.id ?? null,
// citizenId: item.posMaster?.current_holder?.citizenId ?? null,
// prefix: item.posMaster?.current_holder?.prefix ?? null,
// firstName: item.posMaster?.current_holder?.firstName ?? null,
// lastName: item.posMaster?.current_holder?.lastName ?? null,
// posLevel: item.posMaster?.current_holder?.posLevel?.posLevelName ?? null,
// posType: item.posMaster?.current_holder?.posType?.posTypeName ?? null,
// position: item.posMaster?.current_holder?.position ?? null,
// posNo: shortName,
// };
// }),
// );
const data = await Promise.all(
profile.profileActpositions
.filter((x) => x.status)
@ -8910,6 +8840,96 @@ export class ProfileController extends Controller {
},
});
let _Org = null;
let _PosNo = null;
if (!profile.org && !profile.posMasterNo) {
if (profile.isLeave) {
const profileWithSalary = await this.profileRepo.findOne({
where: {
id: id,
profileSalary: {
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"20",
]),
},
},
relations: { profileSalary: true },
order: {
profileSalary: {
order: "DESC",
createdAt: "DESC",
},
},
});
const profileSalaryList = profileWithSalary?.profileSalary || [];
if (profileSalaryList.length > 0) {
const _profileSalary =
profile.leaveType == "RETIRE"
? profileSalaryList.length > 1
? profileSalaryList[1]
: profileSalaryList[0]
: profileSalaryList[0];
if (_profileSalary) {
const orgLeaveParts = [
_profileSalary.orgChild4 ?? null,
_profileSalary.orgChild3 ?? null,
_profileSalary.orgChild2 ?? null,
_profileSalary.orgChild1 ?? null,
_profileSalary.orgRoot ?? null,
];
_Org = orgLeaveParts
.filter((x: any) => x !== undefined && x !== null)
.join("\n");
_PosNo = `${_profileSalary.posNoAbb} ${_profileSalary.posNo}`;
}
}
} else {
_Org = [
child4?.orgChild4Name,
child3?.orgChild3Name,
child2?.orgChild2Name,
child1?.orgChild1Name,
root?.orgRootName,
]
.filter((x) => x != null && x !== "")
.join("\n");
_PosNo =
holder == null
? null
: holder.orgChild4 != null
? `${holder.orgChild4.orgChild4ShortName} ${numPart}`
: holder.orgChild3 != null
? `${holder.orgChild3.orgChild3ShortName} ${numPart}`
: holder.orgChild2 != null
? `${holder.orgChild2.orgChild2ShortName} ${numPart}`
: holder.orgChild1 != null
? `${holder.orgChild1.orgChild1ShortName} ${numPart}`
: holder.orgRoot != null
? `${holder.orgRoot.orgRootShortName} ${numPart}`
: null;
}
} else {
_Org = profile.org;
_PosNo = profile.posMasterNo;
}
const _profile: any = {
profileId: profile.id,
prefix: profile.prefix,
@ -8961,7 +8981,8 @@ export class ProfileController extends Controller {
node: null,
nodeId: null,
nodeDnaId: null,
posNo: shortName,
posNo: _PosNo,
org: _Org,
isPosmasterAct: data.length > 0,
posmasterAct: data,
salary: profile ? profile.amount : null,

View file

@ -6462,6 +6462,92 @@ export class ProfileEmployeeController extends Controller {
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4;
const _numPart = posMaster ? [posMaster.posMasterNoPrefix, posMaster.posMasterNo, posMaster.posMasterNoSuffix].filter((p) => p !== null && p !== undefined && p !== '').join(' ') : '';
// org / posNo — ล้อ fallback ของ officer (ProfileController.getProfileByProfileid)
// employee ไม่มี profile.org / profile.posMasterNo จึงแยกตาม isLeave โดยตรง
let _Org: string | null = null;
let _PosNo: string | null = null;
if (profile.isLeave) {
const profileWithSalary = await this.profileRepo.findOne({
where: {
id: id,
profileSalary: {
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"20",
]),
},
},
relations: { profileSalary: true },
order: {
profileSalary: {
order: "DESC",
createdAt: "DESC",
},
},
});
const profileSalaryList = profileWithSalary?.profileSalary || [];
if (profileSalaryList.length > 0) {
const _profileSalary =
profile.leaveType == "RETIRE"
? profileSalaryList.length > 1
? profileSalaryList[1]
: profileSalaryList[0]
: profileSalaryList[0];
if (_profileSalary) {
_Org = [
_profileSalary.orgChild4 ?? null,
_profileSalary.orgChild3 ?? null,
_profileSalary.orgChild2 ?? null,
_profileSalary.orgChild1 ?? null,
_profileSalary.orgRoot ?? null,
]
.filter((x: any) => x !== undefined && x !== null)
.join("\n");
_PosNo = `${_profileSalary.posNoAbb} ${_profileSalary.posNo}`;
}
}
} else {
_Org = [
child4?.orgChild4Name,
child3?.orgChild3Name,
child2?.orgChild2Name,
child1?.orgChild1Name,
root?.orgRootName,
]
.filter((x) => x != null && x !== "")
.join("\n");
_PosNo =
posMaster == null
? null
: child4 != null
? `${child4.orgChild4ShortName} ${_numPart}`
: child3 != null
? `${child3.orgChild3ShortName} ${_numPart}`
: child2 != null
? `${child2.orgChild2ShortName} ${_numPart}`
: child1 != null
? `${child1.orgChild1ShortName} ${_numPart}`
: root != null
? `${root.orgRootShortName} ${_numPart}`
: null;
}
const _profile: any = {
profileId: profile.id,
prefix: profile.prefix,
@ -6474,7 +6560,7 @@ export class ProfileEmployeeController extends Controller {
position: profile.position,
leaveDate: profile.dateLeave,
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
posLevelName: `${profile?.posType?.posTypeShortName ?? ""} ${profile?.posLevel?.posLevelName ?? ""}`,
posLevelName: `${profile?.posType?.posTypeShortName ?? ""} ${profile?.posLevel?.posLevelName ?? ""}`.trim(),
posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank,
posLevelId: profile.posLevel == null ? null : profile.posLevel.id,
posTypeName: profile.posType == null ? null : profile.posType.posTypeName,
@ -6503,7 +6589,8 @@ export class ProfileEmployeeController extends Controller {
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null,
nodeId: null,
posNo: null,
posNo: _PosNo,
org: _Org,
salary: profile.amount,
education:
profile && profile.profileEducations.length > 0
@ -6518,27 +6605,22 @@ export class ProfileEmployeeController extends Controller {
_profile.node = 4;
_profile.nodeId = _profile.child4Id;
_profile.nodeShortName = _profile.child4ShortName;
_profile.posNo = `${_profile.child4ShortName} ${_numPart}`;
} else if (_profile.child3Id != null) {
_profile.node = 3;
_profile.nodeId = _profile.child3Id;
_profile.nodeShortName = _profile.child3ShortName;
_profile.posNo = `${_profile.child3ShortName} ${_numPart}`;
} else if (_profile.child2Id != null) {
_profile.node = 2;
_profile.nodeId = _profile.child2Id;
_profile.nodeShortName = _profile.child2ShortName;
_profile.posNo = `${_profile.child2ShortName} ${_numPart}`;
} else if (_profile.child1Id != null) {
_profile.node = 1;
_profile.nodeId = _profile.child1Id;
_profile.nodeShortName = _profile.child1ShortName;
_profile.posNo = `${_profile.child1ShortName} ${_numPart}`;
} else if (_profile.rootId != null) {
_profile.node = 0;
_profile.nodeId = _profile.rootId;
_profile.nodeShortName = _profile.rootShortName;
_profile.posNo = `${_profile.rootShortName} ${_numPart}`;
}
return new HttpSuccess(_profile);
}