952 lines
32 KiB
TypeScript
952 lines
32 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, 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";
|
||
@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 salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployee);
|
||
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
|
||
private salaryEmployeeRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
||
private poTypeRepository = AppDataSource.getRepository(PosType);
|
||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
|
||
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
|
||
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
|
||
|
||
/**
|
||
* 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,
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* API รายงานอัตราเงินเดือนลูกจ้าง
|
||
*
|
||
* @summary รายงานอัตราเงินเดือนลูกจ้าง
|
||
*
|
||
* @param {string} id Guid, *Id ผังเงินเดือนลูกจ้าง
|
||
*/
|
||
@Get("employee/{id}")
|
||
async SalaryEmployeeReport(@Path() id: string) {
|
||
const salarys = await this.salaryEmployeeRepository.findOne({
|
||
where: { id: id },
|
||
});
|
||
if (!salarys) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้");
|
||
}
|
||
|
||
const salaryRank = await this.salaryEmployeeRankRepository.find({
|
||
where: {
|
||
salaryEmployeeId: salarys.id,
|
||
},
|
||
select: ["id", "step", "salaryMonth", "salaryDay"],
|
||
order: {
|
||
step: "ASC",
|
||
salaryMonth: "ASC",
|
||
},
|
||
});
|
||
|
||
const mapSalaryRank = salaryRank.map((item, index) => ({
|
||
step: item.step == null || item.step == 0 ? "" : item.step.toLocaleString(),
|
||
salaryMonth:
|
||
item.salaryMonth == null || item.salaryMonth == 0 ? "" : item.salaryMonth.toLocaleString(),
|
||
salaryDay:
|
||
item.salaryDay == null || item.salaryDay == 0 ? "" : item.salaryDay.toLocaleString(),
|
||
}));
|
||
|
||
return new HttpSuccess({
|
||
template: "SalaryRankEmployee",
|
||
reportName: "SalaryRankEmployee",
|
||
data: {
|
||
date: Extension.ToThaiFullDate(new Date()),
|
||
group: salarys.group == null || salarys.group == 0 ? "" : salarys.group.toLocaleString(),
|
||
salaryRanks: mapSalaryRank,
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* API รายชื่อข้าราชการผู้ที่ครองตำแหน่ง ณ วันที่ 1 มีนาคม
|
||
*
|
||
* @summary รายชื่อข้าราชการผู้ที่ครองตำแหน่ง ณ วันที่ 1 มีนาคม
|
||
*
|
||
*/
|
||
@Get("gov1-01/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport1(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
},
|
||
});
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
|
||
}
|
||
const salaryPeriodAPR = await this.salaryProfileRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
salaryOrg: {
|
||
snapshot: "SNAP1",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
salaryPeriod: {
|
||
period: "APR",
|
||
},
|
||
},
|
||
},
|
||
order: {
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!salaryPeriodAPR) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
const agency = salaryPeriodAPR[0] == null ? "" : salaryPeriodAPR[0].root;
|
||
|
||
const formattedData = salaryPeriodAPR.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 ? fullName : null,
|
||
posLevel: profile?.posLevel ? profile?.posLevel : null,
|
||
posNumber:
|
||
profile?.orgShortName + profile?.posMasterNo
|
||
? profile?.orgShortName + Extension.ToThaiNumber(profile?.posMasterNo.toLocaleString())
|
||
: null,
|
||
amount: profile?.amount ? Extension.ToThaiNumber(profile?.amount.toLocaleString()) : null,
|
||
reason: null,
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: "gov1-01",
|
||
reportName: "gov1-01",
|
||
data: {
|
||
date: Extension.ToThaiNumber(
|
||
Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)),
|
||
),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* API บัญชีการคำนวณโควตาเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary บัญชีการคำนวณโควตาเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
*/
|
||
@Get("gov1-02/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport2(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
},
|
||
});
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
|
||
}
|
||
const salaryPeriodAPR = await this.salaryOrgRepository.find({
|
||
relations: ["salaryPeriod", "salaryProfiles"],
|
||
where: {
|
||
snapshot: "SNAP1",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
salaryPeriod: {
|
||
period: "APR",
|
||
},
|
||
},
|
||
order: { group: "ASC" },
|
||
});
|
||
const agency =
|
||
salaryPeriodAPR[0] == null || salaryPeriodAPR[0].salaryProfiles[0] == null
|
||
? ""
|
||
: salaryPeriodAPR[0].salaryProfiles[0].root;
|
||
|
||
let data1 = salaryPeriodAPR.find((x) => x.group == "GROUP2");
|
||
let formattedData1;
|
||
if (data1 != null) {
|
||
formattedData1 = {
|
||
total: Extension.ToThaiNumber(data1.salaryProfiles.length.toString()),
|
||
fifteenPercent: Extension.ToThaiNumber(data1.fifteenPercent.toString()),
|
||
full: Extension.ToThaiNumber(
|
||
data1.salaryProfiles.filter((x) => x.type == "FULL").length.toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data1.salaryProfiles.filter((x) => x.type == "NONE").length.toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
let data2 = salaryPeriodAPR.find((x) => x.group == "GROUP1");
|
||
let formattedData2;
|
||
if (data2 != null) {
|
||
formattedData2 = {
|
||
total: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.length.toString(),
|
||
),
|
||
fifteenPercent: Extension.ToThaiNumber(data2.fifteenPercent.toString()),
|
||
full: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.filter((x) => x.type == "FULL")
|
||
.length.toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.filter((x) => x.type == "HAFT")
|
||
.length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.filter((x) => x.type == "NONE")
|
||
.length.toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
let data3 = salaryPeriodAPR.find((x) => x.group == "GROUP1");
|
||
let formattedData3;
|
||
if (data3 != null) {
|
||
formattedData3 = {
|
||
total: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.length.toString(),
|
||
),
|
||
fifteenPercent: Extension.ToThaiNumber(data3.fifteenPercent.toString()),
|
||
full: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.filter((x) => x.type == "FULL")
|
||
.length.toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.filter((x) => x.type == "HAFT")
|
||
.length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.filter((x) => x.type == "NONE")
|
||
.length.toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
let data4 = salaryPeriodAPR.find((x) => x.group == "GROUP1");
|
||
let formattedData4;
|
||
if (data4 != null) {
|
||
formattedData4 = {
|
||
total: Extension.ToThaiNumber(data4.salaryProfiles.length.toString()),
|
||
fifteenPercent: Extension.ToThaiNumber(data4.fifteenPercent.toString()),
|
||
full: Extension.ToThaiNumber(
|
||
data4.salaryProfiles.filter((x) => x.type == "FULL").length.toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data4.salaryProfiles.filter((x) => x.type == "NONE").length.toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
|
||
return new HttpSuccess({
|
||
template: "gov1-02",
|
||
reportName: "gov1-02",
|
||
data: {
|
||
date: Extension.ToThaiNumber(
|
||
Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)),
|
||
),
|
||
dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())),
|
||
agency: agency,
|
||
data1: formattedData1,
|
||
data2: formattedData2,
|
||
data3: formattedData3,
|
||
data4: formattedData4,
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* API รายชื่อข้าราชการที่ได้รับการเสนอขอเลื่อนหนึ่งขั้น
|
||
*
|
||
* @summary รายชื่อข้าราชการที่ได้รับการเสนอขอเลื่อนหนึ่งขั้น
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov1-03/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport3(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
period: "APR",
|
||
isActive: true,
|
||
},
|
||
});
|
||
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||
}
|
||
|
||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodId,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
order: {
|
||
group: "ASC",
|
||
},
|
||
relations: ["salaryProfiles"],
|
||
});
|
||
|
||
const salaryProfile = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
type: "FULL", //หนึ่งขั้น
|
||
},
|
||
select: [
|
||
"id",
|
||
"prefix",
|
||
"firstName",
|
||
"lastName",
|
||
"root",
|
||
"position",
|
||
"posType",
|
||
"posLevel",
|
||
"orgShortName",
|
||
"posMasterNo",
|
||
"amount",
|
||
"amountSpecial",
|
||
],
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: "gov1-03",
|
||
reportName: "gov1-03",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(salaryPeriod.year)),
|
||
root: salaryProfile[0]?.root,
|
||
profile: salaryProfile.map((item, index) => ({
|
||
no: Extension.ToThaiNumber(String(index + 1)),
|
||
fullname:
|
||
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
|
||
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
|
||
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
|
||
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
|
||
(item.root == undefined && item.root == null ? "" : item.root)+
|
||
"/" + item.prefix + item.firstName + " " + item.lastName, // สังกัด/ชื่อ-นามสกุล
|
||
posLevel: item.posLevel,
|
||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount.toLocaleString())),
|
||
salaryIncrease1: null, //การเลื่อนเงินเดือนปีก่อนๆหน้า
|
||
salaryIncrease2: null, //การเลื่อนเงินเดือนปีก่อนหน้า
|
||
score: null, //ผลการประเมินฯ
|
||
remark: null, //หมายเหตุ
|
||
}))
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov1-04/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport4(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
period: "APR",
|
||
isActive: true,
|
||
},
|
||
});
|
||
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||
}
|
||
|
||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodId,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
order: {
|
||
group: "ASC",
|
||
},
|
||
relations: ["salaryProfiles"],
|
||
});
|
||
|
||
const salaryProfile = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
type: Not("NONE"), //ทุก Type ยกเว้นไม่ได้เลื่อน
|
||
},
|
||
select: [
|
||
"id",
|
||
"prefix",
|
||
"firstName",
|
||
"lastName",
|
||
"root",
|
||
"position",
|
||
"posType",
|
||
"posLevel",
|
||
"orgShortName",
|
||
"posMasterNo",
|
||
"amount",
|
||
"amountSpecial",
|
||
],
|
||
});
|
||
|
||
const mapData = {
|
||
effectiveDate: salaryPeriod?.effectiveDate,
|
||
root: salaryProfile[0]?.root,
|
||
profile: salaryProfile.map((item, index) => ({
|
||
no: Extension.ToThaiNumber(String(index + 1)),
|
||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||
position:
|
||
item.position +
|
||
"/" +
|
||
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
|
||
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
|
||
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
|
||
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
|
||
(item.root == undefined && item.root == null ? "" : item.root),
|
||
posLevel: item.posLevel,
|
||
orgShortName: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount)),
|
||
amountSpecial:
|
||
item.amountSpecial == undefined || item.amountSpecial == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amountSpecial)),
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
remark: null, //หมายเหตุ
|
||
})),
|
||
};
|
||
return mapData;
|
||
}
|
||
|
||
/**
|
||
* API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov1-05/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport5(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
period: "APR",
|
||
isActive: true,
|
||
},
|
||
});
|
||
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||
}
|
||
|
||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodId,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
order: {
|
||
group: "ASC",
|
||
},
|
||
relations: ["salaryProfiles"],
|
||
});
|
||
|
||
const salaryProfile = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
type: "NONE", //ไม่ได้เลื่อน
|
||
},
|
||
select: [
|
||
"id",
|
||
"prefix",
|
||
"firstName",
|
||
"lastName",
|
||
"root",
|
||
"position",
|
||
"posType",
|
||
"posLevel",
|
||
"orgShortName",
|
||
"posMasterNo",
|
||
"amount",
|
||
"amountSpecial",
|
||
],
|
||
});
|
||
|
||
const mapData = {
|
||
effectiveDate: salaryPeriod?.effectiveDate,
|
||
root: salaryProfile[0]?.root,
|
||
profile: salaryProfile.map((item, index) => ({
|
||
no: Extension.ToThaiNumber(String(index + 1)),
|
||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||
position:
|
||
item.position +
|
||
"/" +
|
||
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
|
||
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
|
||
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
|
||
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
|
||
(item.root == undefined && item.root == null ? "" : item.root),
|
||
posLevel: item.posLevel,
|
||
orgShortName: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount)),
|
||
amountSpecial:
|
||
item.amountSpecial == undefined || item.amountSpecial == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amountSpecial)),
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
remark: null, //หมายเหตุ
|
||
})),
|
||
};
|
||
return mapData;
|
||
}
|
||
|
||
// /* API แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก
|
||
// *
|
||
// * @summary แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก
|
||
// *
|
||
// * @param {string} rootId Guid, *Id Root
|
||
// * @param {string} salaryPeriodId Guid, *Id Period
|
||
// */
|
||
// @Get("gov1-06/{rootId}/{salaryPeriodId}")
|
||
// async SalaryReport6(){
|
||
|
||
// }
|
||
|
||
/**
|
||
* API คำสั่งเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary คำสั่งเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov1-07/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport7(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
period: "APR",
|
||
isActive: true,
|
||
},
|
||
});
|
||
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||
}
|
||
|
||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodId,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
order: {
|
||
group: "ASC",
|
||
},
|
||
relations: ["salaryProfiles"],
|
||
});
|
||
|
||
const salaryProfile = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
amountSpecial: IsNull() || 0,
|
||
amountUse: MoreThan(1),
|
||
},
|
||
select: [
|
||
"id",
|
||
"prefix",
|
||
"firstName",
|
||
"lastName",
|
||
"root",
|
||
"position",
|
||
"posType",
|
||
"posLevel",
|
||
"orgShortName",
|
||
"posMasterNo",
|
||
"amount",
|
||
"amountUse",
|
||
"positionSalaryAmount",
|
||
],
|
||
order: {
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
const mapData = salaryProfile.map((item, index) => ({
|
||
no: Extension.ToThaiNumber(String(index + 1)),
|
||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||
position: item.position,
|
||
posType: item.posType,
|
||
posLevel: item.posLevel,
|
||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount)),
|
||
positionSalaryAmount:
|
||
item.positionSalaryAmount == undefined || item.positionSalaryAmount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.positionSalaryAmount)),
|
||
remark: null,
|
||
}));
|
||
|
||
return mapData;
|
||
}
|
||
|
||
/**
|
||
* APIคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน
|
||
*
|
||
* @summary คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov1-08/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport8(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
period: "APR",
|
||
isActive: true,
|
||
},
|
||
});
|
||
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||
}
|
||
|
||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodId,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
order: {
|
||
group: "ASC",
|
||
},
|
||
relations: ["salaryProfiles"],
|
||
});
|
||
|
||
const salaryProfileSpecial = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
amountSpecial: MoreThan(1),
|
||
},
|
||
select: [
|
||
"id",
|
||
"prefix",
|
||
"firstName",
|
||
"lastName",
|
||
"root",
|
||
"position",
|
||
"posType",
|
||
"posLevel",
|
||
"orgShortName",
|
||
"posMasterNo",
|
||
"amount",
|
||
"amountSpecial",
|
||
],
|
||
order: {
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
const salaryProfileNoAmount = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
amountUse: IsNull() || 0,
|
||
positionSalaryAmount: IsNull() || 0,
|
||
},
|
||
select: [
|
||
"id",
|
||
"prefix",
|
||
"firstName",
|
||
"lastName",
|
||
"root",
|
||
"position",
|
||
"posType",
|
||
"posLevel",
|
||
"orgShortName",
|
||
"posMasterNo",
|
||
"amount",
|
||
],
|
||
order: {
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
const profileSpecial = salaryProfileSpecial.map((item, index) => ({
|
||
no: Extension.ToThaiNumber(String(index + 1)),
|
||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||
position: item.position,
|
||
posType: item.posType,
|
||
posLevel: item.posLevel,
|
||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount)),
|
||
amountSpecial:
|
||
item.amountSpecial == undefined || item.amountSpecial == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amountSpecial)),
|
||
remark: null,
|
||
}));
|
||
|
||
const profileNoAmount = salaryProfileNoAmount.map((item, index) => ({
|
||
no: Extension.ToThaiNumber(String(index + 1)),
|
||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||
position: item.position,
|
||
posType: item.posType,
|
||
posLevel: item.posLevel,
|
||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount)),
|
||
remark: null,
|
||
}));
|
||
|
||
const mapData = {
|
||
profileSpecial,
|
||
profileNoAmount,
|
||
};
|
||
return mapData;
|
||
}
|
||
}
|