Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
kittapath 2024-10-30 17:54:04 +07:00
commit 0eff2f0a1c

View file

@ -2631,6 +2631,57 @@ export class CommandController extends Controller {
return new HttpSuccess();
}
@Post("command21/employee/report")
public async command21SalaryEmployee(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
const profile = await this.profileEmployeeRepository.find({ where: { id: In(body.refIds) } });
const data = profile.map((_data) => ({
..._data,
statusTemp: "REPORT",
}));
await this.profileEmployeeRepository.save(data);
return new HttpSuccess();
}
@Post("command38/officer/report")
public async command38SalaryOfficer(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
const posMasters = await this.posMasterRepository.find({ where: { id: In(body.refIds) } });
const data = posMasters.map((_data) => ({
..._data,
statusReport: "REPORT",
}));
await this.posMasterRepository.save(data);
return new HttpSuccess();
}
@Post("command40/officer/report")
public async command40SalaryOfficer(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
const posMasters = await this.posMasterActRepository.find({ where: { id: In(body.refIds) } });
const data = posMasters.map((_data) => ({
..._data,
statusReport: "REPORT",
}));
await this.posMasterActRepository.save(data);
return new HttpSuccess();
}
@Post("command21/employee/report/excecute")
public async command21SalaryEmployeeExcecute(
@Request() req: RequestWithUser,
@ -2766,22 +2817,7 @@ export class CommandController extends Controller {
return new HttpSuccess();
}
@Post("command21/employee/report")
public async command21SalaryEmployee(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
const profile = await this.profileEmployeeRepository.find({ where: { id: In(body.refIds) } });
const data = profile.map((_data) => ({
..._data,
statusTemp: "REPORT",
}));
await this.profileEmployeeRepository.save(data);
return new HttpSuccess();
}
@Post("command21/employee/report/delete")
public async command21SalaryEmployeeDelete(
@Request() req: RequestWithUser,
@ -2827,22 +2863,7 @@ export class CommandController extends Controller {
await this.posMasterActRepository.save(data);
return new HttpSuccess();
}
@Post("command40/officer/report")
public async command40SalaryOfficer(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
const posMasters = await this.posMasterActRepository.find({ where: { id: In(body.refIds) } });
const data = posMasters.map((_data) => ({
..._data,
statusReport: "REPORT",
}));
await this.posMasterActRepository.save(data);
return new HttpSuccess();
}
@Post("command40/officer/report/delete")
public async command40SalaryOfficerDelete(
@Request() req: RequestWithUser,
@ -2982,51 +3003,92 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.refIds.map(async (item) => {
const profile = await this.posMasterRepository.findOne({
const posMaster = await this.posMasterRepository.findOne({
where: { id: item.refId },
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
relations: [
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
"current_holder",
"current_holder.posLevel",
"current_holder.posType",
],
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
if (!posMaster) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบตำแหน่งดังกล่าว");
}
if(posMaster.next_holderId != null) {
const dest_item = await this.salaryRepo.findOne({
where: { profileEmployeeId: item.refId },
order: { order: "DESC" },
});
const before = null;
const data = new ProfileSalary();
const shortName =
posMaster != null && posMaster.orgChild4 != null
? `${posMaster.orgChild4.orgChild4ShortName}${posMaster.posMasterNo}`
: posMaster != null && posMaster.orgChild3 != null
? `${posMaster.orgChild3.orgChild3ShortName}${posMaster.posMasterNo}`
: posMaster != null && posMaster.orgChild2 != null
? `${posMaster.orgChild2.orgChild2ShortName}${posMaster.posMasterNo}`
: posMaster != null && posMaster.orgChild1 != null
? `${posMaster.orgChild1.orgChild1ShortName}${posMaster.posMasterNo}`
: posMaster != null && posMaster?.orgRoot != null
? `${posMaster.orgRoot.orgRootShortName}${posMaster.posMasterNo}`
: null;
const profile = await this.profileRepository.findOne({
where: { id: posMaster.next_holderId }
});
const position = await this.positionRepository.findOne({
where: {
posMasterId: posMaster.id,
positionIsSelected: true
}
});
const dest_item = await this.salaryRepo.findOne({
where: { profileId: profile?.id },
order: { order: "DESC" },
});
const before = null;
const data = new ProfileSalary();
const meta = {
profileId: profile.id,
date: new Date(),
amount: item.amount,
commandId: item.commandId,
positionSalaryAmount: item.positionSalaryAmount,
mouthSalaryAmount: item.mouthSalaryAmount,
posNo: "",
position: profile.current_holder?.position || null,
positionType: profile.current_holder?.posType?.posTypeName || null,
positionLevel: profile.current_holder?.posLevel?.posLevelName || null,
refCommandNo: `${item.commandNo}/${Extension.ToThaiYear(item.commandYear)}`,
templateDoc: item.templateDoc,
order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
const meta = {
profileId: profile?.id,
date: new Date(),
amount: item.amount,
commandId: item.commandId,
positionSalaryAmount: item.positionSalaryAmount,
mouthSalaryAmount: item.mouthSalaryAmount,
posNo: shortName ?? null,
position: position?.positionName ?? null,
positionType: position?.posTypeId ?? null,
positionLevel: position?.posLevelId ?? null,
refCommandNo: `${item.commandNo}/${Extension.ToThaiYear(item.commandYear)}`,
templateDoc: item.templateDoc,
order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, meta);
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
Object.assign(data, meta);
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
if (profile != null) {
profile.position = position?.positionName ?? "";
profile.posTypeId = position?.posTypeId ?? "";
profile.posLevelId = position?.posLevelId ?? "";
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date();
await this.profileRepository.save(profile);
}
}
}),
);
const posMasters = await this.posMasterRepository.find({
@ -3034,27 +3096,14 @@ export class CommandController extends Controller {
});
const data = posMasters.map((_data) => ({
..._data,
current_holderId: _data.next_holderId,
next_holderId: null,
statusReport: "PENDING",
}));
await this.posMasterRepository.save(data);
return new HttpSuccess();
}
@Post("command38/officer/report")
public async command38SalaryOfficer(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
const posMasters = await this.posMasterRepository.find({ where: { id: In(body.refIds) } });
const data = posMasters.map((_data) => ({
..._data,
statusReport: "REPORT",
}));
await this.posMasterRepository.save(data);
return new HttpSuccess();
}
@Post("command38/officer/report/delete")
public async command38SalaryOfficerDelete(
@Request() req: RequestWithUser,