add command code 20
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m3s

This commit is contained in:
mamoss 2026-01-21 08:00:21 +07:00
parent b1210d51e8
commit 757da877f6
8 changed files with 268 additions and 218 deletions

View file

@ -49,7 +49,9 @@ export class ProfileSalaryController extends Controller {
private positionEmployeeRepo = AppDataSource.getRepository(TenurePositionEmployee);
private levelOfficerRepo = AppDataSource.getRepository(TenureLevelOfficer);
private levelEmployeeRepo = AppDataSource.getRepository(TenureLevelEmployee);
private positionExecutiveOfficerRepo = AppDataSource.getRepository(TenurePositionExecutiveOfficer);
private positionExecutiveOfficerRepo = AppDataSource.getRepository(
TenurePositionExecutiveOfficer,
);
private commandRepository = AppDataSource.getRepository(Command);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
@ -66,11 +68,12 @@ export class ProfileSalaryController extends Controller {
let _currentDate = CURRENT_DATE[0].today;
for await (const x of profile) {
if (x.isLeave) {
_currentDate = x.leaveDate
? Extension.toDateOnlyString(x.leaveDate)
: _currentDate
_currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate;
}
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [x.id, _currentDate]);
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [
x.id,
_currentDate,
]);
const _position = position.length > 0 ? position[0] : [];
const mapPosition =
_position.length > 1
@ -96,7 +99,7 @@ export class ProfileSalaryController extends Controller {
// Years: (calDayDiff.days_diff / 365.2524).toFixed(4),
// Months: ((calDayDiff.days_diff / 30.4375) % 12).toFixed(4),
// Days: (calDayDiff.days_diff % 30.4375).toFixed(4),
Years: Math.floor(calDayDiff.days_diff / 365.2524),
Years: Math.floor(calDayDiff.days_diff / 365.2524),
Months: Math.floor((calDayDiff.days_diff / 30.4375) % 12),
Days: Math.floor(calDayDiff.days_diff % 30.4375),
};
@ -116,13 +119,11 @@ export class ProfileSalaryController extends Controller {
const profile = await this.profileEmployeeRepo.find();
for await (const x of profile) {
if (x?.isLeave) {
_currentDate = x.leaveDate
? Extension.toDateOnlyString(x.leaveDate)
: _currentDate
_currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate;
}
const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [
x.id,
_currentDate
_currentDate,
]);
const _position = position.length > 0 ? position[0] : [];
const mapPosition =
@ -149,7 +150,7 @@ export class ProfileSalaryController extends Controller {
// Years: (calDayDiff.days_diff / 365.2524).toFixed(4),
// Months: ((calDayDiff.days_diff / 30.4375) % 12).toFixed(4),
// Days: (calDayDiff.days_diff % 30.4375).toFixed(4),
Years: Math.floor(calDayDiff.days_diff / 365.2524),
Years: Math.floor(calDayDiff.days_diff / 365.2524),
Months: Math.floor((calDayDiff.days_diff / 30.4375) % 12),
Days: Math.floor(calDayDiff.days_diff % 30.4375),
};
@ -169,11 +170,12 @@ export class ProfileSalaryController extends Controller {
let _currentDate = CURRENT_DATE[0].today;
for await (const x of profile) {
if (x?.isLeave) {
_currentDate = x.leaveDate
? Extension.toDateOnlyString(x.leaveDate)
: _currentDate
_currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate;
}
const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [x.id, _currentDate]);
const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [
x.id,
_currentDate,
]);
const _positionLevel = positionLevel.length > 0 ? positionLevel[0] : [];
const mapPositionLevel =
_positionLevel.length > 1
@ -226,13 +228,11 @@ export class ProfileSalaryController extends Controller {
let _currentDate = CURRENT_DATE[0].today;
for await (const x of profile) {
if (x?.isLeave) {
_currentDate = x.leaveDate
? Extension.toDateOnlyString(x.leaveDate)
: _currentDate
_currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate;
}
const positionLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?, ?)", [
x.id,
_currentDate
_currentDate,
]);
const _positionLevel = positionLevel.length > 0 ? positionLevel[0] : [];
const mapPositionLevel =
@ -293,9 +293,7 @@ export class ProfileSalaryController extends Controller {
let _currentDate = CURRENT_DATE[0].today;
for await (const x of profile) {
if (x?.isLeave) {
_currentDate = x.leaveDate
? Extension.toDateOnlyString(x.leaveDate)
: _currentDate
_currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate;
}
const position = await this.positionRepo.findOne({
where: {
@ -310,7 +308,10 @@ export class ProfileSalaryController extends Controller {
posExecutive: true,
},
});
const positionExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [x.id, _currentDate]);
const positionExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [
x.id,
_currentDate,
]);
const _position = positionExecutive.length > 0 ? positionExecutive[0] : [];
const mapPosition =
_position.length > 1
@ -349,14 +350,14 @@ export class ProfileSalaryController extends Controller {
const allRegis = await AppDataSource.getRepository(viewRegistryOfficer)
.createQueryBuilder("registryOfficer")
.getMany();
const profileIds = new Set((await this.profileRepo.find()).map(p => p.id));
const profileIds = new Set((await this.profileRepo.find()).map((p) => p.id));
const mapData = allRegis
.filter(x => profileIds.has(x.profileId))
.map(x => ({
.filter((x) => profileIds.has(x.profileId))
.map((x) => ({
...x,
isProbation: Boolean(x.isProbation),
isLeave: Boolean(x.isLeave),
isRetirement: Boolean(x.isRetirement),
isProbation: Boolean(x.isProbation),
isLeave: Boolean(x.isLeave),
isRetirement: Boolean(x.isRetirement),
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
}));
if (mapData.length > 0) {
@ -371,14 +372,14 @@ export class ProfileSalaryController extends Controller {
const allRegis = await AppDataSource.getRepository(viewRegistryEmployee)
.createQueryBuilder("registryEmployee")
.getMany();
const profileEmpIds = new Set((await this.profileEmployeeRepo.find()).map(p => p.id));
const profileEmpIds = new Set((await this.profileEmployeeRepo.find()).map((p) => p.id));
const mapData = allRegis
.filter(x => profileEmpIds.has(x.profileEmployeeId))
.map(x => ({
.filter((x) => profileEmpIds.has(x.profileEmployeeId))
.map((x) => ({
...x,
isProbation: Boolean(x.isProbation),
isLeave: Boolean(x.isLeave),
isRetirement: Boolean(x.isRetirement),
isProbation: Boolean(x.isProbation),
isLeave: Boolean(x.isLeave),
isRetirement: Boolean(x.isRetirement),
Educations: x.Educations ? JSON.stringify(x.Educations) : "",
}));
if (mapData.length > 0) {
@ -407,14 +408,14 @@ export class ProfileSalaryController extends Controller {
if (r.commandId) {
_command = await this.commandRepository.findOne({
where: { id: r.commandId },
relations: ["commandType"]
relations: ["commandType"],
});
}
return {
...r,
commandType: _command && _command?.commandType ? _command?.commandType.code : null
commandType: _command && _command?.commandType ? _command?.commandType.code : null,
};
})
}),
);
return new HttpSuccess(result);
}
@ -444,6 +445,7 @@ export class ProfileSalaryController extends Controller {
"14",
"15",
"16",
"20",
]),
},
{ profileId: profile.id, commandCode: IsNull() },
@ -457,14 +459,14 @@ export class ProfileSalaryController extends Controller {
if (r.commandId) {
_command = await this.commandRepository.findOne({
where: { id: r.commandId },
relations: ["commandType"]
relations: ["commandType"],
});
}
return {
...r,
commandType: _command && _command?.commandType ? _command?.commandType.code : null
commandType: _command && _command?.commandType ? _command?.commandType.code : null,
};
})
}),
);
return new HttpSuccess(result);
}
@ -491,14 +493,14 @@ export class ProfileSalaryController extends Controller {
if (r.commandId) {
_command = await this.commandRepository.findOne({
where: { id: r.commandId },
relations: ["commandType"]
relations: ["commandType"],
});
}
return {
...r,
commandType: _command && _command?.commandType ? _command?.commandType.code : null
commandType: _command && _command?.commandType ? _command?.commandType.code : null,
};
})
}),
);
return new HttpSuccess(result);
}
@ -527,6 +529,7 @@ export class ProfileSalaryController extends Controller {
"14",
"15",
"16",
"20",
]),
},
{ profileId: profileId, commandCode: IsNull() },
@ -548,14 +551,14 @@ export class ProfileSalaryController extends Controller {
if (r.commandId) {
_command = await this.commandRepository.findOne({
where: { id: r.commandId },
relations: ["commandType"]
relations: ["commandType"],
});
}
return {
...r,
commandType: _command && _command?.commandType ? _command?.commandType.code : null
commandType: _command && _command?.commandType ? _command?.commandType.code : null,
};
})
}),
);
return new HttpSuccess(result);
}
@ -572,11 +575,13 @@ export class ProfileSalaryController extends Controller {
const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today");
let _currentDate = CURRENT_DATE[0].today;
if (profile && profile?.isLeave) {
_currentDate = profile && profile.leaveDate
? Extension.toDateOnlyString(profile.leaveDate)
: _currentDate
_currentDate =
profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate;
}
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [profile.id, _currentDate]);
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [
profile.id,
_currentDate,
]);
const _position = position.length > 0 ? position[0] : [];
const mapPosition =
@ -607,7 +612,10 @@ export class ProfileSalaryController extends Controller {
},
[] as { name: string; days: number; year: number; month: number; day: number }[],
);
const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [profile.id, _currentDate]);
const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [
profile.id,
_currentDate,
]);
const _posLevel = posLevel.length > 0 ? posLevel[0] : [];
const mapPosLevel =
_posLevel.length > 1
@ -646,7 +654,7 @@ export class ProfileSalaryController extends Controller {
const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [
profile.id,
_currentDate
_currentDate,
]);
const _posExecutive = posExecutive.length > 0 ? posExecutive[0] : [];
const mapPosExecutive =
@ -691,19 +699,23 @@ export class ProfileSalaryController extends Controller {
// "SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));",
// );
const _profile = await this.profileRepo.findOne({
where: { id: profileId }
})
where: { id: profileId },
});
if (!_profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today");
let _currentDate = CURRENT_DATE[0].today;
if (_profile && _profile?.isLeave) {
_currentDate = _profile && _profile.leaveDate
? Extension.toDateOnlyString(_profile.leaveDate)
: _currentDate
_currentDate =
_profile && _profile.leaveDate
? Extension.toDateOnlyString(_profile.leaveDate)
: _currentDate;
}
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [profileId, _currentDate]);
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [
profileId,
_currentDate,
]);
const _position = position.length > 0 ? position[0] : [];
const mapPosition =
@ -738,7 +750,10 @@ export class ProfileSalaryController extends Controller {
[] as { name: string; days: number; year: number; month: number; day: number }[],
);
const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [profileId, _currentDate]);
const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [
profileId,
_currentDate,
]);
const _posLevel = posLevel.length > 0 ? posLevel[0] : [];
const mapPosLevel =
_posLevel.length > 1
@ -780,7 +795,7 @@ export class ProfileSalaryController extends Controller {
const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [
profileId,
_currentDate
_currentDate,
]);
const _posExecutive = posExecutive.length > 0 ? posExecutive[0] : [];
const mapPosExecutive =
@ -891,9 +906,9 @@ export class ProfileSalaryController extends Controller {
};
const _null: any = null;
if (body.commandCode && !body.commandName) {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
}
Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory();
@ -929,10 +944,10 @@ export class ProfileSalaryController extends Controller {
order: { order: "DESC" },
});
const before = null;
let _posNumCodeSit: string = ""
let _posNumCodeSitAbb: string = ""
let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = "";
const _command = await this.commandRepository.findOne({
where: { id: body.commandId ?? "" }
where: { id: body.commandId ?? "" },
});
if (_command) {
if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") {
@ -941,35 +956,35 @@ export class ProfileSalaryController extends Controller {
isDeputy: true,
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
orgRevisionIsDraft: false,
},
},
relations: ["orgRevision"]
})
relations: ["orgRevision"],
});
_posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร";
_posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป.";
}
else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") {
_posNumCodeSit = "กรุงเทพมหานคร"
_posNumCodeSitAbb = "กทม."
}
else {
} else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") {
_posNumCodeSit = "กรุงเทพมหานคร";
_posNumCodeSitAbb = "กทม.";
} else {
let _profileAdmin = await this.profileRepo.findOne({
where: {
where: {
keycloak: _command?.createdUserId.toString(),
current_holders: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
}
orgRevisionIsDraft: false,
},
},
},
relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"]
relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"],
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
_posNumCodeSitAbb = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? ""
_posNumCodeSit =
_profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ??
"";
_posNumCodeSitAbb =
_profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot
.orgRootShortName ?? "";
}
}
const data = new ProfileSalary();
@ -1014,9 +1029,9 @@ export class ProfileSalaryController extends Controller {
const before = structuredClone(record);
const history = new ProfileSalaryHistory();
if (body.commandCode && !body.commandName) {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
}
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });