From 0e0cfda81c2abe0212063128856e0a6eaf4e39b3 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 14 Nov 2024 18:39:19 +0700 Subject: [PATCH] no message --- src/controllers/ProfileEmployeeController.ts | 12 - .../ProfileEmployeeTempController.ts | 684 +++++++++++------- 2 files changed, 434 insertions(+), 262 deletions(-) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index e9d9b5f0..1c5cce09 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -306,18 +306,6 @@ export class ProfileEmployeeController extends Controller { @Get("kk1/{id}") public async getKk1Employee(@Path() id: string, @Request() req: RequestWithUser) { const profiles = await this.profileRepo.findOne({ - // select: [ - // "citizenId", - // "prefix", - // "firstName", - // "lastName", - // "birthDate", - // "currentAddress", - // "currentDistrictId", - // "currentProvinceId", - // "telephoneNumber", - // "avatar", - // ], relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], order: { profileAvatars: { createdAt: "ASC" }, diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index e5993981..21ea1568 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -65,6 +65,7 @@ import CallAPI from "../interfaces/call-api"; import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileLeave } from "../entities/ProfileLeave"; import permission from "../interfaces/permission"; +import axios from "axios"; @Route("api/v1/org/profile-temp") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -115,8 +116,6 @@ export class ProfileEmployeeTempController extends Controller { */ @Get("kp7-short/{id}") 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({ where: { orgRevisionIsCurrent: true }, }); @@ -133,9 +132,38 @@ export class ProfileEmployeeTempController extends Controller { "current_holders.orgChild4", ], where: { id: id }, + order: { + profileSalary: { + date: "DESC", + }, + }, }); 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({ id: profile.registrationProvinceId, }); @@ -200,50 +228,67 @@ export class ProfileEmployeeTempController extends Controller { where: { profileEmployeeId: id }, order: { lastUpdatedAt: "DESC" }, }); - const Education = educations && educations.length > 0 - ? educations.map((item) => ({ - institute: item.institute ? item.institute : "-", - date: - 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}` : "-", - })) - : [{ - institute: "-", - date: "-", - degree: "-", - }] + const Education = + educations && educations.length > 0 + ? educations.map((item) => ({ + institute: item.institute ? item.institute : "-", + date: + 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}` : "-", + })) + : [ + { + institute: "-", + date: "-", + degree: "-", + }, + ]; + const mapData = { - Id: profile.id, - CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "", - Prefix: profile.prefix != null ? profile.prefix : "", - FirstName: profile.firstName != null ? profile.firstName : "", - LastName: profile.lastName != null ? profile.lastName : "", - DateOfBirth: + // Id: profile.id, + fullName: `${profile?.prefix}${profile?.firstName} ${profile?.lastName}`, + prefix: profile.prefix != null ? profile.prefix : null, + firstName: profile.firstName != null ? profile.firstName : null, + lastName: profile.lastName != null ? profile.lastName : null, + citizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "-", + dateOfBirth: profile.birthDate != null - ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate)) - : "", - DateRetire: + ? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.birthDate)) + : "-", + dateRetire: profile.dateRetire != null - ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.dateRetire)) - : "", - RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, - SalaryAmount: + ? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateRetire)) + : "-", + salaryAmount: profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null ? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString()) - : "", - Education: Education, - AppointText: profile.dateAppoint != null ? profile.dateAppoint : "", - SalaryDate: + : "-", + registrationAddress: Extension.ToThaiNumber( + `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, + ), + salaryDate: profile.profileSalary.length > 0 && profile.profileSalary[0].date != null - ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalary[0].date)) - : "", - PositionName: profile.position != null ? profile.position : "", - OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, + ? Extension.ToThaiNumber( + Extension.ToThaiShortDate_monthYear(profile.profileSalary[0].date), + ) + : "-", + 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}") 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({ - // select: [ - // "citizenId", - // "prefix", - // "firstName", - // "lastName", - // "birthDate", - // "currentAddress", - // "currentDistrictId", - // "currentProvinceId", - // "telephoneNumber", - // "avatar", - // ], - relations: ["currentSubDistrict", "currentDistrict", "currentProvince"], + relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], + order: { + profileAvatars: { createdAt: "ASC" }, + }, 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({ relations: [ "current_holders", @@ -284,7 +367,6 @@ export class ProfileEmployeeTempController extends Controller { ], where: { id: id }, }); - if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const orgRevision = await this.orgRevisionRepo.findOne({ @@ -351,157 +433,124 @@ export class ProfileEmployeeTempController extends Controller { const _child3 = child3 ? `${child3.orgChild3Name}/` : ""; const _child4 = child4 ? `${child4.orgChild4Name}/` : ""; - const Profile = { - 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({ + const cert_raw = await this.certificateRepository.find({ where: { profileEmployeeId: id }, select: ["certificateType", "issuer", "certificateNo", "issueDate"], + order: { createdAt: "ASC" }, }); - const Cert = certs.map((item) => ({ - CertificateType: item.certificateType ?? null, - Issuer: item.issuer ?? null, - CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null, - IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null, - })); - const trainings = await this.trainingRepository.find({ + const certs = + cert_raw.length > 0 + ? cert_raw.slice(-2).map((item) => ({ + CertificateType: item.certificateType ?? null, + Issuer: item.issuer ?? null, + CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null, + IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null, + })) + : [ + { + CertificateType: "-", + Issuer: "-", + CertificateNo: "-", + IssueDate: "-", + }, + ]; + const training_raw = await this.trainingRepository.find({ select: ["startDate", "endDate", "place", "department"], where: { profileEmployeeId: id }, + order: { createdAt: "ASC" }, }); - const Training = trainings.map((item) => ({ - Institute: item.department ?? "", - Start: - item.startDate == null - ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)), - End: - item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)), - Date: - item.startDate && item.endDate - ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` - : "", - Level: "", - Degree: item.name, - Field: "", - })); + const trainings = + training_raw.length > 0 + ? training_raw.slice(-2).map((item) => ({ + Institute: item.department ?? "", + Start: + item.startDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)), + End: + item.endDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)), + Date: + item.startDate && item.endDate + ? `${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"], where: { profileEmployeeId: id }, + order: { createdAt: "ASC" }, }); - const Discipline = disciplines.map((item) => ({ - DisciplineYear: - Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? null, - DisciplineDetail: item.detail ?? null, - RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, - })); + const disciplines = + discipline_raw.length > 0 + ? discipline_raw.slice(-2).map((item) => ({ + DisciplineYear: + 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"], where: { profileEmployeeId: id }, - order: { lastUpdatedAt: "DESC" }, + // order: { lastUpdatedAt: "DESC" }, + order: { createdAt: "ASC" }, }); - const Education = educations.map((item) => ({ - Institute: item.institute ?? null, - Start: - item.startDate == null - ? "" - : Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), - End: - item.endDate == null - ? "" - : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), - Date: - item.startDate && item.endDate - ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` - : "", - Level: item.educationLevel ?? "", - Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "", - Field: item.field ?? "-", - })); - const salarys = await this.salaryRepository.find({ + const educations = + education_raw.length > 0 + ? education_raw.slice(-2).map((item) => ({ + Institute: item.institute, + Start: + item.startDate == null + ? "" + : Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), + End: + item.endDate == null + ? "" + : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), + Date: + item.startDate && item.endDate + ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` + : "", + Level: item.educationLevel ?? "", + Degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", + Field: item.field ?? "-", + })) + : [ + { + Institute: "-", + Start: "-", + End: "-", + Date: "-", + Level: "-", + Degree: "-", + Field: "-", + }, + ]; + const salary_raw = await this.salaryRepository.find({ select: [ "date", "position", @@ -514,26 +563,48 @@ export class ProfileEmployeeTempController extends Controller { "templateDoc", ], where: { profileEmployeeId: id }, + order: { order: "ASC" }, }); - const Salary = salarys.map((item) => ({ - SalaryDate: item.date ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) : null, - Position: item.position != null ? Extension.ToThaiNumber(item.position) : null, - PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, - Salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, - Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, - RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null, - PositionType: item.positionType ?? null, - PositionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, - PositionAmount: - item.positionSalaryAmount == null - ? null - : Extension.ToThaiNumber(item.positionSalaryAmount.toLocaleString()), - FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`, - OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, - })); + const salarys = + salary_raw.length > 0 + ? salary_raw.map((item) => ({ + SalaryDate: item.date + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) + : null, + Position: item.position != null ? Extension.ToThaiNumber(item.position) : null, + PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, + Salary: + item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, + Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, + RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : 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}${_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: { insignia: { insigniaType: true, @@ -542,46 +613,158 @@ export class ProfileEmployeeTempController extends Controller { where: { profileEmployeeId: id }, order: { receiveDate: "ASC" }, }); - const Insignia = insignias.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 ? 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)) - : "", - })); + 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 ? 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)) + : "", + })) + : [ + { + 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 }, where: { profileEmployeeId: id }, order: { dateLeaveStart: "ASC" }, }); - const Leave = leaves.map((item) => ({ - LeaveTypeName: item.leaveType.name, - DateLeaveStart: item.dateLeaveStart - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart)) + const leaves = + leave_raw.length > 0 + ? leave_raw.map((item) => ({ + 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({ - Profile: [Profile], - Cert, - Training, - Discipline, - Education, - Salary, - Insignia, - Leave, + template: "kk1-emp", + reportName: "docx-report", + data: data, }); } @@ -2621,7 +2804,7 @@ export class ProfileEmployeeTempController extends Controller { relations: [ "posLevel", "posType", - "current_holders", + "current_holders", "current_holders.orgRoot", "current_holders.orgChild1", "current_holders.orgChild2", @@ -3453,13 +3636,13 @@ export class ProfileEmployeeTempController extends Controller { "current_holders.orgChild2", "current_holders.orgChild3", "current_holders.orgChild4", - "profileEducations" + "profileEducations", ], - order: { + order: { profileEducations: { - createdAt: "DESC" - } - } + createdAt: "DESC", + }, + }, }); if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); @@ -3579,9 +3762,10 @@ export class ProfileEmployeeTempController extends Controller { node: null, nodeId: null, posNo: shortName, - education: profile && profile.profileEducations.length > 0 - ? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}` - : "-" + education: + profile && profile.profileEducations.length > 0 + ? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}` + : "-", }; if (_profile.child4Id != null) {