diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts index feecfd8..089e22b 100644 --- a/src/controllers/SalaryEmployeeController.ts +++ b/src/controllers/SalaryEmployeeController.ts @@ -245,9 +245,11 @@ export class SalaryEmployeeController extends Controller { @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { await new permission().PermissionList(request, "SYS_WAGE_CHART_EMP"); - const [salaryEmployee, total] = await AppDataSource.getRepository(SalaryEmployee) + let query = await AppDataSource.getRepository(SalaryEmployee) .createQueryBuilder("salaryEmployee") .andWhere( new Brackets((qb) => { @@ -257,12 +259,24 @@ export class SalaryEmployeeController extends Controller { ); }), ) - .orderBy("salaryEmployee.isActive", "DESC") - .addOrderBy("salaryEmployee.group", "ASC") + + if (sortBy) { + query = query.orderBy( + `salaryEmployee.${sortBy}`, + descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy("salaryEmployee.isActive", "DESC") + .addOrderBy("salaryEmployee.group", "ASC") + } + + const [salaryEmployee, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + + const _salaryEmployee = salaryEmployee.map((item) => ({ id: item.id, name: item.name, diff --git a/src/controllers/SalaryFormulaEmployeeController.ts b/src/controllers/SalaryFormulaEmployeeController.ts index d35b899..3f64005 100644 --- a/src/controllers/SalaryFormulaEmployeeController.ts +++ b/src/controllers/SalaryFormulaEmployeeController.ts @@ -237,8 +237,10 @@ export class SalaryFormulaEmployeeController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("posTypeId") posTypeId?: string, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { - const [getFormula, total] = await AppDataSource.getRepository(SalaryFormulaEmployee) + let query = await AppDataSource.getRepository(SalaryFormulaEmployee) .createQueryBuilder("salaryFormulaEmployee") .leftJoinAndSelect("salaryFormulaEmployee.salaryEmployee", "salaryEmployee") .leftJoinAndSelect("salaryFormulaEmployee.posType", "posType") @@ -269,10 +271,42 @@ export class SalaryFormulaEmployeeController extends Controller { ) .andWhere(posTypeId == undefined ? "1=1" : { posTypeId: Like(`%${posTypeId}%`) }) .orderBy("salaryFormulaEmployee.lastUpdatedAt", "DESC") + + if (sortBy) { + if(sortBy === "group"){ + query = query.orderBy( + `salaryEmployee.group`, + descending ? "DESC" : "ASC" + ); + }else if(sortBy === "posLevel"){ + query = query.orderBy( + `posLevel.posLevelName`, + descending ? "DESC" : "ASC" + ); + }else if(sortBy === "posType"){ + query = query.orderBy( + `posType.posTypeName`, + descending ? "DESC" : "ASC" + ); + // }else if(sortBy === "salaryEmployeeMin"){ + // query = query.orderBy( + // `salaryEmployee.group`, + // descending ? "DESC" : "ASC" + // ); + }else{ + query = query.orderBy( + `salaryFormulaEmployee.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + } + + const [getFormula, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + const mapFormula = getFormula.map((item) => ({ id: item.id, posLevel: diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index d7ec146..19ccedd 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -1560,6 +1560,8 @@ export class SalaryPeriodController extends Controller { keyword?: string; type?: any; isRetire?: string | null; + sortBy?: string; + descending?: boolean; }, ) { await new permission().PermissionList(request, "SYS_SALARY_OFFICER"); @@ -1572,7 +1574,7 @@ export class SalaryPeriodController extends Controller { if (!salaryOrg) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } - const [salaryProfile, total] = await AppDataSource.getRepository(SalaryProfile) + let query = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("profile") .andWhere( new Brackets((qb) => { @@ -1686,12 +1688,28 @@ export class SalaryPeriodController extends Controller { child4: _data.child4, }, ) - .orderBy("profile.rootOrder", "ASC") - .addOrderBy("profile.child1Order", "ASC") - .addOrderBy("profile.child2Order", "ASC") - .addOrderBy("profile.child3Order", "ASC") - .addOrderBy("profile.child4Order", "ASC") - .addOrderBy("profile.posMasterNo", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posExecutive"){ + query = query + .orderBy( `profile.posExecutive`,body.descending ? "DESC" : "ASC") + .addOrderBy( `profile.positionExecutiveField`,body.descending ? "DESC" : "ASC"); + }else{ + query = query.orderBy( + `profile.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("profile.rootOrder", "ASC") + .addOrderBy("profile.child1Order", "ASC") + .addOrderBy("profile.child2Order", "ASC") + .addOrderBy("profile.child3Order", "ASC") + .addOrderBy("profile.child4Order", "ASC") + .addOrderBy("profile.posMasterNo", "ASC") + } + + const [salaryProfile, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); @@ -2499,9 +2517,11 @@ export class SalaryPeriodController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("year") year: number = 2024, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { await new permission().PermissionList(request, "SYS_SALARY_ROUND"); - const [salaryPeriod, total] = await AppDataSource.getRepository(SalaryPeriod) + let query = await AppDataSource.getRepository(SalaryPeriod) .createQueryBuilder("salaryPeriod") .andWhere(year != 0 ? "salaryPeriod.year LIKE :year" : "1=1", { year: `${year}` }) .orWhere("salaryPeriod.period LIKE :keyword", { keyword: `${keyword}` }) @@ -2516,8 +2536,18 @@ export class SalaryPeriodController extends Controller { "salaryPeriod.year", "salaryPeriod.revisionId", ]) - .orderBy("salaryPeriod.year", "DESC") - .addOrderBy("salaryPeriod.effectiveDate", "DESC") + + if (sortBy) { + query = query.orderBy( + `salaryPeriod.${sortBy}`, + descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy("salaryPeriod.year", "DESC") + .addOrderBy("salaryPeriod.effectiveDate", "DESC") + } + + const [salaryPeriod, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index 5ec3200..86e9702 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -1080,6 +1080,8 @@ export class SalaryPeriodEmployeeController extends Controller { keyword?: string; type?: any; isRetire?: string | null; + sortBy?: string, + descending?: boolean, }, ) { await new permission().PermissionList(request, "SYS_WAGE"); @@ -1091,7 +1093,7 @@ export class SalaryPeriodEmployeeController extends Controller { if (!salaryOrg) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } - const [salaryProfile, total] = await AppDataSource.getRepository(SalaryProfileEmployee) + let query = await AppDataSource.getRepository(SalaryProfileEmployee) .createQueryBuilder("profile") .andWhere( new Brackets((qb) => { @@ -1156,8 +1158,24 @@ export class SalaryPeriodEmployeeController extends Controller { ); }), ) - .orderBy("profile.citizenId", "ASC") - .addOrderBy("profile.isReserve", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posLevel"){ + query = query + .orderBy( `profile.posTypeShort`,body.descending ? "DESC" : "ASC") + .addOrderBy( `profile.posLevel`,body.descending ? "DESC" : "ASC"); + }else{ + query = query.orderBy( + `profile.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("profile.citizenId", "ASC") + .addOrderBy("profile.isReserve", "ASC") + } + + const [salaryProfile, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount();