diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 863769e..8fb9136 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -920,21 +920,33 @@ export class ReportController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } - const salaryOrg = await this.salaryOrgRepository.findOne({ + const salaryOrg_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodId, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, - order: { - group: "ASC", - }, - relations: ["salaryProfiles"], }); + const salaryOrg_Group2 = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodId, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + if (salaryPeriod.period === "APR") { - const salaryProfile = await this.salaryProfileRepository.find({ + const salaryProfileGroup1 = await this.salaryProfileRepository.find({ where: { - salaryOrgId: salaryOrg?.id, + salaryOrgId: salaryOrg_Group1?.id, + type: "FULL", //หนึ่งขั้น + }, + }); + const salaryProfileGroup2 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: salaryOrg_Group2?.id, type: "FULL", //หนึ่งขั้น }, }); @@ -954,26 +966,51 @@ export class ReportController extends Controller { isActive: true, }, }); - const salaryOrg1_APR = await this.salaryOrgRepository.findOne({ + const salaryOrg1_APR_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_APR?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ + const salaryOrg1_APR_Group2 = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease1_APR?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryOrg1_OCT_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_OCT?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryProfile1 = await this.salaryProfileRepository.find({ + const salaryOrg1_OCT_Group2 = await this.salaryOrgRepository.findOne({ where: { - salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), + salaryPeriodId: salaryPeriodIncrease1_OCT?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryProfile1_Group1 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg1_APR_Group1?.id, salaryOrg1_OCT_Group1?.id]), type: "FULL", }, }); + const salaryProfile1_Group2 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg1_APR_Group2?.id, salaryOrg1_OCT_Group2?.id]), + type: "FULL", + }, + }); + //รอบปีก่อนหน้า const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -989,23 +1026,47 @@ export class ReportController extends Controller { isActive: true, }, }); - const salaryOrg2_APR = await this.salaryOrgRepository.findOne({ + const salaryOrg2_APR_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryOrg2_OCT = await this.salaryOrgRepository.findOne({ + const salaryOrg2_APR_Group2 = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease2_APR?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryOrg2_OCT_GROUP1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_OCT?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryProfile2 = await this.salaryProfileRepository.find({ + const salaryOrg2_OCT_GROUP2 = await this.salaryOrgRepository.findOne({ where: { - salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]), + salaryPeriodId: salaryPeriodIncrease2_OCT?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryProfile2_Group1 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg2_APR_Group1?.id, salaryOrg2_OCT_GROUP1?.id]), + type: "FULL", + }, + }); + const salaryProfile2_Group2 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg2_APR_Group2?.id, salaryOrg2_OCT_GROUP2?.id]), type: "FULL", }, }); @@ -1016,15 +1077,22 @@ export class ReportController extends Controller { const yearIncrease2 = Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)), ); - const fifteenPercent = - salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null + const fifteenPercent_Group1 = + salaryOrg_Group1?.fifteenPercent == undefined || salaryOrg_Group1?.fifteenPercent == null ? "๐" - : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); - const fifteenPoint = - salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null + : Extension.ToThaiNumber(String(salaryOrg_Group1?.fifteenPercent)); + const fifteenPoint_Group1 = + salaryOrg_Group1?.fifteenPoint == undefined || salaryOrg_Group1?.fifteenPoint == null ? ".๐๐" - : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); - + : "." + Extension.ToThaiNumber(String(salaryOrg_Group1?.fifteenPoint)); + const fifteenPercent_Group2 = + salaryOrg_Group2?.fifteenPercent == undefined || salaryOrg_Group2?.fifteenPercent == null + ? "๐" + : Extension.ToThaiNumber(String(salaryOrg_Group2?.fifteenPercent)); + const fifteenPoint_Group2 = + salaryOrg_Group2?.fifteenPoint == undefined || salaryOrg_Group2?.fifteenPoint == null + ? ".๐๐" + : "." + Extension.ToThaiNumber(String(salaryOrg_Group2?.fifteenPoint)); return new HttpSuccess({ template: "gov1-03", reportName: "gov1-03", @@ -1034,9 +1102,10 @@ export class ReportController extends Controller { yearIncrease2: yearIncrease2, yearIncreaseSlice: yearIncrease2.slice(-2), yearSlice: year.slice(-2), - point: fifteenPercent + fifteenPoint, - root: salaryProfile[0]?.root, - profile: salaryProfile.map((item, index) => ({ + point: fifteenPercent_Group1 + fifteenPoint_Group1, + pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, + root: salaryProfileGroup1[0]?.root, + profile: salaryProfileGroup1.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") + @@ -1056,9 +1125,9 @@ export class ReportController extends Controller { ? "๐" : Extension.ToThaiNumber(String(item.amount.toLocaleString())), salaryIncrease1: - salaryProfile1.length > 0 + salaryProfile1_Group1.length > 0 ? (() => { - const filteredAmount = salaryProfile1 + const filteredAmount = salaryProfile1_Group1 .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.amount); const Amount = filteredAmount[0]; @@ -1068,9 +1137,55 @@ export class ReportController extends Controller { })() : "๐", //การเลื่อนเงินเดือนปีก่อนๆหน้า salaryIncrease2: - salaryProfile2.length > 0 + salaryProfile2_Group1.length > 0 ? (() => { - const filteredAmount = salaryProfile2 + const filteredAmount = salaryProfile2_Group1 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.amount); + const Amount = filteredAmount[0]; + return Amount === undefined || Amount === null + ? "๐" + : Extension.ToThaiNumber(Amount?.toLocaleString()); + })() + : "๐", //การเลื่อนเงินเดือนปีก่อนหน้า + score: null, //ผลการประเมินฯ + remark: null, //หมายเหตุ + })), + profileGroup2: salaryProfileGroup2.map((item, index) => ({ + no: Extension.ToThaiNumber(String(index + 1)), + fullname: + (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) + + "/" + + item.prefix + + item.firstName + + " " + + item.lastName, // สังกัด/ชื่อ-นามสกุล + posLevel: item.posLevel, + posMasterNo: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)), + amount: + item.amount == undefined || item.amount == null + ? "๐" + : Extension.ToThaiNumber(String(item.amount.toLocaleString())), + salaryIncrease1: + salaryProfile1_Group2.length > 0 + ? (() => { + const filteredAmount = salaryProfile1_Group2 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.amount); + const Amount = filteredAmount[0]; + return Amount === undefined || Amount === null + ? "๐" + : Extension.ToThaiNumber(Amount?.toLocaleString()); + })() + : "๐", //การเลื่อนเงินเดือนปีก่อนๆหน้า + salaryIncrease2: + salaryProfile2_Group2.length > 0 + ? (() => { + const filteredAmount = salaryProfile2_Group2 .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.amount); const Amount = filteredAmount[0]; @@ -1085,7 +1200,7 @@ export class ReportController extends Controller { }, }); } else if (salaryPeriod.period === "OCT") { - //find period APR + // find period APR const salaryPeriod_APR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", @@ -1093,24 +1208,45 @@ export class ReportController extends Controller { isActive: true, }, }); - const salaryOrg_APR = await this.salaryOrgRepository.findOne({ + const salaryOrg_APR_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriod_APR?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryProfile_APR = await this.salaryProfileRepository.find({ + const salaryOrg_APR_Group2 = await this.salaryOrgRepository.findOne({ where: { - salaryOrgId: salaryOrg_APR?.id, + salaryPeriodId: salaryPeriod_APR?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryProfile_APR_Group1 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: salaryOrg_APR_Group1?.id, + type: In(["HAFT", "FULL"]), + }, + }); + const salaryProfile_APR_Group2 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: salaryOrg_APR_Group2?.id, type: In(["HAFT", "FULL"]), }, }); //end period APR - const salaryProfile = await this.salaryProfileRepository.find({ + const salaryProfileGroup1 = await this.salaryProfileRepository.find({ where: { - salaryOrgId: salaryOrg?.id, + salaryOrgId: salaryOrg_Group1?.id, + type: In(["FULLHAFT", "FULL"]), + }, + }); + const salaryProfileGroup2 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: salaryOrg_Group2?.id, type: In(["FULLHAFT", "FULL"]), }, }); @@ -1130,26 +1266,51 @@ export class ReportController extends Controller { isActive: true, }, }); - const salaryOrg1_APR = await this.salaryOrgRepository.findOne({ + const salaryOrg1_APR_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_APR?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ + const salaryOrg1_APR_Group2 = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease1_APR?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryOrg1_OCT_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_OCT?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryProfile1 = await this.salaryProfileRepository.find({ + const salaryOrg1_OCT_Group2 = await this.salaryOrgRepository.findOne({ where: { - salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), + salaryPeriodId: salaryPeriodIncrease1_OCT?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryProfile1_Group1 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg1_APR_Group1?.id, salaryOrg1_OCT_Group1?.id]), type: "FULL", }, }); + const salaryProfile1_Group2 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg1_APR_Group2?.id, salaryOrg1_OCT_Group2?.id]), + type: "FULL", + }, + }); + //รอบปีก่อนหน้า const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -1165,23 +1326,47 @@ export class ReportController extends Controller { isActive: true, }, }); - const salaryOrg2_APR = await this.salaryOrgRepository.findOne({ + const salaryOrg2_APR_Group1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryOrg2_OCT = await this.salaryOrgRepository.findOne({ + const salaryOrg2_APR_Group2 = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease2_APR?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryOrg2_OCT_GROUP1 = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_OCT?.id, rootId: rootId, snapshot: "SNAP2", + group: "GROUP1", }, }); - const salaryProfile2 = await this.salaryProfileRepository.find({ + const salaryOrg2_OCT_GROUP2 = await this.salaryOrgRepository.findOne({ where: { - salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]), + salaryPeriodId: salaryPeriodIncrease2_OCT?.id, + rootId: rootId, + snapshot: "SNAP2", + group: "GROUP2", + }, + }); + const salaryProfile2_Group1 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg2_APR_Group1?.id, salaryOrg2_OCT_GROUP1?.id]), + type: "FULL", + }, + }); + const salaryProfile2_Group2 = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In([salaryOrg2_APR_Group2?.id, salaryOrg2_OCT_GROUP2?.id]), type: "FULL", }, }); @@ -1193,14 +1378,21 @@ export class ReportController extends Controller { String(Extension.ToThaiYear(salaryPeriod.year - 1)), ); const fifteenPercent = - salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null + salaryOrg_Group1?.fifteenPercent == undefined || salaryOrg_Group1?.fifteenPercent == null ? "๐" - : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); + : Extension.ToThaiNumber(String(salaryOrg_Group1?.fifteenPercent)); const fifteenPoint = - salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null + salaryOrg_Group1?.fifteenPoint == undefined || salaryOrg_Group1?.fifteenPoint == null ? ".๐๐" - : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); - + : "." + Extension.ToThaiNumber(String(salaryOrg_Group1?.fifteenPoint)); + const fifteenPercent_Group2 = + salaryOrg_Group2?.fifteenPercent == undefined || salaryOrg_Group2?.fifteenPercent == null + ? "๐" + : Extension.ToThaiNumber(String(salaryOrg_Group2?.fifteenPercent)); + const fifteenPoint_Group2 = + salaryOrg_Group2?.fifteenPoint == undefined || salaryOrg_Group2?.fifteenPoint == null + ? ".๐๐" + : "." + Extension.ToThaiNumber(String(salaryOrg_Group2?.fifteenPoint)); return new HttpSuccess({ template: "gov2-03", reportName: "gov2-03", @@ -1211,8 +1403,9 @@ export class ReportController extends Controller { yearIncreaseSlice: yearIncrease2.slice(-2), yearSlice: year.slice(-2), point: fifteenPercent + fifteenPoint, - root: salaryProfile[0]?.root, - profile: salaryProfile.map((item, index) => ({ + pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, + root: salaryProfileGroup1[0]?.root, + profile: salaryProfileGroup1.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") + @@ -1232,9 +1425,9 @@ export class ReportController extends Controller { ? "๐" : Extension.ToThaiNumber(String(item.amount.toLocaleString())), salaryIncrease1: - salaryProfile1.length > 0 + salaryProfile1_Group1.length > 0 ? (() => { - const filteredAmount = salaryProfile1 + const filteredAmount = salaryProfile1_Group1 .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.amount); const Amount = filteredAmount[0]; @@ -1244,9 +1437,9 @@ export class ReportController extends Controller { })() : "๐", //การเลื่อนเงินเดือนปีก่อนๆหน้า salaryIncrease2: - salaryProfile2.length > 0 + salaryProfile2_Group1.length > 0 ? (() => { - const filteredAmount = salaryProfile2 + const filteredAmount = salaryProfile2_Group1 .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.amount); const Amount = filteredAmount[0]; @@ -1256,9 +1449,68 @@ export class ReportController extends Controller { })() : "๐", //การเลื่อนเงินเดือนปีก่อนหน้า salaryIncreaseAPR: - salaryProfile_APR.length > 0 + salaryProfile_APR_Group1.length > 0 ? (() => { - const filteredAmount = salaryProfile_APR + const filteredAmount = salaryProfile_APR_Group1 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.amount); + const Amount = filteredAmount[0]; + return Amount === undefined || Amount === null + ? "๐" + : Extension.ToThaiNumber(Amount?.toLocaleString()); + })() + : "๐", //การเลื่อนเงินเดือนรอบเมษา + Type: item.type === "FULL" ? "หนึ่งขั้น" : "หนึ่งขั้นครึ่ง", + score1: null, //ผลการประเมินฯ ครั้งที่ 1 + score2: null, //ผลการประเมินฯ ครั้งที่ 2 + })), + profileGroup2: salaryProfileGroup2.map((item, index) => ({ + no: Extension.ToThaiNumber(String(index + 1)), + fullname: + (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) + + "/" + + item.prefix + + item.firstName + + " " + + item.lastName, // สังกัด/ชื่อ-นามสกุล + posLevel: item.posLevel, + posMasterNo: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)), + amount: + item.amount == undefined || item.amount == null + ? "๐" + : Extension.ToThaiNumber(String(item.amount.toLocaleString())), + salaryIncrease1: + salaryProfile1_Group2.length > 0 + ? (() => { + const filteredAmount = salaryProfile1_Group2 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.amount); + const Amount = filteredAmount[0]; + return Amount === undefined || Amount === null + ? "๐" + : Extension.ToThaiNumber(Amount?.toLocaleString()); + })() + : "๐", //การเลื่อนเงินเดือนปีก่อนๆหน้า + salaryIncrease2: + salaryProfile2_Group2.length > 0 + ? (() => { + const filteredAmount = salaryProfile2_Group2 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.amount); + const Amount = filteredAmount[0]; + return Amount === undefined || Amount === null + ? "๐" + : Extension.ToThaiNumber(Amount?.toLocaleString()); + })() + : "๐", //การเลื่อนเงินเดือนปีก่อนหน้า + salaryIncreaseAPR: + salaryProfile_APR_Group2.length > 0 + ? (() => { + const filteredAmount = salaryProfile_APR_Group2 .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.amount); const Amount = filteredAmount[0];