120 lines
4.7 KiB
TypeScript
120 lines
4.7 KiB
TypeScript
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, IsNull, Not } from "typeorm";
|
|
import { Salarys } from "../entities/Salarys";
|
|
import { SalaryRanks } from "../entities/SalaryRanks";
|
|
import { PosType } from "../entities/PosType";
|
|
import { PosLevel } from "../entities/PosLevel";
|
|
import Extension from "../interfaces/extension";
|
|
@Route("api/v1/salary/report")
|
|
@Tags("Report")
|
|
@Security("bearerAuth")
|
|
@Response(
|
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
|
)
|
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
|
export class ReportController extends Controller {
|
|
private salaryRepository = AppDataSource.getRepository(Salarys);
|
|
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
|
|
private poTypeRepository = AppDataSource.getRepository(PosType);
|
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
|
|
|
/**
|
|
* API รายงานตารางเงินเดือน
|
|
*
|
|
* @summary รายงานตารางเงินเดือน
|
|
*
|
|
* @param {string} id Guid, *Id ผังเงินเดือน
|
|
*/
|
|
@Get("{id}")
|
|
async SalaryReport(@Path() id: string) {
|
|
const salarys = await this.salaryRepository.findOne({
|
|
where: { id: id }
|
|
});
|
|
if (!salarys) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้");
|
|
}
|
|
const posType = await this.poTypeRepository.findOne({
|
|
where: { id: salarys.posTypeId },
|
|
});
|
|
const posLevel = await this.posLevelRepository.findOne({
|
|
where: { id: salarys.posLevelId },
|
|
});
|
|
const salaryRank = await this.salaryRankRepository.find({
|
|
where: {
|
|
salaryId: salarys.id,
|
|
},
|
|
select: [
|
|
"id",
|
|
"salary",
|
|
"salaryHalf",
|
|
"salaryHalfSpecial",
|
|
"salaryFull",
|
|
"salaryFullSpecial",
|
|
"salaryFullHalf",
|
|
"salaryFullHalfSpecial",
|
|
],
|
|
order: {
|
|
salary: "DESC",
|
|
salaryHalf: "DESC",
|
|
}
|
|
});
|
|
|
|
const mapSalaryRank = salaryRank.map((item, index) => ({
|
|
// no: index + 1,
|
|
// id: item.id,
|
|
salary: item.salary == null || item.salary == 0 ? "" :
|
|
item.salary.toLocaleString(),
|
|
salaryHalf: item.salaryHalf == null || item.salaryHalf == 0 ? "" :
|
|
item.salaryHalf.toLocaleString() +
|
|
(item.salaryHalfSpecial == null || item.salaryHalfSpecial == 0 ? "" :
|
|
" ("+item.salaryHalfSpecial.toLocaleString()+"*)"),
|
|
salaryFull: item.salaryFull == null || item.salaryFull == 0 ? "" :
|
|
item.salaryFull.toLocaleString() +
|
|
(item.salaryFullSpecial == null || item.salaryFullSpecial == 0 ? "" :
|
|
" ("+item.salaryFullSpecial.toLocaleString()+"*)"),
|
|
salaryFullHalf: item.salaryFullHalf == null || item.salaryFullHalf == 0 ? "" :
|
|
item.salaryFullHalf.toLocaleString() +
|
|
(item.salaryFullHalfSpecial == null || item.salaryFullHalfSpecial == 0 ? "" :
|
|
" ("+item.salaryFullHalfSpecial.toLocaleString()+"*)"),
|
|
}));
|
|
|
|
return new HttpSuccess({ template: "SalaryRank", reportName: "SalaryRank",
|
|
data: {
|
|
nameType: salarys.name == "OFFICER" ? "ผังข้าราชการกรุงเทพมหานครสามัญ" :
|
|
salarys.name == "EMPLOYEE" ? "ผังลูกจ้างประจำกรุงเทพมหานคร" : "",
|
|
level: posLevel?.posLevelName == null ? "" : posLevel?.posLevelName,
|
|
type: posType?.posTypeName == null ? "" : posType?.posTypeName,
|
|
date: salarys.date == null ? "" :
|
|
salarys.date.getDate() + " " + Extension.ToThaiMonth(salarys.date.getMonth()+1) + " " + Extension.ToThaiYear(salarys.date.getFullYear()),
|
|
startDate: salarys.startDate == null ? "" :
|
|
salarys.startDate.getDate() + " " + Extension.ToThaiMonth(salarys.startDate.getMonth()+1) + " " + Extension.ToThaiYear(salarys.startDate.getFullYear()),
|
|
endDate: salarys.endDate == null ? "" :
|
|
salarys.endDate.getDate() + " " + Extension.ToThaiMonth(salarys.endDate.getMonth()+1) + " " + Extension.ToThaiYear(salarys.endDate.getFullYear()),
|
|
details: salarys.details == null ? "" : salarys.details,
|
|
salaryRanks: mapSalaryRank
|
|
}
|
|
});
|
|
}
|
|
}
|