diff --git a/src/app.ts b/src/app.ts index bb627c36..221a0304 100644 --- a/src/app.ts +++ b/src/app.ts @@ -78,6 +78,7 @@ async function main() { const profileSalaryController = new ProfileSalaryController(); await profileSalaryController.cronjobTenurePositionOfficer(); await profileSalaryController.cronjobTenureLevelOfficer(); + await profileSalaryController.cronjobTenureExecutivePositionOfficer(); await profileSalaryController.cronjobTenurePositionEmployee(); await profileSalaryController.cronjobTenureLevelEmployee(); } catch (error) { diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index bde73c1e..f4e99a28 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2213,7 +2213,6 @@ export class CommandController extends Controller { commandRecive.remarkVertical = item.remarkVertical == null ? _null : item.remarkVertical; commandRecive.remarkHorizontal = item.remarkHorizontal == null ? _null : item.remarkHorizontal; - commandRecive.order = order; commandRecive.commandId = command.id; commandRecive.createdUserId = request.user.sub; commandRecive.createdFullName = request.user.name; @@ -2659,7 +2658,7 @@ export class CommandController extends Controller { ); } } - if (["C-PM-10"].includes(commandCode)) { + if (["C-PM-10", "C-PM-40"].includes(commandCode)) { await Promise.all( requestBody.persons.map(async (item: any) => { const _posMasterDirector = await this.posMasterRepository.findOne({ @@ -6358,8 +6357,8 @@ export class CommandController extends Controller { ? Extension.ToThaiShortDate(item.CommandExcecuteDate) : "-", dateEnd: "-", - RemarkVertical: item.RemarkVertical, - RemarkHorizontal: item.RemarkHorizontal, + RemarkVertical: item.RemarkVertical ? Extension.ToThaiNumber(item.RemarkVertical) : "-", + RemarkHorizontal: item.RemarkHorizontal ? Extension.ToThaiNumber(item.RemarkHorizontal) : "-", order: posMasterAct.posMasterOrder == null ? "-" diff --git a/src/controllers/PosMasterActController.ts b/src/controllers/PosMasterActController.ts index 579c0aa2..48a0b586 100644 --- a/src/controllers/PosMasterActController.ts +++ b/src/controllers/PosMasterActController.ts @@ -408,13 +408,13 @@ export class PosMasterActController extends Controller { let conditionGroup = ""; if (body.type.trim().toUpperCase() == "GROUP1.1") { conditionGroup = - "(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ชำนาญงาน') OR (posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ปฏิบัติงาน') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ปฏิบัติการ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการ')"; + "(posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'ชำนาญงาน') OR (posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'ปฏิบัติงาน') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ปฏิบัติการ') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ชำนาญการ')"; } else if (body.type.trim().toUpperCase() == "GROUP1.2") { conditionGroup = - "(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'อาวุโส') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการพิเศษ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'ต้น')"; + "(posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'อาวุโส') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ชำนาญการพิเศษ') OR (posTypeAct.posTypeName = 'อำนวยการ' AND posLevelAct.posLevelName = 'ต้น')"; } else if (body.type.trim().toUpperCase() == "GROUP2") { conditionGroup = - "(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ทักษะพิเศษ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'เชี่ยวชาญ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ทรงคุณวุฒิ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'สูง') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'ต้น') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'สูง')"; + "(posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'ทักษะพิเศษ') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'เชี่ยวชาญ') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ทรงคุณวุฒิ') OR (posTypeAct.posTypeName = 'อำนวยการ' AND posLevelAct.posLevelName = 'สูง') OR (posTypeAct.posTypeName = 'บริหาร' AND posLevelAct.posLevelName = 'ต้น') OR (posTypeAct.posTypeName = 'บริหาร' AND posLevelAct.posLevelName = 'สูง')"; } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง"); } @@ -431,6 +431,10 @@ export class PosMasterActController extends Controller { .leftJoinAndSelect("posMasterChild.positions", "positions") .leftJoinAndSelect("positions.posType", "posType") .leftJoinAndSelect("positions.posLevel", "posLevel") + .leftJoinAndSelect("posMasterAct.posMaster", "posMaster") + .leftJoinAndSelect("posMaster.positions", "positionActs") + .leftJoinAndSelect("positionActs.posType", "posTypeAct") + .leftJoinAndSelect("positionActs.posLevel", "posLevelAct") .leftJoinAndSelect("posMasterChild.orgRevision", "orgRevision") .andWhere("posMasterChild.orgRootId LIKE :orgRootId", { orgRootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, @@ -444,12 +448,13 @@ export class PosMasterActController extends Controller { orgRevisionIsDraft: false, }) .andWhere("positions.positionIsSelected = :isSelected", { isSelected: true }) + .andWhere("positionActs.positionIsSelected = :isSelected", { isSelected: true }) .andWhere( new Brackets((qb) => { qb.andWhere(conditionGroup); }), ) - .orderBy("posMasterChild.posMasterOrder", "ASC") + .orderBy("posMasterAct.posMasterOrder", "ASC") .select([ "posMasterAct.id", "posMasterChild.posMasterNo", diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 79936bb1..44397d5c 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -27,8 +27,11 @@ import { TenurePositionOfficer } from "../entities/TenurePositionOfficer"; import { TenureLevelOfficer } from "../entities/TenureLevelOfficer"; import { TenurePositionEmployee } from "../entities/TenurePositionEmployee"; import { TenureLevelEmployee } from "../entities/TenureLevelEmployee"; +import { TenurePositionExecutiveOfficer } from "../entities/TenurePositionExecutiveOfficer"; import { Command } from "../entities/Command"; import { OrgRoot } from "../entities/OrgRoot"; +import { OrgRevision } from "../entities/OrgRevision"; +import { Position } from "../entities/Position"; @Route("api/v1/org/profile/salary") @Tags("ProfileSalary") @Security("bearerAuth") @@ -41,8 +44,11 @@ export class ProfileSalaryController extends Controller { private positionEmployeeRepo = AppDataSource.getRepository(TenurePositionEmployee); private levelOfficerRepo = AppDataSource.getRepository(TenureLevelOfficer); private levelEmployeeRepo = AppDataSource.getRepository(TenureLevelEmployee); + private positionExecutiveOfficerRepo = AppDataSource.getRepository(TenurePositionExecutiveOfficer); private commandRepository = AppDataSource.getRepository(Command); private orgRootRepository = AppDataSource.getRepository(OrgRoot); + private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private positionRepo = AppDataSource.getRepository(Position); @Get("TenurePositionOfficer") public async cronjobTenurePositionOfficer() { @@ -229,6 +235,64 @@ export class ProfileSalaryController extends Controller { return new HttpSuccess(); } + @Get("TenurePositionExecutiveOfficer") + public async cronjobTenureExecutivePositionOfficer() { + await this.positionExecutiveOfficerRepo.clear(); + const profile = await this.profileRepo.find(); + const orgRevision = await this.orgRevisionRepository.findOne({ + select: ["id"], + where: { + orgRevisionIsDraft: false, + orgRevisionIsCurrent: true, + }, + }); + for await (const x of profile) { + const position = await this.positionRepo.findOne({ + where: { + positionIsSelected: true, + posMaster: { + orgRevisionId: orgRevision?.id, + current_holderId: x.id, + }, + }, + order: { createdAt: "DESC" }, + relations: { + posExecutive: true, + }, + }); + const positionExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?)", [x.id]); + const _position = positionExecutive.length > 0 ? positionExecutive[0] : []; + const mapPosition = + _position.length > 1 + ? _position.slice(1).map((curr: any, index: number) => ({ + days_diff: curr.days_diff, + positionExecutive: _position[index]?.positionExecutive, + })) + : []; + const _posExecutiveName = position?.posExecutive?.posExecutiveName; + const calDayDiff = mapPosition + .filter((curr: any) => _posExecutiveName && curr.positionExecutive == _posExecutiveName) + .reduce( + (acc: any, curr: any) => { + acc.days_diff += Number(curr.days_diff) || 0; + acc.positionExecutive = curr.positionExecutive; + return acc; + }, + { days_diff: 0, positionExecutive: null }, + ); + const mapData: any = { + profileId: x.id, + positionExecutiveName: calDayDiff.positionExecutive, + days_diff: calDayDiff.days_diff, + Years: (calDayDiff.days_diff / 365.2524).toFixed(4), + Months: ((calDayDiff.days_diff / 30.4375) % 12).toFixed(4), + Days: (calDayDiff.days_diff % 30.4375).toFixed(4), + }; + await this.positionExecutiveOfficerRepo.save(mapData); + } + return new HttpSuccess(); + } + @Get("user") public async getSalaryUser(@Request() request: { user: Record }) { const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 4350aa38..63939de8 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -151,7 +151,7 @@ export class ReportController extends Controller { } else if (tenureType != "" && tenureType == "level") { tenureTypeCondition = "registryOfficer.levelYears BETWEEN :tenureMin AND :tenureMax"; } else if (tenureType != "" && tenureType == "posExecutive") { - tenureTypeCondition = "registryOfficer.levelYears BETWEEN :tenureMin AND :tenureMax"; + tenureTypeCondition = "registryOfficer.posExecutiveYears BETWEEN :tenureMin AND :tenureMax"; } const [lists, total] = await AppDataSource.getRepository(viewRegistryOfficer) diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index 921c4184..ea55ecf2 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -21,6 +21,7 @@ import { PosMasterAct } from "../entities/PosMasterAct"; import { viewDirectorActing } from "../entities/view/viewDirectorActing"; import { viewDirector } from "../entities/view/viewDirector"; import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; @Route("api/v1/org/workflow") @Tags("Workflow") @@ -38,6 +39,7 @@ export class WorkflowController extends Controller { private metaStateRepo = AppDataSource.getRepository(MetaState); private metaStateOperatorRepo = AppDataSource.getRepository(MetaStateOperator); private posMasterRepo = AppDataSource.getRepository(PosMaster); + private posMasterEmpRepo = AppDataSource.getRepository(EmployeePosMaster); private posMasterActRepo = AppDataSource.getRepository(PosMasterAct); private assignRepo = AppDataSource.getRepository(Assign); @@ -806,29 +808,51 @@ export class WorkflowController extends Controller { page: number; pageSize: number; keycloakId?: string | null; + type?: string | null; }, ) { - let posMasterUser: PosMaster = new PosMaster(); + let posMasterUser = null; if (body.keycloakId) { - posMasterUser = (await this.posMasterRepo.findOne({ - where: { - orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, - current_holder: { keycloak: body.keycloakId }, - }, - relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], - })) as PosMaster; + if (body.type == "employee") { + posMasterUser = await this.posMasterEmpRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holder: { keycloak: body.keycloakId }, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + }); + } else { + posMasterUser = await this.posMasterRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holder: { keycloak: body.keycloakId }, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + }); + } } else { - posMasterUser = (await this.posMasterRepo.findOne({ - where: { - orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, - current_holder: { keycloak: request.user.sub }, - }, - relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], - })) as PosMaster; + if (body.type == "employee") { + posMasterUser = await this.posMasterEmpRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holder: { keycloak: request.user.sub }, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + }); + } else { + posMasterUser = await this.posMasterRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holder: { keycloak: request.user.sub }, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + }); + } } - if (!posMasterUser || !posMasterUser.orgRootId) + if (!posMasterUser || !posMasterUser.orgRootId) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน"); + } let condition: any = []; @@ -839,7 +863,7 @@ export class WorkflowController extends Controller { orgChild1Id: IsNull(), }; - if (type.trim().toUpperCase() == "OPERATE") { + if (type.trim().toUpperCase() == "OPERATE" || body.type == "employee") { condition.push({ isDirector: true, orgRootId: posMasterUser.orgRootId, diff --git a/src/entities/ProfileCertificate.ts b/src/entities/ProfileCertificate.ts index 7502b2c6..730bde73 100644 --- a/src/entities/ProfileCertificate.ts +++ b/src/entities/ProfileCertificate.ts @@ -69,7 +69,6 @@ export class ProfileCertificate extends EntityBase { isUpload: boolean; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileChangeName.ts b/src/entities/ProfileChangeName.ts index ae9c46b6..d07f995b 100644 --- a/src/entities/ProfileChangeName.ts +++ b/src/entities/ProfileChangeName.ts @@ -71,7 +71,6 @@ export class ProfileChangeName extends EntityBase { profileEmployeeId: string; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileChildren.ts b/src/entities/ProfileChildren.ts index 001a2f1c..23f3b507 100644 --- a/src/entities/ProfileChildren.ts +++ b/src/entities/ProfileChildren.ts @@ -67,7 +67,6 @@ export class ProfileChildren extends EntityBase { profileEmployeeId: string; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileDiscipline.ts b/src/entities/ProfileDiscipline.ts index 7a4cf951..6220b712 100644 --- a/src/entities/ProfileDiscipline.ts +++ b/src/entities/ProfileDiscipline.ts @@ -77,7 +77,6 @@ export class ProfileDiscipline extends EntityBase { isUpload: boolean; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileDuty.ts b/src/entities/ProfileDuty.ts index 0f53424b..5684f650 100644 --- a/src/entities/ProfileDuty.ts +++ b/src/entities/ProfileDuty.ts @@ -77,7 +77,6 @@ export class ProfileDuty extends EntityBase { isUpload: boolean; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileEducation.ts b/src/entities/ProfileEducation.ts index fcae539e..351aeec0 100644 --- a/src/entities/ProfileEducation.ts +++ b/src/entities/ProfileEducation.ts @@ -191,7 +191,6 @@ export class ProfileEducation extends EntityBase { level: number; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileHonor.ts b/src/entities/ProfileHonor.ts index 79c5f10d..88f390cb 100644 --- a/src/entities/ProfileHonor.ts +++ b/src/entities/ProfileHonor.ts @@ -84,7 +84,6 @@ export class ProfileHonor extends EntityBase { isUpload: boolean; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileInsignia.ts b/src/entities/ProfileInsignia.ts index 0f4bc046..b7fa824d 100644 --- a/src/entities/ProfileInsignia.ts +++ b/src/entities/ProfileInsignia.ts @@ -132,7 +132,6 @@ export class ProfileInsignia extends EntityBase { insigniaId: string; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileLeave.ts b/src/entities/ProfileLeave.ts index c40363cf..2728b32b 100644 --- a/src/entities/ProfileLeave.ts +++ b/src/entities/ProfileLeave.ts @@ -95,7 +95,6 @@ export class ProfileLeave extends EntityBase { leaveId: string; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileNopaid.ts b/src/entities/ProfileNopaid.ts index 973657af..1f90025f 100644 --- a/src/entities/ProfileNopaid.ts +++ b/src/entities/ProfileNopaid.ts @@ -69,7 +69,6 @@ export class ProfileNopaid extends EntityBase { isUpload: boolean; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileOther.ts b/src/entities/ProfileOther.ts index 78891853..b64171ed 100644 --- a/src/entities/ProfileOther.ts +++ b/src/entities/ProfileOther.ts @@ -39,7 +39,6 @@ export class ProfileOther extends EntityBase { date: Date; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", default: false, }) diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index d94c5664..92cb8d0d 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -226,9 +226,8 @@ export class ProfileSalary extends EntityBase { isGovernment: boolean; @Column({ - nullable: false, comment: "ข้อมูลจาก Entry", - default: null, + default: false, }) isEntry: boolean; diff --git a/src/entities/ProfileSalaryTemp.ts b/src/entities/ProfileSalaryTemp.ts index 78733865..6202fb93 100644 --- a/src/entities/ProfileSalaryTemp.ts +++ b/src/entities/ProfileSalaryTemp.ts @@ -239,9 +239,8 @@ export class ProfileSalaryTemp extends EntityBase { isGovernment: boolean; @Column({ - nullable: true, comment: "ข้อมูลจาก Entry", - default: null, + default: false, }) isEntry: boolean; diff --git a/src/entities/view/viewRegistryOfficer.ts b/src/entities/view/viewRegistryOfficer.ts index 668d0bcb..1ddbd88a 100644 --- a/src/entities/view/viewRegistryOfficer.ts +++ b/src/entities/view/viewRegistryOfficer.ts @@ -116,6 +116,14 @@ import { ViewColumn, ViewEntity } from "typeorm"; vctlo.Days, vctlo.profileId FROM tenureLevelOfficer vctlo + ), + PositionExecutiveDate AS ( + SELECT + vcteo.Years, + vcteo.Months, + vcteo.Days, + vcteo.profileId + FROM tenurePositionExecutiveOfficer vcteo ) SELECT p.id as profileId, @@ -168,7 +176,10 @@ import { ViewColumn, ViewEntity } from "typeorm"; vcto.Days, vctlo.Years AS levelYears, vctlo.Months AS levelMonths, - vctlo.Days AS levelDays + vctlo.Days AS levelDays, + vcteo.Years AS posExecutiveYears, + vcteo.Months AS posExecutiveMonths, + vcteo.Days AS posExecutiveDays FROM profile p LEFT JOIN posLevel ON p.posLevelId = posLevel.id LEFT JOIN posType ON p.posTypeId = posType.id @@ -179,6 +190,7 @@ import { ViewColumn, ViewEntity } from "typeorm"; LEFT JOIN Fields fies ON p.id = fies.profileId LEFT JOIN PositionDate vcto ON p.id = vcto.profileId LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId + LEFT JOIN PositionExecutiveDate vcteo ON p.id = vcteo.profileId `, }) export class viewRegistryOfficer {