diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 34dcf91f..29d4dd9b 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -20,7 +20,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { ProfileEmployee } from "../entities/ProfileEmployee"; -import { In, IsNull, LessThan, MoreThan } from "typeorm"; +import { In, IsNull, LessThan, MoreThan, Not } from "typeorm"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; import { TenurePositionOfficer } from "../entities/TenurePositionOfficer"; @@ -43,11 +43,8 @@ export class ProfileSalaryController extends Controller { @Get("TenurePositionOfficer") public async cronjobTenurePositionOfficer() { let data: any = []; - const positionOfficer = await this.positionOfficerRepo.find(); - await this.positionOfficerRepo.remove(positionOfficer); - const profile = await this.profileRepo.find({ - where: { id: "46dec43d-2ed7-4f04-9843-dbade7a156c7" }, - }); + await this.positionOfficerRepo.clear(); + const profile = await this.profileRepo.find(); for await (const x of profile) { const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [x.id]); const _position = position.length > 0 ? position[0] : []; @@ -76,10 +73,8 @@ export class ProfileSalaryController extends Controller { Months: ((calDayDiff.days_diff / 30.4375) % 12).toFixed(4), Days: (calDayDiff.days_diff % 30.4375).toFixed(4), }; - console.log(mapData); - return new HttpSuccess(mapData); // data.push(_mapData); - // await this.positionOfficerRepo.save(mapData); + await this.positionOfficerRepo.save(mapData); } // await this.positionOfficerRepo.save(data); @@ -88,8 +83,7 @@ export class ProfileSalaryController extends Controller { @Get("TenurePositionEmployee") public async cronjobTenurePositionEmployee() { let data: any = []; - const positionEmployee = await this.positionEmployeeRepo.find(); - await this.positionEmployeeRepo.remove(positionEmployee); + await this.positionEmployeeRepo.clear(); const profile = await this.profileEmployeeRepo.find(); for await (const x of profile) { const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [x.id]); @@ -129,9 +123,8 @@ export class ProfileSalaryController extends Controller { @Get("TenureLevelOfficer") public async cronjobTenureLevelOfficer() { let data: any = []; - const positionOfficer = await this.levelOfficerRepo.find(); - await this.levelOfficerRepo.remove(positionOfficer); - const profile = await this.profileRepo.find({ relations: ["posLevel"] }); + await this.levelOfficerRepo.clear(); + const profile = await this.profileRepo.find({ relations: ["posLevel", "posType"] }); for await (const x of profile) { const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?)", [x.id]); const _positionLevel = positionLevel.length > 0 ? positionLevel[0] : []; @@ -145,7 +138,11 @@ export class ProfileSalaryController extends Controller { })) : []; const calDayDiff = mapPositionLevel - .filter((curr: any) => curr.positionLevel == (x.posLevel?.posLevelName ?? null)) + .filter( + (curr: any) => + curr.positionLevel == (x.posLevel?.posLevelName ?? null) && + curr.positionType == (x.posType?.posTypeName ?? null), + ) .reduce( (acc: any, curr: any) => { acc.days_diff += Number(curr.days_diff) || 0; @@ -176,8 +173,7 @@ export class ProfileSalaryController extends Controller { @Get("TenureLevelEmployee") public async cronjobTenureLevelEmployee() { let data: any = []; - const positionEmployee = await this.levelEmployeeRepo.find(); - await this.levelEmployeeRepo.remove(positionEmployee); + await this.levelEmployeeRepo.clear(); const profile = await this.profileEmployeeRepo.find({ relations: ["posLevel"] }); for await (const x of profile) { const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?)", [x.id]);