This commit is contained in:
AdisakKanthawilang 2025-07-11 13:08:05 +07:00
parent edbb502a0e
commit 7c324f1f6f

View file

@ -4289,32 +4289,35 @@ export class ReportController extends Controller {
id: salaryPeriodId, id: salaryPeriodId,
}, },
}); });
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); //*****ปิด Throw ทั้งหมดเพราะ FE อยากได้ preview report เปล่าแทน*****
}
// if (!salaryPeriod) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
// }
const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({ const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({
where: { where: {
year: salaryPeriod.year, year: salaryPeriod?.year,
period: "APR", period: "APR",
}, },
}); });
if (!salaryPeriodAPR) { // if (!salaryPeriodAPR) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือนรอบเดือนเมษายน"); // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือนรอบเดือนเมษายน");
} // }
const aprSnap2 = await this.salaryOrgEmployeeRepository.findOne({ const aprSnap2 = await this.salaryOrgEmployeeRepository.findOne({
relations: ["salaryPeriod", "salaryProfiles"], relations: ["salaryPeriod", "salaryProfiles"],
where: { where: {
snapshot: "SNAP2", snapshot: "SNAP2",
rootId: rootId, rootId: rootId,
salaryPeriodId: salaryPeriodAPR.id, salaryPeriodId: salaryPeriodAPR?.id,
}, },
}); });
if (!aprSnap2) { // if (!aprSnap2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} // }
const octSnap1 = await this.salaryOrgEmployeeRepository.findOne({ const octSnap1 = await this.salaryOrgEmployeeRepository.findOne({
relations: ["salaryPeriod", "salaryProfiles"], relations: ["salaryPeriod", "salaryProfiles"],
@ -4326,9 +4329,9 @@ export class ReportController extends Controller {
}, },
}); });
if (!octSnap1) { // if (!octSnap1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} // }
const octSnap2 = await this.salaryOrgEmployeeRepository.findOne({ const octSnap2 = await this.salaryOrgEmployeeRepository.findOne({
relations: ["salaryPeriod", "salaryProfiles"], relations: ["salaryPeriod", "salaryProfiles"],
@ -4340,9 +4343,9 @@ export class ReportController extends Controller {
}, },
}); });
if (!octSnap2) { // if (!octSnap2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} // }
let fullHaftTotalAmount: any = 0; let fullHaftTotalAmount: any = 0;
let fullHaftCount: any = 0; let fullHaftCount: any = 0;
let fullTotalAmount: any = 0; let fullTotalAmount: any = 0;
@ -4400,11 +4403,11 @@ export class ReportController extends Controller {
template: "emp2-01", template: "emp2-01",
reportName: "emp2-01", reportName: "emp2-01",
data: { data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), year: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))): "",
yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice( yearShort: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice(
-2, -2,
), ):"",
agency: octSnap1.root == null ? "" : octSnap1.root, agency: octSnap1?.root == null ? "" : octSnap1.root,
totalUser: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.total.toLocaleString()), totalUser: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.total.toLocaleString()),
totalSalary: totalSalary:
octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toLocaleString()), octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toLocaleString()),
@ -4414,7 +4417,7 @@ export class ReportController extends Controller {
: Extension.ToThaiNumber(octSnap1.sixPercentAmount.toLocaleString()), : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toLocaleString()),
remainingAmountApr: remainingAmountApr:
// aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toLocaleString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย. // aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toLocaleString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย.
aprSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toLocaleString()), aprSnap2 != null && octSnap2 ? Extension.ToThaiNumber(octSnap2?.spentAmount.toLocaleString()): "",
remainingAmountOct: remainingAmountOct:
//octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toLocaleString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค. //octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toLocaleString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค.
octSnap2 == null octSnap2 == null
@ -4424,7 +4427,7 @@ export class ReportController extends Controller {
), ),
totalOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.total.toLocaleString()), //จำนวน(คน)(โควตาเลื่อนขั้นค่าจ้าง) totalOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.total.toLocaleString()), //จำนวน(คน)(โควตาเลื่อนขั้นค่าจ้าง)
fifteenPercentOld: Extension.ToThaiNumber( fifteenPercentOld: Extension.ToThaiNumber(
`${aprSnap2.fifteenPercent.toLocaleString()}.${aprSnap2.fifteenPoint.toLocaleString()}`, `${aprSnap2?.fifteenPercent.toLocaleString()}.${aprSnap2?.fifteenPoint.toLocaleString()}`,
), ),
totalUseOld: totalUseOld:
aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toLocaleString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง) aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toLocaleString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง)
@ -4496,7 +4499,27 @@ export class ReportController extends Controller {
}, },
}, },
}); });
// let octPreviousYear:any = null;
// let octPreviousYear2:any = null;
// if (salaryPeriod?.year) {
// const yearMi1 = salaryPeriod.year - 1;
// const yearMi2 = salaryPeriod.year - 2;
// octPreviousYear = await this.salaryPeriodRepository.findOne({
// where: {
// period: "OCT",
// year: yearMi1,
// },
// });
// octPreviousYear2 = await this.salaryPeriodRepository.findOne({
// where: {
// period: "OCT",
// year: yearMi2,
// },
// });
// }
const octPreviousYear = await this.salaryPeriodRepository.findOne({ const octPreviousYear = await this.salaryPeriodRepository.findOne({
where: { where: {
period: "OCT", period: "OCT",
@ -4510,7 +4533,6 @@ export class ReportController extends Controller {
year: salaryPeriod?.year - 2, year: salaryPeriod?.year - 2,
}, },
}); });
let octPreviousYearProfile: SalaryProfileEmployee[] = []; let octPreviousYearProfile: SalaryProfileEmployee[] = [];
if (octPreviousYear) { if (octPreviousYear) {
octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({
@ -4678,9 +4700,9 @@ export class ReportController extends Controller {
template: "emp2-02", template: "emp2-02",
reportName: "emp2-02", reportName: "emp2-02",
data: { data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), year: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))):"",
yearOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))), yearOld: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))):"",
yearOld2: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 2))), yearOld2: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 2))):"",
agency: _root?.root == null ? "" : _root?.root, agency: _root?.root == null ? "" : _root?.root,
data: formattedData, data: formattedData,
}, },