fix script retire and fix bug filter registry retire

This commit is contained in:
Warunee Tamkoo 2025-10-03 16:44:43 +07:00
parent c89d1bb6cc
commit 53e6d6fb48
2 changed files with 41 additions and 54 deletions

View file

@ -264,7 +264,7 @@ export class CommandController extends Controller {
yearKeyword = match[1].trim(); yearKeyword = match[1].trim();
} }
let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null; let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null;
// const [commands, total] = await this.commandRepository // const [commands, total] = await this.commandRepository
let query = await this.commandRepository let query = await this.commandRepository
.createQueryBuilder("command") .createQueryBuilder("command")
@ -335,16 +335,13 @@ export class CommandController extends Controller {
); );
}), }),
) )
.orderBy("command.createdAt", "DESC") .orderBy("command.createdAt", "DESC");
if (sortBy) { if (sortBy) {
query = query.orderBy( query = query.orderBy(`command.${sortBy}`, descending ? "DESC" : "ASC");
`command.${sortBy}`, }
descending ? "DESC" : "ASC"
);
}
let [commands, total] = await query let [commands, total] = await query
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
@ -1500,7 +1497,7 @@ export class CommandController extends Controller {
const today = new Date(); const today = new Date();
today.setUTCHours(0, 0, 0, 0); today.setUTCHours(0, 0, 0, 0);
let type: string = "OFFICER"; let type: string = "OFFICER";
let _Date = new Date() let _Date = new Date();
try { try {
const response_ = await axios.get( const response_ = await axios.get(
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`, process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
@ -1513,15 +1510,17 @@ export class CommandController extends Controller {
}, },
); );
if (response_ && response_.data.result) { if (response_ && response_.data.result) {
let signDate:string = "" let signDate: string = "";
if (response_.data.result.signDate != null) { if (response_.data.result.signDate != null) {
signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)) signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate));
} else {
signDate = Extension.ToThaiShortDate_noPrefix(_Date);
} }
else { response_.data.result.profiles = response_.data.result.profiles.filter(
signDate = Extension.ToThaiShortDate_noPrefix(_Date) (x: any) =>
} x.profileId == "7247d218-eca0-472b-b224-e402260f2103" ||
response_.data.result.profiles = response_.data.result.profiles x.profileId == "fe52faf3-ad18-480b-968c-d9a8c1fbca32",
.filter((x: any) => x.profileId == "7247d218-eca0-472b-b224-e402260f2103" || x.profileId == "fe52faf3-ad18-480b-968c-d9a8c1fbca32") );
await Promise.all( await Promise.all(
response_.data.result.profiles.map(async (x: any) => { response_.data.result.profiles.map(async (x: any) => {
const _profile = await this.profileRepository.findOneBy({ id: x.profileId }); const _profile = await this.profileRepository.findOneBy({ id: x.profileId });
@ -1533,7 +1532,7 @@ export class CommandController extends Controller {
// console.log("3. แก้ไขสถานะในทะเบียนประวัติ") // console.log("3. แก้ไขสถานะในทะเบียนประวัติ")
_profile.isRetirement = true; _profile.isRetirement = true;
_profile.isLeave = true; _profile.isLeave = true;
_profile.isActive = false _profile.isActive = false;
_profile.leaveType = "RETIRE"; _profile.leaveType = "RETIRE";
_profile.leaveReason = "เกษียณอายุราชการ"; _profile.leaveReason = "เกษียณอายุราชการ";
_profile.leaveDate = _Date; _profile.leaveDate = _Date;
@ -1568,12 +1567,11 @@ export class CommandController extends Controller {
}, },
); );
if (response_ && response_.data.result) { if (response_ && response_.data.result) {
let signDate:string = "" let signDate: string = "";
if (response_.data.result.signDate != null) { if (response_.data.result.signDate != null) {
signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)) signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate));
} } else {
else { signDate = Extension.ToThaiShortDate_noPrefix(_Date);
signDate = Extension.ToThaiShortDate_noPrefix(_Date)
} }
await Promise.all( await Promise.all(
@ -1587,7 +1585,7 @@ export class CommandController extends Controller {
// แก้ไขสถานะในทะเบียนประวัติ // แก้ไขสถานะในทะเบียนประวัติ
_profileEmp.isRetirement = true; _profileEmp.isRetirement = true;
_profileEmp.isLeave = true; _profileEmp.isLeave = true;
_profileEmp.isActive = false _profileEmp.isActive = false;
_profileEmp.leaveType = "RETIRE"; _profileEmp.leaveType = "RETIRE";
_profileEmp.leaveReason = "เกษียณอายุราชการ"; _profileEmp.leaveReason = "เกษียณอายุราชการ";
_profileEmp.leaveDate = _Date; _profileEmp.leaveDate = _Date;
@ -1612,9 +1610,8 @@ export class CommandController extends Controller {
} }
async profileSalaryRetire(profileId: string, type: string, signDate: string, _Date: Date) { async profileSalaryRetire(profileId: string, type: string, signDate: string, _Date: Date) {
const whereKey = type == "OFFICER" const whereKey =
? { profileId: profileId } type == "OFFICER" ? { profileId: profileId } : { profileEmployeeId: profileId };
: { profileEmployeeId: profileId };
const maxOrder = await this.salaryRepo.findOne({ const maxOrder = await this.salaryRepo.findOne({
select: { order: true }, select: { order: true },
where: whereKey, where: whereKey,
@ -1657,8 +1654,7 @@ export class CommandController extends Controller {
if (type == "OFFICER") { if (type == "OFFICER") {
data.profileId = profileId; data.profileId = profileId;
data.profileEmployeeId = null; data.profileEmployeeId = null;
} } else if (type == "EMPLOYEE") {
else if (type == "EMPLOYEE"){
data.profileEmployeeId = profileId; data.profileEmployeeId = profileId;
data.profileId = null; data.profileId = null;
} }
@ -1668,12 +1664,12 @@ export class CommandController extends Controller {
} }
async posMasterRetire(profileId: string, type: string, _Date: Date) { async posMasterRetire(profileId: string, type: string, _Date: Date) {
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
if (orgRevision) { if (orgRevision) {
let _posMaster:any = null; let _posMaster: any = null;
let _position:any = null; let _position: any = null;
if (type == "OFFICER") { if (type == "OFFICER") {
_posMaster = await this.posMasterRepository.findOne({ _posMaster = await this.posMasterRepository.findOne({
where: { where: {
@ -1683,10 +1679,10 @@ export class CommandController extends Controller {
}); });
if (_posMaster) { if (_posMaster) {
_position = await this.positionRepository.findOne({ _position = await this.positionRepository.findOne({
where: { where: {
posMasterId: _posMaster.id, posMasterId: _posMaster.id,
positionIsSelected: true positionIsSelected: true,
} },
}); });
if (_position) { if (_position) {
_position.positionIsSelected = false; _position.positionIsSelected = false;
@ -1694,15 +1690,13 @@ export class CommandController extends Controller {
_position.lastUpdatedAt = _Date; _position.lastUpdatedAt = _Date;
await this.positionRepository.save(_position); await this.positionRepository.save(_position);
} }
_posMaster.isSit = false;
_posMaster.current_holderId = null; _posMaster.current_holderId = null;
_posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdateFullName = "System Administrator";
_posMaster.lastUpdatedAt = _Date; _posMaster.lastUpdatedAt = _Date;
await this.posMasterRepository.save(_posMaster); await this.posMasterRepository.save(_posMaster);
await CreatePosMasterHistoryOfficer(_posMaster.id, null); await CreatePosMasterHistoryOfficer(_posMaster.id, null);
} }
} } else if (type == "EMPLOYEE") {
else if (type == "EMPLOYEE") {
_posMaster = await this.employeePosMasterRepository.findOne({ _posMaster = await this.employeePosMasterRepository.findOne({
where: { where: {
orgRevisionId: orgRevision.id, orgRevisionId: orgRevision.id,
@ -1711,10 +1705,10 @@ export class CommandController extends Controller {
}); });
if (_posMaster) { if (_posMaster) {
_position = await this.employeePositionRepository.findOne({ _position = await this.employeePositionRepository.findOne({
where: { where: {
posMasterId: _posMaster.id, posMasterId: _posMaster.id,
positionIsSelected: true positionIsSelected: true,
} },
}); });
if (_position) { if (_position) {
_position.positionIsSelected = false; _position.positionIsSelected = false;
@ -1722,7 +1716,6 @@ export class CommandController extends Controller {
_position.lastUpdatedAt = _Date; _position.lastUpdatedAt = _Date;
await this.employeePositionRepository.save(_position); await this.employeePositionRepository.save(_position);
} }
_posMaster.isSit = false;
_posMaster.current_holderId = null; _posMaster.current_holderId = null;
_posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdateFullName = "System Administrator";
_posMaster.lastUpdatedAt = _Date; _posMaster.lastUpdatedAt = _Date;
@ -3207,13 +3200,10 @@ export class CommandController extends Controller {
where: { refId: In(_refId) }, where: { refId: In(_refId) },
}); });
// 2. ดึง commandId ที่ไม่ซ้ำ // 2. ดึง commandId ที่ไม่ซ้ำ
const commandIds = Array.from(new Set(commandRecives.map(x => x.commandId).filter(Boolean))); const commandIds = Array.from(new Set(commandRecives.map((x) => x.commandId).filter(Boolean)));
// 3. อัปเดต status ของ command // 3. อัปเดต status ของ command
if (commandIds.length > 0) { if (commandIds.length > 0) {
await this.commandRepository.update( await this.commandRepository.update({ id: In(commandIds) }, { status: "CANCEL" });
{ id: In(commandIds) },
{ status: "CANCEL" }
);
} }
return new HttpSuccess(); return new HttpSuccess();
} }
@ -3723,7 +3713,7 @@ export class CommandController extends Controller {
if (commandRecive && commandRecive.commandId) { if (commandRecive && commandRecive.commandId) {
await this.commandRepository.update( await this.commandRepository.update(
{ id: commandRecive?.commandId }, { id: commandRecive?.commandId },
{ status: "CANCEL" } { status: "CANCEL" },
); );
} }
} }
@ -4059,7 +4049,7 @@ export class CommandController extends Controller {
if (commandRecive && commandRecive.commandId) { if (commandRecive && commandRecive.commandId) {
await this.commandRepository.update( await this.commandRepository.update(
{ id: commandRecive?.commandId }, { id: commandRecive?.commandId },
{ status: "CANCEL" } { status: "CANCEL" },
); );
} }
} }

View file

@ -571,10 +571,7 @@ export class ProfileLeaveService {
} }
if (posLevel) { if (posLevel) {
queryBuilder.andWhere( queryBuilder.andWhere("posLevel.posLevelName LIKE :keyword2", { keyword2: `${posLevel}` });
"CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) LIKE :keyword2",
{ keyword2: `${posLevel}` },
);
} }
if (isProbation !== undefined && isProbation !== null) { if (isProbation !== undefined && isProbation !== null) {