diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 43e5f21..f04b60e 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -36,9 +36,10 @@ import permission from "../interfaces/permission"; import CallAPI from "../interfaces/call-api"; import { isNotEmittedStatement } from "typescript"; +import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee"; @Route("api/v1/salary/report") @Tags("Report") -@Security("bearerAuth") +// @Security("bearerAuth") @Response( HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", @@ -56,6 +57,8 @@ export class ReportController extends Controller { private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee); private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile); private salaryProfileEmployeeRepository = AppDataSource.getRepository(SalaryProfileEmployee); + private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee); + /** * API รายงานอัตราเงินเดือน @@ -3233,7 +3236,32 @@ export class ReportController extends Controller { const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; - const formattedData = _salaryPeriod.map((profile, index) => { + //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม + const filteredProfiles = await Promise.all( + _salaryPeriod.map(async (profile) => { + const salaryRankMax = await this.salaryEmployeeRankRepository + .createQueryBuilder("rank") + .leftJoin("rank.salaryEmployee_", "emp") + .where("emp.isActive = :isActive", { isActive: true }) + .andWhere("emp.group = :group", { group: profile.group }) + .orderBy("rank.step", "DESC") + .getOne(); + + const match = + salaryRankMax != null && + profile.salaryLevel != null && + profile.salaryLevel === salaryRankMax.step && + profile.amount === salaryRankMax.salaryMonth; + + if (!match) return null; + + return { profile, salaryRankMax }; + }) + ); + + const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); + + const formattedData = validProfiles.map(({ profile }, index) => { const fullNameParts = [ profile.child4, profile.child3, @@ -3241,12 +3269,12 @@ export class ReportController extends Controller { profile.child1, profile.root, ]; - + const affiliation = fullNameParts .filter((part) => part !== undefined && part !== null) .join("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; - + return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, @@ -3261,15 +3289,20 @@ export class ReportController extends Controller { " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) : "-", - amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", + amount: profile.amount + ? Extension.ToThaiNumber(profile.amount.toLocaleString()) + : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", reasonSign: "", - score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน - reason: profile.remark, //เหตุผลที่ไม่สมควรหรือไม่อาจเลื่อนขั้นค่าจ้าง + score: profile.result + ? Extension.ToThaiNumber(profile.result) + : "-", + reason: profile.remark, }; }); + return new HttpSuccess({ template: "emp1-07", @@ -3281,6 +3314,7 @@ export class ReportController extends Controller { }, }); } + // /** // * API 08-แบบ ลจ.กทม.3-บัญชีแสดงวันลาในครึ่งปีของลูกจ้าง // * @@ -5125,7 +5159,32 @@ export class ReportController extends Controller { }); // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; - const formattedData = _salaryPeriod.map((profile, index) => { + //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม + const filteredProfiles = await Promise.all( + _salaryPeriod.map(async (profile) => { + const salaryRankMax = await this.salaryEmployeeRankRepository + .createQueryBuilder("rank") + .leftJoin("rank.salaryEmployee_", "emp") + .where("emp.isActive = :isActive", { isActive: true }) + .andWhere("emp.group = :group", { group: profile.group }) + .orderBy("rank.step", "DESC") + .getOne(); + + const match = + salaryRankMax != null && + profile.salaryLevel != null && + profile.salaryLevel === salaryRankMax.step && + profile.amount === salaryRankMax.salaryMonth; + + if (!match) return null; + + return { profile, salaryRankMax }; + }) + ); + + const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); + + const formattedData = validProfiles.map(({ profile }, index) => { const fullNameParts = [ profile.child4, profile.child3, @@ -5878,7 +5937,32 @@ export class ReportController extends Controller { const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; - const formattedData = _salaryPeriod.map((profile, index) => { + //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม + const filteredProfiles = await Promise.all( + _salaryPeriod.map(async (profile) => { + const salaryRankMax = await this.salaryEmployeeRankRepository + .createQueryBuilder("rank") + .leftJoin("rank.salaryEmployee_", "emp") + .where("emp.isActive = :isActive", { isActive: true }) + .andWhere("emp.group = :group", { group: profile.group }) + .orderBy("rank.step", "DESC") + .getOne(); + + const match = + salaryRankMax != null && + profile.salaryLevel != null && + profile.salaryLevel === salaryRankMax.step && + profile.amount === salaryRankMax.salaryMonth; + + if (!match) return null; + + return { profile, salaryRankMax }; + }) + ); + + const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); + + const formattedData = validProfiles.map(({ profile }, index) => { const fullNameParts = [ profile.child4, profile.child3, @@ -6288,7 +6372,32 @@ export class ReportController extends Controller { const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; - const formattedData = _salaryPeriod.map((profile, index) => { + //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม + const filteredProfiles = await Promise.all( + _salaryPeriod.map(async (profile) => { + const salaryRankMax = await this.salaryEmployeeRankRepository + .createQueryBuilder("rank") + .leftJoin("rank.salaryEmployee_", "emp") + .where("emp.isActive = :isActive", { isActive: true }) + .andWhere("emp.group = :group", { group: profile.group }) + .orderBy("rank.step", "DESC") + .getOne(); + + const match = + salaryRankMax != null && + profile.salaryLevel != null && + profile.salaryLevel === salaryRankMax.step && + profile.amount === salaryRankMax.salaryMonth; + + if (!match) return null; + + return { profile, salaryRankMax }; + }) + ); + + const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); + + const formattedData = validProfiles.map(({ profile }, index) => { const fullNameParts = [ profile.child4, profile.child3,