diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 6a6988b9..e084d6ed 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -30,7 +30,7 @@ import { UpdateProfileFather, UpdateProfileMother, UpdateProfileCouple, - UpdatePrivacyDto + UpdatePrivacyDto, } from "../entities/Profile"; import { Brackets, In, IsNull, Like, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; @@ -280,7 +280,7 @@ export class ProfileController extends Controller { // ], where: { profileId: id, - commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), + commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), }, order: { order: "ASC" }, }); @@ -1428,7 +1428,7 @@ export class ProfileController extends Controller { const position_raw = await this.salaryRepo.find({ where: { profileId: id, - commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), + commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), isEntry: false, }, order: { order: "ASC" }, @@ -5186,7 +5186,7 @@ export class ProfileController extends Controller { @Put("privacy") async updatePrivacy( @Request() request: { user: Record }, - @Body() body: UpdatePrivacyDto + @Body() body: UpdatePrivacyDto, ) { let isEmployee = false; let profile: any = null; @@ -5220,15 +5220,12 @@ export class ProfileController extends Controller { break; default: - throw new HttpError( - HttpStatus.BAD_REQUEST, - "system ไม่ถูกต้อง" - ); + throw new HttpError(HttpStatus.BAD_REQUEST, "system ไม่ถูกต้อง"); } profile.lastUpdateUserId = request.user.sub; profile.lastUpdateFullName = request.user.name; profile.lastUpdatedAt = new Date(); - + if (isEmployee) { await this.profileEmpRepo.save(profile, { data: request }); } else { @@ -7418,7 +7415,7 @@ export class ProfileController extends Controller { posNo: null, privacyCheckin: profile.privacyCheckin, privacyUser: profile.privacyUser, - privacyMgt : profile.privacyMgt, + privacyMgt: profile.privacyMgt, isDeputy: root?.isDeputy ?? false, // root?.orgRootShortName && posMaster?.posMasterNo // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` @@ -7591,7 +7588,7 @@ export class ProfileController extends Controller { posNo: null, privacyCheckin: profile.privacyCheckin, privacyUser: profile.privacyUser, - privacyMgt : profile.privacyMgt, + privacyMgt: profile.privacyMgt, isDeputy: root?.isDeputy ?? false, // root?.orgRootShortName && posMaster?.posMasterNo // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` @@ -10940,12 +10937,12 @@ export class ProfileController extends Controller { .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); - + const mapDataProfile = await Promise.all( findProfile.map(async (item: Profile) => { const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; let shortName = null; - let root = null; + let root = null; let posMasterNo = null; if (item.isLeave == false) { shortName = @@ -10956,14 +10953,15 @@ export class ProfileController extends Controller { null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` @@ -10983,21 +10981,36 @@ export class ProfileController extends Controller { posMasterNo = item.current_holders?.find( (x) => x.orgRevisionId == findRevision.id, )?.posMasterNo; - } - else { + } else { const profileSalary = await this.salaryRepo .createQueryBuilder("s") .where("s.profileId = :profileId", { profileId: item.id }) .andWhere("s.commandCode IN (:...codes)", { - codes: ["0","9","1","2","3","4","8","10","11","12","13","14","15","16"], + codes: [ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "20", + ], }) .orderBy("s.order", "DESC") .addOrderBy("s.createdAt", "DESC") .take(2) .getMany(); if (profileSalary.length > 0) { - shortName = item.isRetirement - ? profileSalary.length > 1 + shortName = item.isRetirement + ? profileSalary.length > 1 ? `${profileSalary[1]?.posNoAbb} ${profileSalary[1]?.posNo}` : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}` : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}`; @@ -11006,7 +11019,7 @@ export class ProfileController extends Controller { ? profileSalary[1]?.posNo : profileSalary[0]?.posNo : profileSalary[0]?.posNo; - root = item.isRetirement + root = item.isRetirement ? profileSalary.length > 1 ? profileSalary[1]?.orgRoot : profileSalary[0]?.orgRoot diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 8ef90cc0..b37e115f 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -275,7 +275,7 @@ export class ProfileEmployeeController extends Controller { // ], where: { profileEmployeeId: id, - commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), + commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), }, order: { order: "ASC" }, }); @@ -1423,7 +1423,7 @@ export class ProfileEmployeeController extends Controller { const position_raw = await this.salaryRepo.find({ where: { profileEmployeeId: id, - commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), + commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), isEntry: false, }, order: { order: "ASC" }, @@ -5735,61 +5735,61 @@ export class ProfileEmployeeController extends Controller { if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - + let queryLike = "1=1"; - switch (body.fieldName) { - case "citizenId": - queryLike = "profile.citizenId LIKE :keyword"; - break; - - case "fullname": - case "fullName": - queryLike = - "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; - break; - - case "firstname": - case "firstName": - queryLike = "profile.firstName LIKE :keyword"; - break; - - case "lastname": - case "lastName": - queryLike = "profile.lastName LIKE :keyword"; - break; - - default: - queryLike = "1=1"; - break; - } - - let query = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .leftJoinAndSelect("profile.current_holders", "current_holders") - .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("profile.keycloak IS NULL") - .andWhere( - new Brackets((qb) => { - qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); - }), - ); - - const [findProfile, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + switch (body.fieldName) { + case "citizenId": + queryLike = "profile.citizenId LIKE :keyword"; + break; + + case "fullname": + case "fullName": + queryLike = + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; + break; + + case "firstname": + case "firstName": + queryLike = "profile.firstName LIKE :keyword"; + break; + + case "lastname": + case "lastName": + queryLike = "profile.lastName LIKE :keyword"; + break; + + default: + queryLike = "1=1"; + break; + } + + let query = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .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("profile.keycloak IS NULL") + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); + }), + ); + + const [findProfile, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const mapDataProfile = await Promise.all( findProfile.map(async (item: ProfileEmployee) => { const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; let shortName = null; - let root = null; + let root = null; let posMasterNo = null; if (item.isLeave == false) { shortName = @@ -5800,14 +5800,15 @@ export class ProfileEmployeeController extends Controller { null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` @@ -5828,21 +5829,36 @@ export class ProfileEmployeeController extends Controller { posMasterNo = item.current_holders?.find( (x) => x.orgRevisionId == findRevision.id, )?.posMasterNo; - } - else { - const profileSalary = await this.salaryRepo + } else { + const profileSalary = await this.salaryRepo .createQueryBuilder("s") .where("s.profileEmployeeId = :profileId", { profileId: item.id }) .andWhere("s.commandCode IN (:...codes)", { - codes: ["0","9","1","2","3","4","8","10","11","12","13","14","15","16"], + codes: [ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "20", + ], }) .orderBy("s.order", "DESC") .addOrderBy("s.createdAt", "DESC") .take(2) .getMany(); if (profileSalary.length > 0) { - shortName = item.isRetirement - ? profileSalary.length > 1 + shortName = item.isRetirement + ? profileSalary.length > 1 ? `${profileSalary[1]?.posNoAbb} ${profileSalary[1]?.posNo}` : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}` : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}`; @@ -5851,14 +5867,13 @@ export class ProfileEmployeeController extends Controller { ? profileSalary[1]?.posNo : profileSalary[0]?.posNo : profileSalary[0]?.posNo; - root = item.isRetirement + root = item.isRetirement ? profileSalary.length > 1 ? profileSalary[1]?.orgRoot : profileSalary[0]?.orgRoot : profileSalary[0]?.orgRoot; } } - const latestProfileEducation = await this.profileEducationRepo.findOne({ where: { profileEmployeeId: item.id }, diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 0bbeff46..ce66c221 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -248,7 +248,7 @@ export class ProfileEmployeeTempController extends Controller { // ], where: { profileEmployeeId: id, - commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), + commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), }, order: { order: "ASC" }, }); diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 3ecdabc9..f2208036 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -187,6 +187,7 @@ export class ProfileGovernmentHistoryController extends Controller { "14", "15", "16", + "20", ]), }, }, @@ -359,6 +360,7 @@ export class ProfileGovernmentHistoryController extends Controller { "14", "15", "16", + "20", ]), }, }, diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index ecc796dc..c44b3583 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -229,6 +229,7 @@ export class ProfileGovernmentEmployeeController extends Controller { "14", "15", "16", + "20", ]), }, order: { @@ -387,6 +388,7 @@ export class ProfileGovernmentEmployeeController extends Controller { "14", "15", "16", + "20", ]), }, order: { diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 93c792f5..47e267f4 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -276,34 +276,35 @@ export class ProfileInsigniaController extends Controller { } const profileSalarys = await this.profileSalaryRepo.find({ where: [ - { - profileId: body.profileId, - commandCode: In([ - "0", - "9", - "1", - "2", - "3", - "4", - "8", - "10", - "11", - "12", - "13", - "14", - "15", - "16", - ]), - }, - { profileId: body.profileId, commandCode: IsNull() }, - ], + { + profileId: body.profileId, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "20", + ]), + }, + { profileId: body.profileId, commandCode: IsNull() }, + ], order: { order: "ASC" }, }); if (!profileSalarys) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูลตำแหน่งและเงินเดือน"); } const birth = new Date(profile.birthDate); - const mapData = profileSalarys.map(x => { + const mapData = profileSalarys.map((x) => { // คำนวณอายุ let age = null; if (x.commandDateAffect && profile.birthDate) { @@ -317,16 +318,16 @@ export class ProfileInsigniaController extends Controller { } } return { - dateAffect: x.commandDateAffect, - position: x.positionName, - root: x.orgRoot, - child1: x.orgChild1, - child2: x.orgChild2, - child3: x.orgChild3, - child4: x.orgChild4, - age: age, - amount: x.amount, - remark: x.remark + dateAffect: x.commandDateAffect, + position: x.positionName, + root: x.orgRoot, + child1: x.orgChild1, + child2: x.orgChild2, + child3: x.orgChild3, + child4: x.orgChild4, + age: age, + amount: x.amount, + remark: x.remark, }; }); return new HttpSuccess(mapData); diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 6809f326..78975593 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -49,7 +49,9 @@ 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 positionExecutiveOfficerRepo = AppDataSource.getRepository( + TenurePositionExecutiveOfficer, + ); private commandRepository = AppDataSource.getRepository(Command); private orgRootRepository = AppDataSource.getRepository(OrgRoot); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); @@ -66,11 +68,12 @@ export class ProfileSalaryController extends Controller { let _currentDate = CURRENT_DATE[0].today; for await (const x of profile) { if (x.isLeave) { - _currentDate = x.leaveDate - ? Extension.toDateOnlyString(x.leaveDate) - : _currentDate + _currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate; } - const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [x.id, _currentDate]); + const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [ + x.id, + _currentDate, + ]); const _position = position.length > 0 ? position[0] : []; const mapPosition = _position.length > 1 @@ -96,7 +99,7 @@ export class ProfileSalaryController extends Controller { // 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), - Years: Math.floor(calDayDiff.days_diff / 365.2524), + Years: Math.floor(calDayDiff.days_diff / 365.2524), Months: Math.floor((calDayDiff.days_diff / 30.4375) % 12), Days: Math.floor(calDayDiff.days_diff % 30.4375), }; @@ -116,13 +119,11 @@ export class ProfileSalaryController extends Controller { const profile = await this.profileEmployeeRepo.find(); for await (const x of profile) { if (x?.isLeave) { - _currentDate = x.leaveDate - ? Extension.toDateOnlyString(x.leaveDate) - : _currentDate + _currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate; } const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [ x.id, - _currentDate + _currentDate, ]); const _position = position.length > 0 ? position[0] : []; const mapPosition = @@ -149,7 +150,7 @@ export class ProfileSalaryController extends Controller { // 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), - Years: Math.floor(calDayDiff.days_diff / 365.2524), + Years: Math.floor(calDayDiff.days_diff / 365.2524), Months: Math.floor((calDayDiff.days_diff / 30.4375) % 12), Days: Math.floor(calDayDiff.days_diff % 30.4375), }; @@ -169,11 +170,12 @@ export class ProfileSalaryController extends Controller { let _currentDate = CURRENT_DATE[0].today; for await (const x of profile) { if (x?.isLeave) { - _currentDate = x.leaveDate - ? Extension.toDateOnlyString(x.leaveDate) - : _currentDate + _currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate; } - const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [x.id, _currentDate]); + const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [ + x.id, + _currentDate, + ]); const _positionLevel = positionLevel.length > 0 ? positionLevel[0] : []; const mapPositionLevel = _positionLevel.length > 1 @@ -226,13 +228,11 @@ export class ProfileSalaryController extends Controller { let _currentDate = CURRENT_DATE[0].today; for await (const x of profile) { if (x?.isLeave) { - _currentDate = x.leaveDate - ? Extension.toDateOnlyString(x.leaveDate) - : _currentDate + _currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate; } const positionLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?, ?)", [ x.id, - _currentDate + _currentDate, ]); const _positionLevel = positionLevel.length > 0 ? positionLevel[0] : []; const mapPositionLevel = @@ -293,9 +293,7 @@ export class ProfileSalaryController extends Controller { let _currentDate = CURRENT_DATE[0].today; for await (const x of profile) { if (x?.isLeave) { - _currentDate = x.leaveDate - ? Extension.toDateOnlyString(x.leaveDate) - : _currentDate + _currentDate = x.leaveDate ? Extension.toDateOnlyString(x.leaveDate) : _currentDate; } const position = await this.positionRepo.findOne({ where: { @@ -310,7 +308,10 @@ export class ProfileSalaryController extends Controller { posExecutive: true, }, }); - const positionExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [x.id, _currentDate]); + const positionExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [ + x.id, + _currentDate, + ]); const _position = positionExecutive.length > 0 ? positionExecutive[0] : []; const mapPosition = _position.length > 1 @@ -349,14 +350,14 @@ export class ProfileSalaryController extends Controller { const allRegis = await AppDataSource.getRepository(viewRegistryOfficer) .createQueryBuilder("registryOfficer") .getMany(); - const profileIds = new Set((await this.profileRepo.find()).map(p => p.id)); + const profileIds = new Set((await this.profileRepo.find()).map((p) => p.id)); const mapData = allRegis - .filter(x => profileIds.has(x.profileId)) - .map(x => ({ + .filter((x) => profileIds.has(x.profileId)) + .map((x) => ({ ...x, - isProbation: Boolean(x.isProbation), - isLeave: Boolean(x.isLeave), - isRetirement: Boolean(x.isRetirement), + isProbation: Boolean(x.isProbation), + isLeave: Boolean(x.isLeave), + isRetirement: Boolean(x.isRetirement), Educations: x.Educations ? JSON.stringify(x.Educations) : "", })); if (mapData.length > 0) { @@ -371,14 +372,14 @@ export class ProfileSalaryController extends Controller { const allRegis = await AppDataSource.getRepository(viewRegistryEmployee) .createQueryBuilder("registryEmployee") .getMany(); - const profileEmpIds = new Set((await this.profileEmployeeRepo.find()).map(p => p.id)); + const profileEmpIds = new Set((await this.profileEmployeeRepo.find()).map((p) => p.id)); const mapData = allRegis - .filter(x => profileEmpIds.has(x.profileEmployeeId)) - .map(x => ({ + .filter((x) => profileEmpIds.has(x.profileEmployeeId)) + .map((x) => ({ ...x, - isProbation: Boolean(x.isProbation), - isLeave: Boolean(x.isLeave), - isRetirement: Boolean(x.isRetirement), + isProbation: Boolean(x.isProbation), + isLeave: Boolean(x.isLeave), + isRetirement: Boolean(x.isRetirement), Educations: x.Educations ? JSON.stringify(x.Educations) : "", })); if (mapData.length > 0) { @@ -407,14 +408,14 @@ export class ProfileSalaryController extends Controller { if (r.commandId) { _command = await this.commandRepository.findOne({ where: { id: r.commandId }, - relations: ["commandType"] + relations: ["commandType"], }); } return { ...r, - commandType: _command && _command?.commandType ? _command?.commandType.code : null + commandType: _command && _command?.commandType ? _command?.commandType.code : null, }; - }) + }), ); return new HttpSuccess(result); } @@ -444,6 +445,7 @@ export class ProfileSalaryController extends Controller { "14", "15", "16", + "20", ]), }, { profileId: profile.id, commandCode: IsNull() }, @@ -457,14 +459,14 @@ export class ProfileSalaryController extends Controller { if (r.commandId) { _command = await this.commandRepository.findOne({ where: { id: r.commandId }, - relations: ["commandType"] + relations: ["commandType"], }); } return { ...r, - commandType: _command && _command?.commandType ? _command?.commandType.code : null + commandType: _command && _command?.commandType ? _command?.commandType.code : null, }; - }) + }), ); return new HttpSuccess(result); } @@ -491,14 +493,14 @@ export class ProfileSalaryController extends Controller { if (r.commandId) { _command = await this.commandRepository.findOne({ where: { id: r.commandId }, - relations: ["commandType"] + relations: ["commandType"], }); } return { ...r, - commandType: _command && _command?.commandType ? _command?.commandType.code : null + commandType: _command && _command?.commandType ? _command?.commandType.code : null, }; - }) + }), ); return new HttpSuccess(result); } @@ -527,6 +529,7 @@ export class ProfileSalaryController extends Controller { "14", "15", "16", + "20", ]), }, { profileId: profileId, commandCode: IsNull() }, @@ -548,14 +551,14 @@ export class ProfileSalaryController extends Controller { if (r.commandId) { _command = await this.commandRepository.findOne({ where: { id: r.commandId }, - relations: ["commandType"] + relations: ["commandType"], }); } return { ...r, - commandType: _command && _command?.commandType ? _command?.commandType.code : null + commandType: _command && _command?.commandType ? _command?.commandType.code : null, }; - }) + }), ); return new HttpSuccess(result); } @@ -572,11 +575,13 @@ export class ProfileSalaryController extends Controller { const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today"); let _currentDate = CURRENT_DATE[0].today; if (profile && profile?.isLeave) { - _currentDate = profile && profile.leaveDate - ? Extension.toDateOnlyString(profile.leaveDate) - : _currentDate + _currentDate = + profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate; } - const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [profile.id, _currentDate]); + const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [ + profile.id, + _currentDate, + ]); const _position = position.length > 0 ? position[0] : []; const mapPosition = @@ -607,7 +612,10 @@ export class ProfileSalaryController extends Controller { }, [] as { name: string; days: number; year: number; month: number; day: number }[], ); - const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [profile.id, _currentDate]); + const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [ + profile.id, + _currentDate, + ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel = _posLevel.length > 1 @@ -646,7 +654,7 @@ export class ProfileSalaryController extends Controller { const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [ profile.id, - _currentDate + _currentDate, ]); const _posExecutive = posExecutive.length > 0 ? posExecutive[0] : []; const mapPosExecutive = @@ -691,19 +699,23 @@ export class ProfileSalaryController extends Controller { // "SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));", // ); const _profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!_profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today"); let _currentDate = CURRENT_DATE[0].today; if (_profile && _profile?.isLeave) { - _currentDate = _profile && _profile.leaveDate - ? Extension.toDateOnlyString(_profile.leaveDate) - : _currentDate + _currentDate = + _profile && _profile.leaveDate + ? Extension.toDateOnlyString(_profile.leaveDate) + : _currentDate; } - const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [profileId, _currentDate]); + const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [ + profileId, + _currentDate, + ]); const _position = position.length > 0 ? position[0] : []; const mapPosition = @@ -738,7 +750,10 @@ export class ProfileSalaryController extends Controller { [] as { name: string; days: number; year: number; month: number; day: number }[], ); - const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [profileId, _currentDate]); + const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?, ?)", [ + profileId, + _currentDate, + ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel = _posLevel.length > 1 @@ -780,7 +795,7 @@ export class ProfileSalaryController extends Controller { const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?, ?)", [ profileId, - _currentDate + _currentDate, ]); const _posExecutive = posExecutive.length > 0 ? posExecutive[0] : []; const mapPosExecutive = @@ -891,9 +906,9 @@ export class ProfileSalaryController extends Controller { }; const _null: any = null; if (body.commandCode && !body.commandName) { - if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" - else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" - else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" + if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"; + else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"; } Object.assign(data, { ...body, ...meta }); const history = new ProfileSalaryHistory(); @@ -929,10 +944,10 @@ export class ProfileSalaryController extends Controller { order: { order: "DESC" }, }); const before = null; - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.commandId ?? "" } + where: { id: body.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -941,35 +956,35 @@ export class ProfileSalaryController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepo.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } const data = new ProfileSalary(); @@ -1014,9 +1029,9 @@ export class ProfileSalaryController extends Controller { const before = structuredClone(record); const history = new ProfileSalaryHistory(); if (body.commandCode && !body.commandName) { - if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" - else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" - else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" + if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"; + else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"; } Object.assign(record, body); Object.assign(history, { ...record, id: undefined }); diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index a9047ae8..36576788 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -80,6 +80,7 @@ export class ProfileSalaryEmployeeController extends Controller { "14", "15", "16", + "20", ]), }, { profileEmployeeId: profile.id, commandCode: IsNull() }, @@ -128,6 +129,7 @@ export class ProfileSalaryEmployeeController extends Controller { "14", "15", "16", + "20", ]), }, { profileEmployeeId: profileId, commandCode: IsNull() }, @@ -146,13 +148,12 @@ export class ProfileSalaryEmployeeController extends Controller { const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today"); let _currentDate = CURRENT_DATE[0].today; if (profile && profile?.isLeave) { - _currentDate = profile && profile.leaveDate - ? Extension.toDateOnlyString(profile.leaveDate) - : _currentDate + _currentDate = + profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate; } const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [ profile.id, - _currentDate + _currentDate, ]); const _position = position.length > 0 ? position[0] : []; const mapPosition = @@ -185,7 +186,7 @@ export class ProfileSalaryEmployeeController extends Controller { const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?, ?)", [ profile.id, - _currentDate + _currentDate, ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel = @@ -228,21 +229,22 @@ export class ProfileSalaryEmployeeController extends Controller { @Get("tenure/{profileId}") public async getPositionTenure(@Path() profileId: string, @Request() req: RequestWithUser) { const _profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!_profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today"); let _currentDate = CURRENT_DATE[0].today; if (_profile && _profile?.isLeave) { - _currentDate = _profile && _profile.leaveDate - ? Extension.toDateOnlyString(_profile.leaveDate) - : _currentDate + _currentDate = + _profile && _profile.leaveDate + ? Extension.toDateOnlyString(_profile.leaveDate) + : _currentDate; } const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [ profileId, - _currentDate + _currentDate, ]); const _position = position.length > 0 ? position[0] : []; const mapPosition = @@ -275,7 +277,7 @@ export class ProfileSalaryEmployeeController extends Controller { const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?, ?)", [ profileId, - _currentDate + _currentDate, ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel =