คิวรี่รายงาน, extension
This commit is contained in:
parent
865993e5e7
commit
a778912218
2 changed files with 161 additions and 0 deletions
112
src/controllers/ReportController.ts
Normal file
112
src/controllers/ReportController.ts
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
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, "ไม่พบข้อมูลไอดี: " + id);
|
||||
}
|
||||
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 || 0 ? "" : item.salary.toLocaleString() ,
|
||||
salaryHalf: item.salaryHalf == null || 0 ? "" : item.salaryHalf.toLocaleString(),
|
||||
salaryHalfSpecial: item.salaryHalfSpecial == null || 0 ? "" : item.salaryHalfSpecial.toLocaleString(),
|
||||
salaryFull: item.salaryFull == null || 0 ? "" : item.salaryFull.toLocaleString(),
|
||||
salaryFullSpecial: item.salaryFullSpecial == null || 0 ? "" : item.salaryFullSpecial.toLocaleString(),
|
||||
salaryFullHalf: item.salaryFullHalf == null || 0 ? "" : item.salaryFullHalf.toLocaleString(),
|
||||
salaryFullHalfSpecial: item.salaryFullHalfSpecial == null || 0 ? "" : item.salaryFullHalfSpecial.toLocaleString(),
|
||||
}));
|
||||
|
||||
const mapData = {
|
||||
nameType: salarys.salaryType == "OFFICER" ? "ผังข้าราชการกรุงเทพมหานครสามัญ" :
|
||||
salarys.salaryType == "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
|
||||
}
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
}
|
||||
49
src/interfaces/extension.ts
Normal file
49
src/interfaces/extension.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
class Extension {
|
||||
|
||||
public static ToThaiMonth(value: number) {
|
||||
switch (value) {
|
||||
case 1: return "มกราคม";
|
||||
case 2: return "กุมภาพันธ์";
|
||||
case 3: return "มีนาคม";
|
||||
case 4: return "เมษายน";
|
||||
case 5: return "พฤษภาคม";
|
||||
case 6: return "มิถุนายน";
|
||||
case 7: return "กรกฎาคม";
|
||||
case 8: return "สิงหาคม";
|
||||
case 9: return "กันยายน";
|
||||
case 10: return "ตุลาคม";
|
||||
case 11: return "พฤศจิกายน";
|
||||
case 12: return "ธันวาคม";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static ToThaiYear(value: number) {
|
||||
if (value < 2400)
|
||||
return value + 543;
|
||||
else return value;
|
||||
}
|
||||
|
||||
public static ToCeYear(value: number) {
|
||||
if (value >= 2400)
|
||||
return value - 543;
|
||||
else return value;
|
||||
}
|
||||
|
||||
public static ToThaiNumber(value: string) {
|
||||
let arabicNumbers = "0123456789";
|
||||
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
|
||||
let result = "";
|
||||
for (let digit of value) {
|
||||
let index = arabicNumbers.indexOf(digit);
|
||||
if (index >= 0) {
|
||||
result += thaiNumbers[index];
|
||||
} else {
|
||||
result += digit;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export default Extension;
|
||||
Loading…
Add table
Add a link
Reference in a new issue