คำสั่ง

This commit is contained in:
kittapath 2024-10-04 22:36:34 +07:00
parent 67aacedff5
commit 497decefe4
3 changed files with 498 additions and 30 deletions

View file

@ -41,6 +41,7 @@ import { EmployeePosition } from "../entities/EmployeePosition";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
import { PosMasterAct } from "../entities/PosMasterAct";
@Route("api/v1/org/command")
@Tags("Command")
@ -68,6 +69,7 @@ export class CommandController extends Controller {
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory);
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
/**
* API list
@ -1284,7 +1286,12 @@ export class CommandController extends Controller {
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...item, ...meta });
Object.assign(data, {
...item,
...meta,
profileEmployeeId: item.profileId,
profileId: undefined,
});
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
@ -1485,7 +1492,12 @@ export class CommandController extends Controller {
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...item, ...meta });
Object.assign(data, {
...item,
...meta,
profileEmployeeId: item.profileId,
profileId: undefined,
});
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
@ -1616,7 +1628,12 @@ export class CommandController extends Controller {
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...item, ...meta });
Object.assign(data, {
...item,
...meta,
profileEmployeeId: item.profileId,
profileId: undefined,
});
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
@ -1751,12 +1768,472 @@ export class CommandController extends Controller {
return new HttpSuccess();
}
@Post("excexute/salary-probation")
public async newSalaryAndUpdateLeaveDisciplinefgh(
@Request() req: RequestWithUser,
@Body()
body: {
data: {
profileId: string;
date?: Date | null;
refCommandNo?: string | null;
salaryRef?: string | null;
}[];
},
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
relations: ["profileSalary"],
where: { id: item.profileId },
order: {
profileSalary: {
order: "DESC",
},
},
});
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
// ประวัติตำแหน่ง
const data = new ProfileSalary();
const meta = {
profileId: item.profileId,
date: item.date,
refCommandNo: item.refCommandNo,
templateDoc: item.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null,
positionType:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null,
positionLevel:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null,
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null,
positionLine:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null,
positionPathSide:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null,
positionExecutive:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[0].order + 1
: 1
: null,
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 });
await this.salaryRepo.save(data);
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history);
}),
);
return new HttpSuccess();
}
@Post("excexute/salary-probation-leave")
async ExecuteCommand12Async(
@Request() req: RequestWithUser,
@Body()
body: {
data: {
profileId: string;
date?: Date | null;
refCommandNo?: string | null;
salaryRef?: string | null;
}[];
},
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
relations: ["profileSalary"],
where: { id: item.profileId },
order: {
profileSalary: {
order: "DESC",
},
},
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
const _profile = await this.profileRepository.findOne({
where: { id: item.profileId },
});
if (!_profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = item.date;
await removeProfileInOrganize(profile.id, "OFFICER");
_profile.isLeave = true;
_profile.leaveReason =
"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
_profile.dateLeave = dateLeave_;
_profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date();
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: item.profileId,
date: item.date,
refCommandNo: item.refCommandNo,
templateDoc: item.salaryRef,
position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null,
positionType:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null,
positionLevel:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null,
posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null,
positionLine:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null,
positionPathSide:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null,
positionExecutive:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null,
amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
positionSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null,
mouthSalaryAmount:
profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[0].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
});
await Promise.all([
this.profileRepository.save(_profile),
this.salaryRepo.save(profileSalary),
]);
const history = new ProfileSalaryHistory();
Object.assign(history, { ...profileSalary, id: undefined });
history.profileSalaryId = profileSalary.id;
await this.salaryHistoryRepo.save(history);
}),
);
return new HttpSuccess();
}
@Post("command21/employee/report/excecute")
public async command21SalaryEmployeeExcecute(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: {
refId: string;
commandAffectDate: Date | null;
commandNo: string | null;
commandYear: number;
templateDoc: string | null;
amount: Double | null;
positionSalaryAmount: Double | null;
mouthSalaryAmount: Double | null;
}[];
},
) {
await Promise.all(
body.refIds.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOneBy({ id: item.refId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const dest_item = await this.salaryRepo.findOne({
where: { profileEmployeeId: item.refId },
order: { order: "DESC" },
});
const before = null;
const data = new ProfileSalary();
const meta = {
profileEmployeeId: profile.id,
date: new Date(),
amount: item.amount,
positionSalaryAmount: item.positionSalaryAmount,
mouthSalaryAmount: item.mouthSalaryAmount,
posNo: profile.posMasterNoTemp,
position: profile.positionTemp,
positionType: profile.posTypeNameTemp,
positionLevel: profile.posLevelNameTemp,
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 });
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
const posMaster = await this.employeePosMasterRepository.findOne({
where: { id: profile.posmasterIdTemp },
relations: ["orgRoot"],
});
if (posMaster == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
const posMasterOld = await this.employeePosMasterRepository.findOne({
where: {
current_holderId: profile.id,
orgRevisionId: posMaster.orgRevisionId,
},
});
if (posMasterOld != null) posMasterOld.current_holderId = null;
if (posMasterOld != null) posMasterOld.next_holderId = null;
const positionOld = await this.employeePositionRepository.findOne({
where: {
posMasterId: posMasterOld?.id,
positionIsSelected: true,
},
});
if (positionOld != null) {
positionOld.positionIsSelected = false;
await this.employeePositionRepository.save(positionOld);
}
const checkPosition = await this.employeePositionRepository.find({
where: {
posMasterId: profile.posmasterIdTemp,
positionIsSelected: true,
},
});
if (checkPosition.length > 0) {
const clearPosition = checkPosition.map((positions) => ({
...positions,
positionIsSelected: false,
}));
await this.employeePositionRepository.save(clearPosition);
}
posMaster.current_holderId = profile.id;
posMaster.next_holderId = profile.id;
if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld);
await this.employeePosMasterRepository.save(posMaster);
const positionNew = await this.employeePositionRepository.findOne({
where: {
id: profile.positionIdTemp,
posMasterId: profile.posmasterIdTemp,
},
});
if (positionNew != null) {
positionNew.positionIsSelected = true;
profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName;
profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null;
profile.positionEmployeePositionId = positionNew.positionName;
profile.statusTemp = "DONE";
profile.employeeClass = "PERM";
const _null: any = null;
profile.employeeWage = item.amount == null ? _null : item.amount.toString();
await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew);
}
}),
);
return new HttpSuccess();
}
@Post("command21/employee/report")
public async command21SalaryEmployee(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
return new HttpSuccess();
}
@Post("command40/officer/report/excecute")
public async command40SalaryOfficerExcecute(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: {
refId: string;
commandAffectDate: Date | null;
commandNo: string | null;
commandYear: number;
templateDoc: string | null;
amount: Double | null;
positionSalaryAmount: Double | null;
mouthSalaryAmount: Double | null;
}[];
},
) {
return new HttpSuccess();
}
@Post("command40/officer/report")
public async command40SalaryOfficer(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
return new HttpSuccess();
}
@Post("command40/officer/report/attachment")
public async command40SalaryOfficerAttachment(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
let data: any = [];
await Promise.all(
body.refIds.map(async (item, i) => {
const posMasterAct = await this.posMasterActRepository.findOne({
relations: [
"posMaster",
"posMaster",
"posMaster.orgRoot",
"posMaster.orgChild1",
"posMaster.orgChild2",
"posMaster.orgChild3",
"posMaster.orgChild4",
"posMaster.current_holder",
"posMasterChild",
"posMasterChild.orgRoot",
"posMasterChild.orgChild1",
"posMasterChild.orgChild2",
"posMasterChild.orgChild3",
"posMasterChild.orgChild4",
"posMasterChild.current_holder",
"posMasterChild.current_holder.posLevel",
"posMasterChild.current_holder.posType",
],
where: {
id: item,
},
});
if (!posMasterAct) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
const organization = [
posMasterAct.posMasterChild?.current_holder?.position ?? null,
posMasterAct.posMasterChild?.orgChild4?.orgChild4Name ?? null,
posMasterAct.posMasterChild?.orgChild3?.orgChild3Name ?? null,
posMasterAct.posMasterChild?.orgChild2?.orgChild2Name ?? null,
posMasterAct.posMasterChild?.orgChild1?.orgChild1Name ?? null,
posMasterAct.posMasterChild?.orgRoot?.orgRootName ?? null,
];
const _organization = organization
.filter((part) => part !== undefined && part !== null)
.join("/");
const organizationNew = [
posMasterAct.posMaster?.current_holder?.position ?? null,
posMasterAct.posMaster?.orgChild4?.orgChild4Name ?? null,
posMasterAct.posMaster?.orgChild3?.orgChild3Name ?? null,
posMasterAct.posMaster?.orgChild2?.orgChild2Name ?? null,
posMasterAct.posMaster?.orgChild1?.orgChild1Name ?? null,
posMasterAct.posMaster?.orgRoot?.orgRootName ?? null,
];
const _organizationNew = organizationNew
.filter((part) => part !== undefined && part !== null)
.join("/");
var _data = {
no: Extension.ToThaiNumber((i + 1).toString()),
fullName:
posMasterAct.posMasterChild?.current_holder?.prefix ??
"" + posMasterAct.posMasterChild?.current_holder?.firstName ??
"" + " " + posMasterAct.posMasterChild?.current_holder?.lastName ??
null,
organization: _organization,
position: posMasterAct.posMasterChild?.current_holder?.position ?? null,
postype: posMasterAct.posMasterChild?.current_holder?.posType?.posTypeName ?? null,
poslevel: posMasterAct.posMasterChild?.current_holder?.posLevel?.posLevelName ?? null,
organizationNew: _organizationNew,
// date: Extension.ToThaiShortDate_noPrefix(new Date()),
dateStart: "",
dateEnd: "",
order:
posMasterAct.posMasterOrder == null
? "-"
: "ลำดับที่ " + Extension.ToThaiNumber(posMasterAct.posMasterOrder.toString()),
};
data.push(_data);
}),
);
return new HttpSuccess(data);
}
@Post("command38/officer/report/excecute")
public async command38SalaryOfficerExcecute(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: {
refId: string;
commandAffectDate: Date | null;
commandNo: string | null;
commandYear: number;
templateDoc: string | null;
amount: Double | null;
positionSalaryAmount: Double | null;
mouthSalaryAmount: Double | null;
}[];
},
) {
return new HttpSuccess();
}
@Post("command38/officer/report")
public async command38SalaryOfficer(
@Request() req: RequestWithUser,
@Body()
body: {
refIds: string[];
},
) {
return new HttpSuccess();
}
commandTypePath(commandCode: string) {
switch (commandCode) {
case "C-PM-01":
return "/placement/recruit/report";
return "/placement/recruit/report"; //
case "C-PM-02":
return "/placement/candidate/report";
return "/placement/candidate/report"; //
case "C-PM-03":
return "/placement/appoint/report";
case "C-PM-04":
@ -1774,9 +2251,9 @@ export class CommandController extends Controller {
case "C-PM-10":
return "/xxxxxx";
case "C-PM-11":
return "/order/command11/report";
return "/probation/report/command11/officer/report";
case "C-PM-12":
return "/order/command12/report";
return "/probation/report/command12/officer/report";
case "C-PM-13":
return "/placement/transfer/command/report";
case "C-PM-14":
@ -1790,11 +2267,11 @@ export class CommandController extends Controller {
case "C-PM-18":
return "/retirement/out/command/report";
case "C-PM-19":
return "/order/command19/report";
return "/discipline/result/command19/report";
case "C-PM-20":
return "/order/command20/report";
return "/discipline/result/command20/report";
case "C-PM-21":
return "/order/command21/report";
return "/org/command/command21/employee/report";
case "C-PM-22":
return "/placement/appointment/employee-appoint/report";
case "C-PM-23":
@ -1818,21 +2295,21 @@ export class CommandController extends Controller {
case "C-PM-32":
return "/discipline/result/command32/report";
case "C-PM-33":
return "/command/officer/report";
return "/salary/report/command/officer/report";
case "C-PM-34":
return "/command/officer/report";
return "/salary/report/command/officer/report";
case "C-PM-35":
return "/command/officer/report";
return "/salary/report/command/officer/report";
case "C-PM-36":
return "/command/employee/report";
return "/salary/report/command/employee/report";
case "C-PM-37":
return "/command/employee/report";
return "/salary/report/command/employee/report";
case "C-PM-38":
return "/order/command38/report";
return "/org/command/command38/officer/report";
case "C-PM-39":
return "/placement/slip/report";
case "C-PM-40":
return "/order/command40/report";
return "/org/command/command40/officer/report";
case "C-PM-41":
return "/retirement/resign/leave-cancel/report";
default:

View file

@ -263,6 +263,7 @@ export class PosMasterActController extends Controller {
@Get("{posMasterActId}/{profileId}")
async GetPosMasterActProfileReport(
@Path() posMasterActId: string,
profileId: string,
@Request() request: { user: Record<string, any> },
) {
const posMasterAct = await this.posMasterActRepository.findOne({

View file

@ -5756,21 +5756,11 @@ export class ProfileController extends Controller {
if (requestBody.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER");
}
if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) {
profile.leaveReason = requestBody.leaveReason;
} else {
}
if (requestBody.dateLeave != undefined && requestBody.dateLeave != null) {
profile.dateLeave = requestBody.dateLeave;
} else {
profile.dateLeave = _null;
}
await this.profileRepo.save(profile, { data: request });
setLogDataDiff(request, { before, after: profile });
// const profileSalary = await this.salaryRepository.findOne({
// where: { profileId: id },
// order: { createdAt: "DESC" },
// });
return new HttpSuccess();
}
/**
* API keycloak