diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 57ef9d1..d96a195 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -77,7 +77,6 @@ export class SalaryPeriodController extends Controller { where: { id: id, }, - select: ["total", "fifteenPercent"], relations: ["salaryProfiles"], }); if (!salaryOrg) { @@ -350,18 +349,16 @@ export class SalaryPeriodController extends Controller { @Request() request: { user: Record }, ) { const salaryPeriod = Object.assign(new SalaryPeriod(), requestBody); - + const chk_toUpper = ["SPECIAL", "APR", "OCT"]; if (!chk_toUpper.includes(salaryPeriod.period.toUpperCase())) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง"); } - const startOfYear = new Date(salaryPeriod.effectiveDate.getFullYear(), 0, 1); - const endOfYear = new Date(salaryPeriod.effectiveDate.getFullYear(), 11, 31); const chk_period = await this.salaryPeriodRepository.findOne({ where: { period: salaryPeriod.period, - effectiveDate: Between(startOfYear, endOfYear), + year: requestBody.year, }, }); @@ -405,14 +402,11 @@ export class SalaryPeriodController extends Controller { if (!chk_toUpper.includes(requestBody.period.toUpperCase())) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง"); } - - const startOfYear = new Date(requestBody.effectiveDate.getFullYear(), 0, 1); - const endOfYear = new Date(requestBody.effectiveDate.getFullYear(), 11, 31); const chk_period = await this.salaryPeriodRepository.findOne({ where: { period: requestBody.period, id: Not(id), - effectiveDate: Between(startOfYear, endOfYear), + year: requestBody.year, }, }); @@ -462,7 +456,7 @@ export class SalaryPeriodController extends Controller { async GetSalaryPeriod_ById(@Path() id: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: id }, - select: ["id", "period", "isActive", "effectiveDate", "isActive", "status"], + select: ["id", "period", "isActive", "effectiveDate", "isActive", "status", "year"], }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); @@ -483,61 +477,14 @@ export class SalaryPeriodController extends Controller { @Query("keyword") keyword?: string, @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, - // }); - // } - - // 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, - // })); - // 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}%`,}) + .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.id", "SalaryPeriod.period", "SalaryPeriod.isActive", "SalaryPeriod.effectiveDate", @@ -551,5 +498,4 @@ export class SalaryPeriodController extends Controller { return new HttpSuccess({ data: salaryPeriod, total }); } - } diff --git a/src/entities/SalaryPeriod.ts b/src/entities/SalaryPeriod.ts index aafa67a..69aa9c8 100644 --- a/src/entities/SalaryPeriod.ts +++ b/src/entities/SalaryPeriod.ts @@ -49,6 +49,9 @@ export class CreateSalaryPeriod { @Column() effectiveDate: Date; + + @Column() + year: number; } export class UpdateSalaryPeriod { @@ -60,4 +63,7 @@ export class UpdateSalaryPeriod { @Column() effectiveDate: Date; + + @Column() + year: number; }