snap salary(ยังไม่เสร็จ)
This commit is contained in:
parent
5f222498cb
commit
f0e6ca6a56
7 changed files with 476 additions and 125 deletions
|
|
@ -15,7 +15,7 @@ import {
|
|||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { DeepPartial, In, IsNull, Not, Between, MoreThan } from "typeorm";
|
||||
import { DeepPartial, In, IsNull, Not, Between, MoreThan, Like, Brackets } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -46,14 +46,13 @@ export class SalaryPeriodController extends Controller {
|
|||
* @summary SLR_030 - รอบล่าสุด #29
|
||||
*
|
||||
*/
|
||||
@Get("latest/{id}")
|
||||
async GetGroupSalaryPeriodLatest(@Path() id: string) {
|
||||
//xxxx รอบเงินเดือนล่าสุดยังไม่แน่ใจเอาจากรอบไหน
|
||||
//xxxx หาสังกัดคนนั้น
|
||||
// const dateNow = new Date();
|
||||
@Post("latest")
|
||||
async GetGroupSalaryPeriodLatest(
|
||||
@Body() body: { rootId: string; salaryPeriodId: string; snapshot: string },
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
// effectiveDate: MoreThan(dateNow),
|
||||
id: body.salaryPeriodId,
|
||||
isActive: true,
|
||||
},
|
||||
order: { effectiveDate: "DESC" },
|
||||
|
|
@ -65,13 +64,33 @@ export class SalaryPeriodController extends Controller {
|
|||
|
||||
const data = {
|
||||
group1id:
|
||||
salaryPeriod.salaryOrgs.find((x) => x.group == "GROUP1" && x.rootId == id) == null
|
||||
salaryPeriod.salaryOrgs.find(
|
||||
(x) =>
|
||||
x.group == "GROUP1" &&
|
||||
x.rootId == body.rootId &&
|
||||
x.snapshot == body.snapshot.toLocaleUpperCase(),
|
||||
) == null
|
||||
? null
|
||||
: salaryPeriod.salaryOrgs.find((x) => x.group == "GROUP1" && x.rootId == id)?.id,
|
||||
: salaryPeriod.salaryOrgs.find(
|
||||
(x) =>
|
||||
x.group == "GROUP1" &&
|
||||
x.rootId == body.rootId &&
|
||||
x.snapshot == body.snapshot.toLocaleUpperCase(),
|
||||
)?.id,
|
||||
group2id:
|
||||
salaryPeriod.salaryOrgs.find((x) => x.group == "GROUP2" && x.rootId == id) == null
|
||||
salaryPeriod.salaryOrgs.find(
|
||||
(x) =>
|
||||
x.group == "GROUP2" &&
|
||||
x.rootId == body.rootId &&
|
||||
x.snapshot == body.snapshot.toLocaleUpperCase(),
|
||||
) == null
|
||||
? null
|
||||
: salaryPeriod.salaryOrgs.find((x) => x.group == "GROUP2" && x.rootId == id)?.id,
|
||||
: salaryPeriod.salaryOrgs.find(
|
||||
(x) =>
|
||||
x.group == "GROUP2" &&
|
||||
x.rootId == body.rootId &&
|
||||
x.snapshot == body.snapshot.toLocaleUpperCase(),
|
||||
)?.id,
|
||||
effectiveDate: salaryPeriod.effectiveDate,
|
||||
period: salaryPeriod.period,
|
||||
};
|
||||
|
|
@ -164,36 +183,62 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
//Salary
|
||||
const salarys = await this.salaryRepository.findOne({
|
||||
where: {
|
||||
posTypeId : Level.posTypeId,
|
||||
posLevelId : Level.id,
|
||||
isActive : true
|
||||
}
|
||||
where: {
|
||||
posTypeId: Level.posTypeId,
|
||||
posLevelId: Level.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
//SalaryRank
|
||||
const SalaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryId: salarys?.id,
|
||||
salary: salaryProfile.amount
|
||||
}
|
||||
});
|
||||
if (!SalaryRanks) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบผังเงินเดือน");
|
||||
if (!salarys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
}
|
||||
//SalaryRank
|
||||
let salaryRanks: any = null;
|
||||
if (salaryProfile.amount != null) {
|
||||
salaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryId: salarys.id,
|
||||
salary: salaryProfile.amount,
|
||||
},
|
||||
});
|
||||
}
|
||||
if (salaryProfile.type == "NONE") {
|
||||
|
||||
if (salaryProfile.type == "NONE") {
|
||||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = salaryProfile.amount;
|
||||
} else if (salaryProfile.type == "HAFT") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryHalfSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryHalf) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryHalf);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryHalf;
|
||||
} else if (salaryProfile.type == "FULL") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryFull) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFull);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryFullSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFull == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFull - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFull;
|
||||
} else if (salaryProfile.type == "FULLHAFT") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullHalfSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryFullHalf) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFullHalf);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryFullHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFullHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFullHalf;
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
|
|
@ -264,34 +309,59 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
//Salary
|
||||
const salarys = await this.salaryRepository.findOne({
|
||||
where: {
|
||||
posTypeId : Level.posTypeId,
|
||||
posLevelId : Level.id,
|
||||
isActive : true
|
||||
}
|
||||
where: {
|
||||
posTypeId: Level.posTypeId,
|
||||
posLevelId: Level.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
if (!salarys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
}
|
||||
//SalaryRank
|
||||
const SalaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryId: salarys?.id,
|
||||
salary: salaryProfile.amount
|
||||
}
|
||||
});
|
||||
|
||||
let salaryRanks: any = null;
|
||||
if (salaryProfile.amount != null) {
|
||||
salaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryId: salarys.id,
|
||||
salary: salaryProfile.amount,
|
||||
},
|
||||
});
|
||||
}
|
||||
if (body.type == "NONE") {
|
||||
|
||||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = salaryProfile.amount;
|
||||
} else if (body.type == "HAFT") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryHalfSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryHalf) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryHalf);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryHalf;
|
||||
} else if (body.type == "FULL") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryFull) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFull);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryFullSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFull == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFull - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFull;
|
||||
} else if (body.type == "FULLHAFT") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullHalfSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryFullHalf) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFullHalf);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryFullHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFullHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFullHalf;
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
|
@ -319,32 +389,44 @@ export class SalaryPeriodController extends Controller {
|
|||
if (!salaryOrg) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
|
||||
const [salaryProfile, total] = await AppDataSource.getRepository(SalaryProfile)
|
||||
.createQueryBuilder("profile")
|
||||
.andWhere({
|
||||
salaryOrgId: salaryOrg.id,
|
||||
})
|
||||
.andWhere(body.type != null && body.type != "" ? "profile.type LIKE :type" : "1=1", {
|
||||
type: `%${body.type}%`,
|
||||
})
|
||||
//xxxx รอ fe ว่าแสดงค่าไหนบ่างใหเfilterเฉพาะค่านั้น
|
||||
.orWhere("profile.posMasterNoPrefix LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.posMasterNo LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.posMasterNoSuffix LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.orgShortName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.citizenId LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.posType LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.posLevel LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.posExecutive LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.amount LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.amountSpecial LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.amountUse LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.positionSalaryAmount LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.andWhere(body.type != null && body.type != "" ? "profile.type LIKE :type" : "1=1", {
|
||||
type: `%${body.type.toUpperCase()}%`,
|
||||
})
|
||||
.andWhere({
|
||||
salaryOrgId: salaryOrg.id,
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere("profile.posMasterNoPrefix LIKE :keyword", {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere("profile.posMasterNo LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.posMasterNoSuffix LIKE :keyword", {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere("profile.orgShortName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.citizenId LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.posType LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.posLevel LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
// .orWhere("profile.posExecutive LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.amount LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.amountSpecial LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.amountUse LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.positionSalaryAmount LIKE :keyword", {
|
||||
keyword: `%${body.keyword}%`,
|
||||
});
|
||||
}),
|
||||
);
|
||||
}),
|
||||
)
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
|
|
@ -399,52 +481,79 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfile = Object.assign(new SalaryProfile(), requestBody);
|
||||
salaryProfile.type = salaryProfile.type.toUpperCase();
|
||||
//Type & Level
|
||||
const Type = await this.posTypeRepository.findOne({
|
||||
const type = await this.posTypeRepository.findOne({
|
||||
where: {
|
||||
posTypeName: salaryProfile.posType,
|
||||
},
|
||||
});
|
||||
if (!Type) {
|
||||
if (!type) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทตำแหน่ง");
|
||||
}
|
||||
const Level = await this.posLevelRepository.findOne({
|
||||
const level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posTypeId: type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
if (!level) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
}
|
||||
//Salary
|
||||
const salarys = await this.salaryRepository.findOne({
|
||||
where: {
|
||||
posTypeId : Level.posTypeId,
|
||||
posLevelId : Level.id,
|
||||
isActive : true
|
||||
}
|
||||
where: {
|
||||
posTypeId: level.posTypeId,
|
||||
posLevelId: level.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
if (!salarys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
|
||||
}
|
||||
//SalaryRank
|
||||
const SalaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryId: salarys?.id,
|
||||
salary: salaryProfile.amount
|
||||
}
|
||||
});
|
||||
let salaryRanks: any = null;
|
||||
if (salaryProfile.amount != null) {
|
||||
salaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: {
|
||||
salaryId: salarys.id,
|
||||
salary: salaryProfile.amount,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (salaryProfile.type == "NONE") {
|
||||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = salaryProfile.amount;
|
||||
} else if (salaryProfile.type == "HAFT") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryHalfSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryHalf) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryHalf);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryHalf;
|
||||
} else if (salaryProfile.type == "FULL") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryFull) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFull);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryFullSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFull == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFull - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFull;
|
||||
} else if (salaryProfile.type == "FULLHAFT") {
|
||||
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullHalfSpecial);
|
||||
salaryProfile.amountUse = Number(SalaryRanks?.salaryFullHalf) - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFullHalf);
|
||||
salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryFullHalfSpecial;
|
||||
salaryProfile.amountUse =
|
||||
salaryRanks == null ||
|
||||
salaryProfile == null ||
|
||||
salaryRanks.salaryFullHalf == null ||
|
||||
salaryProfile.amount == null
|
||||
? 0
|
||||
: salaryRanks.salaryFullHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFullHalf;
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
|
@ -563,9 +672,9 @@ export class SalaryPeriodController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
|
||||
}
|
||||
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: { salaryPeriodId: SalaryPeriod.id }
|
||||
})
|
||||
if(SalaryOrg){
|
||||
where: { salaryPeriodId: SalaryPeriod.id },
|
||||
});
|
||||
if (SalaryOrg) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||
}
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
||||
|
|
@ -583,7 +692,16 @@ 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", "year"],
|
||||
select: [
|
||||
"id",
|
||||
"period",
|
||||
"isActive",
|
||||
"effectiveDate",
|
||||
"isActive",
|
||||
"status",
|
||||
"year",
|
||||
"revisionId",
|
||||
],
|
||||
});
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
|
||||
|
|
@ -605,24 +723,152 @@ export class SalaryPeriodController extends Controller {
|
|||
@Query("year") year: number = 2024,
|
||||
) {
|
||||
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}%` })
|
||||
.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",
|
||||
"salaryPeriod.id",
|
||||
"salaryPeriod.period",
|
||||
"salaryPeriod.isActive",
|
||||
"salaryPeriod.effectiveDate",
|
||||
"salaryPeriod.status",
|
||||
"salaryPeriod.year",
|
||||
"salaryPeriod.revisionId",
|
||||
])
|
||||
.orderBy("SalaryPeriod.effectiveDate", "DESC")
|
||||
.orderBy("salaryPeriod.effectiveDate", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: salaryPeriod, total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการรอบเงินเดือน
|
||||
*
|
||||
* @summary SLR_020 - รายการรอบเงินเดือน #20
|
||||
*
|
||||
*/
|
||||
@Get("snapshot/{snaphot}/{salaryPeriodId}")
|
||||
async SnapshotSalary(
|
||||
@Path() snaphot: string,
|
||||
salaryPeriodId: string,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
snaphot = snaphot.toLocaleUpperCase();
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: salaryPeriodId },
|
||||
});
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการสร้างเงินเดือน");
|
||||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot },
|
||||
});
|
||||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
|
||||
let orgs: any;
|
||||
let orgProfiles: any;
|
||||
let revisionId: any;
|
||||
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snaphot;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
}),
|
||||
);
|
||||
|
||||
let salaryProfileOld: SalaryProfile[] = [];
|
||||
if (snaphot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgRepository.findOne({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
if (salaryOrgOld != null) salaryProfileOld = salaryOrgOld.salaryProfiles;
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
orgProfiles.map(async (profile: any) => {
|
||||
let group = "GROUP1";
|
||||
if (
|
||||
(profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") ||
|
||||
(profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") ||
|
||||
(profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") ||
|
||||
(profile.posType == "อำนวยการ" && profile.posLevel == "สูง") ||
|
||||
(profile.posType == "บริหาร" && profile.posLevel == "ต้น") ||
|
||||
(profile.posType == "บริหาร" && profile.posLevel == "สูง")
|
||||
) {
|
||||
group = "GROUP2";
|
||||
}
|
||||
const salaryOrgNew = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: profile.rootId,
|
||||
snapshot: snaphot,
|
||||
group: group,
|
||||
},
|
||||
});
|
||||
|
||||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
|
||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
|
||||
if (snaphot == "SNAP2") {
|
||||
const salaryOld = salaryProfileOld.find(
|
||||
(x) => x.citizenId == salaryProfileNew.citizenId,
|
||||
);
|
||||
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
|
||||
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
|
||||
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
|
||||
salaryProfileNew.positionSalaryAmount =
|
||||
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfileNew);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
const salaryOrgNew = await this.salaryOrgRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue