เพิ่มปี
This commit is contained in:
parent
9b3028eb8a
commit
0a8cccc3aa
2 changed files with 12 additions and 60 deletions
|
|
@ -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<string, any> },
|
||||
) {
|
||||
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 });
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue