diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index de6ddf9..f3ae545 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -931,14 +931,14 @@ export class ReportController extends Controller { }, relations: ["salaryProfiles"], }); - if(salaryPeriod.period === 'APR'){ + if (salaryPeriod.period === "APR") { const salaryProfile = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg?.id, type: "FULL", //หนึ่งขั้น - } + }, }); - + //รอบปีก่อนๆ const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -1010,13 +1010,21 @@ export class ReportController extends Controller { }, }); const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))); - const yearIncrease1 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-2))); - const yearIncrease2 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1))); - const fifteenPercent = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? - "๐" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); - const fifteenPoint = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ? - ".๐๐" : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); - + const yearIncrease1 = Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year - 2)), + ); + const yearIncrease2 = Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year - 1)), + ); + const fifteenPercent = + salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null + ? "๐" + : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); + const fifteenPoint = + salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null + ? ".๐๐" + : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); + return new HttpSuccess({ template: "gov1-03", reportName: "gov1-03", @@ -1025,7 +1033,7 @@ export class ReportController extends Controller { yearIncrease1: yearIncrease1, yearIncrease2: yearIncrease2, yearIncreaseSlice: yearIncrease2.slice(-2), - yearSlice: year.slice(-2), + yearSlice: year.slice(-2), point: fifteenPercent + fifteenPoint, root: salaryProfile[0]?.root, profile: salaryProfile.map((item, index) => ({ @@ -1064,8 +1072,7 @@ export class ReportController extends Controller { })), }, }); - } - else if(salaryPeriod.period === 'OCT'){ + } else if (salaryPeriod.period === "OCT") { //find period APR const salaryPeriod_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -1079,23 +1086,23 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriod_APR?.id, rootId: rootId, snapshot: "SNAP2", - } + }, }); const salaryProfile_APR = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg_APR?.id, - type: In(["HAFT","FULL"]), - } + type: In(["HAFT", "FULL"]), + }, }); //end period APR const salaryProfile = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg?.id, - type: In(["FULLHAFT","FULL"]), - } + type: In(["FULLHAFT", "FULL"]), + }, }); - + //รอบปีก่อนๆ const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -1167,13 +1174,21 @@ export class ReportController extends Controller { }, }); const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))); - const yearIncrease1 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-2))); - const yearIncrease2 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1))); - const fifteenPercent = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? - "๐" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); - const fifteenPoint = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ? - ".๐๐" : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); - + const yearIncrease1 = Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year - 2)), + ); + const yearIncrease2 = Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year - 1)), + ); + const fifteenPercent = + salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null + ? "๐" + : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); + const fifteenPoint = + salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null + ? ".๐๐" + : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); + return new HttpSuccess({ template: "gov2-03", reportName: "gov2-03", @@ -1182,7 +1197,7 @@ export class ReportController extends Controller { yearIncrease1: yearIncrease1, yearIncrease2: yearIncrease2, yearIncreaseSlice: yearIncrease2.slice(-2), - yearSlice: year.slice(-2), + yearSlice: year.slice(-2), point: fifteenPercent + fifteenPoint, root: salaryProfile[0]?.root, profile: salaryProfile.map((item, index) => ({ @@ -1219,8 +1234,8 @@ export class ReportController extends Controller { salaryIncreaseAPR: salaryProfile_APR.length > 0 ? salaryProfile_APR - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.amount) + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.amount) : "๐", //การเลื่อนเงินเดือนรอบเมษา Type: item.type === "FULL" ? "หนึ่งขั้น" : "หนึ่งขั้นครึ่ง", score1: null, //ผลการประเมินฯ ครั้งที่ 1 @@ -1935,6 +1950,7 @@ export class ReportController extends Controller { const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { + type: "FULL", salaryOrg: { snapshot: "SNAP1", rootId: rootId, @@ -1982,6 +1998,7 @@ export class ReportController extends Controller { posNumber: profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + score: null, reason: null, }; }); @@ -2023,6 +2040,7 @@ export class ReportController extends Controller { relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["HAFT", "FULL", "FULLHAFT"]), + isNext: false, salaryOrg: { snapshot: "SNAP2", rootId: rootId, @@ -2100,6 +2118,7 @@ export class ReportController extends Controller { relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["HAFT", "FULL", "FULLHAFT"]), + isNext: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, @@ -2142,6 +2161,10 @@ export class ReportController extends Controller { positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : null, + amountSpecial: + profile.amountSpecial > 0 + ? "(" + Extension.ToThaiNumber(profile.amountSpecial.toString()) + ")" + : "", score: null, //สรุปผลการประเมินฯ ระดับและคะแนน reason: null, }; diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index ccaa325..28fbd4c 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -346,16 +346,48 @@ export class SalaryPeriodEmployeeController extends Controller { salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay; salaryProfile.groupNew = salaryFormula.salaryEmployee.group; salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + if (salaryRankAmountMax != null) { + if (step - salaryRankAmountMax.step <= 0.5) { + salaryProfile.positionSalaryAmountPer = 0.2; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.2; + } else if (step - salaryRankAmountMax.step <= 1) { + salaryProfile.positionSalaryAmountPer = 0.4; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.4; + } else { + salaryProfile.positionSalaryAmountPer = 0.6; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.6; + } + } else { + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } } else { + salaryProfile.isNext = false; salaryProfile.amountUse = salaryRanks.salaryMonth - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks.salaryMonth; salaryProfile.positionSalaryDayAmount = salaryRanks.salaryDay; salaryProfile.groupNew = group; salaryProfile.salaryLevelNew = step; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; } } else { + salaryProfile.isNext = false; salaryProfile.amountUse = 0; salaryProfile.positionSalaryAmount = salaryProfile.amount; + salaryProfile.positionSalaryDayAmount = 0; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; } } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); @@ -644,18 +676,49 @@ export class SalaryPeriodEmployeeController extends Controller { salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay; salaryProfile.groupNew = salaryFormula.salaryEmployee.group; salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + if (salaryRankAmountMax != null) { + if (step - salaryRankAmountMax.step <= 0.5) { + salaryProfile.positionSalaryAmountPer = 0.2; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.2; + } else if (step - salaryRankAmountMax.step <= 1) { + salaryProfile.positionSalaryAmountPer = 0.4; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.4; + } else { + salaryProfile.positionSalaryAmountPer = 0.6; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.6; + } + } else { + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } } else { + salaryProfile.isNext = false; salaryProfile.amountUse = salaryRanks.salaryMonth - (salaryProfile.amount == null ? 0 : salaryProfile.amount); salaryProfile.positionSalaryAmount = salaryRanks.salaryMonth; salaryProfile.positionSalaryDayAmount = salaryRanks.salaryDay; salaryProfile.groupNew = group; salaryProfile.salaryLevelNew = step; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; } } else { + salaryProfile.isNext = false; salaryProfile.amountUse = 0; salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount; + salaryProfile.positionSalaryDayAmount = 0; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; } } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); @@ -1000,18 +1063,49 @@ export class SalaryPeriodEmployeeController extends Controller { salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay; salaryProfile.groupNew = salaryFormula.salaryEmployee.group; salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + if (salaryRankAmountMax != null) { + if (step - salaryRankAmountMax.step <= 0.5) { + salaryProfile.positionSalaryAmountPer = 0.2; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.2; + } else if (step - salaryRankAmountMax.step <= 1) { + salaryProfile.positionSalaryAmountPer = 0.4; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.4; + } else { + salaryProfile.positionSalaryAmountPer = 0.6; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.6; + } + } else { + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } } else { + salaryProfile.isNext = false; salaryProfile.amountUse = salaryRanks.salaryMonth - (salaryProfile.amount == null ? 0 : salaryProfile.amount); salaryProfile.positionSalaryAmount = salaryRanks.salaryMonth; salaryProfile.positionSalaryDayAmount = salaryRanks.salaryDay; salaryProfile.groupNew = group; salaryProfile.salaryLevelNew = step; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; } } else { + salaryProfile.isNext = false; salaryProfile.amountUse = 0; salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount; + salaryProfile.positionSalaryDayAmount = 0; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; } } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); diff --git a/src/entities/SalaryProfileEmployee.ts b/src/entities/SalaryProfileEmployee.ts index f9af587..e85fc43 100644 --- a/src/entities/SalaryProfileEmployee.ts +++ b/src/entities/SalaryProfileEmployee.ts @@ -172,6 +172,13 @@ export class SalaryProfileEmployee extends EntityBase { }) positionSalaryAmount: number; + @Column({ + type: "double", + comment: "เปอร์เซ็นเงินพิเศษ", + default: 0, + }) + positionSalaryAmountPer: number; + @Column({ type: "double", comment: "เงินเดือนหลังเลื่อน(รายวัน)", diff --git a/src/migration/1711081845764-update_table_profileemployee_add_groupNew2.ts b/src/migration/1711081845764-update_table_profileemployee_add_groupNew2.ts new file mode 100644 index 0000000..06578d1 --- /dev/null +++ b/src/migration/1711081845764-update_table_profileemployee_add_groupNew2.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfileemployeeAddGroupNew21711081845764 implements MigrationInterface { + name = 'UpdateTableProfileemployeeAddGroupNew21711081845764' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`positionSalaryAmountPer\` double NOT NULL COMMENT 'เปอร์เซ็นเงินพิเศษ' DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`positionSalaryAmountPer\``); + } + +}