update exe 40

This commit is contained in:
mamoss 2025-07-26 12:54:34 +07:00
parent 17c76ee1cc
commit 3f735accdd

View file

@ -1672,14 +1672,14 @@ export class CommandController extends Controller {
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
"profileSalary"
"profileSalary",
],
order: {
profileSalary: {
order: "DESC",
createdAt: "DESC"
}
}
createdAt: "DESC",
},
},
});
const shortName =
profile?.current_holders.length == 0
@ -1761,7 +1761,7 @@ export class CommandController extends Controller {
let _child2 = child2?.orgChild2Name;
let _child3 = child3?.orgChild3Name;
let _child4 = child4?.orgChild4Name;
let _OrgLeave:any = []
let _OrgLeave: any = [];
if (profile?.isLeave && profile?.profileSalary.length > 0) {
_OrgLeave = [
profile?.profileSalary[0].orgChild4 ? profile?.profileSalary[0].orgChild4 : null,
@ -1771,20 +1771,18 @@ export class CommandController extends Controller {
profile?.profileSalary[0].orgRoot ? profile?.profileSalary[0].orgRoot : null,
];
}
const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n");
const orgLeave = _OrgLeave.filter((x: any) => x !== undefined && x !== null).join("\n");
return {
no: Extension.ToThaiNumber((idx + 1).toString()),
org:
commandCode != "C-PM-21"
? profile?.isLeave == false
?
(_child4 == null ? "" : _child4 + "\n") +
? (_child4 == null ? "" : _child4 + "\n") +
(_child3 == null ? "" : _child3 + "\n") +
(_child2 == null ? "" : _child2 + "\n") +
(_child1 == null ? "" : _child1 + "\n") +
(_root == null ? "" : _root)
:
orgLeave
: orgLeave
: (profile?.child4Temp == null ? "" : profile?.child4Temp + "\n") +
(profile?.child3Temp == null ? "" : profile?.child3Temp + "\n") +
(profile?.child2Temp == null ? "" : profile?.child2Temp + "\n") +
@ -3434,7 +3432,7 @@ export class CommandController extends Controller {
}
//ลบตำแหน่งที่รักษาการแทน
const code = _command?.commandType?.code;
if(code && ["C-PM-08","C-PM-17", "C-PM-18"].includes(code)){
if (code && ["C-PM-08", "C-PM-17", "C-PM-18"].includes(code)) {
removePostMasterAct(profile.id);
}
let _commandYear = item.commandYear;
@ -3507,8 +3505,8 @@ export class CommandController extends Controller {
//ปั๊มตำแหน่งใหม่
const posMaster = await this.posMasterRepository.findOne({
where: { id: item.posmasterId?.toString() },
});
});
if (posMaster) {
const checkPosition = await this.positionRepository.find({
where: {
@ -3908,7 +3906,7 @@ export class CommandController extends Controller {
//ลบตำแหน่งที่รักษาการแทน
const code = _command?.commandType?.code;
if(code && ["C-PM-13"].includes(code)){
if (code && ["C-PM-13"].includes(code)) {
removePostMasterAct(profile.id);
}
@ -4252,10 +4250,10 @@ export class CommandController extends Controller {
//ลบตำแหน่งที่รักษาการแทน
const code = _command?.commandType?.code;
if(code && ["C-PM-19", "C-PM-20"].includes(code)){
if (code && ["C-PM-19", "C-PM-20"].includes(code)) {
removePostMasterAct(profile.id);
}
const orgRevision = await this.orgRevisionRepo.findOne({
where: {
orgRevisionIsCurrent: true,
@ -6542,6 +6540,13 @@ export class CommandController extends Controller {
}[];
},
) {
// อัปเดตสถานะรวดเดียว
await this.posMasterActRepository.update(
{ id: In(body.refIds.map((x) => x.refId)) },
{ statusReport: "DONE" },
);
// ดึงข้อมูลที่จำเป็น
const posMasters = await this.posMasterActRepository.find({
where: { id: In(body.refIds.map((x) => x.refId)) },
relations: [
@ -6555,37 +6560,20 @@ export class CommandController extends Controller {
"posMaster.orgChild4",
],
});
const data = posMasters.map((_data) => ({
..._data,
statusReport: "DONE",
}));
await this.posMasterActRepository.save(data);
await Promise.all(
posMasters.map(async (item) => {
if (item.posMasterChild != null && item.posMasterChild.current_holderId != null) {
// ประวัติคำสั่งให้รักษาการแทน
const _actposition = await this.actpositionRepository.find({
where: { profileId: item.posMasterChild.current_holderId },
});
const profileActs = _actposition.map((_data) => ({
..._data,
status: false,
dateEnd: _data.status == true ? new Date() : _data.dateEnd,
}));
await this.actpositionRepository.save(profileActs);
if (item.posMasterChild?.current_holderId) {
// ปรับ shortName ให้สั้น
const shortName =
item.posMaster != null && item.posMaster.orgChild4 != null
? `${item.posMaster.orgChild4.orgChild4ShortName}`
: item.posMaster != null && item.posMaster?.orgChild3 != null
? `${item.posMaster.orgChild3.orgChild3ShortName}`
: item.posMaster != null && item.posMaster?.orgChild2 != null
? `${item.posMaster.orgChild2.orgChild2ShortName}`
: item.posMaster != null && item.posMaster?.orgChild1 != null
? `${item.posMaster.orgChild1.orgChild1ShortName}`
: item.posMaster != null && item.posMaster?.orgRoot != null
? `${item.posMaster.orgRoot.orgRootShortName}`
: null;
[
item.posMaster?.orgChild4?.orgChild4ShortName,
item.posMaster?.orgChild3?.orgChild3ShortName,
item.posMaster?.orgChild2?.orgChild2ShortName,
item.posMaster?.orgChild1?.orgChild1ShortName,
item.posMaster?.orgRoot?.orgRootShortName,
].find(Boolean) || "";
const metaAct = {
profileId: item.posMasterChild.current_holderId,
dateStart: body.refIds[0].commandDateAffect,
@ -6619,6 +6607,17 @@ export class CommandController extends Controller {
await this.actpositionRepository.save(dataAct);
historyAct.profileActpositionId = dataAct.id;
await this.actpositionHistoryRepository.save(historyAct);
// ปิดสถานะรักษาการเดิม
const _actposition = await this.actpositionRepository.find({
where: { profileId: item.posMasterChild.current_holderId },
});
const profileActs = _actposition.map((_data) => ({
..._data,
status: false,
dateEnd: _data.status == true ? new Date() : _data.dateEnd,
}));
await this.actpositionRepository.save(profileActs);
}
}),
);