fix report 25

This commit is contained in:
AdisakKanthawilang 2024-04-10 11:16:19 +07:00
parent e4710ed004
commit 5cd2a3ff3d

View file

@ -5178,7 +5178,7 @@ export class ReportController extends Controller {
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
isRetired: true,
type: "NONE",
isNext: false,
salaryOrg: {
snapshot: "SNAP2",
rootId: rootId,
@ -5782,29 +5782,29 @@ export class ReportController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
}
let perviousYearAPR:any;
let perviousYearOCT:any;
let salaryProfilePerviousAPR:any;
let salaryProfilePerviousOCT:any;
//งวดปีก่อนหน้า
const perviousYearAPR = await this.salaryPeriodRepository.findOne({
perviousYearAPR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriodOCT.year - 1,
},
});
if (!perviousYearAPR) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือนก่อนหน้า");
}
const perviousYearOCT = await this.salaryPeriodRepository.findOne({
perviousYearOCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriodOCT.year - 1,
},
});
if (!perviousYearOCT) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือนก่อนหน้า");
}
//ปีก่อนหน้า
const salaryProfilePerviousAPR = await this.salaryProfileEmployeeRepository.find({
salaryProfilePerviousAPR = await this.salaryProfileEmployeeRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
@ -5818,11 +5818,7 @@ export class ReportController extends Controller {
},
});
if (!salaryProfilePerviousAPR) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const salaryProfilePerviousOCT = await this.salaryProfileEmployeeRepository.find({
salaryProfilePerviousOCT = await this.salaryProfileEmployeeRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
@ -5836,10 +5832,6 @@ export class ReportController extends Controller {
},
});
if (!salaryProfilePerviousOCT) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
//ปีปัจุบัน
const salaryProfileCurrentAPR = await this.salaryProfileEmployeeRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
@ -5881,12 +5873,21 @@ export class ReportController extends Controller {
const formattedData = salaryProfileCurrentOCT.map((profile, index) => {
//งวดปีก่อนหน้า
const matchedAPRProfileOld = salaryProfilePerviousAPR.find(
(aprProfile_old) => aprProfile_old.citizenId === profile.citizenId,
);
const matchedOCTProfileOld = salaryProfilePerviousOCT.find(
(octProfile_old) => octProfile_old.citizenId === profile.citizenId,
);
let matchedAPRProfileOld: SalaryProfile | null = null;
let matchedOCTProfileOld: SalaryProfile | null = null;
if (salaryProfilePerviousAPR && salaryProfilePerviousAPR.length > 0) {
matchedAPRProfileOld = salaryProfilePerviousAPR.find(
(aprProfile_old: SalaryProfile) => aprProfile_old.citizenId === profile.citizenId,
);
}
if (salaryProfilePerviousOCT && salaryProfilePerviousOCT.length > 0) {
matchedOCTProfileOld = salaryProfilePerviousOCT.find(
(octProfile_old: SalaryProfile) => octProfile_old.citizenId === profile.citizenId,
);
}
const amountUseAPR_Old = matchedAPRProfileOld ? matchedAPRProfileOld.amountUse : 0;
const amountUseOCT_Old = matchedOCTProfileOld ? matchedOCTProfileOld.amountUse : 0;
const amountUseOld = amountUseAPR_Old + amountUseOCT_Old;