no message

This commit is contained in:
kittapath 2024-11-14 18:39:19 +07:00
parent 1c991a5ad8
commit 0e0cfda81c
2 changed files with 434 additions and 262 deletions

View file

@ -306,18 +306,6 @@ export class ProfileEmployeeController extends Controller {
@Get("kk1/{id}") @Get("kk1/{id}")
public async getKk1Employee(@Path() id: string, @Request() req: RequestWithUser) { public async getKk1Employee(@Path() id: string, @Request() req: RequestWithUser) {
const profiles = await this.profileRepo.findOne({ const profiles = await this.profileRepo.findOne({
// select: [
// "citizenId",
// "prefix",
// "firstName",
// "lastName",
// "birthDate",
// "currentAddress",
// "currentDistrictId",
// "currentProvinceId",
// "telephoneNumber",
// "avatar",
// ],
relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"],
order: { order: {
profileAvatars: { createdAt: "ASC" }, profileAvatars: { createdAt: "ASC" },

View file

@ -65,6 +65,7 @@ import CallAPI from "../interfaces/call-api";
import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileLeave } from "../entities/ProfileLeave"; import { ProfileLeave } from "../entities/ProfileLeave";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import axios from "axios";
@Route("api/v1/org/profile-temp") @Route("api/v1/org/profile-temp")
@Tags("ProfileEmployee") @Tags("ProfileEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -115,8 +116,6 @@ export class ProfileEmployeeTempController extends Controller {
*/ */
@Get("kp7-short/{id}") @Get("kp7-short/{id}")
async kp7ShortById(@Path() id: string, @Request() req: RequestWithUser) { async kp7ShortById(@Path() id: string, @Request() req: RequestWithUser) {
let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
@ -133,9 +132,38 @@ export class ProfileEmployeeTempController extends Controller {
"current_holders.orgChild4", "current_holders.orgChild4",
], ],
where: { id: id }, where: { id: id },
order: {
profileSalary: {
date: "DESC",
},
},
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_TEMP");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_TEMP", profile.id);
let ImgUrl: any;
if (profile?.avatar != null && profile?.avatarName != null) {
// await new CallAPI()
// .GetData(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
// .then(async (x) => {
// ImgUrl = x.downloadUrl;
// })
// .catch();
let req_: any = req;
const token_ = "Bearer " + req_.headers.authorization.replace("Bearer ", "");
const url = process.env.API_URL + `/salary/file/${profile?.avatar}/${profile?.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 province = await this.provinceRepository.findOneBy({ const province = await this.provinceRepository.findOneBy({
id: profile.registrationProvinceId, id: profile.registrationProvinceId,
}); });
@ -200,50 +228,67 @@ export class ProfileEmployeeTempController extends Controller {
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
}); });
const Education = educations && educations.length > 0 const Education =
? educations.map((item) => ({ educations && educations.length > 0
institute: item.institute ? item.institute : "-", ? educations.map((item) => ({
date: institute: item.institute ? item.institute : "-",
item.startDate && item.endDate date:
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` item.startDate && item.endDate
: "-", ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
degree: item.degree && item.field ? `${item.degree} ${item.field}` : "-", : "-",
})) degree: item.degree && item.field ? `${item.degree} ${item.field}` : "-",
: [{ }))
institute: "-", : [
date: "-", {
degree: "-", institute: "-",
}] date: "-",
degree: "-",
},
];
const mapData = { const mapData = {
Id: profile.id, // Id: profile.id,
CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "", fullName: `${profile?.prefix}${profile?.firstName} ${profile?.lastName}`,
Prefix: profile.prefix != null ? profile.prefix : "", prefix: profile.prefix != null ? profile.prefix : null,
FirstName: profile.firstName != null ? profile.firstName : "", firstName: profile.firstName != null ? profile.firstName : null,
LastName: profile.lastName != null ? profile.lastName : "", lastName: profile.lastName != null ? profile.lastName : null,
DateOfBirth: citizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "-",
dateOfBirth:
profile.birthDate != null profile.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate)) ? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.birthDate))
: "", : "-",
DateRetire: dateRetire:
profile.dateRetire != null profile.dateRetire != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.dateRetire)) ? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateRetire))
: "", : "-",
RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, salaryAmount:
SalaryAmount:
profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null
? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString()) ? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString())
: "", : "-",
Education: Education, registrationAddress: Extension.ToThaiNumber(
AppointText: profile.dateAppoint != null ? profile.dateAppoint : "", `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
SalaryDate: ),
salaryDate:
profile.profileSalary.length > 0 && profile.profileSalary[0].date != null profile.profileSalary.length > 0 && profile.profileSalary[0].date != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalary[0].date)) ? Extension.ToThaiNumber(
: "", Extension.ToThaiShortDate_monthYear(profile.profileSalary[0].date),
PositionName: profile.position != null ? profile.position : "", )
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, : "-",
positionName: profile.position != null ? profile.position : "-",
appointText:
profile.dateAppoint != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateAppoint))
: "-",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
educations: Education,
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
}; };
return new HttpSuccess(mapData); return new HttpSuccess({
template: "kp7",
reportName: "docx-report",
data: mapData,
});
} }
/** /**
@ -255,24 +300,62 @@ export class ProfileEmployeeTempController extends Controller {
*/ */
@Get("kk1/{id}") @Get("kk1/{id}")
public async getKk1Employee(@Path() id: string, @Request() req: RequestWithUser) { public async getKk1Employee(@Path() id: string, @Request() req: RequestWithUser) {
let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const profiles = await this.profileRepo.findOne({ const profiles = await this.profileRepo.findOne({
// select: [ relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"],
// "citizenId", order: {
// "prefix", profileAvatars: { createdAt: "ASC" },
// "firstName", },
// "lastName",
// "birthDate",
// "currentAddress",
// "currentDistrictId",
// "currentProvinceId",
// "telephoneNumber",
// "avatar",
// ],
relations: ["currentSubDistrict", "currentDistrict", "currentProvince"],
where: { id: id }, where: { id: id },
}); });
if (profiles) {
let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_TEMP");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_TEMP", profiles.id);
}
if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
let ImgUrl: any;
let _ImgUrl: any = [];
if (profiles?.avatar != null && profiles?.avatarName != null) {
// await new CallAPI()
// .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
// .then(async (x) => {
// ImgUrl = x.downloadUrl;
// })
// .catch();
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 profileOc = await this.profileRepo.findOne({ const profileOc = await this.profileRepo.findOne({
relations: [ relations: [
"current_holders", "current_holders",
@ -284,7 +367,6 @@ export class ProfileEmployeeTempController extends Controller {
], ],
where: { id: id }, where: { id: id },
}); });
if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
@ -351,157 +433,124 @@ export class ProfileEmployeeTempController extends Controller {
const _child3 = child3 ? `${child3.orgChild3Name}/` : ""; const _child3 = child3 ? `${child3.orgChild3Name}/` : "";
const _child4 = child4 ? `${child4.orgChild4Name}/` : ""; const _child4 = child4 ? `${child4.orgChild4Name}/` : "";
const Profile = { const cert_raw = await this.certificateRepository.find({
CitizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
Prefix: profiles?.prefix != null ? profiles.prefix : "",
FirstName: profiles?.firstName != null ? profiles.firstName : "",
LastName: profiles?.lastName != null ? profiles.lastName : "",
FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
BirthDay: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getDate().toString())
: null,
BirthDayText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString())
: "",
BirthMonth: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getMonth() + (1).toString())
: null, // Months are zero-based
BirthYear: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getFullYear().toString())
: null,
BirthYearText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString())
: "",
Address: "",
District: "",
Area: "",
Province: "",
Telephone:
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
CouplePrefix: profileFamilyCouple?.couplePrefix ?? "",
CoupleFullName:
profileFamilyCouple?.couplePrefix ||
profileFamilyCouple?.coupleFirstName ||
profileFamilyCouple?.coupleLastNameOld
? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastNameOld ?? ""}`.trim()
: null,
FatherPrefix: profileFamilyFather?.fatherPrefix ?? "",
FatherFullName:
profileFamilyFather?.fatherPrefix ||
profileFamilyFather?.fatherFirstName ||
profileFamilyFather?.fatherLastName
? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
: null,
MotherPrefix: profileFamilyMother?.motherPrefix ?? "",
MotherFullName:
profileFamilyMother?.motherPrefix ||
profileFamilyMother?.motherFirstName ||
profileFamilyMother?.motherLastName
? `${profileFamilyMother?.motherPrefix ?? ""}${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
: null,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
Division: "",
Institute: "",
StartDate: profiles?.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateStart))
: "",
AppointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "",
BirthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: "",
RetireDate:
profiles.dateRetireLaw != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw))
: "",
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)
: "",
// AvatarId: profiles?.avatar ?? null,
};
const certs = await this.certificateRepository.find({
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
select: ["certificateType", "issuer", "certificateNo", "issueDate"], select: ["certificateType", "issuer", "certificateNo", "issueDate"],
order: { createdAt: "ASC" },
}); });
const Cert = certs.map((item) => ({ const certs =
CertificateType: item.certificateType ?? null, cert_raw.length > 0
Issuer: item.issuer ?? null, ? cert_raw.slice(-2).map((item) => ({
CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null, CertificateType: item.certificateType ?? null,
IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null, Issuer: item.issuer ?? null,
})); CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null,
const trainings = await this.trainingRepository.find({ IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null,
}))
: [
{
CertificateType: "-",
Issuer: "-",
CertificateNo: "-",
IssueDate: "-",
},
];
const training_raw = await this.trainingRepository.find({
select: ["startDate", "endDate", "place", "department"], select: ["startDate", "endDate", "place", "department"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
order: { createdAt: "ASC" },
}); });
const Training = trainings.map((item) => ({ const trainings =
Institute: item.department ?? "", training_raw.length > 0
Start: ? training_raw.slice(-2).map((item) => ({
item.startDate == null Institute: item.department ?? "",
? "" Start:
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)), item.startDate == null
End: ? ""
item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)), : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)),
Date: End:
item.startDate && item.endDate item.endDate == null
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` ? ""
: "", : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)),
Level: "", Date:
Degree: item.name, item.startDate && item.endDate
Field: "", ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
})); : "",
Level: "",
Degree: item.name,
Field: "",
}))
: [
{
Institute: "-",
Start: "-",
End: "-",
Date: "-",
Level: "-",
Degree: "-",
Field: "-",
},
];
const disciplines = await this.disciplineRepository.find({ const discipline_raw = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail"], select: ["refCommandDate", "refCommandNo", "detail"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
order: { createdAt: "ASC" },
}); });
const Discipline = disciplines.map((item) => ({ const disciplines =
DisciplineYear: discipline_raw.length > 0
Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? null, ? discipline_raw.slice(-2).map((item) => ({
DisciplineDetail: item.detail ?? null, DisciplineYear:
RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ??
})); null,
DisciplineDetail: item.detail ?? null,
RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null,
}))
: [
{
DisciplineYear: "-",
DisciplineDetail: "-",
RefNo: "-",
},
];
const educations = await this.educationRepository.find({ const education_raw = await this.educationRepository.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
order: { lastUpdatedAt: "DESC" }, // order: { lastUpdatedAt: "DESC" },
order: { createdAt: "ASC" },
}); });
const Education = educations.map((item) => ({ const educations =
Institute: item.institute ?? null, education_raw.length > 0
Start: ? education_raw.slice(-2).map((item) => ({
item.startDate == null Institute: item.institute,
? "" Start:
: Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), item.startDate == null
End: ? ""
item.endDate == null : Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()),
? "" End:
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), item.endDate == null
Date: ? ""
item.startDate && item.endDate : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` Date:
: "", item.startDate && item.endDate
Level: item.educationLevel ?? "", ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "", : "",
Field: item.field ?? "-", Level: item.educationLevel ?? "",
})); Degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "",
const salarys = await this.salaryRepository.find({ Field: item.field ?? "-",
}))
: [
{
Institute: "-",
Start: "-",
End: "-",
Date: "-",
Level: "-",
Degree: "-",
Field: "-",
},
];
const salary_raw = await this.salaryRepository.find({
select: [ select: [
"date", "date",
"position", "position",
@ -514,26 +563,48 @@ export class ProfileEmployeeTempController extends Controller {
"templateDoc", "templateDoc",
], ],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
order: { order: "ASC" },
}); });
const Salary = salarys.map((item) => ({ const salarys =
SalaryDate: item.date ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) : null, salary_raw.length > 0
Position: item.position != null ? Extension.ToThaiNumber(item.position) : null, ? salary_raw.map((item) => ({
PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, SalaryDate: item.date
Salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date))
Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, : null,
RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null, Position: item.position != null ? Extension.ToThaiNumber(item.position) : null,
PositionType: item.positionType ?? null, PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null,
PositionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, Salary:
PositionAmount: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
item.positionSalaryAmount == null Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
? null RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null,
: Extension.ToThaiNumber(item.positionSalaryAmount.toLocaleString()), PositionLevel:
FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`, item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, PositionType: item.positionType ?? null,
})); PositionAmount:
item.positionSalaryAmount == null
? null
: Extension.ToThaiNumber(item.positionSalaryAmount.toLocaleString()),
FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
}))
: [
{
SalaryDate: "-",
Position: "-",
PosNo: "-",
Salary: "-",
Rank: "-",
RefAll: "-",
PositionLevel: "-",
PositionType: "-",
PositionAmount: "-",
FullName: "-",
OcFullPath: "-",
},
];
const insignias = await this.profileInsigniaRepo.find({ const insignia_raw = await this.profileInsigniaRepo.find({
relations: { relations: {
insignia: { insignia: {
insigniaType: true, insigniaType: true,
@ -542,46 +613,158 @@ export class ProfileEmployeeTempController extends Controller {
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
order: { receiveDate: "ASC" }, order: { receiveDate: "ASC" },
}); });
const Insignia = insignias.map((item) => ({ const insignias =
ReceiveDate: item.receiveDate insignia_raw.length > 0
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate)) ? insignia_raw.map((item) => ({
: "", ReceiveDate: item.receiveDate
InsigniaName: item.insignia.name, ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate))
InsigniaShortName: item.insignia.shortName, : "",
InsigniaTypeName: item.insignia.insigniaType.name, InsigniaName: item.insignia.name,
No: item.no ? Extension.ToThaiNumber(item.no) : "", InsigniaShortName: item.insignia.shortName,
Issue: item.issue ? item.issue : "", InsigniaTypeName: item.insignia.insigniaType.name,
VolumeNo: item.volumeNo ? Extension.ToThaiNumber(item.volumeNo) : "", No: item.no ? Extension.ToThaiNumber(item.no) : "",
Volume: item.volume ? Extension.ToThaiNumber(item.volume) : "", Issue: item.issue ? item.issue : "",
Section: item.section ? Extension.ToThaiNumber(item.section) : "", VolumeNo: item.volumeNo ? Extension.ToThaiNumber(item.volumeNo) : "",
Page: item.page ? Extension.ToThaiNumber(item.page) : "", Volume: item.volume ? Extension.ToThaiNumber(item.volume) : "",
RefCommandDate: item.refCommandDate Section: item.section ? Extension.ToThaiNumber(item.section) : "",
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) Page: item.page ? Extension.ToThaiNumber(item.page) : "",
: "", RefCommandDate: item.refCommandDate
})); ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate))
: "",
}))
: [
{
ReceiveDate: "-",
InsigniaName: "-",
InsigniaShortName: "-",
InsigniaTypeName: "-",
No: "-",
Issue: "-",
VolumeNo: "-",
Volume: "-",
Section: "-",
Page: "-",
RefCommandDate: "-",
},
];
const leaves = await this.profileLeaveRepository.find({ const leave_raw = await this.profileLeaveRepository.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: id }, where: { profileEmployeeId: id },
order: { dateLeaveStart: "ASC" }, order: { dateLeaveStart: "ASC" },
}); });
const Leave = leaves.map((item) => ({ const leaves =
LeaveTypeName: item.leaveType.name, leave_raw.length > 0
DateLeaveStart: item.dateLeaveStart ? leave_raw.map((item) => ({
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart)) LeaveTypeName: item.leaveType.name,
DateLeaveStart: item.dateLeaveStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart))
: "",
LeaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "",
}))
: [
{
LeaveTypeName: "-",
DateLeaveStart: "-",
LeaveDays: "-",
},
];
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 : "",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
birthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: "", : "",
LeaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "", retireDate:
})); profiles.dateRetireLaw != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw))
: "",
appointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "",
citizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
fatherFullName:
profileFamilyFather?.fatherPrefix ||
profileFamilyFather?.fatherFirstName ||
profileFamilyFather?.fatherLastName
? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
: null,
motherFullName:
profileFamilyMother?.motherPrefix ||
profileFamilyMother?.motherFirstName ||
profileFamilyMother?.motherLastName
? `${profileFamilyMother?.motherPrefix ?? ""}${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
: null,
coupleFullName:
profileFamilyCouple?.couplePrefix ||
profileFamilyCouple?.coupleFirstName ||
profileFamilyCouple?.coupleLastNameOld
? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastName ?? ""}`.trim()
: null,
coupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
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)
: "",
telephone:
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
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,
insignias,
leaves,
certs,
trainings,
disciplines,
educations,
salarys,
};
return new HttpSuccess({ return new HttpSuccess({
Profile: [Profile], template: "kk1-emp",
Cert, reportName: "docx-report",
Training, data: data,
Discipline,
Education,
Salary,
Insignia,
Leave,
}); });
} }
@ -2621,7 +2804,7 @@ export class ProfileEmployeeTempController extends Controller {
relations: [ relations: [
"posLevel", "posLevel",
"posType", "posType",
"current_holders", "current_holders",
"current_holders.orgRoot", "current_holders.orgRoot",
"current_holders.orgChild1", "current_holders.orgChild1",
"current_holders.orgChild2", "current_holders.orgChild2",
@ -3453,13 +3636,13 @@ export class ProfileEmployeeTempController extends Controller {
"current_holders.orgChild2", "current_holders.orgChild2",
"current_holders.orgChild3", "current_holders.orgChild3",
"current_holders.orgChild4", "current_holders.orgChild4",
"profileEducations" "profileEducations",
], ],
order: { order: {
profileEducations: { profileEducations: {
createdAt: "DESC" createdAt: "DESC",
} },
} },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
@ -3579,9 +3762,10 @@ export class ProfileEmployeeTempController extends Controller {
node: null, node: null,
nodeId: null, nodeId: null,
posNo: shortName, posNo: shortName,
education: profile && profile.profileEducations.length > 0 education:
? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}` profile && profile.profileEducations.length > 0
: "-" ? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}`
: "-",
}; };
if (_profile.child4Id != null) { if (_profile.child4Id != null) {