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