From 171817691134aeba60ea84ec5d2b4843457e9af9 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 18 Jul 2024 14:16:46 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88?= =?UTF-8?q?=E0=B8=87=E0=B8=A3=E0=B8=B1=E0=B8=81=E0=B8=A9=E0=B8=B2=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B9=81=E0=B8=97=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PosMasterActController.ts | 155 +++++++++++++++++ src/controllers/PositionController.ts | 30 ++-- src/controllers/ProfileController.ts | 198 +++++++++++----------- 3 files changed, 269 insertions(+), 114 deletions(-) diff --git a/src/controllers/PosMasterActController.ts b/src/controllers/PosMasterActController.ts index f7ba6dc3..4ca0766b 100644 --- a/src/controllers/PosMasterActController.ts +++ b/src/controllers/PosMasterActController.ts @@ -20,6 +20,8 @@ import HttpError from "../interfaces/http-error"; import { PosMasterAct } from "../entities/PosMasterAct"; import { PosMaster } from "../entities/PosMaster"; import { LessThan, MoreThan } from "typeorm"; +import { OrgRevision } from "../entities/OrgRevision"; +import Extension from "../interfaces/extension"; @Route("api/v1/org/pos/act") @Tags("PosMasterAct") @@ -30,6 +32,7 @@ import { LessThan, MoreThan } from "typeorm"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class PosMasterActController extends Controller { + private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private posMasterActRepository = AppDataSource.getRepository(PosMasterAct); private posMasterRepository = AppDataSource.getRepository(PosMaster); @@ -178,6 +181,158 @@ export class PosMasterActController extends Controller { return new HttpSuccess(); } + /** + * API รายชื่อรักษาการในตำแหน่ง + * + * @summary รายชื่อรักษาการในตำแหน่ง (ADMIN) + * + * @param {string} id Id รักษาการในตำแหน่ง + */ + @Get("profile") + async GetPosMasterActProfile() { + const orgRevisionActive = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }); + if (!orgRevisionActive) { + return new HttpSuccess(); + } + const posMasterActs = await this.posMasterActRepository.find({ + relations: [ + "posMaster", + "posMasterChild", + "posMasterChild.orgRoot", + "posMasterChild.orgChild1", + "posMasterChild.orgChild2", + "posMasterChild.orgChild3", + "posMasterChild.orgChild4", + "posMasterChild.current_holder", + "posMasterChild.current_holder.posLevel", + "posMasterChild.current_holder.posType", + ], + where: { + posMaster: { + orgRevisionId: orgRevisionActive.id, + }, + }, + }); + if (!posMasterActs) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); + } + + const data = await Promise.all( + posMasterActs + .sort((a, b) => a.posMaster.posMasterOrder - b.posMaster.posMasterOrder) + .map((item) => { + const shortName = + item.posMasterChild != null && item.posMasterChild.orgChild4 != null + ? `${item.posMasterChild.orgChild4.orgChild4ShortName}${item.posMasterChild.posMasterNo}` + : item.posMasterChild != null && item.posMasterChild?.orgChild3 != null + ? `${item.posMasterChild.orgChild3.orgChild3ShortName}${item.posMasterChild.posMasterNo}` + : item.posMasterChild != null && item.posMasterChild?.orgChild2 != null + ? `${item.posMasterChild.orgChild2.orgChild2ShortName}${item.posMasterChild.posMasterNo}` + : item.posMasterChild != null && item.posMasterChild?.orgChild1 != null + ? `${item.posMasterChild.orgChild1.orgChild1ShortName}${item.posMasterChild.posMasterNo}` + : item.posMasterChild != null && item.posMasterChild?.orgRoot != null + ? `${item.posMasterChild.orgRoot.orgRootShortName}${item.posMasterChild.posMasterNo}` + : null; + return { + id: item.id, + posMasterOrder: item.posMasterOrder, + profileId: item.posMasterChild?.current_holder?.id ?? null, + citizenId: item.posMasterChild?.current_holder?.citizenId ?? null, + prefix: item.posMasterChild?.current_holder?.prefix ?? null, + firstName: item.posMasterChild?.current_holder?.firstName ?? null, + lastName: item.posMasterChild?.current_holder?.lastName ?? null, + posLevel: item.posMasterChild?.current_holder?.posLevel?.posLevelName ?? null, + posType: item.posMasterChild?.current_holder?.posType?.posTypeName ?? null, + position: item.posMasterChild?.current_holder?.position ?? null, + posNo: shortName, + }; + }), + ); + return new HttpSuccess(data); + } + + /** + * API รายชื่อรักษาการในตำแหน่ง + * + * @summary รายชื่อรักษาการในตำแหน่ง (ADMIN) + * + * @param {string} id Id รักษาการในตำแหน่ง + */ + @Get("{posMasterActId}/{profileId}") + async GetPosMasterActProfileReport( + @Path() posMasterActId: string, + profileId: string, + @Request() request: { user: Record }, + ) { + const posMasterAct = await this.posMasterActRepository.findOne({ + relations: [ + "posMaster", + "posMaster", + "posMaster.orgRoot", + "posMaster.orgChild1", + "posMaster.orgChild2", + "posMaster.orgChild3", + "posMaster.orgChild4", + "posMaster.current_holder", + "posMasterChild", + "posMasterChild.orgRoot", + "posMasterChild.orgChild1", + "posMasterChild.orgChild2", + "posMasterChild.orgChild3", + "posMasterChild.orgChild4", + "posMasterChild.current_holder", + "posMasterChild.current_holder.posLevel", + "posMasterChild.current_holder.posType", + ], + where: { + id: posMasterActId, + }, + }); + if (!posMasterAct) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); + } + const organization = [ + posMasterAct.posMasterChild?.current_holder?.position ?? null, + posMasterAct.posMasterChild?.orgChild4?.orgChild4Name ?? null, + posMasterAct.posMasterChild?.orgChild3?.orgChild3Name ?? null, + posMasterAct.posMasterChild?.orgChild2?.orgChild2Name ?? null, + posMasterAct.posMasterChild?.orgChild1?.orgChild1Name ?? null, + posMasterAct.posMasterChild?.orgRoot?.orgRootName ?? null, + ]; + const _organization = organization + .filter((part) => part !== undefined && part !== null) + .join("/"); + + const organizationNew = [ + posMasterAct.posMaster?.current_holder?.position ?? null, + posMasterAct.posMaster?.orgChild4?.orgChild4Name ?? null, + posMasterAct.posMaster?.orgChild3?.orgChild3Name ?? null, + posMasterAct.posMaster?.orgChild2?.orgChild2Name ?? null, + posMasterAct.posMaster?.orgChild1?.orgChild1Name ?? null, + posMasterAct.posMaster?.orgRoot?.orgRootName ?? null, + ]; + const _organizationNew = organizationNew + .filter((part) => part !== undefined && part !== null) + .join("/"); + return new HttpSuccess({ + prefix: posMasterAct.posMasterChild?.current_holder?.prefix ?? null, + firstName: posMasterAct.posMasterChild?.current_holder?.firstName ?? null, + lastName: posMasterAct.posMasterChild?.current_holder?.lastName ?? null, + organization: _organization, // + position: posMasterAct.posMasterChild?.current_holder?.position ?? null, + postype: posMasterAct.posMasterChild?.current_holder?.posType?.posTypeName ?? null, + poslevel: posMasterAct.posMasterChild?.current_holder?.posLevel?.posLevelName ?? null, + organizationNew: _organizationNew, + date: Extension.ToThaiShortDate_noPrefix(new Date()), + order: + posMasterAct.posMasterOrder == null + ? "-" + : "ลำดับที่ " + Extension.ToThaiNumber(posMasterAct.posMasterOrder.toString()), + }); + } + /** * API รายละเอียดรักษาการในตำแหน่ง * diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index c98dd71e..bcb0fddf 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3373,28 +3373,28 @@ export class PositionController extends Controller { }, }); if (posMasterOld != null) posMasterOld.current_holderId = null; - + const positionOld = await this.positionRepository.findOne({ where: { posMasterId: posMasterOld?.id, - positionIsSelected: true - } - }) + positionIsSelected: true, + }, + }); if (positionOld != null) { - positionOld.positionIsSelected = false + positionOld.positionIsSelected = false; await this.positionRepository.save(positionOld); } const checkPosition = await this.positionRepository.find({ where: { posMasterId: body.posmasterId, - positionIsSelected: true - } - }) + positionIsSelected: true, + }, + }); if (checkPosition.length > 0) { - const clearPosition = checkPosition.map(positions => ({ + const clearPosition = checkPosition.map((positions) => ({ ...positions, - positionIsSelected: false + positionIsSelected: false, })); await this.positionRepository.save(clearPosition); } @@ -3412,11 +3412,11 @@ export class PositionController extends Controller { const positionNew = await this.positionRepository.findOne({ where: { id: body.positionId, - posMasterId: body.posmasterId - } - }) - if(positionNew != null) { - positionNew.positionIsSelected = true + posMasterId: body.posmasterId, + }, + }); + if (positionNew != null) { + positionNew.positionIsSelected = true; await this.positionRepository.save(positionNew); } return new HttpSuccess(); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 3889043a..8781a4f6 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -396,7 +396,7 @@ export class ProfileController extends Controller { StartDate: profiles?.dateStart ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateStart)) : "", - AppointDate: profiles?.dateAppoint + AppointDate: profiles?.dateAppoint ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint)) : "", BirthDate: profiles?.birthDate @@ -1820,12 +1820,12 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ภาคทัณฑ์"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + // let dateLeave_: any = body.date; + // profile.isLeave = true; + // profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ภาคทัณฑ์"; + // profile.dateLeave = dateLeave_; + // profile.lastUpdateUserId = req.user.sub; + // profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -1891,12 +1891,12 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ตัดเงินเดือน"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + // let dateLeave_: any = body.date; + // profile.isLeave = true; + // profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ตัดเงินเดือน"; + // profile.dateLeave = dateLeave_; + // profile.lastUpdateUserId = req.user.sub; + // profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -1962,12 +1962,12 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ลดขั้นเงินเดือน"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + // let dateLeave_: any = body.date; + // profile.isLeave = true; + // profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ลดขั้นเงินเดือน"; + // profile.dateLeave = dateLeave_; + // profile.lastUpdateUserId = req.user.sub; + // profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -2033,12 +2033,83 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย เพิ่มโทษ"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + // let dateLeave_: any = body.date; + // profile.isLeave = true; + // profile.leaveReason = "ได้รับโทษทางวินัย เพิ่มโทษ"; + // profile.dateLeave = dateLeave_; + // profile.lastUpdateUserId = req.user.sub; + // profile.lastUpdateFullName = req.user.name; + const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { + profileId: body.profileId, + date: body.date, + refCommandNo: body.refCommandNo, + templateDoc: body.salaryRef, + position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, + positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, + positionLevel: + profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, + posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, + positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, + positionPathSide: + profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, + positionExecutive: + profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, + amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null, + positionSalaryAmount: + profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null, + mouthSalaryAmount: + profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null, + order: + profile.profileSalary.length >= 0 + ? profile.profileSalary.length > 0 + ? profile.profileSalary[0].order + 1 + : 1 + : null, + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }); + await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + + return new HttpSuccess(); + } + + /** + * API ออกคำสั่ง คำสั่งงดโทษ + * + * @summary API ออกคำสั่ง คำสั่งงดโทษ (ADMIN) + * + */ + @Post("command31/{profileId}") + async ExecuteCommand31Async( + @Request() req: RequestWithUser, + @Body() + body: { + profileId: string; + date: Date | null; + refCommandNo: string | null; + salaryRef: string | null; + }, + ) { + const profile = await this.profileRepo.findOne({ + relations: ["profileSalary"], + where: { id: body.profileId }, + order: { + profileSalary: { + order: "DESC", + }, + }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); + } + // let dateLeave_: any = body.date; + // profile.isLeave = true; + // profile.leaveReason = "ได้รับโทษทางวินัย งดโทษ"; + // profile.dateLeave = dateLeave_; + // profile.lastUpdateUserId = req.user.sub; + // profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -2147,77 +2218,6 @@ export class ProfileController extends Controller { return new HttpSuccess(); } - /** - * API ออกคำสั่ง คำสั่งงดโทษ - * - * @summary API ออกคำสั่ง คำสั่งงดโทษ (ADMIN) - * - */ - @Post("command31/{profileId}") - async ExecuteCommand31Async( - @Request() req: RequestWithUser, - @Body() - body: { - profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - }, - ) { - const profile = await this.profileRepo.findOne({ - relations: ["profileSalary"], - where: { id: body.profileId }, - order: { - profileSalary: { - order: "DESC", - }, - }, - }); - if (!profile) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); - } - let dateLeave_: any = body.date; - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย งดโทษ"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; - const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { - profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.profileSalary.length > 0 ? profile.profileSalary[0].position : null, - positionType: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionType : null, - positionLevel: - profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLevel : null, - posNo: profile.profileSalary.length > 0 ? profile.profileSalary[0].posNo : null, - positionLine: profile.profileSalary.length > 0 ? profile.profileSalary[0].positionLine : null, - positionPathSide: - profile.profileSalary.length > 0 ? profile.profileSalary[0].positionPathSide : null, - positionExecutive: - profile.profileSalary.length > 0 ? profile.profileSalary[0].positionExecutive : null, - amount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null, - positionSalaryAmount: - profile.profileSalary.length > 0 ? profile.profileSalary[0].positionSalaryAmount : null, - mouthSalaryAmount: - profile.profileSalary.length > 0 ? profile.profileSalary[0].mouthSalaryAmount : null, - order: - profile.profileSalary.length >= 0 - ? profile.profileSalary.length > 0 - ? profile.profileSalary[0].order + 1 - : 1 - : null, - createdUserId: req.user.sub, - createdFullName: req.user.name, - lastUpdateUserId: req.user.sub, - lastUpdateFullName: req.user.name, - }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); - - return new HttpSuccess(); - } - /** * API คำนวนวันเกษียณ * @@ -2298,9 +2298,9 @@ export class ProfileController extends Controller { // chkDigit = cal % 10; // } - // if (citizenIdDigits[12] !== chkDigit) { - // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - // } + // if (citizenIdDigits[12] !== chkDigit) { + // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); + // } } const record = await this.profileRepo.findOneBy({ id });