#246 เสริมคำสั่ง C-PM-25,C-PM-26
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m10s

This commit is contained in:
Adisak 2026-05-29 10:12:46 +07:00
parent 521a748de1
commit 755ae992dd
2 changed files with 42 additions and 98 deletions

View file

@ -41,7 +41,6 @@ import {
removeProfileInOrganize,
setLogDataDiff,
checkReturnCommandType,
checkExceptCommandType,
checkCommandType,
removePostMasterAct,
logPositionIsSelectedChange,
@ -5629,20 +5628,10 @@ export class CommandController extends Controller {
_profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date();
if (item.isLeave == true) {
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = `${item.commandNo}/${_commandYear}`;
_profile.leaveRemark = exceptClear.leaveRemark ?? _null;
_profile.leaveDate = item.commandDateAffect ?? _null;
_profile.leaveType = exceptClear.LeaveType ?? _null;
} else {
if (orgRevisionRef) {
await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE");
}
await removeProfileInOrganize(_profile.id, "OFFICER");
if (orgRevisionRef) {
await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE");
}
await removeProfileInOrganize(_profile.id, "OFFICER");
}
const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile.status) {
@ -5821,32 +5810,22 @@ export class CommandController extends Controller {
_profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date();
if (item.isLeave == true) {
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = `${item.commandNo}/${_commandYear}`;
_profile.leaveRemark = exceptClear.leaveRemark ?? _null;
_profile.leaveDate = item.commandDateAffect ?? _null;
_profile.leaveType = exceptClear.LeaveType ?? _null;
} else {
// บันทึกประวัติก่อนลบตำแหน่ง
const curRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
// บันทึกประวัติก่อนลบตำแหน่ง
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 (curRevision) {
const curPosMaster = await this.employeePosMasterRepository.findOne({
where: {
current_holderId: _profile.id,
orgRevisionId: curRevision.id,
},
});
if (curPosMaster) {
await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE");
}
if (curPosMaster) {
await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE");
}
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
}
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
}
const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile.status) {
@ -6166,32 +6145,22 @@ export class CommandController extends Controller {
_profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date();
if (item.isLeave == true) {
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = `${item.commandNo}/${_commandYear}`;
_profile.leaveRemark = exceptClear.leaveRemark ?? _null;
_profile.leaveDate = item.commandDateAffect ?? _null;
_profile.leaveType = exceptClear.LeaveType ?? _null;
} else {
// บันทึกประวัติก่อนลบตำแหน่ง
const curRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
// บันทึกประวัติก่อนลบตำแหน่ง
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 (curRevision) {
const curPosMaster = await this.employeePosMasterRepository.findOne({
where: {
current_holderId: _profile.id,
orgRevisionId: curRevision.id,
},
});
if (curPosMaster) {
await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE");
}
if (curPosMaster) {
await CreatePosMasterHistoryEmployee(curPosMaster.id, req, "DELETE");
}
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
}
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
}
const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile.status) {

View file

@ -326,7 +326,7 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
await AppDataSource.getRepository(EmployeePosMaster)
.createQueryBuilder()
.update(EmployeePosMaster)
.set({ current_holderId: null })
.set({ current_holderId: null, isSit: false })
.where("id = :id", { id: findProfileInEmpPosMaster?.id })
.execute();
@ -395,43 +395,6 @@ export async function checkReturnCommandType(commandId: string) {
return true;
}
export async function checkExceptCommandType(commandId: string) {
const commandRepository = AppDataSource.getRepository(Command);
const commandReciveRepository = AppDataSource.getRepository(CommandRecive);
const _type = await commandRepository.findOne({
where: {
id: commandId,
},
relations: ["commandType"],
});
if (!["C-PM-25", "C-PM-26"].includes(String(_type?.commandType.code))) {
return { status: false, LeaveType: null, leaveRemark: null };
}
const _commandRecive = await commandReciveRepository.findOne({
where: { commandId: commandId },
});
let _leaveType: string = "";
switch (String(_type?.commandType.code)) {
case "C-PM-25": {
_leaveType = "DISCIPLINE_SUSPEND"; //คำสั่งพักจากราชการ
break;
}
case "C-PM-26": {
_leaveType = "DISCIPLINE_TEMP_SUSPEND"; //คำสั่งให้ออกจากราชการไว้ก่อน
break;
}
default: {
_leaveType = "";
}
}
return {
status: true,
LeaveType: _leaveType,
leaveRemark: _commandRecive ? _commandRecive.remarkVertical : null,
};
}
export async function checkCommandType(commandId: string) {
const commandRepository = AppDataSource.getRepository(Command);
const commandReciveRepository = AppDataSource.getRepository(CommandRecive);
@ -451,6 +414,8 @@ export async function checkCommandType(commandId: string) {
"C-PM-23",
"C-PM-19",
"C-PM-20",
"C-PM-25",
"C-PM-26",
"C-PM-43",
].includes(String(_type?.commandType.code))
) {
@ -500,6 +465,16 @@ export async function checkCommandType(commandId: string) {
_retireTypeName = "ลาออกจากราชการ";
break;
}
case "C-PM-25": {
_leaveType = "DISCIPLINE_SUSPEND";
_retireTypeName = "พักจากราชการ";
break;
}
case "C-PM-26": {
_leaveType = "DISCIPLINE_TEMP_SUSPEND";
_retireTypeName = "ให้ออกจากราชการไว้ก่อน";
break;
}
case "C-PM-43": {
_leaveType = "RETIRE_OUT_EMP";
_retireTypeName = "ให้ออกจากราชการ";