diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index ea0d37c..a1744e9 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -245,12 +245,12 @@ export class ReportController extends Controller { const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ - profile?.child4, - profile?.child3, - profile?.child2, - profile?.child1, - profile?.root, - `${profile?.prefix}${profile?.firstName} ${profile?.lastName}`, + profile.child4, + profile.child3, + profile.child2, + profile.child1, + profile.root, + `${profile.prefix}${profile.firstName} ${profile.lastName}`, ]; const fullName = fullNameParts @@ -259,13 +259,11 @@ export class ReportController extends Controller { return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), - fullName: fullName ? fullName : null, - posLevel: profile?.posLevel ? profile?.posLevel : null, + fullName: fullName, + posLevel: profile.posLevel, posNumber: - profile?.orgShortName + profile?.posMasterNo - ? profile?.orgShortName + Extension.ToThaiNumber(profile?.posMasterNo.toLocaleString()) - : null, - amount: profile?.amount ? Extension.ToThaiNumber(profile?.amount.toLocaleString()) : null, + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); @@ -274,7 +272,7 @@ export class ReportController extends Controller { template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", data: { - year: Extension.ToThaiNumber((salaryPeriod.year + 543).toString()), + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, @@ -304,7 +302,6 @@ export class ReportController extends Controller { rootId: rootId, salaryPeriodId: salaryPeriodId, }, - order: { group: "ASC" }, }); const agency = _salaryPeriod[0] == null || _salaryPeriod[0].salaryProfiles[0] == null @@ -442,7 +439,7 @@ export class ReportController extends Controller { date: Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)), ), - year: Extension.ToThaiNumber((salaryPeriod.year + 543).toString()), + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())), agency: agency, data1: formattedData1, @@ -463,7 +460,6 @@ export class ReportController extends Controller { year: salaryPeriod.year, }, }, - order: { group: "ASC" }, }); const _salaryPeriodAPR2 = await this.salaryOrgRepository.findOne({ where: { @@ -475,7 +471,6 @@ export class ReportController extends Controller { year: salaryPeriod.year, }, }, - order: { group: "ASC" }, }); let formattedData1; if (data1 != null) { @@ -884,7 +879,7 @@ export class ReportController extends Controller { date: Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)), ), - year: Extension.ToThaiNumber((salaryPeriod.year + 543).toString()), + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())), agency: agency, data1: formattedData1, @@ -1079,8 +1074,6 @@ export class ReportController extends Controller { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, - // period: "APR", - isActive: true, }, }); @@ -1088,76 +1081,77 @@ export class ReportController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } - const salaryOrg = await this.salaryOrgRepository.findOne({ + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { - salaryPeriodId: salaryPeriodId, - rootId: rootId, - snapshot: "SNAP2", - }, - order: { - group: "ASC", - }, - relations: ["salaryProfiles"], - }); - - const salaryProfile = await this.salaryProfileRepository.find({ - relations: ["salaryOrg"], - where: { - salaryOrgId: salaryOrg?.id, + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + type: "NONE", //ไม่ได้เลื่อน }, order: { salaryOrg: { group: "ASC", }, type: "DESC", + orgShortName: "ASC", posMasterNo: "ASC", }, }); + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.map((profile, index) => { + return { + no: Extension.ToThaiNumber(String(index + 1)), + fullname: profile.prefix + profile.firstName + " " + profile.lastName, + log_group: profile.salaryOrg.group, + log_type: profile.type, + log_isNext: profile.isNext, + position: + profile.position + + "/" + + (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + "/") + + (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + "/") + + (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + "/") + + (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + "/") + + (profile.root == undefined && profile.root == null ? "" : profile.root), + posLevel: profile.posLevel, + orgShortName: profile.orgShortName + Extension.ToThaiNumber(String(profile.posMasterNo)), + amount: + profile.amount == undefined || profile.amount == null || profile.amount == 0 + ? "" + : Extension.ToThaiNumber(String(profile.amount)), + amountSpecial: + (profile.positionSalaryAmount == undefined || + profile.positionSalaryAmount == null || + profile.positionSalaryAmount == 0 + ? "" + : Extension.ToThaiNumber(String(profile.positionSalaryAmount))) + + (profile.amountSpecial == undefined || + profile.amountSpecial == null || + profile.amountSpecial == 0 + ? "" + : `(${Extension.ToThaiNumber(String(profile.amountSpecial))})`), + score: null, //สรุปผลการประเมินฯ ระดับและคะแนน + remark: + `${profile.type === "FULL" ? "หนึ่งขั้น" : ""}\n` + + `${profile.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` + + `${profile.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` + + `${profile.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ + }; + }); + return new HttpSuccess({ - template: salaryPeriod.period === "APR" ? "gov1-04" : "gov2-04", - reportName: salaryPeriod.period === "APR" ? "gov1-04" : "gov2-04", + template: salaryPeriod.period == "APR" ? "gov1-04" : "gov2-04", + reportName: salaryPeriod.period == "APR" ? "gov1-04" : "gov2-04", data: { - year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod?.year))), - effectiveDate: salaryPeriod?.effectiveDate, - root: salaryProfile[0]?.root, - profile: salaryProfile.map((item, index) => ({ - no: Extension.ToThaiNumber(String(index + 1)), - fullname: item.prefix + item.firstName + " " + item.lastName, - log_group: item.salaryOrg.group, - log_type: item.type, - log_isNext: item.isNext, - position: - item.position + - "/" + - (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") + - (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") + - (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") + - (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") + - (item.root == undefined && item.root == null ? "" : item.root), - posLevel: item.posLevel, - orgShortName: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)), - amount: - item.amount == undefined || item.amount == null || item.amount == 0 - ? "" - : Extension.ToThaiNumber(String(item.amount)), - amountSpecial: - (item.positionSalaryAmount == undefined || - item.positionSalaryAmount == null || - item.positionSalaryAmount == 0 - ? "" - : Extension.ToThaiNumber(String(item.positionSalaryAmount))) + - (item.amountSpecial == undefined || - item.amountSpecial == null || - item.amountSpecial == 0 - ? "" - : `(${Extension.ToThaiNumber(String(item.amountSpecial))})`), - score: null, //สรุปผลการประเมินฯ ระดับและคะแนน - remark: - `${item.type === "FULL" ? "หนึ่งขั้น" : ""}\n` + - `${item.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` + - `${item.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ - })), + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + effectiveDate: salaryPeriod.effectiveDate, + root: agency, + profile: formattedData, }, }); } @@ -1175,8 +1169,6 @@ export class ReportController extends Controller { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, - period: "APR", - isActive: true, }, }); @@ -1184,68 +1176,63 @@ export class ReportController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } - const salaryOrg = await this.salaryOrgRepository.findOne({ + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { - salaryPeriodId: salaryPeriodId, - rootId: rootId, - snapshot: "SNAP2", - }, - order: { - group: "ASC", - }, - relations: ["salaryProfiles"], - }); - - const salaryProfile = await this.salaryProfileRepository.find({ - where: { - salaryOrgId: salaryOrg?.id, + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, type: "NONE", //ไม่ได้เลื่อน }, - select: [ - "id", - "prefix", - "firstName", - "lastName", - "root", - "position", - "posType", - "posLevel", - "orgShortName", - "posMasterNo", - "amount", - "amountSpecial", - ], + order: { + salaryOrg: { + group: "ASC", + }, + orgShortName: "ASC", + posMasterNo: "ASC", + }, }); - const mapData = { - effectiveDate: salaryPeriod?.effectiveDate, - root: salaryProfile[0]?.root, - profile: salaryProfile.map((item, index) => ({ - no: Extension.ToThaiNumber(String(index + 1)), - fullname: item.prefix + item.firstName + " " + item.lastName, - position: - item.position + - "/" + - (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") + - (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") + - (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") + - (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") + - (item.root == undefined && item.root == null ? "" : item.root), - posLevel: item.posLevel, - orgShortName: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)), - amount: - item.amount == undefined || item.amount == null - ? "๐" - : Extension.ToThaiNumber(String(item.amount)), - amountSpecial: - item.amountSpecial == undefined || item.amountSpecial == null - ? "๐" - : Extension.ToThaiNumber(String(item.amountSpecial)), + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.map((profile, index) => { + const fullNameParts = [ + profile.position, + profile.child4, + profile.child3, + profile.child2, + profile.child1, + profile.root, + ]; + + const position = fullNameParts + .filter((part) => part !== undefined && part !== null) + .join("/"); + + return { + no: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullname: profile.prefix + profile.firstName + " " + profile.lastName, + position: position, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, score: null, //สรุปผลการประเมินฯ ระดับและคะแนน - remark: null, //หมายเหตุ - })), - }; - return mapData; + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05", + reportName: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); } // /* API แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก @@ -1325,15 +1312,17 @@ export class ReportController extends Controller { ? `(${Extension.ToThaiNumber(String(item.positionSalaryAmount))})` : ""), remark: - (item.type == "FULL" ? `หนึ่งขั้น ` : item.type == "FULLHAFT" ? `หนึ่งขั้นครึ่ง ` : "") + - (item.isNext == true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""), + `${item.type === "FULL" ? "หนึ่งขั้น" : ""}\n` + + `${item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` + + `${item.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` + + `${item.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // ห })); return new HttpSuccess({ template: "gov1-07", reportName: "gov1-07", data: { - year: Extension.ToThaiNumber((salaryPeriod.year + 543).toString()), + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearOld: Extension.ToThaiNumber((salaryPeriod.year + 542).toString()), date: Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)),