Migrate add table profileSalaryBackup & เพิ่ม insert รักษาการ และช่วยราชการ #2292

This commit is contained in:
harid 2026-02-06 14:47:13 +07:00
parent 203ec6cb84
commit 5b726e69c8
5 changed files with 406 additions and 21 deletions

View file

@ -397,8 +397,7 @@ export class ProfileSalaryController extends Controller {
const record = await this.salaryRepo.find({
where: {
profileId: profile.id,
// commandCode: In(["5", "6", "7"])
commandCode: In(["5", "6", "7"]),
commandCode: In(["5", "6", "7", "19"]),
},
order: { order: "ASC" },
});
@ -477,7 +476,7 @@ export class ProfileSalaryController extends Controller {
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.salaryRepo.find({
where: { profileId: profileId, commandCode: In(["5", "6", "7"]) },
where: { profileId: profileId, commandCode: In(["5", "6", "7", "19"]) },
order: { order: "ASC" },
});
// const result = record.map((r) => ({
@ -842,7 +841,7 @@ export class ProfileSalaryController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_SALARY_OFFICER");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_SALARY_OFFICER");
const record = await this.salaryRepo.find({
where: { profileId: profileId, commandCode: In(["5", "6", "7"]) },
where: { profileId: profileId, commandCode: In(["5", "6", "7", "19"]) },
order: { order: "ASC" },
});
return new HttpSuccess(record);
@ -909,6 +908,7 @@ export class ProfileSalaryController extends Controller {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง";
}
Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory();
@ -1032,6 +1032,7 @@ export class ProfileSalaryController extends Controller {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง";
}
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });

View file

@ -49,7 +49,7 @@ export class ProfileSalaryEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.salaryRepo.find({
where: { profileEmployeeId: profile.id, commandCode: In(["5", "6", "7"]) },
where: { profileEmployeeId: profile.id, commandCode: In(["5", "6", "7", "19"]) },
order: { order: "ASC" },
});
return new HttpSuccess(record);
@ -96,7 +96,7 @@ export class ProfileSalaryEmployeeController extends Controller {
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const record = await this.salaryRepo.find({
where: { profileEmployeeId: profileId, commandCode: In(["5", "6", "7"]) },
where: { profileEmployeeId: profileId, commandCode: In(["5", "6", "7", "19"]) },
order: { order: "ASC" },
});
return new HttpSuccess(record);
@ -322,7 +322,7 @@ export class ProfileSalaryEmployeeController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE");
const record = await this.salaryRepo.find({
where: { profileEmployeeId: profileId, commandCode: In(["5", "6", "7"]) },
where: { profileEmployeeId: profileId, commandCode: In(["5", "6", "7", "19"]) },
order: { order: "ASC" },
});
return new HttpSuccess(record);
@ -395,6 +395,7 @@ export class ProfileSalaryEmployeeController extends Controller {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง";
}
Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory();
@ -528,6 +529,7 @@ export class ProfileSalaryEmployeeController extends Controller {
if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ";
else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ";
else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง";
}
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });

View file

@ -35,7 +35,9 @@ import {
CreatePositionSalaryEditHistory,
PositionSalaryEditHistory,
} from "../entities/PositionSalaryEditHistory";
import { ProfileSalaryBackup } from "../entities/ProfileSalaryBackup";
import { ProfileActposition } from "../entities/ProfileActposition";
import { ProfileAssistance } from "../entities/ProfileAssistance";
@Route("api/v1/org/profile/salaryTemp")
@Tags("ProfileSalaryTemp")
@Security("bearerAuth")
@ -1328,12 +1330,6 @@ export class ProfileSalaryTempController extends Controller {
// const toUpdate = salaryTemps.filter((t) => t.salaryId && t.isEdit && !t.isDelete);
const backupTemp = salaryTemps;
const toInsert = salaryTemps.filter((t) => !t.isDelete);
const dateNow = new Date();
const metaUpdate = {
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
lastUpdatedAt: dateNow,
};
// delete profile salary temp
await queryRunner.manager.delete(ProfileSalaryTemp, {
@ -1341,6 +1337,23 @@ export class ProfileSalaryTempController extends Controller {
});
// add insert to profile salary backup
const profileSalaryBeforeDelete = await queryRunner.manager.find(ProfileSalary, {
where: {
...(isOfficer
? { profileId: body.profileId }
: { profileEmployeeId: body.profileId }),
},
});
if (profileSalaryBeforeDelete.length > 0) {
const backupRows = profileSalaryBeforeDelete.map(({ id, ...salary }) =>
queryRunner.manager.create(ProfileSalaryBackup, {
...salary,
profileSalaryId: id,
})
);
await queryRunner.manager.insert(ProfileSalaryBackup, backupRows);
}
// delete profile salary
await queryRunner.manager.delete(ProfileSalary, {
@ -1366,18 +1379,78 @@ export class ProfileSalaryTempController extends Controller {
* 5. INSERT (bulk)
* ========================= */
if (toInsert.length > 0) {
const metaCreate = {
const dateNow = new Date();
const metaCreated = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
createdAt: dateNow,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
lastUpdatedAt: dateNow,
};
const insertData = toInsert.map(({ id, ...data }) => ({
...data,
...metaCreate,
...metaUpdate,
}));
await queryRunner.manager.insert(ProfileSalary, insertData);
const salaryRows = toInsert.filter(
x => !["17", "18"].includes(x.commandCode)
);
// ส่งไปรักษาการ
const actPositionRows = toInsert.filter(
x => x.commandCode === "17"
);
// ส่งไปช่วยราชการ
const assistanceRows = toInsert.filter(
x => x.commandCode === "18"
);
if (salaryRows.length) {
await queryRunner.manager.insert(
ProfileSalary,
salaryRows.map(({ id, ...data }) => ({
...data,
...metaCreated,
}))
);
}
if (actPositionRows.length) {
await queryRunner.manager.insert(
ProfileActposition,
actPositionRows.map(x => ({
profileId: x.profileId,
profileEmployeeId: x.profileEmployeeId,
dateStart: x.commandDateAffect,
dateEnd: x.commandDateAffect,
posNo: x.posNo,
position: x.positionName,
commandId: x.commandId,
refCommandNo: x.commandNo,
refCommandDate: x.commandDateAffect,
status: false,
isDeleted: false,
...metaCreated,
}))
);
}
if (assistanceRows.length) {
await queryRunner.manager.insert(
ProfileAssistance,
assistanceRows.map(x => ({
profileId: x.profileId,
profileEmployeeId: x.profileEmployeeId,
agency: x.orgRoot,
dateStart: x.commandDateAffect,
dateEnd: x.commandDateAffect,
commandId: x.commandId,
commandNo: x.commandNo,
commandName: x.commandName,
refCommandDate: x.commandDateSign,
refId: x.refId,
status: "DONE",
isUpload: false,
...metaCreated,
}))
);
}
}
// insert profile salary temp new