diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 98b0515..134d14a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -248,8 +248,14 @@ export class ReportController extends Controller { if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - - const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + const _root = await this.salaryOrgRepository.findOne({ + where: { + rootId: rootId, + salaryPeriodId: salaryPeriodId, + } + }) + const root = _root?.root == null ? "" : _root.root; + // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ @@ -281,7 +287,7 @@ export class ReportController extends Controller { reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - agency: agency, + agency: root, data: formattedData, }, }); @@ -311,6 +317,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, }); + const agency = _salaryPeriod[0] == null || _salaryPeriod[0].salaryProfiles[0] == null ? "" @@ -1104,7 +1111,7 @@ export class ReportController extends Controller { yearSlice: year.slice(-2), point: fifteenPercent_Group1 + fifteenPoint_Group1, pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, - root: salaryProfileGroup1[0]?.root, + root: salaryOrg_Group1?.root, profile: salaryProfileGroup1.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: @@ -1404,7 +1411,7 @@ export class ReportController extends Controller { yearSlice: year.slice(-2), point: fifteenPercent + fifteenPoint, pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, - root: salaryProfileGroup1[0]?.root, + root: salaryOrg_Group1?.root, profile: salaryProfileGroup1.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: @@ -1557,7 +1564,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน - isReserve: false, //กรองเฉพาะคนที่ไม่เกษียณ + isRetired: false, //กรองเฉพาะคนที่ไม่เกษียณ }, order: { salaryOrg: { @@ -1568,8 +1575,14 @@ export class ReportController extends Controller { posMasterNo: "ASC", }, }); - - const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + const _root = await this.salaryOrgRepository.findOne({ + where: { + rootId: rootId, + salaryPeriodId: salaryPeriodId, + } + }) + const root = _root?.root == null ? "" : _root.root; + // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { return { @@ -1618,7 +1631,7 @@ export class ReportController extends Controller { data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), effectiveDate: salaryPeriod.effectiveDate, - root: agency, + root: root, profile: formattedData, }, }); @@ -1653,7 +1666,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน - isReserve: true, //กรองเฉพาะคนที่เกษียณ + isRetired: true, //กรองเฉพาะคนที่เกษียณ }, order: { salaryOrg: { @@ -1664,8 +1677,14 @@ export class ReportController extends Controller { posMasterNo: "ASC", }, }); - - const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + const _root = await this.salaryOrgRepository.findOne({ + where: { + rootId: rootId, + salaryPeriodId: salaryPeriodId, + } + }) + const root = _root?.root == null ? "" : _root.root; + // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { return { @@ -1714,7 +1733,7 @@ export class ReportController extends Controller { data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), effectiveDate: salaryPeriod.effectiveDate, - root: agency, + root: root, profile: formattedData, }, }); @@ -1749,7 +1768,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน - isReserve: false, //กรองเฉพาะคนที่ไม่เกษียณ + isRetired: false, //กรองเฉพาะคนที่ไม่เกษียณ }, order: { salaryOrg: { @@ -1759,8 +1778,14 @@ export class ReportController extends Controller { posMasterNo: "ASC", }, }); - - const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + const _root = await this.salaryOrgRepository.findOne({ + where: { + rootId: rootId, + salaryPeriodId: salaryPeriodId, + } + }) + const root = _root?.root == null ? "" : _root.root; + // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ @@ -1795,7 +1820,7 @@ export class ReportController extends Controller { reportName: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - agency: agency, + agency: root, data: formattedData, }, }); @@ -1830,7 +1855,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน - isReserve: true, //กรองเฉพาะคนที่เกษียณ + isRetired: true, //กรองเฉพาะคนที่เกษียณ }, order: { salaryOrg: { @@ -1840,8 +1865,14 @@ export class ReportController extends Controller { posMasterNo: "ASC", }, }); - - const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + const _root = await this.salaryOrgRepository.findOne({ + where: { + rootId: rootId, + salaryPeriodId: salaryPeriodId, + } + }) + const root = _root?.root == null ? "" : _root.root; + // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ @@ -1875,7 +1906,7 @@ export class ReportController extends Controller { reportName: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - agency: agency, + agency: root, data: formattedData, }, }); @@ -1930,7 +1961,14 @@ export class ReportController extends Controller { posMasterNo: "ASC", }, }); - const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root; + const _root = await this.salaryOrgRepository.findOne({ + where: { + rootId: rootId, + salaryPeriodId: salaryPeriodId, + } + }) + const root = _root?.root == null ? "" : _root.root; + // const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root; const formattedData = salaryProfile.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), @@ -1973,7 +2011,7 @@ export class ReportController extends Controller { date: Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)), ), - agency: agency, + agency: root, data: formattedData, }, });