fix commandCode

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-04-29 16:58:20 +07:00
parent 0732071da0
commit d9799e642f

View file

@ -24,7 +24,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { In, LessThan, MoreThan } from "typeorm"; import { In, LessThan, IsNull, MoreThan } from "typeorm";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils"; import { setLogDataDiff } from "../interfaces/utils";
import { Command } from "../entities/Command"; import { Command } from "../entities/Command";
@ -47,7 +47,7 @@ export class ProfileSalaryEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.salaryRepo.find({ const record = await this.salaryRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, commandCode: In(["5", "6", "7"]) },
order: { order: "ASC" }, order: { order: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -60,7 +60,28 @@ export class ProfileSalaryEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.salaryRepo.find({ const record = await this.salaryRepo.find({
where: { profileEmployeeId: profile.id }, where: [
{
profileEmployeeId: profile.id,
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
]),
},
{ profileEmployeeId: profile.id, commandCode: IsNull() },
],
order: { order: "ASC" }, order: { order: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -87,7 +108,28 @@ export class ProfileSalaryEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const record = await this.salaryRepo.find({ const record = await this.salaryRepo.find({
where: { profileEmployeeId: profileId }, where: [
{
profileEmployeeId: profileId,
commandCode: In([
"0",
"9",
"1",
"2",
"3",
"4",
"8",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
]),
},
{ profileEmployeeId: profileId, commandCode: IsNull() },
],
order: { order: "ASC" }, order: { order: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -131,7 +173,9 @@ export class ProfileSalaryEmployeeController extends Controller {
[] as { name: string; days: number; year: number; month: number; day: number }[], [] as { name: string; days: number; year: number; month: number; day: number }[],
); );
const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [profile.id]); const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [
profile.id,
]);
const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const _posLevel = posLevel.length > 0 ? posLevel[0] : [];
const mapPosLevel = const mapPosLevel =
_posLevel.length > 1 _posLevel.length > 1
@ -204,7 +248,9 @@ export class ProfileSalaryEmployeeController extends Controller {
[] as { name: string; days: number; year: number; month: number; day: number }[], [] as { name: string; days: number; year: number; month: number; day: number }[],
); );
const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [profileId]); const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [
profileId,
]);
const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const _posLevel = posLevel.length > 0 ? posLevel[0] : [];
const mapPosLevel = const mapPosLevel =
_posLevel.length > 1 _posLevel.length > 1
@ -248,7 +294,7 @@ export class ProfileSalaryEmployeeController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE"); let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE");
const record = await this.salaryRepo.find({ const record = await this.salaryRepo.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, commandCode: In(["5", "6", "7"]) },
order: { order: "ASC" }, order: { order: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -318,9 +364,9 @@ export class ProfileSalaryEmployeeController extends Controller {
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}; };
if (body.commandCode && !body.commandName) { if (body.commandCode && !body.commandName) {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
} }
Object.assign(data, { ...body, ...meta }); Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
@ -359,10 +405,10 @@ export class ProfileSalaryEmployeeController extends Controller {
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const before = null; const before = null;
let _posNumCodeSit: string = "" let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = "" let _posNumCodeSitAbb: string = "";
const _command = await this.commandRepository.findOne({ const _command = await this.commandRepository.findOne({
where: { id: body.commandId ?? "" } where: { id: body.commandId ?? "" },
}); });
if (_command) { if (_command) {
if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") {
@ -371,35 +417,35 @@ export class ProfileSalaryEmployeeController extends Controller {
isDeputy: true, isDeputy: true,
orgRevision: { orgRevision: {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
orgRevisionIsDraft: false orgRevisionIsDraft: false,
} },
}, },
relations: ["orgRevision"] relations: ["orgRevision"],
}) });
_posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร";
_posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป.";
} } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") {
else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { _posNumCodeSit = "กรุงเทพมหานคร";
_posNumCodeSit = "กรุงเทพมหานคร" _posNumCodeSitAbb = "กทม.";
_posNumCodeSitAbb = "กทม." } else {
}
else {
let _profileAdmin = await this.profileGovementRepo.findOne({ let _profileAdmin = await this.profileGovementRepo.findOne({
where: { where: {
keycloak: _command?.createdUserId.toString(), keycloak: _command?.createdUserId.toString(),
current_holders: { current_holders: {
orgRevision: { orgRevision: {
orgRevisionIsCurrent: true, 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 _posNumCodeSit =
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ??
_posNumCodeSitAbb = _profileAdmin?.current_holders "";
.find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" _posNumCodeSitAbb =
_profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot
.orgRootShortName ?? "";
} }
} }
const data = new ProfileSalary(); const data = new ProfileSalary();
@ -451,9 +497,9 @@ export class ProfileSalaryEmployeeController extends Controller {
const before = structuredClone(record); const before = structuredClone(record);
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
if (body.commandCode && !body.commandName) { if (body.commandCode && !body.commandName) {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
} }
Object.assign(record, body); Object.assign(record, body);
Object.assign(history, { ...record, id: undefined }); Object.assign(history, { ...record, id: undefined });