diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 051b3ea..9e5c0e4 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1210,13 +1210,13 @@ export class ReportController extends Controller { type: Not(In(["NONE", "PENDING"])), }, }); - const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))); - const yearIncrease1 = Extension.ToThaiNumber( + const year = salaryPeriod.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))):""; + const yearIncrease1 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 2)), - ); - const yearIncrease2 = Extension.ToThaiNumber( + ):""; + const yearIncrease2 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)), - ); + ):""; const fifteenPercent_Group1 = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? "๐" @@ -1240,8 +1240,8 @@ export class ReportController extends Controller { year: year, yearIncrease1: yearIncrease1, yearIncrease2: yearIncrease2, - yearIncreaseSlice: yearIncrease2.slice(-2), - yearSlice: year.slice(-2), + yearIncreaseSlice: yearIncrease2?yearIncrease2.slice(-2):"", + yearSlice: year?year.slice(-2):"", point: fifteenPercent_Group1 + fifteenPoint_Group1, pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, root: salaryOrg?.root, @@ -1352,7 +1352,8 @@ export class ReportController extends Controller { }, }); //รอบตุลา - } else if (salaryOrg && salaryPeriod.period === "OCT") { + } else if (salaryPeriod.period === "OCT") { + // find period APR const salaryPeriod_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -1369,7 +1370,7 @@ export class ReportController extends Controller { group: convertGroup, }, }); - + const salaryProfile_APR = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg_APR?.id, @@ -1412,7 +1413,7 @@ export class ReportController extends Controller { where: { salaryPeriodId: salaryPeriodIncrease1_APR?.id, // rootId: rootId, - root: salaryOrg.root, + root: salaryOrg?.root, snapshot: "SNAP1", group: convertGroup, }, @@ -1425,13 +1426,12 @@ export class ReportController extends Controller { where: { salaryPeriodId: salaryPeriodIncrease1_OCT?.id, // rootId: rootId, - root: salaryOrg.root, + root: salaryOrg?.root, snapshot: "SNAP1", group: convertGroup, }, }); } - const salaryProfile1 = await this.salaryProfileRepository.find({ where: { salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), @@ -1454,14 +1454,13 @@ export class ReportController extends Controller { isActive: true, }, }); - let salaryOrg2_APR = null; if (salaryPeriodIncrease2_APR) { salaryOrg2_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, // rootId: rootId, - root: salaryOrg.root, + root: salaryOrg?.root, snapshot: "SNAP1", group: convertGroup, }, @@ -1474,13 +1473,12 @@ export class ReportController extends Controller { where: { salaryPeriodId: salaryPeriodIncrease2_OCT?.id, // rootId: rootId, - root: salaryOrg.root, + root: salaryOrg?.root, snapshot: "SNAP1", group: convertGroup, }, }); } - const salaryProfile2 = await this.salaryProfileRepository.find({ //เอามาหาว่าทั้งปีได้เลื่อนขั้นไหม where: { @@ -1488,14 +1486,13 @@ export class ReportController extends Controller { type: Not(In(["NONE", "PENDING"])), }, }); - - const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))); - const yearIncrease1 = Extension.ToThaiNumber( + const year = salaryPeriod.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))):""; + const yearIncrease1 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 2)), - ); - const yearIncrease2 = Extension.ToThaiNumber( + ):""; + const yearIncrease2 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)), - ); + ):""; const fifteenPercent = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? "๐" @@ -1519,8 +1516,8 @@ export class ReportController extends Controller { year: year, yearIncrease1: yearIncrease1, yearIncrease2: yearIncrease2, - yearIncreaseSlice: yearIncrease2.slice(-2), - yearSlice: year.slice(-2), + yearIncreaseSlice: yearIncrease2?yearIncrease2.slice(-2):"", + yearSlice: year?year.slice(-2):"", point: fifteenPercent + fifteenPoint, pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, root: salaryOrg?.root,