Edit SLR_020
This commit is contained in:
parent
7d99487523
commit
309bf670bf
1 changed files with 63 additions and 42 deletions
|
|
@ -178,52 +178,73 @@ export class SalaryPeriodController extends Controller {
|
|||
@Query("year") year: number = 2024,
|
||||
) {
|
||||
//ssss total ผิด
|
||||
let salaryPeriod: any;
|
||||
let total: any;
|
||||
if (year != 0) {
|
||||
const startOfYear = new Date(year, 0, 1);
|
||||
const endOfYear = new Date(year, 11, 31);
|
||||
[salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
where: {
|
||||
effectiveDate: Between(startOfYear, endOfYear),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
[salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
}
|
||||
// let salaryPeriod: any;
|
||||
// let total: any;
|
||||
// if (year != 0) {
|
||||
// const startOfYear = new Date(year, 0, 1);
|
||||
// const endOfYear = new Date(year, 11, 31);
|
||||
// [salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
|
||||
// skip: (page - 1) * pageSize,
|
||||
// take: pageSize,
|
||||
// where: {
|
||||
// effectiveDate: Between(startOfYear, endOfYear),
|
||||
// },
|
||||
// });
|
||||
// } else {
|
||||
// [salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
|
||||
// skip: (page - 1) * pageSize,
|
||||
// take: pageSize,
|
||||
// });
|
||||
// }
|
||||
|
||||
if (keyword != undefined && keyword !== "") {
|
||||
const filteredSalaryPeriod = salaryPeriod.filter(
|
||||
(x: any) =>
|
||||
x.period.toString().includes(keyword) ||
|
||||
x.isActive.toString().includes(keyword) ||
|
||||
x.effectiveDate.getFullYear().toString().includes(keyword),
|
||||
);
|
||||
// if (keyword != undefined && keyword !== "") {
|
||||
// const filteredSalaryPeriod = salaryPeriod.filter(
|
||||
// (x: any) =>
|
||||
// x.period.toString().includes(keyword) ||
|
||||
// x.isActive.toString().includes(keyword) ||
|
||||
// x.effectiveDate.getFullYear().toString().includes(keyword),
|
||||
// );
|
||||
|
||||
const formattedData = filteredSalaryPeriod.map((item: any) => ({
|
||||
id: item.id,
|
||||
period: item.period,
|
||||
isActive: item.isActive,
|
||||
effectiveDate: item.effectiveDate,
|
||||
status: item.status,
|
||||
}));
|
||||
// const formattedData = filteredSalaryPeriod.map((item: any) => ({
|
||||
// id: item.id,
|
||||
// period: item.period,
|
||||
// isActive: item.isActive,
|
||||
// effectiveDate: item.effectiveDate,
|
||||
// status: item.status,
|
||||
// }));
|
||||
// return new HttpSuccess({ data: formattedData, total: formattedData.length });
|
||||
// }
|
||||
|
||||
return new HttpSuccess({ data: formattedData, total: formattedData.length });
|
||||
}
|
||||
// const formattedData = salaryPeriod.map((item: any) => ({
|
||||
// id: item.id,
|
||||
// period: item.period,
|
||||
// isActive: item.isActive,
|
||||
// effectiveDate: item.effectiveDate,
|
||||
// status: item.status,
|
||||
// }));
|
||||
// return new HttpSuccess({ data: formattedData, total });
|
||||
|
||||
const [salaryPeriod, total] = await AppDataSource.getRepository(SalaryPeriod)
|
||||
.createQueryBuilder("SalaryPeriod")
|
||||
.andWhere(year != 0 ? "SalaryPeriod.year LIKE :year" : "1=1", {year: `%${year}%`,})
|
||||
.orWhere("SalaryPeriod.period LIKE :keyword", { keyword: `%${keyword}%` })
|
||||
.orWhere("SalaryPeriod.isActive LIKE :keyword", { keyword: `%${keyword}%` })
|
||||
.orWhere("SalaryPeriod.year LIKE :keyword", { keyword: `%${year}%` })
|
||||
.select([
|
||||
"SalaryPeriod.id",
|
||||
"SalaryPeriod.period",
|
||||
"SalaryPeriod.isActive",
|
||||
"SalaryPeriod.effectiveDate",
|
||||
"SalaryPeriod.status",
|
||||
"SalaryPeriod.year",
|
||||
])
|
||||
.orderBy("SalaryPeriod.effectiveDate", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: salaryPeriod, total });
|
||||
|
||||
const formattedData = salaryPeriod.map((item: any) => ({
|
||||
id: item.id,
|
||||
period: item.period,
|
||||
isActive: item.isActive,
|
||||
effectiveDate: item.effectiveDate,
|
||||
status: item.status,
|
||||
}));
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue