This commit is contained in:
Adisak 2026-05-11 13:01:48 +07:00
parent 09fd606b86
commit cf3ef00b7f
2 changed files with 28 additions and 4 deletions

View file

@ -4543,9 +4543,7 @@ export class CommandController extends Controller {
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date();
if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "EMPLOYEE");
}
// บันทึกประวัติก่อนลบตำแหน่ง
const clearProfile = await checkCommandType(String(item.commandId));
const curRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
@ -4574,6 +4572,14 @@ export class CommandController extends Controller {
orgChild2Ref = curPosMaster?.orgChild2 ?? null;
orgChild3Ref = curPosMaster?.orgChild3 ?? null;
orgChild4Ref = curPosMaster?.orgChild4 ?? null;
if (curPosMaster) {
await CreatePosMasterHistoryEmployee(curPosMaster.id, req);
}
}
// ลบตำแหน่ง
if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "EMPLOYEE");
}
if (clearProfile.status) {
@ -5817,6 +5823,21 @@ export class CommandController extends Controller {
_profile.leaveDate = item.commandDateAffect ?? _null;
_profile.leaveType = exceptClear.LeaveType ?? _null;
} else {
// บันทึกประวัติก่อนลบตำแหน่ง
const curRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (curRevision) {
const curPosMaster = await this.employeePosMasterRepository.findOne({
where: {
current_holderId: _profile.id,
orgRevisionId: curRevision.id,
},
});
if (curPosMaster) {
await CreatePosMasterHistoryEmployee(curPosMaster.id, req);
}
}
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
}
}

View file

@ -81,7 +81,7 @@ import { ProfileAssistance } from "../entities/ProfileAssistance";
import { ProfileChangeName } from "../entities/ProfileChangeName";
import { ProfileChildren } from "../entities/ProfileChildren";
import { ProfileDuty } from "../entities/ProfileDuty";
import { getTopDegrees } from "../services/PositionService";
import { CreatePosMasterHistoryEmployee, getTopDegrees } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService";
import { PostRetireToExprofile } from "./ExRetirementController";
import { CommandCode } from "../entities/CommandCode";
@ -5778,6 +5778,9 @@ export class ProfileEmployeeController extends Controller {
}
await this.profileRepo.save(profile);
if (requestBody.isLeave == true) {
if (orgRevisionRef) {
await CreatePosMasterHistoryEmployee(orgRevisionRef.id, request);
}
await removeProfileInOrganize(profile.id, "EMPLOYEE");
}
let organizeName = "";