fix issue #1554, #1558 กรณีกับเข้าราชการปลดตำแหน่งเดิมและปั๊มตำแหน่งใหม่

This commit is contained in:
Bright 2025-06-04 17:04:42 +07:00
parent ebcd94a701
commit 6bba703b85

View file

@ -3323,6 +3323,16 @@ export class CommandController extends Controller {
positionTypeNew?: string | null;
positionLevelNew?: string | null;
positionNameNew?: string | null;
posmasterId?: string| null;
posTypeNameNew?: string | null;
posLevelNameNew?: string | null;
posNoNew?: string | null;
posNoAbbNew?: string | null;
orgRootNew?: string | null;
orgChild1New?: string | null;
orgChild2New?: string | null;
orgChild3New?: string | null;
orgChild4New?: string | null;
}[];
},
) {
@ -3381,16 +3391,18 @@ export class CommandController extends Controller {
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
const returnWork = await checkReturnCommandType(String(item.commandId));
const dest_item = await this.salaryRepo.findOne({
where: { profileId: item.profileId },
order: { order: "DESC" },
});
const before = null;
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
data.posNumCodeSitAbb = _posNumCodeSitAbb;
data.dateGovernment = new Date();
data.order = dest_item == null ? 1 : dest_item.order + 1;
const meta = {
order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
@ -3398,16 +3410,15 @@ export class CommandController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
data.posNumCodeSit = _posNumCodeSit;
data.posNumCodeSitAbb = _posNumCodeSitAbb;
Object.assign(data, { ...item, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
data.dateGovernment = meta.createdAt;
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
if(!returnWork) {
Object.assign(data, { ...item, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
}
const _null: any = null;
profile.isLeave = item.isLeave;
@ -3440,8 +3451,71 @@ export class CommandController extends Controller {
// profile.posLevelId = _null;
}
if (item.isGovernment == true) {
const returnWork = await checkReturnCommandType(String(item.commandId));
if (returnWork) {
//ปลดตำแหน่งเดิมที่ไม่ถูกปลดออกจากกิ่งครั้งเมื่อออกคำสั่งพักราชการหรือออกราชการไว้
await removeProfileInOrganize(profile.id, "OFFICER");
//ปั๊มตำแหน่งใหม่
const posMaster = await this.posMasterRepository.findOne({
where: { id: item.posmasterId?.toString() },
});
if (posMaster) {
const checkPosition = await this.positionRepository.find({
where: {
posMasterId: posMaster.id,
positionIsSelected: true,
},
});
if (checkPosition.length > 0) {
const clearPosition = checkPosition.map((positions) => ({
...positions,
positionIsSelected: false,
}));
await this.positionRepository.save(clearPosition);
}
posMaster.current_holderId = profile.id;
await this.posMasterRepository.save(posMaster);
const positionNew = await this.positionRepository.findOne({
where: {
posMasterId: posMaster.id,
},
});
if(positionNew) {
positionNew.positionIsSelected = true;
await this.positionRepository.save(positionNew, { data: req });
}
}
const newMapProfileSalary = {
profileId: profile.id,
commandId: item.commandId,
positionName: item.positionNameNew ?? null,
positionType: item.posTypeNameNew ?? null,
positionLevel: item.posLevelNameNew ?? null,
amount: item.amount ? item.amount : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
amountSpecial: item.amountSpecial ? item.amountSpecial : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
posNo: item.posNoNew,
posNoAbb: item.posNoAbbNew,
orgRoot: item.orgRootNew,
orgChild1: item.orgChild1New,
orgChild2: item.orgChild2New,
orgChild3: item.orgChild3New,
orgChild4: item.orgChild4New,
isGovernment: item.isGovernment,
commandNo: item.commandNo,
commandYear: item.commandYear,
commandDateAffect: item.commandDateAffect,
commandDateSign: item.commandDateSign,
commandCode: item.commandCode,
commandName: item.commandName,
remark: item.remark,
};
Object.assign(data, {...newMapProfileSalary, ...meta});
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data);
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history);
profile.leaveReason = _null;
profile.leaveCommandId = _null;
profile.leaveCommandNo = _null;