template ลูกจ้าง
This commit is contained in:
parent
d8a47d88bc
commit
a0c4c8a27c
2 changed files with 906 additions and 4 deletions
|
|
@ -71,6 +71,13 @@ import { EmployeePosition } from "../entities/EmployeePosition";
|
|||
import { deleteUser } from "../keycloak";
|
||||
import { PermissionProfile } from "../entities/PermissionProfile";
|
||||
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
||||
import { ProfileAbility } from "../entities/ProfileAbility";
|
||||
import { ProfileActposition } from "../entities/ProfileActposition";
|
||||
import { ProfileAssessment } from "../entities/ProfileAssessment";
|
||||
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
||||
import { ProfileChangeName } from "../entities/ProfileChangeName";
|
||||
import { ProfileChildren } from "../entities/ProfileChildren";
|
||||
import { ProfileDuty } from "../entities/ProfileDuty";
|
||||
@Route("api/v1/org/profile-employee")
|
||||
@Tags("ProfileEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -115,6 +122,13 @@ export class ProfileEmployeeController extends Controller {
|
|||
private positionRepository = AppDataSource.getRepository(Position);
|
||||
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
|
||||
private permissionProflileRepository = AppDataSource.getRepository(PermissionProfile);
|
||||
private profileChildrenRepository = AppDataSource.getRepository(ProfileChildren);
|
||||
private changeNameRepository = AppDataSource.getRepository(ProfileChangeName);
|
||||
private profileActpositionRepo = AppDataSource.getRepository(ProfileActposition);
|
||||
private dutyRepository = AppDataSource.getRepository(ProfileDuty);
|
||||
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
|
||||
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
|
||||
private profileAssistanceRepository = AppDataSource.getRepository(ProfileAssistance);
|
||||
|
||||
/**
|
||||
* report ประวัติแบบย่อ ลูกจ้าง
|
||||
|
|
@ -417,7 +431,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
*
|
||||
* @param {string} id Id โปรไฟล์
|
||||
*/
|
||||
@Get("kk1/{id}")
|
||||
@Get("old/{id}")
|
||||
public async getKk1Employee(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
const profiles = await this.profileRepo.findOne({
|
||||
relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"],
|
||||
|
|
@ -892,6 +906,895 @@ export class ProfileEmployeeController extends Controller {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* รายงาน ก.ก.1 (ลูกจ้างประจำ) ใหม่
|
||||
*
|
||||
* @summary รายงาน ก.ก.1 (ลูกจ้างประจำ) ใหม่
|
||||
*
|
||||
* @param {string} id Id โปรไฟล์
|
||||
*/
|
||||
@Get("kk1/{id}")
|
||||
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
const profiles = await this.profileRepo.findOne({
|
||||
relations: [
|
||||
"currentSubDistrict",
|
||||
"currentDistrict",
|
||||
"currentProvince",
|
||||
"registrationSubDistrict",
|
||||
"registrationDistrict",
|
||||
"registrationProvince",
|
||||
"profileAvatars",
|
||||
"current_holders",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
],
|
||||
order: {
|
||||
profileAvatars: { createdAt: "ASC" },
|
||||
},
|
||||
where: { id: id },
|
||||
});
|
||||
if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
let ImgUrl: any = null;
|
||||
let _ImgUrl: any = [];
|
||||
if (profiles?.avatar != null && profiles?.avatarName != null) {
|
||||
let req_: any = req;
|
||||
const token_ = "Bearer " + req_.headers.authorization.replace("Bearer ", "");
|
||||
|
||||
await Promise.all(
|
||||
await profiles.profileAvatars.slice(-7).map(async (x, i) => {
|
||||
if (x == null) {
|
||||
_ImgUrl[i] = null;
|
||||
} else {
|
||||
const url = process.env.API_URL + `/salary/file/${x?.avatar}/${x?.avatarName}`;
|
||||
try {
|
||||
const response_ = await axios.get(url, {
|
||||
headers: {
|
||||
Authorization: `${token_}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
_ImgUrl[i] = response_.data.downloadUrl;
|
||||
} catch {}
|
||||
}
|
||||
}),
|
||||
);
|
||||
const url = process.env.API_URL + `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`;
|
||||
try {
|
||||
const response_ = await axios.get(url, {
|
||||
headers: {
|
||||
Authorization: `${token_}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
ImgUrl = response_.data.downloadUrl;
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
|
||||
const profileFamilyCouple = await this.profileFamilyCoupleRepository.findOne({
|
||||
where: { profileEmployeeId: id },
|
||||
select: ["couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({
|
||||
where: { profileEmployeeId: id },
|
||||
select: ["motherPrefix", "motherFirstName", "motherLastName"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({
|
||||
where: { profileEmployeeId: id },
|
||||
select: ["fatherPrefix", "fatherFirstName", "fatherLastName"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
const root =
|
||||
profiles.current_holders == null ||
|
||||
profiles.current_holders.length == 0 ||
|
||||
profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
|
||||
? null
|
||||
: profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot;
|
||||
|
||||
const child1 =
|
||||
profiles.current_holders == null ||
|
||||
profiles.current_holders.length == 0 ||
|
||||
profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
|
||||
? null
|
||||
: profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1;
|
||||
|
||||
const child2 =
|
||||
profiles.current_holders == null ||
|
||||
profiles.current_holders.length == 0 ||
|
||||
profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
|
||||
? null
|
||||
: profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2;
|
||||
|
||||
const child3 =
|
||||
profiles.current_holders == null ||
|
||||
profiles.current_holders.length == 0 ||
|
||||
profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
|
||||
? null
|
||||
: profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3;
|
||||
|
||||
const child4 =
|
||||
profiles.current_holders == null ||
|
||||
profiles.current_holders.length == 0 ||
|
||||
profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
|
||||
? null
|
||||
: profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
|
||||
|
||||
// Construct org path
|
||||
let _root = root?.orgRootName;
|
||||
let _child1 = child1?.orgChild1Name;
|
||||
let _child2 = child2?.orgChild2Name;
|
||||
let _child3 = child3?.orgChild3Name;
|
||||
let _child4 = child4?.orgChild4Name;
|
||||
|
||||
const cert_raw = await this.certificateRepository.find({
|
||||
where: { profileEmployeeId: id },
|
||||
select: ["certificateType", "issuer", "certificateNo", "issueDate"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const certs =
|
||||
cert_raw.length > 0
|
||||
? cert_raw.map((item) => ({
|
||||
certificateType: item.certificateType ?? null,
|
||||
issuer: item.issuer ?? null,
|
||||
certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null,
|
||||
issueDate: item.issueDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate))
|
||||
: null,
|
||||
expireDate: item.expireDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate))
|
||||
: null,
|
||||
issueToExpireDate: item.issueDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate))
|
||||
: "" + item.expireDate
|
||||
? " - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate))
|
||||
: null,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
certificateType: "-",
|
||||
issuer: "-",
|
||||
certificateNo: "-",
|
||||
issueDate: "-",
|
||||
expireDate: "-",
|
||||
issueToExpireDate: "-",
|
||||
},
|
||||
];
|
||||
const training_raw = await this.trainingRepository.find({
|
||||
select: ["place", "department", "name", "duration"],
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const trainings =
|
||||
training_raw.length > 0
|
||||
? training_raw.map((item) => ({
|
||||
institute: item.department ?? "",
|
||||
degree: item.name ? Extension.ToThaiNumber(item.name) : "",
|
||||
place: item.place ? Extension.ToThaiNumber(item.place) : "",
|
||||
duration: item.duration ? Extension.ToThaiNumber(item.duration) : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
institute: "-",
|
||||
degree: "-",
|
||||
place: "-",
|
||||
duration: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const discipline_raw = await this.disciplineRepository.find({
|
||||
select: ["refCommandDate", "refCommandNo", "detail", "level"],
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const disciplines =
|
||||
discipline_raw.length > 0
|
||||
? discipline_raw.map((item) => ({
|
||||
disciplineYear: item.refCommandDate
|
||||
? Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString())
|
||||
: null,
|
||||
disciplineDetail: item.detail ?? null,
|
||||
refNo: Extension.ToThaiNumber(item.refCommandNo) ?? null,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
disciplineYear: "-",
|
||||
disciplineDetail: "-",
|
||||
refNo: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const education_raw = await this.profileEducationRepo
|
||||
.createQueryBuilder("education")
|
||||
.where("education.profileEmployeeId = :profileId", { profileId: id })
|
||||
.orderBy("CASE WHEN education.isEducation = true THEN 1 ELSE 2 END", "ASC")
|
||||
.addOrderBy("education.level", "ASC")
|
||||
.getMany();
|
||||
const educations =
|
||||
education_raw.length > 0
|
||||
? education_raw.map((item) => ({
|
||||
institute: item.institute,
|
||||
date: item.isDate
|
||||
? item.startDate && item.endDate
|
||||
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
|
||||
: ""
|
||||
: item.startDate && item.endDate
|
||||
? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}`
|
||||
: "",
|
||||
degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
institute: "-",
|
||||
date: "-",
|
||||
degree: "-",
|
||||
},
|
||||
];
|
||||
const salary_raw = await this.salaryRepo.find({
|
||||
select: [
|
||||
"commandDateAffect",
|
||||
"positionName",
|
||||
"posNoAbb",
|
||||
"posNo",
|
||||
"positionType",
|
||||
"positionLevel",
|
||||
"positionSalaryAmount",
|
||||
"commandNo",
|
||||
"amount",
|
||||
"remark",
|
||||
],
|
||||
where: {
|
||||
profileEmployeeId: id,
|
||||
commandCode: In(["5", "6"]),
|
||||
isEntry: false,
|
||||
},
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
|
||||
const salarys =
|
||||
salary_raw.length > 0
|
||||
? salary_raw.map((item) => ({
|
||||
salaryDate: item.commandDateAffect
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
||||
: null,
|
||||
position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : null,
|
||||
posNo:
|
||||
item.posNoAbb && item.posNo
|
||||
? Extension.ToThaiNumber(`${item.posNoAbb}${item.posNo}`)
|
||||
: null,
|
||||
salary:
|
||||
item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
|
||||
rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
|
||||
refAll: item.remark ? Extension.ToThaiNumber(item.remark) : null,
|
||||
positionLevel:
|
||||
item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
|
||||
positionType: item.positionType ?? null,
|
||||
positionAmount:
|
||||
item.positionSalaryAmount == null
|
||||
? null
|
||||
: Extension.ToThaiNumber(item.positionSalaryAmount.toLocaleString()),
|
||||
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
|
||||
ocFullPath:
|
||||
(_child4 == null ? "" : _child4 + "\n") +
|
||||
(_child3 == null ? "" : _child3 + "\n") +
|
||||
(_child2 == null ? "" : _child2 + "\n") +
|
||||
(_child1 == null ? "" : _child1 + "\n") +
|
||||
(_root == null ? "" : _root),
|
||||
}))
|
||||
: [
|
||||
{
|
||||
salaryDate: "-",
|
||||
position: "-",
|
||||
posNo: "-",
|
||||
salary: "-",
|
||||
rank: "-",
|
||||
refAll: "-",
|
||||
positionLevel: "-",
|
||||
positionType: "-",
|
||||
positionAmount: "-",
|
||||
fullName: "-",
|
||||
ocFullPath: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const insignia_raw = await this.profileInsigniaRepo.find({
|
||||
relations: {
|
||||
insignia: {
|
||||
insigniaType: true,
|
||||
},
|
||||
},
|
||||
where: { profileEmployeeId: id },
|
||||
order: { receiveDate: "ASC" },
|
||||
});
|
||||
const insignias =
|
||||
insignia_raw.length > 0
|
||||
? insignia_raw.map((item) => ({
|
||||
receiveDate: item.receiveDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate))
|
||||
: "",
|
||||
insigniaName: item.insignia.name,
|
||||
insigniaShortName: item.insignia.shortName,
|
||||
insigniaTypeName: item.insignia.insigniaType.name,
|
||||
no: item.no ? Extension.ToThaiNumber(item.no) : "",
|
||||
issue: item.issue ? Extension.ToThaiNumber(item.issue) : "",
|
||||
volumeNo: item.volumeNo ? Extension.ToThaiNumber(item.volumeNo) : "",
|
||||
volume: item.volume ? Extension.ToThaiNumber(item.volume) : "",
|
||||
section: item.section ? Extension.ToThaiNumber(item.section) : "",
|
||||
page: item.page ? Extension.ToThaiNumber(item.page) : "",
|
||||
refCommandDate: item.refCommandDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate))
|
||||
: "",
|
||||
note: item.note ? Extension.ToThaiNumber(item.note) : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
receiveDate: "-",
|
||||
insigniaName: "-",
|
||||
insigniaShortName: "-",
|
||||
insigniaTypeName: "-",
|
||||
no: "-",
|
||||
issue: "-",
|
||||
volumeNo: "-",
|
||||
volume: "-",
|
||||
section: "-",
|
||||
page: "-",
|
||||
refCommandDate: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const leave_raw = await this.profileLeaveRepository
|
||||
.createQueryBuilder("profileLeave")
|
||||
.leftJoinAndSelect("profileLeave.leaveType", "leaveType")
|
||||
.select([
|
||||
"profileLeave.leaveTypeId",
|
||||
"leaveType.name as name",
|
||||
"leaveType.code as code",
|
||||
"profileLeave.status",
|
||||
"profileLeave.profileEmployeeId",
|
||||
"MAX(profileLeave.dateLeaveStart) as maxDateLeaveStart",
|
||||
])
|
||||
.addSelect("SUM(profileLeave.leaveDays)", "totalLeaveDays")
|
||||
.where("profileLeave.profileEmployeeId = :profileId", { profileId: id })
|
||||
.andWhere("profileLeave.status = :status", { status: "approve" })
|
||||
.groupBy("profileLeave.leaveTypeId")
|
||||
.orderBy("code", "ASC")
|
||||
.addOrderBy("maxDateLeaveStart", "ASC")
|
||||
.getRawMany();
|
||||
|
||||
const leaves: any[] = [];
|
||||
|
||||
leave_raw.forEach((item) => {
|
||||
const leaveTypeCode = item.code ? item.code.trim().toUpperCase() : "";
|
||||
if (leaveTypeCode.startsWith("LV-")) {
|
||||
const lvIndex = parseInt(leaveTypeCode.split("-")[1], 10);
|
||||
|
||||
if (lvIndex >= 1 && lvIndex <= 11) {
|
||||
const leaveTypeCodeKey = `leaveTypeCodeLv${lvIndex}`;
|
||||
const totalLeaveDaysKey = `totalLeaveDaysLv${lvIndex}`;
|
||||
const leaveTypeNameKey = `leaveTypeNameLv${lvIndex}`;
|
||||
|
||||
const leaveDate = new Date(item.maxDateLeaveStart);
|
||||
const year = leaveDate ? Extension.ToThaiNumber(leaveDate.getFullYear().toString()) : "";
|
||||
|
||||
let yearData = leaves.find((data) => data.year === year);
|
||||
if (!yearData) {
|
||||
yearData = { year };
|
||||
|
||||
for (let i = 1; i <= 11; i++) {
|
||||
yearData[`leaveTypeCodeLv${i}`] = "-";
|
||||
yearData[`totalLeaveDaysLv${i}`] = "-";
|
||||
yearData[`leaveTypeNameLv${i}`] = "-";
|
||||
}
|
||||
|
||||
leaves.push(yearData);
|
||||
}
|
||||
|
||||
yearData[leaveTypeCodeKey] = item.code ? item.code : "-";
|
||||
yearData[totalLeaveDaysKey] = item.totalLeaveDays
|
||||
? Extension.ToThaiNumber(item.totalLeaveDays.toString())
|
||||
: "-";
|
||||
yearData[leaveTypeNameKey] = item.name ? item.name : "-";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const leave2_raw = await this.profileLeaveRepository
|
||||
.createQueryBuilder("profileLeave")
|
||||
.leftJoinAndSelect("profileLeave.leaveType", "leaveType")
|
||||
.select([
|
||||
"profileLeave.leaveTypeId",
|
||||
"profileLeave.dateLeaveStart",
|
||||
"profileLeave.dateLeaveEnd",
|
||||
"leaveType.name as name",
|
||||
"leaveType.code as code",
|
||||
"profileLeave.status",
|
||||
"profileLeave.profileEmployeeId",
|
||||
"profileLeave.leaveDays",
|
||||
"profileLeave.reason",
|
||||
])
|
||||
.where("profileLeave.profileEmployeeId = :profileId", { profileId: id })
|
||||
.andWhere("leaveType.code IN (:...codes)", { codes: ["LV-008", "LV-009", "LV-010"] })
|
||||
.andWhere("profileLeave.status = :status", { status: "approve" })
|
||||
.orderBy("leaveType.code", "ASC")
|
||||
.getRawMany();
|
||||
const leaves2 =
|
||||
leave2_raw.length > 0
|
||||
? leave2_raw.map((item) => ({
|
||||
date: item.dateLeaveStart
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart))
|
||||
: item.dateLeaveEnd
|
||||
? " - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveEnd))
|
||||
: "",
|
||||
type: item.name || "-",
|
||||
leaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays) : "-",
|
||||
reason: item.reason || "-",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
date: "-",
|
||||
type: "-",
|
||||
leaveDays: "-",
|
||||
reason: "-",
|
||||
},
|
||||
];
|
||||
const children_raw = await this.profileChildrenRepository.find({
|
||||
where: { profileEmployeeId: id },
|
||||
});
|
||||
const children =
|
||||
children_raw.length > 0
|
||||
? children_raw.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber((index + 1).toString()),
|
||||
childrenPrefix: item.childrenPrefix,
|
||||
childrenFirstName: item.childrenFirstName,
|
||||
childrenLastName: item.childrenLastName,
|
||||
childrenFullName: `${item.childrenPrefix}${item.childrenFirstName} ${item.childrenLastName}`,
|
||||
childrenLive: item.childrenLive == true ? "มีชีวิต" : "ถึงแก่กรรม",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
no: "",
|
||||
childrenPrefix: "-",
|
||||
childrenFirstName: "-",
|
||||
childrenLastName: "-",
|
||||
childrenFullName: "-",
|
||||
childrenLive: "-",
|
||||
},
|
||||
];
|
||||
const changeName_raw = await this.changeNameRepository.find({
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const changeName =
|
||||
changeName_raw.length > 0
|
||||
? changeName_raw.map((item) => ({
|
||||
createdAt: item.createdAt
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.createdAt))
|
||||
: null,
|
||||
status: item.status,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
createdAt: "-",
|
||||
status: "-",
|
||||
prefix: "-",
|
||||
firstName: "-",
|
||||
lastName: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const position_raw = await this.salaryRepo.find({
|
||||
where: {
|
||||
profileEmployeeId: id,
|
||||
commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]),
|
||||
isEntry: false,
|
||||
},
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
const positionList =
|
||||
position_raw.length > 0
|
||||
? position_raw.map((item) => ({
|
||||
commandDateAffect: item.commandDateAffect
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
||||
: "",
|
||||
commandDateSign: item.commandDateSign
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
|
||||
: "",
|
||||
posNo:
|
||||
item.posNoAbb && item.posNo
|
||||
? Extension.ToThaiNumber(`${item.posNoAbb}${item.posNo}`)
|
||||
: "",
|
||||
position: item.positionName,
|
||||
posType: item.positionType,
|
||||
posLevel: item.positionLevel ? Extension.ToThaiNumber(item.positionLevel) : "",
|
||||
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
|
||||
positionSalaryAmount: item.positionSalaryAmount
|
||||
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString())
|
||||
: "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
commandDateAffect: "-",
|
||||
commandDateSign: "-",
|
||||
posNo: "-",
|
||||
position: "-",
|
||||
posType: "-",
|
||||
posLevel: "-",
|
||||
amount: "-",
|
||||
positionSalaryAmount: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const actposition_raw = await this.profileActpositionRepo.find({
|
||||
select: ["dateStart", "dateEnd", "position"],
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const assistance_raw = await this.profileAssistanceRepository.find({
|
||||
select: ["dateStart", "dateEnd", "commandName", "agency", "document"],
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
|
||||
const _actposition =
|
||||
actposition_raw.length > 0
|
||||
? actposition_raw.map((item) => ({
|
||||
date: item.dateStart
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
|
||||
: "" + item.dateEnd
|
||||
? " - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
|
||||
: "",
|
||||
position: item.position ? Extension.ToThaiNumber(item.position) : "",
|
||||
commandName: "รักษาการในตำแหน่ง",
|
||||
agency: "",
|
||||
document: "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
date: "-",
|
||||
position: "-",
|
||||
commandName: "-",
|
||||
agency: "-",
|
||||
document: "-",
|
||||
},
|
||||
];
|
||||
const _assistance =
|
||||
assistance_raw.length > 0
|
||||
? assistance_raw.map((item) => ({
|
||||
date: item.dateStart
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
|
||||
: "" + item.dateEnd
|
||||
? " - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
|
||||
: "",
|
||||
position: "",
|
||||
commandName: item.commandName ? Extension.ToThaiNumber(item.commandName) : "",
|
||||
agency: item.agency ? Extension.ToThaiNumber(item.agency) : "",
|
||||
document: item.document ? Extension.ToThaiNumber(item.document) : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
date: "-",
|
||||
position: "-",
|
||||
commandName: "-",
|
||||
agency: "-",
|
||||
document: "-",
|
||||
},
|
||||
];
|
||||
const actposition = [..._actposition, ..._assistance];
|
||||
const duty_raw = await this.dutyRepository.find({
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const duty =
|
||||
duty_raw.length > 0
|
||||
? duty_raw.map((item) => ({
|
||||
date: item.dateStart
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
|
||||
: "" + item.dateEnd
|
||||
? " - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
|
||||
: "",
|
||||
refCommandDate: item.refCommandDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate))
|
||||
: "",
|
||||
refCommandNo: item.refCommandNo ? Extension.ToThaiNumber(item.refCommandNo) : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
date: "-",
|
||||
refCommandDate: "-",
|
||||
refCommandNo: "-",
|
||||
},
|
||||
];
|
||||
const assessments_raw = await this.profileAssessmentsRepository.find({
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const assessments =
|
||||
assessments_raw.length > 0
|
||||
? assessments_raw.map((item) => ({
|
||||
year: item.year ? Extension.ToThaiNumber(item.year) : "",
|
||||
period: item.period && item.period == "APR" ? "เมษายน" : "ตุลาคม",
|
||||
point1: item.point1 ? Extension.ToThaiNumber(item.point1.toString()) : "",
|
||||
point1Total: item.point1Total
|
||||
? Extension.ToThaiNumber(item.point1Total.toString())
|
||||
: "",
|
||||
point2: item.point2 ? Extension.ToThaiNumber(item.point2.toString()) : "",
|
||||
point2Total: item.point2Total
|
||||
? Extension.ToThaiNumber(item.point2Total.toString())
|
||||
: "",
|
||||
pointSum: item.pointSum ? Extension.ToThaiNumber(item.pointSum.toString()) : "",
|
||||
pointSumTh: item.pointSum ? Extension.textPoint(item.pointSum) : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
year: "-",
|
||||
period: "-",
|
||||
point1: "-",
|
||||
point2: "-",
|
||||
pointSum: "-",
|
||||
pointSumTh: "-",
|
||||
},
|
||||
];
|
||||
const profileAbility_raw = await this.profileAbilityRepo.find({
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const profileAbility =
|
||||
profileAbility_raw.length > 0
|
||||
? profileAbility_raw.map((item) => ({
|
||||
field: item.field ? item.field : "",
|
||||
detail: item.detail ? item.detail : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
field: "-",
|
||||
detail: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const otherIncome_raw = await this.salaryRepo.find({
|
||||
where: {
|
||||
profileEmployeeId: id,
|
||||
commandCode: "7",
|
||||
isEntry: false,
|
||||
},
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
const otherIncome =
|
||||
otherIncome_raw.length > 0
|
||||
? otherIncome_raw.map((item) => ({
|
||||
commandDateAffect: item.commandDateAffect
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
||||
: "",
|
||||
commandDateSign: item.commandDateSign
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
|
||||
: "",
|
||||
commandNo: item.commandNo ? Extension.ToThaiNumber(item.commandNo) : "",
|
||||
position: item.positionName,
|
||||
posLevel: item.positionLevel ? Extension.ToThaiNumber(item.positionLevel) : "",
|
||||
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
|
||||
}))
|
||||
: [
|
||||
{
|
||||
commandDateAffect: "-",
|
||||
commandDateSign: "-",
|
||||
commandNo: "-",
|
||||
position: "-",
|
||||
posLevel: "-",
|
||||
amount: "-",
|
||||
},
|
||||
];
|
||||
|
||||
const sum = profiles
|
||||
? Extension.ToThaiNumber(
|
||||
(
|
||||
Number(profiles.amount) +
|
||||
Number(profiles.positionSalaryAmount) +
|
||||
Number(profiles.mouthSalaryAmount) +
|
||||
Number(profiles.amountSpecial)
|
||||
).toLocaleString(),
|
||||
)
|
||||
: "";
|
||||
const fullCurrentAddress =
|
||||
profiles && profiles.currentAddress
|
||||
? Extension.ToThaiNumber(
|
||||
profiles.currentAddress +
|
||||
" ตำบล/แขวง " +
|
||||
profiles.currentSubDistrict.name +
|
||||
" อำเภอ/เขต " +
|
||||
profiles.currentDistrict.name +
|
||||
" จังหวัด " +
|
||||
profiles.currentProvince.name +
|
||||
profiles.currentZipCode,
|
||||
)
|
||||
: "";
|
||||
const fullRegistrationAddress =
|
||||
profiles && profiles.registrationAddress
|
||||
? Extension.ToThaiNumber(
|
||||
profiles.registrationAddress +
|
||||
" ตำบล/แขวง " +
|
||||
profiles.registrationSubDistrict.name +
|
||||
" อำเภอ/เขต " +
|
||||
profiles.registrationDistrict.name +
|
||||
" จังหวัด " +
|
||||
profiles.registrationProvince.name +
|
||||
profiles.registrationZipCode,
|
||||
)
|
||||
: "";
|
||||
const data = {
|
||||
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
|
||||
prefix: profiles?.prefix != null ? profiles.prefix : "",
|
||||
firstName: profiles?.firstName != null ? profiles.firstName : "",
|
||||
lastName: profiles?.lastName != null ? profiles.lastName : "",
|
||||
position: profiles?.position != null ? profiles.position : "",
|
||||
amount:
|
||||
profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "",
|
||||
positionSalaryAmount:
|
||||
profiles?.positionSalaryAmount != null
|
||||
? Extension.ToThaiNumber(profiles.positionSalaryAmount.toLocaleString())
|
||||
: "",
|
||||
mouthSalaryAmount:
|
||||
profiles?.mouthSalaryAmount != null
|
||||
? Extension.ToThaiNumber(profiles.mouthSalaryAmount.toLocaleString())
|
||||
: "",
|
||||
amountSpecial:
|
||||
profiles?.amountSpecial != null
|
||||
? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString())
|
||||
: "",
|
||||
salarySum: sum,
|
||||
ocFullPath:
|
||||
(_child4 == null ? "" : _child4 + "\n") +
|
||||
(_child3 == null ? "" : _child3 + "\n") +
|
||||
(_child2 == null ? "" : _child2 + "\n") +
|
||||
(_child1 == null ? "" : _child1 + "\n") +
|
||||
(_root == null ? "" : _root),
|
||||
birthDate: profiles?.birthDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
|
||||
: "",
|
||||
retireDate:
|
||||
profiles.dateRetireLaw != null
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw))
|
||||
: "",
|
||||
appointDate: profiles?.dateAppoint
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
|
||||
: "",
|
||||
positionDate:
|
||||
positionList.length > 0 ? positionList[positionList.length - 1].commandDateAffect : "",
|
||||
citizenId:
|
||||
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
|
||||
fatherFullName:
|
||||
profileFamilyFather?.fatherPrefix ||
|
||||
profileFamilyFather?.fatherFirstName ||
|
||||
profileFamilyFather?.fatherLastName
|
||||
? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
|
||||
: null,
|
||||
fatherLive:
|
||||
profileFamilyFather && profileFamilyFather?.fatherLive == true ? "มีชีวิต" : "ถึงแก่กรรม",
|
||||
motherFullName:
|
||||
profileFamilyMother?.motherPrefix ||
|
||||
profileFamilyMother?.motherFirstName ||
|
||||
profileFamilyMother?.motherLastName
|
||||
? `${profileFamilyMother?.motherPrefix ?? ""}${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
|
||||
: null,
|
||||
motherLive:
|
||||
profileFamilyMother && profileFamilyMother?.motherLive == true ? "มีชีวิต" : "ถึงแก่กรรม",
|
||||
coupleFullName:
|
||||
profileFamilyCouple?.couplePrefix ||
|
||||
profileFamilyCouple?.coupleFirstName ||
|
||||
profileFamilyCouple?.coupleLastNameOld
|
||||
? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastName ?? ""}`.trim()
|
||||
: null,
|
||||
coupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
|
||||
coupleLive:
|
||||
profileFamilyCouple && profileFamilyCouple?.coupleLive == true ? "มีชีวิต" : "ถึงแก่กรรม",
|
||||
currentAddress:
|
||||
profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "",
|
||||
currentSubDistrict:
|
||||
profiles.currentSubDistrict != null
|
||||
? Extension.ToThaiNumber(profiles.currentSubDistrict.name)
|
||||
: "",
|
||||
currentDistrict:
|
||||
profiles.currentDistrict != null
|
||||
? Extension.ToThaiNumber(profiles.currentDistrict.name)
|
||||
: "",
|
||||
currentProvince:
|
||||
profiles.currentProvince != null
|
||||
? Extension.ToThaiNumber(profiles.currentProvince.name)
|
||||
: "",
|
||||
currentZipcode:
|
||||
profiles.currentZipCode != null ? Extension.ToThaiNumber(profiles.currentZipCode) : "",
|
||||
fullCurrentAddress: fullCurrentAddress,
|
||||
registrationAddress:
|
||||
profiles.registrationAddress != null
|
||||
? Extension.ToThaiNumber(profiles.registrationAddress)
|
||||
: "",
|
||||
registrationSubDistrict:
|
||||
profiles.registrationSubDistrict != null
|
||||
? Extension.ToThaiNumber(profiles.registrationSubDistrict.name)
|
||||
: "",
|
||||
registrationDistrict:
|
||||
profiles.registrationDistrict != null
|
||||
? Extension.ToThaiNumber(profiles.registrationDistrict.name)
|
||||
: "",
|
||||
registrationProvince:
|
||||
profiles.registrationProvince != null
|
||||
? Extension.ToThaiNumber(profiles.registrationProvince.name)
|
||||
: "",
|
||||
registrationZipcode:
|
||||
profiles.registrationZipCode != null
|
||||
? Extension.ToThaiNumber(profiles.registrationZipCode)
|
||||
: "",
|
||||
fullRegistrationAddress: fullRegistrationAddress,
|
||||
telephone: profiles.phone != null ? Extension.ToThaiNumber(profiles.phone) : "",
|
||||
url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_MGT}`,
|
||||
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
|
||||
yearUpload1: profiles.profileAvatars[0]
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
|
||||
: null,
|
||||
url2: _ImgUrl[1] ? _ImgUrl[1] : null,
|
||||
yearUpload2: profiles.profileAvatars[1]
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[1].createdAt))
|
||||
: null,
|
||||
url3: _ImgUrl[2] ? _ImgUrl[2] : null,
|
||||
yearUpload3: profiles.profileAvatars[2]
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[2].createdAt))
|
||||
: null,
|
||||
url4: _ImgUrl[3] ? _ImgUrl[3] : null,
|
||||
yearUpload4: profiles.profileAvatars[3]
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[3].createdAt))
|
||||
: null,
|
||||
url5: _ImgUrl[4] ? _ImgUrl[4] : null,
|
||||
yearUpload5: profiles.profileAvatars[4]
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[4].createdAt))
|
||||
: null,
|
||||
url6: _ImgUrl[5] ? _ImgUrl[5] : null,
|
||||
yearUpload6: profiles.profileAvatars[5]
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[5].createdAt))
|
||||
: null,
|
||||
url7: _ImgUrl[6] ? _ImgUrl[6] : null,
|
||||
yearUpload7: profiles.profileAvatars[6]
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[6].createdAt))
|
||||
: null,
|
||||
urlQRcode: "https://seis.ocsc.go.th",
|
||||
children,
|
||||
insignias,
|
||||
leaves,
|
||||
leaves2,
|
||||
certs,
|
||||
trainings,
|
||||
disciplines,
|
||||
educations,
|
||||
salarys,
|
||||
changeName,
|
||||
positionList,
|
||||
actposition,
|
||||
duty,
|
||||
assessments,
|
||||
profileAbility,
|
||||
otherIncome,
|
||||
};
|
||||
|
||||
return new HttpSuccess({
|
||||
template: "new_kk1-emp",
|
||||
reportName: "docx-report",
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API สร้างทะเบียนประวัติ
|
||||
*
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ class Extension {
|
|||
}
|
||||
|
||||
public static ToThaiNumber(value: string) {
|
||||
if (value == null) return "";
|
||||
let arabicNumbers = "0123456789";
|
||||
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
|
||||
let result = "";
|
||||
|
|
@ -230,9 +231,7 @@ class Extension {
|
|||
|
||||
public static ToThaiShortDate_monthYear2(value: Date) {
|
||||
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
||||
return (
|
||||
value.getDate() + " " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy
|
||||
);
|
||||
return value.getDate() + " " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy;
|
||||
}
|
||||
|
||||
public static ToThaiShortYear(value: Date) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue