Merge branch 'develop' into adiDev
This commit is contained in:
commit
5efb7346d6
5 changed files with 186 additions and 31 deletions
|
|
@ -1478,7 +1478,7 @@ export class CommandController extends Controller {
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
async cronjobUpdateRetirementStatus() {
|
async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) {
|
||||||
let body = {
|
let body = {
|
||||||
client_id: "gettoken",
|
client_id: "gettoken",
|
||||||
client_secret: process.env.AUTH_ACCOUNT_SECRET,
|
client_secret: process.env.AUTH_ACCOUNT_SECRET,
|
||||||
|
|
@ -1499,6 +1499,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()
|
||||||
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()}`,
|
||||||
|
|
@ -1510,23 +1511,46 @@ export class CommandController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (response && response_.data.result.length > 0) {
|
if (response_ && response_.data.result) {
|
||||||
let profiles: Profile[] = [];
|
let signDate:string = ""
|
||||||
|
if (response_.data.result.signDate != null) {
|
||||||
|
signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
signDate = Extension.ToThaiShortDate_noPrefix(_Date)
|
||||||
|
}
|
||||||
|
// let profiles: Profile[] = [];
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
response_.data.result.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 });
|
||||||
if (_profile) {
|
if (_profile) {
|
||||||
|
// console.log("1. บันทึกลงประวัติตำแหน่ง")
|
||||||
|
await this.profileSalaryRetire(x.profileId, type, signDate, _Date);
|
||||||
|
// console.log("2. ปลดออกจากโครงสร้าง")
|
||||||
|
await this.posMasterRetire(x.profileId, type, _Date);
|
||||||
|
// console.log("3. แก้ไขสถานะในทะเบียนประวัติ")
|
||||||
_profile.isRetirement = true;
|
_profile.isRetirement = true;
|
||||||
_profile.isLeave = true;
|
_profile.isLeave = true;
|
||||||
|
_profile.isActive = false
|
||||||
_profile.leaveType = "RETIRE";
|
_profile.leaveType = "RETIRE";
|
||||||
_profile.leaveDate = new Date();
|
_profile.leaveReason = "เกษียณอายุราชการ";
|
||||||
_profile.dateLeave = new Date();
|
_profile.leaveDate = _Date;
|
||||||
_profile.lastUpdatedAt = new Date();
|
_profile.dateLeave = _Date;
|
||||||
profiles.push(_profile);
|
_profile.lastUpdatedAt = _Date;
|
||||||
|
if (_profile.keycloak != null && _profile.keycloak != "") {
|
||||||
|
// console.log("4. disable keycloak/authen")
|
||||||
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
_profile.keycloak = "";
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// profiles.push(_profile);
|
||||||
|
// console.log("5. save profile ",_profile)
|
||||||
|
await this.profileRepository.save(_profile);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
await this.profileRepository.save(profiles);
|
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
|
|
@ -1542,29 +1566,144 @@ export class CommandController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (response && response_.data.result.length > 0) {
|
if (response_ && response_.data.result) {
|
||||||
let profiles: ProfileEmployee[] = [];
|
let signDate:string = ""
|
||||||
|
if (response_.data.result.signDate != null) {
|
||||||
|
signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
signDate = Extension.ToThaiShortDate_noPrefix(_Date)
|
||||||
|
}
|
||||||
|
// let profiles: ProfileEmployee[] = [];
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
response_.data.result.map(async (x: any) => {
|
response_.data.result.profiles.map(async (x: any) => {
|
||||||
const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId });
|
const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId });
|
||||||
if (_profileEmp) {
|
if (_profileEmp) {
|
||||||
|
// บันทึกลงประวัติตำแหน่ง
|
||||||
|
await this.profileSalaryRetire(x.profileId, type, signDate, _Date);
|
||||||
|
// ปลดออกจากโครงสร้าง
|
||||||
|
await this.posMasterRetire(x.profileId, type, _Date);
|
||||||
|
// แก้ไขสถานะในทะเบียนประวัติ
|
||||||
_profileEmp.isRetirement = true;
|
_profileEmp.isRetirement = true;
|
||||||
_profileEmp.isLeave = true;
|
_profileEmp.isLeave = true;
|
||||||
|
_profileEmp.isActive = false
|
||||||
_profileEmp.leaveType = "RETIRE";
|
_profileEmp.leaveType = "RETIRE";
|
||||||
_profileEmp.leaveDate = new Date();
|
_profileEmp.leaveReason = "เกษียณอายุราชการ";
|
||||||
_profileEmp.dateLeave = new Date();
|
_profileEmp.leaveDate = _Date;
|
||||||
_profileEmp.lastUpdatedAt = new Date();
|
_profileEmp.dateLeave = _Date;
|
||||||
profiles.push(_profileEmp);
|
_profileEmp.lastUpdatedAt = _Date;
|
||||||
|
if (_profileEmp.keycloak != null && _profileEmp.keycloak != "") {
|
||||||
|
// disable keycloak/authen
|
||||||
|
const delUserKeycloak = await deleteUser(_profileEmp.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
_profileEmp.keycloak = "";
|
||||||
|
_profileEmp.roleKeycloaks = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// profiles.push(_profileEmp);
|
||||||
|
await this.profileEmployeeRepository.save(_profileEmp);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
await this.profileEmployeeRepository.save(profiles);
|
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async profileSalaryRetire(profileId: string, type: string, signDate: string, _Date: Date) {
|
||||||
|
const whereKey = type == "OFFICER"
|
||||||
|
? { profileId: profileId }
|
||||||
|
: { profileEmployeeId: profileId };
|
||||||
|
const maxOrder = await this.salaryRepo.findOne({
|
||||||
|
select: { order: true },
|
||||||
|
where: whereKey,
|
||||||
|
order: { order: "DESC" },
|
||||||
|
});
|
||||||
|
const data: any = {
|
||||||
|
order: maxOrder ? maxOrder.order + 1 : 1,
|
||||||
|
amount: null,
|
||||||
|
positionSalaryAmount: null,
|
||||||
|
mouthSalaryAmount: null,
|
||||||
|
posNo: null,
|
||||||
|
positionExecutive: null,
|
||||||
|
positionType: null,
|
||||||
|
positionLevel: null,
|
||||||
|
amountSpecial: null,
|
||||||
|
orgRoot: null,
|
||||||
|
orgChild1: null,
|
||||||
|
orgChild2: null,
|
||||||
|
orgChild3: null,
|
||||||
|
orgChild4: null,
|
||||||
|
commandYear: _Date.getFullYear() + 543,
|
||||||
|
commandDateAffect: _Date,
|
||||||
|
commandCode: "16",
|
||||||
|
commandName: "พ้นจากราชการ",
|
||||||
|
posNoAbb: null,
|
||||||
|
isEntry: false,
|
||||||
|
positionName: "เกษียณอายุราชการ",
|
||||||
|
createdUserId: "",
|
||||||
|
createdFullName: "System Administrator",
|
||||||
|
lastUpdateUserId: "",
|
||||||
|
lastUpdateFullName: "System Administrator",
|
||||||
|
createdAt: _Date,
|
||||||
|
lastUpdatedAt: _Date,
|
||||||
|
remark: `ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. ${signDate}`, // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง
|
||||||
|
isGovernment: false,
|
||||||
|
};
|
||||||
|
const history = new ProfileSalaryHistory();
|
||||||
|
Object.assign(history, { ...data, id: undefined });
|
||||||
|
data.dateGovernment = _Date;
|
||||||
|
if (type == "OFFICER") {
|
||||||
|
data.profileId = profileId;
|
||||||
|
data.profileEmployeeId = null;
|
||||||
|
}
|
||||||
|
else if (type == "EMPLOYEE"){
|
||||||
|
data.profileEmployeeId = profileId;
|
||||||
|
data.profileId = null;
|
||||||
|
}
|
||||||
|
const savedData = await this.salaryRepo.save(data);
|
||||||
|
history.profileSalaryId = savedData.id;
|
||||||
|
await this.salaryHistoryRepo.save(history);
|
||||||
|
}
|
||||||
|
|
||||||
|
async posMasterRetire(profileId: string, type: string, _Date: Date) {
|
||||||
|
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }
|
||||||
|
});
|
||||||
|
if (orgRevision) {
|
||||||
|
let _posMaster:any = null;
|
||||||
|
if (type == "OFFICER") {
|
||||||
|
_posMaster = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: orgRevision.id,
|
||||||
|
current_holderId: profileId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (_posMaster) {
|
||||||
|
_posMaster.current_holderId = null;
|
||||||
|
_posMaster.lastUpdateFullName = "System Administrator";
|
||||||
|
_posMaster.lastUpdatedAt = _Date;
|
||||||
|
await this.posMasterRepository.save(_posMaster);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == "EMPLOYEE") {
|
||||||
|
_posMaster = await this.employeePosMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: orgRevision.id,
|
||||||
|
current_holderId: profileId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (_posMaster) {
|
||||||
|
_posMaster.current_holderId = null;
|
||||||
|
_posMaster.lastUpdateFullName = "System Administrator";
|
||||||
|
_posMaster.lastUpdatedAt = _Date;
|
||||||
|
await this.employeePosMasterRepository.save(_posMaster);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Get("cornjob/cronjobUpdateRetirementStatus")
|
@Get("cornjob/cronjobUpdateRetirementStatus")
|
||||||
async runCronjobUpdateRetirementStatus() {
|
async runCronjobUpdateRetirementStatus() {
|
||||||
await this.cronjobUpdateRetirementStatus();
|
await this.cronjobUpdateRetirementStatus();
|
||||||
|
|
|
||||||
|
|
@ -5888,7 +5888,7 @@ export class ProfileController extends Controller {
|
||||||
)
|
)
|
||||||
// .andWhere("profile.leaveCommandId Is NOT NULL")
|
// .andWhere("profile.leaveCommandId Is NOT NULL")
|
||||||
.andWhere(
|
.andWhere(
|
||||||
"profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and profileSalary.positionName != 'เกษียณอายุราชการ')",
|
"profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and ps.positionName != 'เกษียณอายุราชการ')",
|
||||||
)
|
)
|
||||||
|
|
||||||
.andWhere(
|
.andWhere(
|
||||||
|
|
|
||||||
|
|
@ -2786,7 +2786,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
)
|
)
|
||||||
// .andWhere("profileEmployee.leaveCommandId Is NOT NULL")
|
// .andWhere("profileEmployee.leaveCommandId Is NOT NULL")
|
||||||
.andWhere(
|
.andWhere(
|
||||||
"profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id and profileSalary.positionName != 'เกษียณอายุราชการ')",
|
"profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id and ps.positionName != 'เกษียณอายุราชการ')",
|
||||||
)
|
)
|
||||||
|
|
||||||
// .andWhere(
|
// .andWhere(
|
||||||
|
|
|
||||||
|
|
@ -249,9 +249,13 @@ export class ProfileGovernmentHistoryController extends Controller {
|
||||||
if (record.leaveType == "RETIRE") {
|
if (record.leaveType == "RETIRE") {
|
||||||
_profileSalary = record?.profileSalary.length > 1
|
_profileSalary = record?.profileSalary.length > 1
|
||||||
? record?.profileSalary[1]
|
? record?.profileSalary[1]
|
||||||
: null;
|
: record?.profileSalary.length > 0
|
||||||
|
? record?.profileSalary[0]
|
||||||
|
: null;
|
||||||
} else {
|
} else {
|
||||||
_profileSalary = record?.profileSalary[0];
|
_profileSalary = record?.profileSalary.length > 0
|
||||||
|
? record?.profileSalary[0]
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
if (_profileSalary) {
|
if (_profileSalary) {
|
||||||
_OrgLeave = [
|
_OrgLeave = [
|
||||||
|
|
@ -404,9 +408,13 @@ export class ProfileGovernmentHistoryController extends Controller {
|
||||||
if (record.leaveType == "RETIRE") {
|
if (record.leaveType == "RETIRE") {
|
||||||
_profileSalary = record?.profileSalary.length > 1
|
_profileSalary = record?.profileSalary.length > 1
|
||||||
? record?.profileSalary[1]
|
? record?.profileSalary[1]
|
||||||
: null;
|
: record?.profileSalary.length > 0
|
||||||
|
? record?.profileSalary[0]
|
||||||
|
: null;
|
||||||
} else {
|
} else {
|
||||||
_profileSalary = record?.profileSalary[0];
|
_profileSalary = record?.profileSalary.length > 0
|
||||||
|
? record?.profileSalary[0]
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
if (_profileSalary) {
|
if (_profileSalary) {
|
||||||
_OrgLeave = [
|
_OrgLeave = [
|
||||||
|
|
|
||||||
|
|
@ -264,11 +264,15 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
||||||
// profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
|
// profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
|
||||||
// ];
|
// ];
|
||||||
if (record.leaveType == "RETIRE") {
|
if (record.leaveType == "RETIRE") {
|
||||||
_profileSalary = record?.profileSalary.length > 1
|
_profileSalary = profileSalary.length > 1
|
||||||
? record?.profileSalary[1]
|
? profileSalary[1]
|
||||||
: null;
|
: profileSalary.length > 0
|
||||||
|
? profileSalary[0]
|
||||||
|
: null;
|
||||||
} else {
|
} else {
|
||||||
_profileSalary = record?.profileSalary[0];
|
_profileSalary = profileSalary.length > 0
|
||||||
|
? profileSalary[0]
|
||||||
|
: null
|
||||||
}
|
}
|
||||||
if (_profileSalary) {
|
if (_profileSalary) {
|
||||||
_OrgLeave = [
|
_OrgLeave = [
|
||||||
|
|
@ -435,11 +439,15 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
||||||
// profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
|
// profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
|
||||||
// ];
|
// ];
|
||||||
if (record.leaveType == "RETIRE") {
|
if (record.leaveType == "RETIRE") {
|
||||||
_profileSalary = record?.profileSalary.length > 1
|
_profileSalary = profileSalary.length > 1
|
||||||
? record?.profileSalary[1]
|
? profileSalary[1]
|
||||||
: null;
|
: profileSalary.length > 0
|
||||||
|
? profileSalary[0]
|
||||||
|
: null;
|
||||||
} else {
|
} else {
|
||||||
_profileSalary = record?.profileSalary[0];
|
_profileSalary = profileSalary.length > 0
|
||||||
|
? profileSalary[0]
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
if (_profileSalary) {
|
if (_profileSalary) {
|
||||||
_OrgLeave = [
|
_OrgLeave = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue