เพิ่มปี

This commit is contained in:
Kittapath 2024-02-27 11:27:12 +07:00
parent 9b3028eb8a
commit 0a8cccc3aa
2 changed files with 12 additions and 60 deletions

View file

@ -77,7 +77,6 @@ export class SalaryPeriodController extends Controller {
where: { where: {
id: id, id: id,
}, },
select: ["total", "fifteenPercent"],
relations: ["salaryProfiles"], relations: ["salaryProfiles"],
}); });
if (!salaryOrg) { if (!salaryOrg) {
@ -356,12 +355,10 @@ export class SalaryPeriodController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง"); 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({ const chk_period = await this.salaryPeriodRepository.findOne({
where: { where: {
period: salaryPeriod.period, 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())) { if (!chk_toUpper.includes(requestBody.period.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง"); 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({ const chk_period = await this.salaryPeriodRepository.findOne({
where: { where: {
period: requestBody.period, period: requestBody.period,
id: Not(id), 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) { async GetSalaryPeriod_ById(@Path() id: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({ const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id }, where: { id: id },
select: ["id", "period", "isActive", "effectiveDate", "isActive", "status"], select: ["id", "period", "isActive", "effectiveDate", "isActive", "status", "year"],
}); });
if (!salaryPeriod) { if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
@ -483,56 +477,9 @@ export class SalaryPeriodController extends Controller {
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
@Query("year") year: number = 2024, @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) const [salaryPeriod, total] = await AppDataSource.getRepository(SalaryPeriod)
.createQueryBuilder("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.period LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("SalaryPeriod.isActive LIKE :keyword", { keyword: `%${keyword}%` }) .orWhere("SalaryPeriod.isActive LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("SalaryPeriod.year LIKE :keyword", { keyword: `%${year}%` }) .orWhere("SalaryPeriod.year LIKE :keyword", { keyword: `%${year}%` })
@ -551,5 +498,4 @@ export class SalaryPeriodController extends Controller {
return new HttpSuccess({ data: salaryPeriod, total }); return new HttpSuccess({ data: salaryPeriod, total });
} }
} }

View file

@ -49,6 +49,9 @@ export class CreateSalaryPeriod {
@Column() @Column()
effectiveDate: Date; effectiveDate: Date;
@Column()
year: number;
} }
export class UpdateSalaryPeriod { export class UpdateSalaryPeriod {
@ -60,4 +63,7 @@ export class UpdateSalaryPeriod {
@Column() @Column()
effectiveDate: Date; effectiveDate: Date;
@Column()
year: number;
} }