From 6ca5706a00767da7bdda5ed3e1f97831372eaea7 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 4 Mar 2025 10:52:23 +0700 Subject: [PATCH 1/4] new report kk1 checkpoint --- src/controllers/ProfileController.ts | 702 ++++++++++++++++++++++++++- 1 file changed, 697 insertions(+), 5 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 82d0ed8c..dd9f8090 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -71,6 +71,12 @@ import { viewDirector } from "../entities/view/viewDirector"; import { viewDirectorActing } from "../entities/view/viewDirectorActing"; import CallAPI from "../interfaces/call-api"; import { OrgRoot } from "../entities/OrgRoot"; +import { ProfileChildren } from "../entities/ProfileChildren"; +import { ProfileChangeName } from "../entities/ProfileChangeName"; +import { ProfileActposition } from "../entities/ProfileActposition"; +import { ProfileDuty } from "../entities/ProfileDuty"; +import { ProfileAssessment } from "../entities/ProfileAssessment"; +import { ProfileAbility } from "../entities/ProfileAbility"; @Route("api/v1/org/profile") @Tags("Profile") @Security("bearerAuth") @@ -109,6 +115,13 @@ export class ProfileController extends Controller { private profileInsigniaRepo = AppDataSource.getRepository(ProfileInsignia); private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave); private posMasterActRepository = AppDataSource.getRepository(PosMasterAct); + 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); + /** * report ประวัติแบบย่อ ข้าราชการ @@ -382,17 +395,489 @@ export class ProfileController extends Controller { }); } + // /** + // * รายงาน ก.ก.1 (ข้าราชการ) + // * + // * @summary รายงาน ก.ก.1 (ข้าราชการ) + // * + // * @param {string} id Id โปรไฟล์ + // */ + // @Get("kk1/{id}") + // public async getKk1(@Path() id: string, @Request() req: RequestWithUser) { + // const profiles = await this.profileRepo.findOne({ + // relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], + // 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) { + // // 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", + // "current_holders.orgRoot", + // "current_holders.orgChild1", + // "current_holders.orgChild2", + // "current_holders.orgChild3", + // "current_holders.orgChild4", + // ], + // where: { id: id }, + // }); + // if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // const orgRevision = await this.orgRevisionRepo.findOne({ + // where: { orgRevisionIsCurrent: true }, + // }); + + // const profileFamilyCouple = await this.profileFamilyCoupleRepository.findOne({ + // where: { profileId: id }, + // select: ["couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld"], + // order: { lastUpdatedAt: "DESC" }, + // }); + + // const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({ + // where: { profileId: id }, + // select: ["motherPrefix", "motherFirstName", "motherLastName"], + // order: { lastUpdatedAt: "DESC" }, + // }); + + // const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({ + // where: { profileId: id }, + // select: ["fatherPrefix", "fatherFirstName", "fatherLastName"], + // order: { lastUpdatedAt: "DESC" }, + // }); + + // const root = + // profileOc.current_holders == null || + // profileOc.current_holders.length == 0 || + // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + // ? null + // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot; + + // const child1 = + // profileOc.current_holders == null || + // profileOc.current_holders.length == 0 || + // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + // ? null + // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1; + + // const child2 = + // profileOc.current_holders == null || + // profileOc.current_holders.length == 0 || + // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + // ? null + // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2; + + // const child3 = + // profileOc.current_holders == null || + // profileOc.current_holders.length == 0 || + // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + // ? null + // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3; + + // const child4 = + // profileOc.current_holders == null || + // profileOc.current_holders.length == 0 || + // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + // ? null + // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; + + // // Construct org path + // const _root = root ? `${root.orgRootName}` : ""; + // const _child1 = child1 ? `${child1.orgChild1Name}/` : ""; + // const _child2 = child2 ? `${child2.orgChild2Name}/` : ""; + // const _child3 = child3 ? `${child3.orgChild3Name}/` : ""; + // const _child4 = child4 ? `${child4.orgChild4Name}/` : ""; + + // const cert_raw = await this.certificateRepository.find({ + // where: { profileId: id }, + // select: ["certificateType", "issuer", "certificateNo", "issueDate"], + // order: { createdAt: "ASC" }, + // }); + // 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", "name"], + // where: { profileId: id }, + // order: { createdAt: "ASC" }, + // }); + // 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 discipline_raw = await this.disciplineRepository.find({ + // select: ["refCommandDate", "refCommandNo", "detail"], + // where: { profileId: id }, + // order: { createdAt: "ASC" }, + // }); + // 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 education_raw = await this.profileEducationRepo.find({ + // select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], + // where: { profileId: id }, + // // order: { lastUpdatedAt: "DESC" }, + // order: { level: "ASC" }, + // }); + // 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.salaryRepo.find({ + // select: [ + // "commandDateAffect", + // "positionName", + // "posNo", + // "positionType", + // "positionLevel", + // "positionSalaryAmount", + // "commandNo", + // "amount", + // "remark", + // ], + // where: { profileId: id }, + // 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.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.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}${_child3}${_child2}${_child1}${_root}`, + // })) + // : [ + // { + // salaryDate: "-", + // position: "-", + // posNo: "-", + // salary: "-", + // rank: "-", + // refAll: "-", + // positionLevel: "-", + // positionType: "-", + // positionAmount: "-", + // fullName: "-", + // ocFullPath: "-", + // }, + // ]; + + // const insignia_raw = await this.profileInsigniaRepo.find({ + // relations: { + // insignia: { + // insigniaType: true, + // }, + // }, + // where: { profileId: 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 ? 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 leave_raw = await this.profileLeaveRepository.find({ + // relations: { leaveType: true }, + // where: { profileId: id }, + // order: { dateLeaveStart: "ASC" }, + // }); + // 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)) + // : "", + // 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 : `${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, + // insignias, + // leaves, + // certs, + // trainings, + // disciplines, + // educations, + // salarys, + // }; + + // return new HttpSuccess({ + // template: "kk1", + // reportName: "docx-report", + // data: data, + // }); + // } + /** - * รายงาน ก.ก.1 (ข้าราชการ) + * รายงาน ก.ก.1 (ข้าราชการ) ใหม่ * - * @summary รายงาน ก.ก.1 (ข้าราชการ) + * @summary รายงาน ก.ก.1 (ข้าราชการ) ใหม่ * * @param {string} id Id โปรไฟล์ */ @Get("kk1/{id}") public async getKk1(@Path() id: string, @Request() req: RequestWithUser) { const profiles = await this.profileRepo.findOne({ - relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], + relations: ["currentSubDistrict", "currentDistrict", "currentProvince","registrationSubDistrict", "registrationDistrict", "registrationProvince", "profileAvatars"], order: { profileAvatars: { createdAt: "ASC" }, }, @@ -531,6 +1016,8 @@ export class ProfileController extends Controller { issuer: item.issuer ?? null, certificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null, issueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null, + expireDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)) ?? null, + issueToExpireDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? "" + item.expireDate?" - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)): null, })) : [ { @@ -538,6 +1025,8 @@ export class ProfileController extends Controller { issuer: "-", certificateNo: "-", issueDate: "-", + expireDate: "-", + issueToExpireDate: "-", }, ]; const training_raw = await this.trainingRepository.find({ @@ -709,7 +1198,7 @@ export class ProfileController extends Controller { insigniaShortName: item.insignia.shortName, insigniaTypeName: item.insignia.insigniaType.name, no: item.no ? Extension.ToThaiNumber(item.no) : "", - issue: item.issue ? item.issue : "", + 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) : "", @@ -756,11 +1245,178 @@ export class ProfileController extends Controller { }, ]; + const children_raw = await this.profileChildrenRepository.find({ + where: { profileId: 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: { profileId: 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: { profileId: id }, + 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?Extension.ToThaiNumber(item.posNoAbb):"" + item.posNo?Extension.ToThaiNumber(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: "-", + refCommandNo: "-", + posNo: "-", + position: "-", + posType: "-", + posLevel: "-", + amount: "-", + positionSalaryAmount: "-", + }, + ]; + + const actposition_raw = await this.profileActpositionRepo.find({ + where: { profileId: 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)):"", + refCommandDate: item.refCommandDate?Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)):"", + refCommandNo: item.refCommandNo?Extension.ToThaiNumber(item.refCommandNo):"", + position: item.position, + posNo: item.posNo, + })) + : [ + { + date: "-", + refCommandDate: "-", + refCommandNo: "-", + position: "-", + posNo: "-", + }, + ]; + const duty_raw = await this.dutyRepository.find({ + where: { profileId: 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: { profileId: 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: { profileId: 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 sum = profiles?Extension.ToThaiNumber((Number(profiles.amount) + Number(profiles.positionSalaryAmount) + Number(profiles.mouthSalaryAmount) + Number(profiles.amountSpecial)).toLocaleString()):""; + const fullCurrentAddress = profiles?Extension.ToThaiNumber(profiles.currentAddress + " ตำบล/แขวง " + profiles.currentSubDistrict.name + " อำเภอ/เขต " + profiles.currentDistrict.name + " จังหวัด " + profiles.currentProvince.name + profiles.currentZipCode):""; + const fullRegistrationAddress = profiles?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}${_child3}${_child2}${_child1}${_root}`, birthDate: profiles?.birthDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate)) @@ -780,12 +1436,14 @@ export class ProfileController extends Controller { 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 || @@ -793,6 +1451,7 @@ export class ProfileController extends Controller { ? `${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: @@ -807,6 +1466,30 @@ export class ProfileController extends Controller { 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.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "", url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_MGT}`, @@ -838,6 +1521,8 @@ export class ProfileController extends Controller { yearUpload7: profiles.profileAvatars[6] ? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[6].createdAt)) : null, + urlQRcode: "https://seis.ocsc.go.th", + children, insignias, leaves, certs, @@ -845,14 +1530,21 @@ export class ProfileController extends Controller { disciplines, educations, salarys, + changeName, + positionList, + actposition, + duty, + assessments, + profileAbility, }; return new HttpSuccess({ - template: "kk1", + template: "new_kk1", reportName: "docx-report", data: data, }); } + /** * * From 8278d9ddffac5e65149a6f31ae5b428335f00eaa Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 4 Mar 2025 11:00:11 +0700 Subject: [PATCH 2/4] fix year --- src/controllers/ProfileController.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index dd9f8090..650bd4f5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1075,8 +1075,7 @@ export class ProfileController extends Controller { discipline_raw.length > 0 ? discipline_raw.slice(-2).map((item) => ({ disciplineYear: - Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? - null, + item.refCommandDate?Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()):null, disciplineDetail: item.detail ?? null, refNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, })) From 190451a910d862de6eede60b72ef109e1ba35f05 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 4 Mar 2025 13:00:33 +0700 Subject: [PATCH 3/4] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88?= =?UTF-8?q?=E0=B8=87=E0=B9=83=E0=B8=99=E0=B8=A3=E0=B8=B0=E0=B8=94=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileSalaryController.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index dc945be6..b6d95842 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -97,14 +97,17 @@ export class ProfileSalaryController extends Controller { })) : []; - const posLevel: any = [ - // { - // year: 1, - // month: 0, - // day: 0, - // name: "ต้น", - // } - ]; + const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?)", [profileId]); + const _posLevel = posLevel.length > 0 ? posLevel[0] : []; + const mapPosLevel = + _posLevel.length > 1 + ? _posLevel.slice(1).map((curr: any, index: number) => ({ + year: curr.Years ? Math.floor(Number(curr.Years)) : 0, + month: curr.Months ? Math.floor(Number(curr.Months)) : 0, + day: curr.Days ? Math.floor(Number(curr.Days)) : 0, + name: _posLevel[index]?.positionLevel, + })) + : []; const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?)", [ profileId, @@ -122,7 +125,7 @@ export class ProfileSalaryController extends Controller { return new HttpSuccess({ position: mapPosition, - posLevel: posLevel, + posLevel: mapPosLevel, posExecutive: mapPosExecutive, }); } From 293effa89af28f255dede88df914c2cbed96e288 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 4 Mar 2025 14:14:57 +0700 Subject: [PATCH 4/4] fix --- src/controllers/ProfileController.ts | 908 +++++++++++++-------------- 1 file changed, 454 insertions(+), 454 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 650bd4f5..a3f592b3 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -395,477 +395,477 @@ export class ProfileController extends Controller { }); } - // /** - // * รายงาน ก.ก.1 (ข้าราชการ) - // * - // * @summary รายงาน ก.ก.1 (ข้าราชการ) - // * - // * @param {string} id Id โปรไฟล์ - // */ - // @Get("kk1/{id}") - // public async getKk1(@Path() id: string, @Request() req: RequestWithUser) { - // const profiles = await this.profileRepo.findOne({ - // relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], - // 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) { - // // await new CallAPI() - // // .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) - // // .then(async (x) => { - // // ImgUrl = x.downloadUrl; - // // }) - // // .catch(); + /** + * รายงาน ก.ก.1 (ข้าราชการ) + * + * @summary รายงาน ก.ก.1 (ข้าราชการ) + * + * @param {string} id Id โปรไฟล์ + */ + @Get("kk1/{id}") + public async getKk1(@Path() id: string, @Request() req: RequestWithUser) { + const profiles = await this.profileRepo.findOne({ + relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], + 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) { + // 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 ", ""); + 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", - // "current_holders.orgRoot", - // "current_holders.orgChild1", - // "current_holders.orgChild2", - // "current_holders.orgChild3", - // "current_holders.orgChild4", - // ], - // where: { id: id }, - // }); - // if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - // const orgRevision = await this.orgRevisionRepo.findOne({ - // where: { orgRevisionIsCurrent: true }, - // }); + 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", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + where: { id: id }, + }); + if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const orgRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); - // const profileFamilyCouple = await this.profileFamilyCoupleRepository.findOne({ - // where: { profileId: id }, - // select: ["couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld"], - // order: { lastUpdatedAt: "DESC" }, - // }); + const profileFamilyCouple = await this.profileFamilyCoupleRepository.findOne({ + where: { profileId: id }, + select: ["couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld"], + order: { lastUpdatedAt: "DESC" }, + }); - // const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({ - // where: { profileId: id }, - // select: ["motherPrefix", "motherFirstName", "motherLastName"], - // order: { lastUpdatedAt: "DESC" }, - // }); + const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({ + where: { profileId: id }, + select: ["motherPrefix", "motherFirstName", "motherLastName"], + order: { lastUpdatedAt: "DESC" }, + }); - // const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({ - // where: { profileId: id }, - // select: ["fatherPrefix", "fatherFirstName", "fatherLastName"], - // order: { lastUpdatedAt: "DESC" }, - // }); + const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({ + where: { profileId: id }, + select: ["fatherPrefix", "fatherFirstName", "fatherLastName"], + order: { lastUpdatedAt: "DESC" }, + }); - // const root = - // profileOc.current_holders == null || - // profileOc.current_holders.length == 0 || - // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null - // ? null - // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot; + const root = + profileOc.current_holders == null || + profileOc.current_holders.length == 0 || + profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + ? null + : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot; - // const child1 = - // profileOc.current_holders == null || - // profileOc.current_holders.length == 0 || - // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null - // ? null - // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1; + const child1 = + profileOc.current_holders == null || + profileOc.current_holders.length == 0 || + profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + ? null + : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1; - // const child2 = - // profileOc.current_holders == null || - // profileOc.current_holders.length == 0 || - // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null - // ? null - // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2; + const child2 = + profileOc.current_holders == null || + profileOc.current_holders.length == 0 || + profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + ? null + : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2; - // const child3 = - // profileOc.current_holders == null || - // profileOc.current_holders.length == 0 || - // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null - // ? null - // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3; + const child3 = + profileOc.current_holders == null || + profileOc.current_holders.length == 0 || + profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + ? null + : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3; - // const child4 = - // profileOc.current_holders == null || - // profileOc.current_holders.length == 0 || - // profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null - // ? null - // : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; + const child4 = + profileOc.current_holders == null || + profileOc.current_holders.length == 0 || + profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null + ? null + : profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; - // // Construct org path - // const _root = root ? `${root.orgRootName}` : ""; - // const _child1 = child1 ? `${child1.orgChild1Name}/` : ""; - // const _child2 = child2 ? `${child2.orgChild2Name}/` : ""; - // const _child3 = child3 ? `${child3.orgChild3Name}/` : ""; - // const _child4 = child4 ? `${child4.orgChild4Name}/` : ""; + // Construct org path + const _root = root ? `${root.orgRootName}` : ""; + const _child1 = child1 ? `${child1.orgChild1Name}/` : ""; + const _child2 = child2 ? `${child2.orgChild2Name}/` : ""; + const _child3 = child3 ? `${child3.orgChild3Name}/` : ""; + const _child4 = child4 ? `${child4.orgChild4Name}/` : ""; - // const cert_raw = await this.certificateRepository.find({ - // where: { profileId: id }, - // select: ["certificateType", "issuer", "certificateNo", "issueDate"], - // order: { createdAt: "ASC" }, - // }); - // 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", "name"], - // where: { profileId: id }, - // order: { createdAt: "ASC" }, - // }); - // 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 cert_raw = await this.certificateRepository.find({ + where: { profileId: id }, + select: ["certificateType", "issuer", "certificateNo", "issueDate"], + order: { createdAt: "ASC" }, + }); + 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", "name"], + where: { profileId: id }, + order: { createdAt: "ASC" }, + }); + 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 discipline_raw = await this.disciplineRepository.find({ - // select: ["refCommandDate", "refCommandNo", "detail"], - // where: { profileId: id }, - // order: { createdAt: "ASC" }, - // }); - // 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 discipline_raw = await this.disciplineRepository.find({ + select: ["refCommandDate", "refCommandNo", "detail"], + where: { profileId: id }, + order: { createdAt: "ASC" }, + }); + 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 education_raw = await this.profileEducationRepo.find({ - // select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], - // where: { profileId: id }, - // // order: { lastUpdatedAt: "DESC" }, - // order: { level: "ASC" }, - // }); - // 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.salaryRepo.find({ - // select: [ - // "commandDateAffect", - // "positionName", - // "posNo", - // "positionType", - // "positionLevel", - // "positionSalaryAmount", - // "commandNo", - // "amount", - // "remark", - // ], - // where: { profileId: id }, - // order: { order: "ASC" }, - // }); + const education_raw = await this.profileEducationRepo.find({ + select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], + where: { profileId: id }, + // order: { lastUpdatedAt: "DESC" }, + order: { level: "ASC" }, + }); + 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.salaryRepo.find({ + select: [ + "commandDateAffect", + "positionName", + "posNo", + "positionType", + "positionLevel", + "positionSalaryAmount", + "commandNo", + "amount", + "remark", + ], + where: { profileId: id }, + 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.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.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}${_child3}${_child2}${_child1}${_root}`, - // })) - // : [ - // { - // salaryDate: "-", - // position: "-", - // posNo: "-", - // salary: "-", - // rank: "-", - // refAll: "-", - // positionLevel: "-", - // positionType: "-", - // positionAmount: "-", - // fullName: "-", - // ocFullPath: "-", - // }, - // ]; + 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.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.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}${_child3}${_child2}${_child1}${_root}`, + })) + : [ + { + salaryDate: "-", + position: "-", + posNo: "-", + salary: "-", + rank: "-", + refAll: "-", + positionLevel: "-", + positionType: "-", + positionAmount: "-", + fullName: "-", + ocFullPath: "-", + }, + ]; - // const insignia_raw = await this.profileInsigniaRepo.find({ - // relations: { - // insignia: { - // insigniaType: true, - // }, - // }, - // where: { profileId: 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 ? 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 insignia_raw = await this.profileInsigniaRepo.find({ + relations: { + insignia: { + insigniaType: true, + }, + }, + where: { profileId: 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 ? 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 leave_raw = await this.profileLeaveRepository.find({ - // relations: { leaveType: true }, - // where: { profileId: id }, - // order: { dateLeaveStart: "ASC" }, - // }); - // 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 leave_raw = await this.profileLeaveRepository.find({ + relations: { leaveType: true }, + where: { profileId: id }, + order: { dateLeaveStart: "ASC" }, + }); + 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)) - // : "", - // 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 : `${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, - // insignias, - // leaves, - // certs, - // trainings, - // disciplines, - // educations, - // salarys, - // }; + 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)) + : "", + 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 : `${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, + insignias, + leaves, + certs, + trainings, + disciplines, + educations, + salarys, + }; - // return new HttpSuccess({ - // template: "kk1", - // reportName: "docx-report", - // data: data, - // }); - // } + return new HttpSuccess({ + template: "kk1", + reportName: "docx-report", + data: data, + }); + } /** * รายงาน ก.ก.1 (ข้าราชการ) ใหม่ @@ -874,8 +874,8 @@ export class ProfileController extends Controller { * * @param {string} id Id โปรไฟล์ */ - @Get("kk1/{id}") - public async getKk1(@Path() id: string, @Request() req: RequestWithUser) { + @Get("kk1new/{id}") + public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) { const profiles = await this.profileRepo.findOne({ relations: ["currentSubDistrict", "currentDistrict", "currentProvince","registrationSubDistrict", "registrationDistrict", "registrationProvince", "profileAvatars"], order: {