From fc5f28ee3655ccfda49127b636bec4bc3e62398d Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Wed, 19 Mar 2025 17:51:01 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B8=95?= =?UTF-8?q?=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandCodeController.ts | 2 +- .../ProfileSalaryTempController.ts | 1013 +++++++++++++++++ src/entities/Command.ts | 4 + src/entities/Profile.ts | 11 + src/entities/ProfileEmployee.ts | 11 + src/entities/ProfileSalary.ts | 4 + src/entities/ProfileSalaryTemp.ts | 359 ++++++ 7 files changed, 1403 insertions(+), 1 deletion(-) create mode 100644 src/controllers/ProfileSalaryTempController.ts create mode 100644 src/entities/ProfileSalaryTemp.ts diff --git a/src/controllers/CommandCodeController.ts b/src/controllers/CommandCodeController.ts index 1049376b..b04bb4e2 100644 --- a/src/controllers/CommandCodeController.ts +++ b/src/controllers/CommandCodeController.ts @@ -49,7 +49,7 @@ export class CommandCodeController extends Controller { "createdFullName", "lastUpdateFullName", ], - order: { code: "ASC" }, + order: { id: "ASC" }, }); return new HttpSuccess(_commandCode); } diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts new file mode 100644 index 00000000..6b0c9e2a --- /dev/null +++ b/src/controllers/ProfileSalaryTempController.ts @@ -0,0 +1,1013 @@ +import { + Body, + Controller, + Get, + Patch, + Path, + Post, + Query, + Request, + Route, + Security, + Tags, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import { ProfileSalary } from "../entities/ProfileSalary"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatus from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { RequestWithUser } from "../middlewares/user"; +import { Brackets, LessThan, MoreThan } from "typeorm"; +import { setLogDataDiff } from "../interfaces/utils"; +import { + CreateProfileSalaryTemp, + ProfileSalaryTemp, + UpdateProfileSalaryTemp, +} from "../entities/ProfileSalaryTemp"; +import { Profile } from "../entities/Profile"; +import { ProfileEmployee } from "../entities/ProfileEmployee"; +import permission from "../interfaces/permission"; +import { OrgRevision } from "../entities/OrgRevision"; +import Extension from "../interfaces/extension"; +@Route("api/v1/org/profile/salaryTemp") +@Tags("ProfileSalaryTemp") +@Security("bearerAuth") +export class ProfileSalaryTempController extends Controller { + private profileRepo = AppDataSource.getRepository(Profile); + private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); + private salaryRepo = AppDataSource.getRepository(ProfileSalaryTemp); + private salaryOldRepo = AppDataSource.getRepository(ProfileSalary); + private orgRevisionRepo = AppDataSource.getRepository(OrgRevision); + + /** + * API ค้นหารายการคน + * + * @summary API ค้นหารายการคน + * + */ + @Get() + async listProfile( + @Request() request: RequestWithUser, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query() + searchField?: "firstName" | "lastName" | "fullName" | "citizenId", + @Query() type: string = "OFFICER", + @Query() searchKeyword: string = "", + @Query() statusCheckEdit?: string | null, + @Query() rootId?: string, + ) { + if (type.trim().toUpperCase() == "OFFICER") { + let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); + let queryLike = + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; + if (searchField == "citizenId") { + queryLike = "profile.citizenId LIKE :keyword"; + } + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + const [record, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.positions", "positions") + .leftJoinAndSelect("positions.posExecutive", "posExecutive") + .leftJoinAndSelect("current_holders.orgRevision", "orgRevision") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .where("current_holders.orgRevisionId = :orgRevisionId", { + orgRevisionId: findRevision.id, + }) + .andWhere( + statusCheckEdit != undefined && statusCheckEdit != null + ? "profile.statusCheckEdit = :statusCheckEdit" + : "1=1", + { + statusCheckEdit: statusCheckEdit?.trim()?.toUpperCase() ?? null, + }, + ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holders.orgRootId IN (:...root)` + : `current_holders.orgRootId is null` + : "1=1", + { + root: _data.root, + }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holders.orgChild1Id IN (:...child1)` + : `current_holders.orgChild1Id is null` + : "1=1", + { + child1: _data.child1, + }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holders.orgChild2Id IN (:...child2)` + : `current_holders.orgChild2Id is null` + : "1=1", + { + child2: _data.child2, + }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holders.orgChild3Id IN (:...child3)` + : `current_holders.orgChild3Id is null` + : "1=1", + { + child3: _data.child3, + }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holders.orgChild4Id IN (:...child4)` + : `current_holders.orgChild4Id is null` + : "1=1", + { + child4: _data.child4, + }, + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere( + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + ? queryLike + : "1=1", + { + keyword: `%${searchKeyword}%`, + }, + ); + }), + ) + .andWhere("current_holders.orgRootId = :rootId", { + rootId: rootId, + }) + .orderBy("current_holders.posMasterNo", "ASC") + // .orderBy(`${sortBy}`, sort) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const data = await Promise.all( + record.map((_data) => { + const posExecutive = + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions + .length == 0 || + _data.current_holders + .find((x) => x.orgRevisionId == findRevision.id) + ?.positions.find((x: any) => x.positionIsSelected == true) == null || + _data.current_holders + .find((x) => x.orgRevisionId == findRevision.id) + ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null + ? null + : _data.current_holders + .find((x) => x.orgRevisionId == findRevision.id) + ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive + ?.posExecutiveName; + + const shortName = + _data.current_holders.length == 0 + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild4 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild3 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild2 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild1 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgRoot != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : null; + const root = + _data.current_holders.length == 0 || + (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == + null) + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + + const child1 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; + + const child2 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; + + const child3 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; + + const child4 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; + + let _child1 = child1 == null ? "" : `${child1.orgChild1Name} `; + let _child2 = child2 == null ? "" : `${child2.orgChild2Name} `; + let _child3 = child3 == null ? "" : `${child3.orgChild3Name} `; + let _child4 = child4 == null ? "" : `${child4.orgChild4Name} `; + + return { + id: _data.id, + avatar: _data.avatar, + avatarName: _data.avatarName, + prefix: _data.prefix, + rank: _data.rank, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + posLevelId: _data.posLevel == null ? null : _data.posLevel.id, + posTypeId: _data.posType == null ? null : _data.posType.id, + position: _data.position, + posExecutive: posExecutive, + posNo: shortName, + rootId: root == null ? null : root.id, + root: root == null ? null : root.orgRootName, + orgRootShortName: root == null ? null : root.orgRootShortName, + orgRevisionId: root == null ? null : root.orgRevisionId, + org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`, + }; + }), + ); + + return new HttpSuccess({ data: data, total }); + } else { + let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP"); + let queryLike = + "CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword"; + if (searchField == "citizenId") { + queryLike = "profileEmployee.citizenId LIKE :keyword"; + } + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + const [record, total] = await this.profileEmployeeRepo + .createQueryBuilder("profileEmployee") + .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") + .leftJoinAndSelect("profileEmployee.posType", "posType") + .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") + .leftJoinAndSelect("profileEmployee.profileEmployeeEmployment", "profileEmployeeEmployment") + .leftJoinAndSelect("current_holders.positions", "positions") + .leftJoinAndSelect("current_holders.orgRevision", "orgRevision") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .where("current_holders.orgRevisionId = :orgRevisionId", { + orgRevisionId: findRevision.id, + }) + .andWhere( + statusCheckEdit != undefined && statusCheckEdit != null + ? "profile.statusCheckEdit = :statusCheckEdit" + : "1=1", + { + statusCheckEdit: statusCheckEdit?.trim()?.toUpperCase() ?? null, + }, + ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holders.orgRootId IN (:...root)` + : `current_holders.orgRootId is null` + : "1=1", + { + root: _data.root, + }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holders.orgChild1Id IN (:...child1)` + : `current_holders.orgChild1Id is null` + : "1=1", + { + child1: _data.child1, + }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holders.orgChild2Id IN (:...child2)` + : `current_holders.orgChild2Id is null` + : "1=1", + { + child2: _data.child2, + }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holders.orgChild3Id IN (:...child3)` + : `current_holders.orgChild3Id is null` + : "1=1", + { + child3: _data.child3, + }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holders.orgChild4Id IN (:...child4)` + : `current_holders.orgChild4Id is null` + : "1=1", + { + child4: _data.child4, + }, + ) + // .andWhere("profileEmployee.employeeClass LIKE :type", { + // type: "PERM", + // }) + .andWhere( + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + ? queryLike + : "1=1", + { + keyword: `%${searchKeyword}%`, + }, + ) + .andWhere("current_holders.orgRootId = :rootId", { + rootId: rootId, + }) + .orderBy("current_holders.posMasterNo", "ASC") + // .orderBy(`${sortBy}`, sort) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const data = await Promise.all( + record.map((_data) => { + const shortName = + _data.current_holders.length == 0 + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild4 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild3 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild2 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild1 != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgRoot != null + ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : null; + const dateEmployment = + _data.profileEmployeeEmployment.length == 0 + ? null + : _data.profileEmployeeEmployment.reduce((latest, current) => { + return latest.date > current.date ? latest : current; + }).date; + const root = + _data.current_holders.length == 0 || + (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == + null) + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + + const child1 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; + + const child2 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; + + const child3 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; + + const child4 = + _data.current_holders == null || + _data.current_holders.length == 0 || + _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; + + let _child1 = child1 == null ? "" : `${child1.orgChild1Name} `; + let _child2 = child2 == null ? "" : `${child2.orgChild2Name} `; + let _child3 = child3 == null ? "" : `${child3.orgChild3Name} `; + let _child4 = child4 == null ? "" : `${child4.orgChild4Name} `; + return { + id: _data.id, + prefix: _data.prefix, + rank: _data.rank, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + posTypeShortName: _data.posType == null ? null : _data.posType.posTypeShortName, + posLevelId: _data.posLevel == null ? null : _data.posLevel.id, + posTypeId: _data.posType == null ? null : _data.posType.id, + positionId: _data.positionIdTemp, + posmasterId: _data.posmasterIdTemp, + position: _data.position, + posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, + employeeClass: _data.employeeClass == null ? null : _data.employeeClass, + govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + dateEmployment: dateEmployment, + dateAppoint: _data.dateAppoint, + dateStart: _data.dateStart, + createdAt: _data.createdAt, + dateRetireLaw: _data.dateRetireLaw, + draftOrganizationOrganization: + _data.nodeTemp == "0" + ? _data.rootTemp + : _data.nodeTemp == "1" + ? _data.child1Temp + : _data.nodeTemp == "2" + ? _data.child2Temp + : _data.nodeTemp == "3" + ? _data.child3Temp + : _data.nodeTemp == "4" + ? _data.child4Temp + : null, + draftPositionEmployee: _data.positionTemp, + draftOrgEmployeeStatus: _data.statusTemp, + node: _data.nodeTemp, + nodeId: _data.nodeIdTemp, + nodeName: + _data.nodeTemp == "0" + ? _data.rootTemp + : _data.nodeTemp == "1" + ? _data.child1Temp + : _data.nodeTemp == "2" + ? _data.child2Temp + : _data.nodeTemp == "3" + ? _data.child3Temp + : _data.nodeTemp == "4" + ? _data.child4Temp + : null, + nodeShortName: + _data.nodeTemp == "0" + ? _data.rootShortNameTemp + : _data.nodeTemp == "1" + ? _data.child1ShortNameTemp + : _data.nodeTemp == "2" + ? _data.child1ShortNameTemp + : _data.nodeTemp == "3" + ? _data.child3ShortNameTemp + : _data.nodeTemp == "4" + ? _data.child4ShortNameTemp + : null, + root: _data.rootTemp ? _data.rootTemp : null, + rootId: _data.rootIdTemp ? _data.rootIdTemp : null, + rootShortName: _data.rootShortNameTemp ? _data.rootShortNameTemp : null, + child1: _data.child1Temp ? _data.child1Temp : null, + child1Id: _data.child1IdTemp ? _data.child1IdTemp : null, + child1ShortName: _data.child1ShortNameTemp ? _data.child1ShortNameTemp : null, + child2: _data.child2Temp ? _data.child2Temp : null, + child2Id: _data.child2IdTemp ? _data.child2IdTemp : null, + child2ShortName: _data.child2ShortNameTemp ? _data.child2ShortNameTemp : null, + child3: _data.child3Temp ? _data.child3Temp : null, + child3Id: _data.child3IdTemp ? _data.child3IdTemp : null, + child3ShortName: _data.child3ShortNameTemp ? _data.child3ShortNameTemp : null, + child4: _data.child4Temp ? _data.child4Temp : null, + child4Id: _data.child4IdTemp ? _data.child4IdTemp : null, + child4ShortName: _data.child4ShortNameTemp ? _data.child4ShortNameTemp : null, + org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`, + }; + }), + ); + + return new HttpSuccess({ data: data, total }); + } + } + + // /** + // * API Clone ใหม่ตำแหน่งเงินเดือน + // * + // * @summary API Clone ใหม่ตำแหน่งเงินเดือน + // * + // */ + // @Get("{type}/new-clone/{profileId}") + // public async newCloneSalary( + // @Path() profileId: string, + // @Path() type: string, + // @Request() req: RequestWithUser, + // ) { + // if (type.toLocaleUpperCase() == "OFFICER") { + // const salary = await this.salaryRepo.find({ where: { profileId: profileId } }); + // await this.salaryRepo.remove(salary); + // let salaryOld = await this.salaryOldRepo.find({ + // where: { profileId: profileId }, + // }); + // salaryOld.forEach((item: any) => { + // item.salaryId = item.id; + // }); + // let salaryNew = salaryOld.map(({ id, ...rest }: ProfileSalary) => ({ + // ...rest, + // isDelete: false, + // isEdit: false, + // createdUserId: req.user.sub, + // createdFullName: req.user.name, + // lastUpdateUserId: req.user.sub, + // lastUpdateFullName: req.user.name, + // createdAt: new Date(), + // lastUpdatedAt: new Date(), + // })); + // await this.salaryRepo.save(salaryNew); + // return new HttpSuccess(salaryNew); + // } else { + // const salary = await this.salaryRepo.find({ where: { profileEmployeeId: profileId } }); + // await this.salaryRepo.remove(salary); + // let salaryOld = await this.salaryOldRepo.find({ + // where: { profileEmployeeId: profileId }, + // }); + // salaryOld.forEach((item: any) => { + // item.salaryId = item.id; + // }); + // let salaryNew = salaryOld.map(({ id, ...rest }: ProfileSalary) => ({ + // ...rest, + // isDelete: false, + // isEdit: false, + // createdUserId: req.user.sub, + // createdFullName: req.user.name, + // lastUpdateUserId: req.user.sub, + // lastUpdateFullName: req.user.name, + // createdAt: new Date(), + // lastUpdatedAt: new Date(), + // })); + // await this.salaryRepo.save(salaryNew); + // return new HttpSuccess(salaryNew); + // } + // } + + /** + * API List ตำแหน่งเงินเดือน + * + * @summary API List ตำแหน่งเงินเดือน + * + */ + @Get("{type}/{profileId}") + public async listSalary( + @Path() profileId: string, + @Path() type: string, + @Request() req: RequestWithUser, + ) { + if (type.toLocaleUpperCase() == "OFFICER") { + const salary = await this.salaryRepo.find({ where: { profileId: profileId } }); + if (salary.length <= 0) { + let salaryOld = await this.salaryOldRepo.find({ + where: { profileId: profileId }, + }); + salaryOld.forEach((item: any) => { + item.salaryId = item.id; + }); + let salaryNew = salaryOld.map(({ id, ...rest }: ProfileSalary) => ({ + ...rest, + isDelete: false, + isEdit: false, + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + })); + await this.salaryRepo.save(salaryNew); + return new HttpSuccess( + salaryNew.map((item) => ({ + ...item, + status: item.isDelete == true ? "DELETE" : item.isEdit == true ? "EDIT" : "PENDING", + })), + ); + } + return new HttpSuccess(salary); + } else { + const salary = await this.salaryRepo.find({ where: { profileEmployeeId: profileId } }); + if (salary.length <= 0) { + let salaryOld = await this.salaryOldRepo.find({ + where: { profileEmployeeId: profileId }, + }); + salaryOld.forEach((item: any) => { + item.salaryId = item.id; + }); + let salaryNew = salaryOld.map(({ id, ...rest }: ProfileSalary) => ({ + ...rest, + isDelete: false, + isEdit: false, + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + })); + await this.salaryRepo.save(salaryNew); + return new HttpSuccess( + salaryNew.map((item) => ({ + ...item, + status: item.isDelete == true ? "DELETE" : item.isEdit == true ? "EDIT" : "PENDING", + })), + ); + } + return new HttpSuccess( + salary.map((item) => ({ + ...item, + status: item.isDelete == true ? "DELETE" : item.isEdit == true ? "EDIT" : "PENDING", + })), + ); + } + } + + /** + * API List ตำแหน่งเงินเดือนแก้ไขแล้ว + * + * @summary API List ตำแหน่งเงินเดือนแก้ไขแล้ว + * + */ + @Get("{type}/done/{profileId}") + public async listDoneSalary( + @Path() profileId: string, + @Path() type: string, + @Request() req: RequestWithUser, + ) { + if (type.toLocaleUpperCase() == "OFFICER") { + const salary = await this.salaryRepo.find({ + where: { profileId: profileId, isDelete: false }, + }); + if (!salary) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + return new HttpSuccess( + salary.map((item) => ({ + ...item, + status: item.isDelete == true ? "DELETE" : item.isEdit == true ? "EDIT" : "PENDING", + })), + ); + } else { + const salary = await this.salaryRepo.find({ + where: { profileEmployeeId: profileId, isDelete: false }, + }); + if (!salary) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + return new HttpSuccess( + salary.map((item) => ({ + ...item, + status: item.isDelete == true ? "DELETE" : item.isEdit == true ? "EDIT" : "PENDING", + })), + ); + } + } + + /** + * API Get ตำแหน่งเงินเดือน + * + * @summary API Get ตำแหน่งเงินเดือน + * + */ + @Get("get/{salaryId}") + public async getSalary(@Path() salaryId: string, @Request() req: RequestWithUser) { + const salary = await this.salaryRepo.findOne({ + where: { id: salaryId }, + relations: ["profileSalary"], + }); + if (!salary) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + return new HttpSuccess({ salaryNew: salary, salaryOld: salary.profileSalary }); + } + + /** + * API สร้างตำแหน่งเงินเดือน + * + * @summary API สร้างตำแหน่งเงินเดือน + * + */ + @Post() + public async newSalary(@Request() req: RequestWithUser, @Body() body: CreateProfileSalaryTemp) { + let dest_item = 1; + + if (body.type.toLocaleUpperCase() == "OFFICER") { + if (body.profileId) { + const salary = await this.salaryRepo.findOne({ + where: { profileId: body.profileId }, + order: { order: "DESC" }, + }); + if (salary) { + dest_item = salary.order; + } + // const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + // if (!profile) { + // throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + // } + // profile.statusCheckEdit = "EDITED" + // await this.profileRepo.save(profile); + } else { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + } else { + if (body.profileEmployeeId) { + const salary = await this.salaryRepo.findOne({ + where: { profileEmployeeId: body.profileEmployeeId }, + order: { order: "DESC" }, + }); + if (salary) { + dest_item = salary.order; + } + // const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileId }); + // if (!profile) { + // throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + // } + // profile.statusCheckEdit = "EDITED" + // await this.profileRepo.save(profile); + } else { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + } + const before = null; + const data = new ProfileSalaryTemp(); + + const meta = { + order: dest_item, + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + isEdit: true, + }; + Object.assign(data, { ...body, ...meta }); + await this.salaryRepo.save(data, { data: req }); + setLogDataDiff(req, { before, after: data }); + + return new HttpSuccess(); + } + + /** + * API แก้สถานะเป็นยังไม่แก้ไข + * + * @summary API แก้สถานะเป็นยังไม่แก้ไข + * + */ + @Post("confirm-pending") + public async confirmPendingSalary( + @Request() req: RequestWithUser, + @Body() body: { profileId: string; type: string }, + ) { + if (body.type.toLocaleUpperCase() == "OFFICER") { + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + profile.statusCheckEdit = "PENDING"; + await this.profileRepo.save(profile); + } else { + const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileId }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + profile.statusCheckEdit = "PENDING"; + await this.profileEmployeeRepo.save(profile); + } + return new HttpSuccess(); + } + + /** + * API ยืนยันเสร็จสิ้นการแก้ไข + * + * @summary API ยืนยันเสร็จสิ้นการแก้ไข + * + */ + @Post("confirm-edit") + public async confirmEditSalary( + @Request() req: RequestWithUser, + @Body() body: { profileId: string; type: string }, + ) { + if (body.type.toLocaleUpperCase() == "OFFICER") { + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + profile.statusCheckEdit = "EDITED"; + await this.profileRepo.save(profile); + } else { + const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileId }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + profile.statusCheckEdit = "EDITED"; + await this.profileEmployeeRepo.save(profile); + } + return new HttpSuccess(); + } + + /** + * API ยืนยันข้อมูลถูกต้อง + * + * @summary API ยืนยันข้อมูลถูกต้อง + * + */ + @Post("confirm-done") + public async confirmDoneSalary( + @Request() req: RequestWithUser, + @Body() body: { profileId: string; type: string }, + ) { + if (body.type.toLocaleUpperCase() == "OFFICER") { + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + profile.statusCheckEdit = "CHECKED"; + await this.profileRepo.save(profile); + } else { + const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileId }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + profile.statusCheckEdit = "CHECKED"; + await this.profileEmployeeRepo.save(profile); + } + return new HttpSuccess(); + } + + /** + * API แก้ไขข้อมูล + * + * @summary API แก้ไขข้อมูล + * + */ + @Patch("{salaryId}") + public async editSalary( + @Request() req: RequestWithUser, + @Body() body: UpdateProfileSalaryTemp, + @Path() salaryId: string, + ) { + const record = await this.salaryRepo.findOneBy({ id: salaryId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + + Object.assign(record, body); + + record.isEdit = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = new Date(); + + await Promise.all([ + this.salaryRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + ]); + + return new HttpSuccess(); + } + + /** + * API ลบข้อมูล + * + * @summary API ลบข้อมูล + * + */ + @Post("delete") + public async deleteIsSalary( + @Request() req: RequestWithUser, + @Body() body: { salaryId: string; type: string }, + ) { + const data = await this.salaryRepo.findOneBy({ id: body.salaryId }); + if (data == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + data.isDelete = true; + await this.salaryRepo.save(data); + + return new HttpSuccess(); + } + + /** + * API ย้อนลบข้อมูล + * + * @summary API ย้อนลบข้อมูล + * + */ + @Post("delete-renew") + public async deleteReNewIsSalary( + @Request() req: RequestWithUser, + @Body() body: { salaryId: string; type: string }, + ) { + const data = await this.salaryRepo.findOneBy({ id: body.salaryId }); + if (data == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + data.isDelete = false; + await this.salaryRepo.save(data); + + return new HttpSuccess(); + } + + /** + * API สลับตำแหน่ง + * + * @summary API สลับตำแหน่ง + * + */ + @Get("swap/{direction}/{salaryId}") + public async swapSalary( + @Path() direction: string, + salaryId: string, + @Request() req: RequestWithUser, + ) { + const source_item = await this.salaryRepo.findOne({ where: { id: salaryId } }); + // if (source_item) { + //await new permission().PermissionOrgUserGet(req,"SYS_REGISTRY_OFFICER",source_item.profileId,); //ไม่แน่ใจOFFปิดไว้ก่อน + // } + if (source_item == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const sourceOrder = source_item.order; + if (direction.trim().toUpperCase() == "UP") { + const dest_item = await this.salaryRepo.findOne({ + where: { profileId: source_item.profileId, order: LessThan(sourceOrder) }, + order: { order: "DESC" }, + }); + if (dest_item == null) return new HttpSuccess(); + var destOrder = dest_item.order; + dest_item.order = sourceOrder; + dest_item.isEdit = true; + source_item.order = destOrder; + source_item.isEdit = true; + await Promise.all([this.salaryRepo.save(source_item), this.salaryRepo.save(dest_item)]); + } else { + const dest_item = await this.salaryRepo.findOne({ + where: { profileId: source_item.profileId, order: MoreThan(sourceOrder) }, + order: { order: "ASC" }, + }); + if (dest_item == null) return new HttpSuccess(); + var destOrder = dest_item.order; + dest_item.order = sourceOrder; + dest_item.isEdit = true; + source_item.order = destOrder; + source_item.isEdit = true; + await Promise.all([this.salaryRepo.save(source_item), this.salaryRepo.save(dest_item)]); + } + return new HttpSuccess(); + } +} diff --git a/src/entities/Command.ts b/src/entities/Command.ts index 614aad0d..029f4cdc 100644 --- a/src/entities/Command.ts +++ b/src/entities/Command.ts @@ -7,6 +7,7 @@ import { CommandRecive } from "./CommandRecive"; import { ProfileSalary } from "./ProfileSalary"; import { ProfileSalaryHistory } from "./ProfileSalaryHistory"; import { CommandSign } from "./CommandSign"; +import { ProfileSalaryTemp } from "./ProfileSalaryTemp"; @Entity("command") export class Command extends EntityBase { @@ -167,6 +168,9 @@ export class Command extends EntityBase { @OneToMany(() => ProfileSalary, (profileSalary) => profileSalary.command) profileSalarys: ProfileSalary[]; + @OneToMany(() => ProfileSalaryTemp, (profileSalaryTemp) => profileSalaryTemp.command) + profileSalaryTemps: ProfileSalaryTemp[]; + @OneToMany(() => ProfileSalaryHistory, (profileSalaryHistory) => profileSalaryHistory.command) profileSalaryHistorys: ProfileSalaryHistory[]; } diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 41f9375f..5f4f9454 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -47,6 +47,7 @@ import { CommandSign } from "./CommandSign"; import { RoleKeycloak } from "./RoleKeycloak"; import { ProfileActposition } from "./ProfileActposition"; import { ProfileAssistance } from "./ProfileAssistance"; +import { ProfileSalaryTemp } from "./ProfileSalaryTemp"; @Entity("profile") export class Profile extends EntityBase { @@ -411,6 +412,13 @@ export class Profile extends EntityBase { }) leaveType: string; + @Column({ + comment: "สถานะการตรวจสอบ", + length: 40, + default: "PENDING", + }) + statusCheckEdit: string; + @OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder) current_holders: PosMaster[]; @@ -420,6 +428,9 @@ export class Profile extends EntityBase { @OneToMany(() => ProfileSalary, (profileSalary) => profileSalary.profile) profileSalary: ProfileSalary[]; + @OneToMany(() => ProfileSalaryTemp, (profileSalaryTemp) => profileSalaryTemp.profile) + profileSalaryTemp: ProfileSalaryTemp[]; + @OneToMany(() => ProfileDiscipline, (profileDiscipline) => profileDiscipline.profile) profileDisciplines: ProfileDiscipline[]; diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 6bf72fd4..84dcc1c4 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -36,6 +36,7 @@ import { DevelopmentRequest } from "./DevelopmentRequest"; import { RoleKeycloak } from "./RoleKeycloak"; import { StateOperatorUser } from "./StateOperatorUser"; import { EmployeeTempPosMaster } from "./EmployeeTempPosMaster"; +import { ProfileSalaryTemp } from "./ProfileSalaryTemp"; @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { @@ -663,6 +664,13 @@ export class ProfileEmployee extends EntityBase { }) leaveType: string; + @Column({ + comment: "สถานะการตรวจสอบ", + length: 40, + default: "PENDING", + }) + statusCheckEdit: string; + @OneToMany(() => ProfileEmployeeInformationHistory, (v) => v.profileEmployeeInformation) information_histories: ProfileEmployeeInformationHistory[]; @@ -684,6 +692,9 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileSalary, (v) => v.profileEmployee) profileSalary: ProfileSalary[]; + @OneToMany(() => ProfileSalaryTemp, (v) => v.profileEmployee) + profileSalaryTemp: ProfileSalaryTemp[]; + @OneToMany(() => ProfileCertificate, (v) => v.profileEmployee) profileCertificates: ProfileCertificate[]; diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index b92db473..7c86759d 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -4,6 +4,7 @@ import { Profile } from "./Profile"; import { ProfileEmployee } from "./ProfileEmployee"; import { ProfileSalaryHistory } from "./ProfileSalaryHistory"; import { Command } from "./Command"; +import { ProfileSalaryTemp } from "./ProfileSalaryTemp"; @Entity("profileSalary") export class ProfileSalary extends EntityBase { @@ -262,6 +263,9 @@ export class ProfileSalary extends EntityBase { @OneToMany(() => ProfileSalaryHistory, (profileSalaryHistory) => profileSalaryHistory.histories) profileSalaryHistories: ProfileSalaryHistory[]; + @OneToMany(() => ProfileSalaryTemp, (profileSalaryTemp) => profileSalaryTemp.profileSalary) + profileSalaryTemps: ProfileSalaryTemp[]; + @ManyToOne(() => Profile, (profile) => profile.profileSalary) @JoinColumn({ name: "profileId" }) profile: Profile; diff --git a/src/entities/ProfileSalaryTemp.ts b/src/entities/ProfileSalaryTemp.ts new file mode 100644 index 00000000..96a3a93f --- /dev/null +++ b/src/entities/ProfileSalaryTemp.ts @@ -0,0 +1,359 @@ +import { Entity, Column, OneToMany, JoinColumn, ManyToOne, Double } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Profile } from "./Profile"; +import { ProfileEmployee } from "./ProfileEmployee"; +import { Command } from "./Command"; +import { ProfileSalary } from "./ProfileSalary"; + +@Entity("profileSalaryTemp") +export class ProfileSalaryTemp extends EntityBase { + @Column({ + nullable: true, + comment: "ข้อมูลที่ลบ", + default: null, + }) + isDelete: boolean; + + @Column({ + nullable: true, + comment: "ข้อมูลที่แก้ไข", + default: null, + }) + isEdit: boolean; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง profile", + type: "uuid", + default: null, + }) + profileId: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileEmployee", + default: null, + }) + profileEmployeeId: string; + + @Column({ + nullable: true, + comment: "เรียงลำดับใหมาตามการนำเข้า", + default: null, + }) + order: number; + + @Column({ + nullable: true, + comment: "เลขที่คำสั่ง", + default: null, + }) + commandNo: string; + + @Column({ + nullable: true, + comment: "ปีที่ออกคำสั่ง", + default: null, + }) + commandYear: number; + + @Column({ + comment: "คำสั่งวันที่", + type: "datetime", + nullable: true, + }) + commandDateSign: Date; + + @Column({ + comment: "คำสั่งมีผลวันที่", + type: "datetime", + nullable: true, + }) + commandDateAffect: Date; + + @Column({ + nullable: true, + comment: "รหัสประเภทของคำสั่ง", + default: null, + }) + commandCode: string; + + @Column({ + nullable: true, + comment: "ชื่อประเภทคำสั่ง", + default: null, + }) + commandName: string; + + @Column({ + nullable: true, + length: 40, + comment: "ตัวย่อเลขที่ตำแหน่ง", + default: null, + }) + posNoAbb: string; + + @Column({ + nullable: true, + length: 40, + comment: "เลขที่ตำแหน่ง", + default: null, + }) + posNo: string; + + @Column({ + nullable: true, + length: 255, + comment: "ตำแหน่ง", + default: null, + }) + positionName: string; + + @Column({ + nullable: true, + length: 255, + comment: "ประเภทตำแหน่ง", + default: null, + }) + positionType: string; + + @Column({ + nullable: true, + length: 255, + comment: "ระดับตำแหน่ง", + default: null, + }) + positionLevel: string; + + @Column({ + nullable: true, + comment: "ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง", + default: null, + }) + positionCee: string; + + @Column({ + nullable: true, + comment: "root name", + default: null, + }) + orgRoot: string; + + @Column({ + nullable: true, + comment: "child1 name", + default: null, + }) + orgChild1: string; + + @Column({ + nullable: true, + comment: "child2 name", + default: null, + }) + orgChild2: string; + + @Column({ + nullable: true, + comment: "child3 name", + default: null, + }) + orgChild3: string; + + @Column({ + nullable: true, + comment: "child4 name", + default: null, + }) + orgChild4: string; + + @Column({ + nullable: true, + length: 255, + comment: "ตำแหน่งทางการบริหาร", + default: null, + }) + positionExecutive: string; + + @Column({ + comment: "เงินเดือนฐาน", + default: 0, + nullable: true, + type: "double", + }) + amount: Double; + + @Column({ + comment: "เงินพิเศษ", + default: 0, + nullable: true, + type: "double", + }) + amountSpecial: Double; + + @Column({ + comment: "เงินประจำตำแหน่ง", + default: 0, + nullable: true, + type: "double", + }) + positionSalaryAmount: Double; + + @Column({ + comment: "เงินค่าตอบแทนรายเดือน", + default: 0, + nullable: true, + type: "double", + }) + mouthSalaryAmount: Double; + + @Column({ + nullable: true, + length: 255, + comment: "หมายเหตุ", + default: null, + }) + remark: string; + + @Column({ + nullable: true, + comment: "refId", + default: null, + }) + refId: number; + + @Column({ + comment: "วันที่", + type: "datetime", + nullable: true, + }) + dateGovernment: Date; + + @Column({ + nullable: true, + comment: "เข้ารับราชการ", + default: null, + }) + isGovernment: boolean; + + @Column({ + nullable: true, + comment: "ข้อมูลจาก Entry", + default: null, + }) + isEntry: boolean; + + @Column({ + nullable: true, + length: 255, + comment: "ด้านของตำแหน่ง", + default: null, + }) + positionPathSide: string; + + @Column({ + nullable: true, + length: 255, + comment: "ตำแหน่งในสายงาน", + default: null, + }) + positionLine: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง command", + default: null, + }) + commandId: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง profileSalary", + default: null, + }) + salaryId: string; + + @ManyToOne(() => ProfileSalary, (profileSalary) => profileSalary.profileSalaryTemps) + @JoinColumn({ name: "salaryId" }) + profileSalary: ProfileSalary; + + @ManyToOne(() => Command, (command) => command.profileSalaryTemps) + @JoinColumn({ name: "commandId" }) + command: Command; + + @ManyToOne(() => Profile, (profile) => profile.profileSalaryTemp) + @JoinColumn({ name: "profileId" }) + profile: Profile; + + @ManyToOne(() => ProfileEmployee, (profileEmployee) => profileEmployee.profileSalaryTemp) + @JoinColumn({ name: "profileEmployeeId" }) + profileEmployee: ProfileEmployee; +} + +export class CreateProfileSalaryTemp { + type: string; + profileId?: string | null; + profileEmployeeId?: string | null; + commandCode?: string | null; + commandNo?: string | null; + commandYear?: number | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + posNoAbb: string | null; + posNo: string | null; + positionName: string | null; + positionType: string | null; + positionLevel: string | null; + positionLine?: string | null; + positionPathSide?: string | null; + positionExecutive: string | null; + amount?: Double | null; + amountSpecial?: Double | null; + positionSalaryAmount?: Double | null; + mouthSalaryAmount?: Double | null; + orgRoot?: string | null; + orgChild1?: string | null; + orgChild2?: string | null; + orgChild3?: string | null; + orgChild4?: string | null; + remark: string | null; + commandId?: string | null; + isGovernment?: boolean | null; + positionCee?: string | null; + commandName?: string | null; +} + +export type UpdateProfileSalaryTemp = { + type: string; + commandCode?: string | null; + commandNo?: string | null; + commandYear?: number | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + posNoAbb: string | null; + posNo: string | null; + positionName: string | null; + positionType: string | null; + positionLevel: string | null; + positionLine?: string | null; + positionPathSide?: string | null; + positionExecutive: string | null; + amount?: Double | null; + amountSpecial?: Double | null; + positionSalaryAmount?: Double | null; + mouthSalaryAmount?: Double | null; + orgRoot?: string | null; + orgChild1?: string | null; + orgChild2?: string | null; + orgChild3?: string | null; + orgChild4?: string | null; + remark: string | null; + commandId?: string | null; + isGovernment?: boolean | null; + positionCee?: string | null; + commandName?: string | null; +};