hrms-api-salary/src/controllers/TumReportController.ts

353 lines
14 KiB
TypeScript
Raw Normal View History

2024-03-28 18:15:40 +07:00
import {
Controller,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
SuccessResponse,
Response,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { In, Not, IsNull, MoreThan } from "typeorm";
import { Salarys } from "../entities/Salarys";
import { SalaryRanks } from "../entities/SalaryRanks";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import { SalaryPeriod } from "../entities/SalaryPeriod";
import { SalaryOrg } from "../entities/SalaryOrg";
import { SalaryProfile } from "../entities/SalaryProfile";
import Extension from "../interfaces/extension";
import { SalaryEmployee } from "../entities/SalaryEmployee";
import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
import { EmployeePosType } from "../entities/EmployeePosType";
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
@Route("api/v1/salary/report/tum")
@Tags("Tum")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class TumReportController extends Controller {
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
private salaryRepository = AppDataSource.getRepository(Salarys);
private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployee);
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
private salaryEmployeeRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
private poTypeRepository = AppDataSource.getRepository(PosType);
private poTypeEmployeeRepository = AppDataSource.getRepository(EmployeePosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel);
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee);
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
private salaryProfileEmployeeRepository = AppDataSource.getRepository(SalaryProfileEmployee);
2024-03-29 11:27:56 +07:00
2024-03-28 18:15:40 +07:00
/**
2024-03-29 11:27:56 +07:00
* API 11-
*
* @summary 11-
*
*/
@Get("emp2-11/{rootId}/{salaryPeriodId}")
async SalaryReportEmp2_11(@Path() rootId: string, @Path() salaryPeriodId: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
}
const _salaryPeriod = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
2024-03-28 18:15:40 +07:00
snapshot: "SNAP1",
2024-03-29 11:27:56 +07:00
rootId: rootId,
salaryPeriodId: salaryPeriodId,
},
},
order: {
orgShortName: "ASC",
posMasterNo: "ASC",
},
});
2024-03-29 11:12:45 +07:00
2024-03-29 11:27:56 +07:00
if (!_salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
2024-03-29 11:12:45 +07:00
2024-03-29 11:27:56 +07:00
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
2024-03-29 11:12:45 +07:00
2024-03-29 11:27:56 +07:00
const formattedData = _salaryPeriod.map((profile, index) => {
const fullNameParts = [
profile.child4,
profile.child3,
profile.child2,
profile.child1,
profile.root,
`${profile.prefix}${profile.firstName} ${profile.lastName}`,
];
2024-03-29 11:12:45 +07:00
2024-03-29 11:27:56 +07:00
const fullName = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
2024-03-29 11:12:45 +07:00
2024-03-29 11:27:56 +07:00
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName,
posLevel: profile.posLevel,
posNumber:
2024-03-28 18:15:40 +07:00
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
2024-03-29 11:27:56 +07:00
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
reason: null,
};
});
return new HttpSuccess({
template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
agency: agency,
data: formattedData,
},
});
}
/**
* API 13-
*
* @summary 13-
*
*/
@Get("emp2-13/{rootId}/{salaryPeriodId}")
async SalaryReportEmp2_13(@Path() rootId: string, @Path() salaryPeriodId: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
2024-03-28 18:15:40 +07:00
}
2024-03-29 11:27:56 +07:00
const _salaryPeriod = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
snapshot: "SNAP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
2024-03-28 18:15:40 +07:00
},
2024-03-29 11:27:56 +07:00
},
order: {
orgShortName: "ASC",
posMasterNo: "ASC",
},
});
if (!_salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
2024-03-28 18:15:40 +07:00
}
2024-03-29 11:27:56 +07:00
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
const formattedData = _salaryPeriod.map((profile, index) => {
const fullNameParts = [
profile.child4,
profile.child3,
profile.child2,
profile.child1,
profile.root,
`${profile.prefix}${profile.firstName} ${profile.lastName}`,
];
const fullName = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName,
posLevel: profile.posLevel,
posNumber:
2024-03-28 18:15:40 +07:00
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
2024-03-29 11:27:56 +07:00
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
reason: null,
};
});
return new HttpSuccess({
template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
agency: agency,
data: formattedData,
},
});
}
/**
* API 17- ()
*
* @summary 17- ()
*
*/
@Get("emp2-17/{rootId}/{salaryPeriodId}")
async SalaryReportEmp2_17(@Path() rootId: string, @Path() salaryPeriodId: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
}
const _salaryPeriod = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
snapshot: "SNAP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
2024-03-28 18:15:40 +07:00
},
2024-03-29 11:27:56 +07:00
},
order: {
orgShortName: "ASC",
posMasterNo: "ASC",
},
});
if (!_salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
2024-03-28 18:15:40 +07:00
}
2024-03-29 11:27:56 +07:00
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
const formattedData = _salaryPeriod.map((profile, index) => {
const fullNameParts = [
profile.child4,
profile.child3,
profile.child2,
profile.child1,
profile.root,
`${profile.prefix}${profile.firstName} ${profile.lastName}`,
];
const fullName = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName,
posLevel: profile.posLevel,
posNumber:
2024-03-28 18:15:40 +07:00
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
2024-03-29 11:27:56 +07:00
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
reason: null,
};
});
return new HttpSuccess({
template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
agency: agency,
data: formattedData,
},
});
}
/**
* API 25-
*
* @summary 25-
*
*/
@Get("emp2-25/{rootId}/{salaryPeriodId}")
async SalaryReportEmp2_25(@Path() rootId: string, @Path() salaryPeriodId: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
}
const _salaryPeriod = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
snapshot: "SNAP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
2024-03-28 18:15:40 +07:00
},
2024-03-29 11:27:56 +07:00
},
order: {
orgShortName: "ASC",
posMasterNo: "ASC",
},
});
if (!_salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
2024-03-28 18:15:40 +07:00
}
2024-03-29 11:27:56 +07:00
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
const formattedData = _salaryPeriod.map((profile, index) => {
const fullNameParts = [
profile.child4,
profile.child3,
profile.child2,
profile.child1,
profile.root,
`${profile.prefix}${profile.firstName} ${profile.lastName}`,
];
const fullName = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName,
posLevel: profile.posLevel,
posNumber:
2024-03-28 18:15:40 +07:00
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
2024-03-29 11:27:56 +07:00
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
reason: null,
};
});
2024-03-28 18:15:40 +07:00
2024-03-29 11:27:56 +07:00
return new HttpSuccess({
template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
agency: agency,
data: formattedData,
},
});
}
2024-03-28 18:15:40 +07:00
}