fix #708
This commit is contained in:
parent
7abd9eaef3
commit
019f65a454
1 changed files with 135 additions and 86 deletions
|
|
@ -2631,6 +2631,57 @@ export class CommandController extends Controller {
|
||||||
return new HttpSuccess();
|
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")
|
@Post("command21/employee/report/excecute")
|
||||||
public async command21SalaryEmployeeExcecute(
|
public async command21SalaryEmployeeExcecute(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
|
|
@ -2766,22 +2817,7 @@ export class CommandController extends Controller {
|
||||||
|
|
||||||
return new HttpSuccess();
|
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")
|
@Post("command21/employee/report/delete")
|
||||||
public async command21SalaryEmployeeDelete(
|
public async command21SalaryEmployeeDelete(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
|
|
@ -2827,22 +2863,7 @@ export class CommandController extends Controller {
|
||||||
await this.posMasterActRepository.save(data);
|
await this.posMasterActRepository.save(data);
|
||||||
return new HttpSuccess();
|
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")
|
@Post("command40/officer/report/delete")
|
||||||
public async command40SalaryOfficerDelete(
|
public async command40SalaryOfficerDelete(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
|
|
@ -2982,51 +3003,92 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.refIds.map(async (item) => {
|
body.refIds.map(async (item) => {
|
||||||
const profile = await this.posMasterRepository.findOne({
|
const posMaster = await this.posMasterRepository.findOne({
|
||||||
where: { id: item.refId },
|
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) {
|
if (!posMaster) {
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบตำแหน่งดังกล่าว");
|
||||||
}
|
}
|
||||||
|
if(posMaster.next_holderId != null) {
|
||||||
|
|
||||||
const dest_item = await this.salaryRepo.findOne({
|
const shortName =
|
||||||
where: { profileEmployeeId: item.refId },
|
posMaster != null && posMaster.orgChild4 != null
|
||||||
order: { order: "DESC" },
|
? `${posMaster.orgChild4.orgChild4ShortName}${posMaster.posMasterNo}`
|
||||||
});
|
: posMaster != null && posMaster.orgChild3 != null
|
||||||
const before = null;
|
? `${posMaster.orgChild3.orgChild3ShortName}${posMaster.posMasterNo}`
|
||||||
const data = new ProfileSalary();
|
: 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 = {
|
const meta = {
|
||||||
profileId: profile.id,
|
profileId: profile?.id,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
amount: item.amount,
|
amount: item.amount,
|
||||||
commandId: item.commandId,
|
commandId: item.commandId,
|
||||||
positionSalaryAmount: item.positionSalaryAmount,
|
positionSalaryAmount: item.positionSalaryAmount,
|
||||||
mouthSalaryAmount: item.mouthSalaryAmount,
|
mouthSalaryAmount: item.mouthSalaryAmount,
|
||||||
posNo: "",
|
posNo: shortName ?? null,
|
||||||
position: profile.current_holder?.position || null,
|
position: position?.positionName ?? null,
|
||||||
positionType: profile.current_holder?.posType?.posTypeName || null,
|
positionType: position?.posTypeId ?? null,
|
||||||
positionLevel: profile.current_holder?.posLevel?.posLevelName || null,
|
positionLevel: position?.posLevelId ?? null,
|
||||||
refCommandNo: `${item.commandNo}/${Extension.ToThaiYear(item.commandYear)}`,
|
refCommandNo: `${item.commandNo}/${Extension.ToThaiYear(item.commandYear)}`,
|
||||||
templateDoc: item.templateDoc,
|
templateDoc: item.templateDoc,
|
||||||
order: dest_item == null ? 1 : dest_item.order + 1,
|
order: dest_item == null ? 1 : dest_item.order + 1,
|
||||||
createdUserId: req.user.sub,
|
createdUserId: req.user.sub,
|
||||||
createdFullName: req.user.name,
|
createdFullName: req.user.name,
|
||||||
lastUpdateUserId: req.user.sub,
|
lastUpdateUserId: req.user.sub,
|
||||||
lastUpdateFullName: req.user.name,
|
lastUpdateFullName: req.user.name,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
lastUpdatedAt: new Date(),
|
lastUpdatedAt: new Date(),
|
||||||
};
|
};
|
||||||
|
Object.assign(data, meta);
|
||||||
|
const history = new ProfileSalaryHistory();
|
||||||
|
Object.assign(history, { ...data, id: undefined });
|
||||||
|
|
||||||
Object.assign(data, meta);
|
await this.salaryRepo.save(data, { data: req });
|
||||||
const history = new ProfileSalaryHistory();
|
setLogDataDiff(req, { before, after: data });
|
||||||
Object.assign(history, { ...data, id: undefined });
|
history.profileSalaryId = data.id;
|
||||||
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
|
||||||
await this.salaryRepo.save(data, { data: req });
|
if (profile != null) {
|
||||||
setLogDataDiff(req, { before, after: data });
|
profile.position = position?.positionName ?? "";
|
||||||
history.profileSalaryId = data.id;
|
profile.posTypeId = position?.posTypeId ?? "";
|
||||||
await this.salaryHistoryRepo.save(history, { data: req });
|
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({
|
const posMasters = await this.posMasterRepository.find({
|
||||||
|
|
@ -3034,27 +3096,14 @@ export class CommandController extends Controller {
|
||||||
});
|
});
|
||||||
const data = posMasters.map((_data) => ({
|
const data = posMasters.map((_data) => ({
|
||||||
..._data,
|
..._data,
|
||||||
|
current_holderId: _data.next_holderId,
|
||||||
|
next_holderId: null,
|
||||||
statusReport: "PENDING",
|
statusReport: "PENDING",
|
||||||
}));
|
}));
|
||||||
await this.posMasterRepository.save(data);
|
await this.posMasterRepository.save(data);
|
||||||
return new HttpSuccess();
|
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")
|
@Post("command38/officer/report/delete")
|
||||||
public async command38SalaryOfficerDelete(
|
public async command38SalaryOfficerDelete(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue