3052 lines
112 KiB
TypeScript
3052 lines
112 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";
|
||
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")
|
||
@Tags("Report")
|
||
@Security("bearerAuth")
|
||
@Response(
|
||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||
)
|
||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||
export class ReportController 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);
|
||
|
||
/**
|
||
* 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("gov-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 _salaryPeriod = await this.salaryProfileRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
salaryOrg: {
|
||
snapshot: "SNAP1",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
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 บัญชีการคำนวณโควตาเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary บัญชีการคำนวณโควตาเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
*/
|
||
@Get("gov-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 _salaryPeriod = await this.salaryOrgRepository.find({
|
||
relations: ["salaryPeriod", "salaryProfiles"],
|
||
where: {
|
||
snapshot: "SNAP1",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
});
|
||
const agency =
|
||
_salaryPeriod[0] == null || _salaryPeriod[0].salaryProfiles[0] == null
|
||
? ""
|
||
: _salaryPeriod[0].salaryProfiles[0].root;
|
||
if (salaryPeriod.period == "APR") {
|
||
let data1 = _salaryPeriod.find((x) => x.group == "GROUP2");
|
||
let formattedData1;
|
||
if (data1 != null) {
|
||
formattedData1 = {
|
||
total: Extension.ToThaiNumber(data1.total.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 = _salaryPeriod.find((x) => x.group == "GROUP1");
|
||
let formattedData2;
|
||
if (data2 != null) {
|
||
formattedData2 = {
|
||
total: Extension.ToThaiNumber(data2.total.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 = _salaryPeriod.find((x) => x.group == "GROUP1");
|
||
let formattedData3;
|
||
if (data3 != null) {
|
||
formattedData3 = {
|
||
total: Extension.ToThaiNumber(data3.total.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 = _salaryPeriod.find((x) => x.group == "GROUP1");
|
||
let formattedData4;
|
||
if (data4 != null) {
|
||
formattedData4 = {
|
||
total: Extension.ToThaiNumber(data4.total.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`)),
|
||
),
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())),
|
||
agency: agency,
|
||
data1: formattedData1,
|
||
data2: formattedData2,
|
||
data3: formattedData3,
|
||
data4: formattedData4,
|
||
},
|
||
});
|
||
} else {
|
||
let data1 = _salaryPeriod.find((x) => x.group == "GROUP2");
|
||
const _salaryPeriodAPR1 = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
snapshot: "SNAP1",
|
||
group: "GROUP1",
|
||
rootId: rootId,
|
||
salaryPeriod: {
|
||
period: "APR",
|
||
year: salaryPeriod.year,
|
||
},
|
||
},
|
||
});
|
||
const _salaryPeriodAPR2 = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
snapshot: "SNAP1",
|
||
group: "GROUP2",
|
||
rootId: rootId,
|
||
salaryPeriod: {
|
||
period: "APR",
|
||
year: salaryPeriod.year,
|
||
},
|
||
},
|
||
});
|
||
let formattedData1;
|
||
if (data1 != null) {
|
||
const haftSalary = data1.salaryProfiles
|
||
.filter((x) => x.type == "HAFT")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
|
||
const fullSalary = data1.salaryProfiles
|
||
.filter((x) => x.type == "FULL")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
const fullHaftSalary = data1.salaryProfiles
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
formattedData1 = {
|
||
totalSalary: Extension.ToThaiNumber(data1.currentAmount.toString()),
|
||
totalUser: Extension.ToThaiNumber(data1.total.toString()),
|
||
sixPercentAmount: Extension.ToThaiNumber(data1.sixPercentAmount.toString()),
|
||
spentAmount: Extension.ToThaiNumber(data1.spentAmount.toString()),
|
||
remainingAmount: Extension.ToThaiNumber(
|
||
(data1.sixPercentAmount - data1.spentAmount).toString(),
|
||
),
|
||
fifteenPercentOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR2 == null ? 0 : _salaryPeriodAPR2.fifteenPercent).toString(),
|
||
),
|
||
totalOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR2 == null ? 0 : _salaryPeriodAPR2.total).toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(),
|
||
),
|
||
full: Extension.ToThaiNumber(
|
||
data1.salaryProfiles.filter((x) => x.type == "FULL").length.toString(),
|
||
),
|
||
fullHaft: Extension.ToThaiNumber(
|
||
data1.salaryProfiles.filter((x) => x.type == "FULLHAFT").length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data1.salaryProfiles.filter((x) => x.type == "NONE").length.toString(),
|
||
),
|
||
haftSalary: Extension.ToThaiNumber(haftSalary.toString()),
|
||
fullSalary: Extension.ToThaiNumber(fullSalary.toString()),
|
||
fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toString()),
|
||
total: Extension.ToThaiNumber((haftSalary + fullSalary + fullHaftSalary).toString()),
|
||
summary: Extension.ToThaiNumber(
|
||
(
|
||
data1.sixPercentAmount -
|
||
data1.spentAmount -
|
||
haftSalary -
|
||
fullSalary -
|
||
fullHaftSalary
|
||
).toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
let data2 = _salaryPeriod.find((x) => x.group == "GROUP1");
|
||
let formattedData2;
|
||
if (data2 != null) {
|
||
const haftSalary = data2.salaryProfiles
|
||
.filter((x) => x.type == "HAFT")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
|
||
const fullSalary = data2.salaryProfiles
|
||
.filter((x) => x.type == "FULL")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
const fullHaftSalary = data2.salaryProfiles
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
|
||
formattedData2 = {
|
||
totalSalary: Extension.ToThaiNumber(data2.currentAmount.toString()),
|
||
totalUser: Extension.ToThaiNumber(data2.total.toString()),
|
||
sixPercentAmount: Extension.ToThaiNumber(data2.sixPercentAmount.toString()),
|
||
spentAmount: Extension.ToThaiNumber(data2.spentAmount.toString()),
|
||
remainingAmount: Extension.ToThaiNumber(
|
||
(data2.sixPercentAmount - data2.spentAmount).toString(),
|
||
),
|
||
fifteenPercentOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent).toString(),
|
||
),
|
||
totalOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.total).toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.filter((x) => x.type == "HAFT")
|
||
.length.toString(),
|
||
),
|
||
full: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.filter((x) => x.type == "FULL")
|
||
.length.toString(),
|
||
),
|
||
fullHaft: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data2.salaryProfiles
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "อาวุโส" ||
|
||
x.posLevel == "ชำนาญการพิเศษ" ||
|
||
(x.posLevel == "ต้น" && x.posType == "อำนวยการ"),
|
||
)
|
||
.filter((x) => x.type == "NONE")
|
||
.length.toString(),
|
||
),
|
||
haftSalary: Extension.ToThaiNumber(haftSalary.toString()),
|
||
fullSalary: Extension.ToThaiNumber(fullSalary.toString()),
|
||
fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toString()),
|
||
total: Extension.ToThaiNumber((haftSalary + fullSalary + fullHaftSalary).toString()),
|
||
summary: Extension.ToThaiNumber(
|
||
(
|
||
data2.sixPercentAmount -
|
||
data2.spentAmount -
|
||
haftSalary -
|
||
fullSalary -
|
||
fullHaftSalary
|
||
).toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
let data3 = _salaryPeriod.find((x) => x.group == "GROUP1");
|
||
let formattedData3;
|
||
if (data3 != null) {
|
||
const haftSalary = data3.salaryProfiles
|
||
.filter((x) => x.type == "HAFT")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
|
||
const fullSalary = data3.salaryProfiles
|
||
.filter((x) => x.type == "FULL")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
const fullHaftSalary = data3.salaryProfiles
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
formattedData3 = {
|
||
totalSalary: Extension.ToThaiNumber(data3.currentAmount.toString()),
|
||
totalUser: Extension.ToThaiNumber(data3.total.toString()),
|
||
sixPercentAmount: Extension.ToThaiNumber(data3.sixPercentAmount.toString()),
|
||
spentAmount: Extension.ToThaiNumber(data3.spentAmount.toString()),
|
||
remainingAmount: Extension.ToThaiNumber(
|
||
(data3.sixPercentAmount - data3.spentAmount).toString(),
|
||
),
|
||
fifteenPercentOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent).toString(),
|
||
),
|
||
totalOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.total).toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter((x) => x.type == "HAFT")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.length.toString(),
|
||
),
|
||
full: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter((x) => x.type == "FULL")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.length.toString(),
|
||
),
|
||
fullHaft: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data3.salaryProfiles
|
||
.filter((x) => x.type == "NONE")
|
||
.filter(
|
||
(x) =>
|
||
x.posLevel == "ปฏิบัติงาน" ||
|
||
x.posLevel == "ชำนาญงาน" ||
|
||
x.posLevel == "ปฏิบัติการ" ||
|
||
x.posLevel == "ชำนาญการ",
|
||
)
|
||
.length.toString(),
|
||
),
|
||
haftSalary: Extension.ToThaiNumber(haftSalary.toString()),
|
||
fullSalary: Extension.ToThaiNumber(fullSalary.toString()),
|
||
fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toString()),
|
||
total: Extension.ToThaiNumber((haftSalary + fullSalary + fullHaftSalary).toString()),
|
||
summary: Extension.ToThaiNumber(
|
||
(
|
||
data3.sixPercentAmount -
|
||
data3.spentAmount -
|
||
haftSalary -
|
||
fullSalary -
|
||
fullHaftSalary
|
||
).toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
let data4 = _salaryPeriod.find((x) => x.group == "GROUP1");
|
||
let formattedData4;
|
||
if (data4 != null) {
|
||
const haftSalary = data4.salaryProfiles
|
||
.filter((x) => x.type == "HAFT")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
|
||
const fullSalary = data4.salaryProfiles
|
||
.filter((x) => x.type == "FULL")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
const fullHaftSalary = data4.salaryProfiles
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
formattedData4 = {
|
||
totalSalary: Extension.ToThaiNumber(data4.currentAmount.toString()),
|
||
totalUser: Extension.ToThaiNumber(data4.total.toString()),
|
||
sixPercentAmount: Extension.ToThaiNumber(data4.sixPercentAmount.toString()),
|
||
spentAmount: Extension.ToThaiNumber(data4.spentAmount.toString()),
|
||
remainingAmount: Extension.ToThaiNumber(
|
||
(data4.sixPercentAmount - data4.spentAmount).toString(),
|
||
),
|
||
fifteenPercentOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent).toString(),
|
||
),
|
||
totalOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.total).toString(),
|
||
),
|
||
haft: Extension.ToThaiNumber(
|
||
data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(),
|
||
),
|
||
full: Extension.ToThaiNumber(
|
||
data4.salaryProfiles.filter((x) => x.type == "FULL").length.toString(),
|
||
),
|
||
fullHaft: Extension.ToThaiNumber(
|
||
data4.salaryProfiles.filter((x) => x.type == "FULLHAFT").length.toString(),
|
||
),
|
||
notPromoted: Extension.ToThaiNumber(
|
||
data4.salaryProfiles.filter((x) => x.type == "NONE").length.toString(),
|
||
),
|
||
haftSalary: Extension.ToThaiNumber(haftSalary.toString()),
|
||
fullSalary: Extension.ToThaiNumber(fullSalary.toString()),
|
||
fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toString()),
|
||
total: Extension.ToThaiNumber((haftSalary + fullSalary + fullHaftSalary).toString()),
|
||
summary: Extension.ToThaiNumber(
|
||
(
|
||
data4.sixPercentAmount -
|
||
data4.spentAmount -
|
||
haftSalary -
|
||
fullSalary -
|
||
fullHaftSalary
|
||
).toString(),
|
||
),
|
||
reason: null,
|
||
};
|
||
}
|
||
|
||
return new HttpSuccess({
|
||
template: "gov2-02",
|
||
reportName: "gov2-02",
|
||
data: {
|
||
date: Extension.ToThaiNumber(
|
||
Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)),
|
||
),
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
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("gov-03/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport3(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
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"],
|
||
});
|
||
if (salaryPeriod.period === "APR") {
|
||
const salaryProfile = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
type: "FULL", //หนึ่งขั้น
|
||
},
|
||
});
|
||
|
||
//รอบปีก่อนๆ
|
||
const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "APR",
|
||
year: salaryPeriod.year - 2,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "OCT",
|
||
year: salaryPeriod.year - 2,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryOrg1_APR = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease1_APR?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryOrg1_OCT = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease1_OCT?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryProfile1 = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]),
|
||
type: "FULL",
|
||
},
|
||
});
|
||
//รอบปีก่อนหน้า
|
||
const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "APR",
|
||
year: salaryPeriod.year - 1,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryPeriodIncrease2_OCT = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "OCT",
|
||
year: salaryPeriod.year - 1,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryOrg2_APR = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease2_APR?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryOrg2_OCT = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease2_OCT?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryProfile2 = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]),
|
||
type: "FULL",
|
||
},
|
||
});
|
||
const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)));
|
||
const yearIncrease1 = Extension.ToThaiNumber(
|
||
String(Extension.ToThaiYear(salaryPeriod.year - 2)),
|
||
);
|
||
const yearIncrease2 = Extension.ToThaiNumber(
|
||
String(Extension.ToThaiYear(salaryPeriod.year - 1)),
|
||
);
|
||
const fifteenPercent =
|
||
salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent));
|
||
const fifteenPoint =
|
||
salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null
|
||
? ".๐๐"
|
||
: "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint));
|
||
|
||
return new HttpSuccess({
|
||
template: "gov1-03",
|
||
reportName: "gov1-03",
|
||
data: {
|
||
year: year,
|
||
yearIncrease1: yearIncrease1,
|
||
yearIncrease2: yearIncrease2,
|
||
yearIncreaseSlice: yearIncrease2.slice(-2),
|
||
yearSlice: year.slice(-2),
|
||
point: fifteenPercent + fifteenPoint,
|
||
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: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount.toLocaleString())),
|
||
salaryIncrease1:
|
||
salaryProfile1.length > 0
|
||
? salaryProfile1
|
||
.filter((profile) => profile.citizenId === item.citizenId)
|
||
.map((profile) => profile.amount)
|
||
: "๐", //การเลื่อนเงินเดือนปีก่อนๆหน้า
|
||
salaryIncrease2:
|
||
salaryProfile2.length > 0
|
||
? salaryProfile2
|
||
.filter((profile) => profile.citizenId === item.citizenId)
|
||
.map((profile) => profile.amount)
|
||
: "๐", //การเลื่อนเงินเดือนปีก่อนหน้า
|
||
score: null, //ผลการประเมินฯ
|
||
remark: null, //หมายเหตุ
|
||
})),
|
||
},
|
||
});
|
||
} else if (salaryPeriod.period === "OCT") {
|
||
//find period APR
|
||
const salaryPeriod_APR = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "APR",
|
||
year: salaryPeriod?.year,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryOrg_APR = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriod_APR?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryProfile_APR = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg_APR?.id,
|
||
type: In(["HAFT", "FULL"]),
|
||
},
|
||
});
|
||
//end period APR
|
||
|
||
const salaryProfile = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: salaryOrg?.id,
|
||
type: In(["FULLHAFT", "FULL"]),
|
||
},
|
||
});
|
||
|
||
//รอบปีก่อนๆ
|
||
const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "APR",
|
||
year: salaryPeriod.year - 2,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "OCT",
|
||
year: salaryPeriod.year - 2,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryOrg1_APR = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease1_APR?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryOrg1_OCT = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease1_OCT?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryProfile1 = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]),
|
||
type: "FULL",
|
||
},
|
||
});
|
||
//รอบปีก่อนหน้า
|
||
const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "APR",
|
||
year: salaryPeriod.year - 1,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryPeriodIncrease2_OCT = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
period: "OCT",
|
||
year: salaryPeriod.year - 1,
|
||
isActive: true,
|
||
},
|
||
});
|
||
const salaryOrg2_APR = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease2_APR?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryOrg2_OCT = await this.salaryOrgRepository.findOne({
|
||
where: {
|
||
salaryPeriodId: salaryPeriodIncrease2_OCT?.id,
|
||
rootId: rootId,
|
||
snapshot: "SNAP2",
|
||
},
|
||
});
|
||
const salaryProfile2 = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]),
|
||
type: "FULL",
|
||
},
|
||
});
|
||
const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)));
|
||
const yearIncrease1 = Extension.ToThaiNumber(
|
||
String(Extension.ToThaiYear(salaryPeriod.year - 2)),
|
||
);
|
||
const yearIncrease2 = Extension.ToThaiNumber(
|
||
String(Extension.ToThaiYear(salaryPeriod.year - 1)),
|
||
);
|
||
const fifteenPercent =
|
||
salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent));
|
||
const fifteenPoint =
|
||
salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null
|
||
? ".๐๐"
|
||
: "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint));
|
||
|
||
return new HttpSuccess({
|
||
template: "gov2-03",
|
||
reportName: "gov2-03",
|
||
data: {
|
||
year: year,
|
||
yearIncrease1: yearIncrease1,
|
||
yearIncrease2: yearIncrease2,
|
||
yearIncreaseSlice: yearIncrease2.slice(-2),
|
||
yearSlice: year.slice(-2),
|
||
point: fifteenPercent + fifteenPoint,
|
||
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: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
|
||
amount:
|
||
item.amount == undefined || item.amount == null
|
||
? "๐"
|
||
: Extension.ToThaiNumber(String(item.amount.toLocaleString())),
|
||
salaryIncrease1:
|
||
salaryProfile1.length > 0
|
||
? salaryProfile1
|
||
.filter((profile) => profile.citizenId === item.citizenId)
|
||
.map((profile) => profile.amount)
|
||
: "๐", //การเลื่อนเงินเดือนปีก่อนๆหน้า
|
||
salaryIncrease2:
|
||
salaryProfile2.length > 0
|
||
? salaryProfile2
|
||
.filter((profile) => profile.citizenId === item.citizenId)
|
||
.map((profile) => profile.amount)
|
||
: "๐", //การเลื่อนเงินเดือนปีก่อนหน้า
|
||
salaryIncreaseAPR:
|
||
salaryProfile_APR.length > 0
|
||
? salaryProfile_APR
|
||
.filter((profile) => profile.citizenId === item.citizenId)
|
||
.map((profile) => profile.amount)
|
||
: "๐", //การเลื่อนเงินเดือนรอบเมษา
|
||
Type: item.type === "FULL" ? "หนึ่งขั้น" : "หนึ่งขั้นครึ่ง",
|
||
score1: null, //ผลการประเมินฯ ครั้งที่ 1
|
||
score2: null, //ผลการประเมินฯ ครั้งที่ 2
|
||
})),
|
||
},
|
||
});
|
||
}
|
||
}
|
||
|
||
/**
|
||
* API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov-04/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport4(@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: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
type: "NONE", //ไม่ได้เลื่อน
|
||
},
|
||
order: {
|
||
salaryOrg: {
|
||
group: "ASC",
|
||
},
|
||
type: "DESC",
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
|
||
|
||
const formattedData = _salaryPeriod.map((profile, index) => {
|
||
return {
|
||
no: Extension.ToThaiNumber(String(index + 1)),
|
||
fullname: profile.prefix + profile.firstName + " " + profile.lastName,
|
||
log_group: profile.salaryOrg.group,
|
||
log_type: profile.type,
|
||
log_isNext: profile.isNext,
|
||
position:
|
||
profile.position +
|
||
"/" +
|
||
(profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + "/") +
|
||
(profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + "/") +
|
||
(profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + "/") +
|
||
(profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + "/") +
|
||
(profile.root == undefined && profile.root == null ? "" : profile.root),
|
||
posLevel: profile.posLevel,
|
||
orgShortName: profile.orgShortName + Extension.ToThaiNumber(String(profile.posMasterNo)),
|
||
amount:
|
||
profile.amount == undefined || profile.amount == null || profile.amount == 0
|
||
? ""
|
||
: Extension.ToThaiNumber(String(profile.amount)),
|
||
amountSpecial:
|
||
(profile.positionSalaryAmount == undefined ||
|
||
profile.positionSalaryAmount == null ||
|
||
profile.positionSalaryAmount == 0
|
||
? ""
|
||
: Extension.ToThaiNumber(String(profile.positionSalaryAmount))) +
|
||
(profile.amountSpecial == undefined ||
|
||
profile.amountSpecial == null ||
|
||
profile.amountSpecial == 0
|
||
? ""
|
||
: `(${Extension.ToThaiNumber(String(profile.amountSpecial))})`),
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
remark:
|
||
`${profile.type === "FULL" ? "หนึ่งขั้น" : ""}\n` +
|
||
`${profile.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` +
|
||
`${profile.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` +
|
||
`${profile.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "gov1-04" : "gov2-04",
|
||
reportName: salaryPeriod.period == "APR" ? "gov1-04" : "gov2-04",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
effectiveDate: salaryPeriod.effectiveDate,
|
||
root: agency,
|
||
profile: formattedData,
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov-05/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport5(@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: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
type: "NONE", //ไม่ได้เลื่อน
|
||
},
|
||
order: {
|
||
salaryOrg: {
|
||
group: "ASC",
|
||
},
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
|
||
|
||
const formattedData = _salaryPeriod.map((profile, index) => {
|
||
const fullNameParts = [
|
||
profile.position,
|
||
profile.child4,
|
||
profile.child3,
|
||
profile.child2,
|
||
profile.child1,
|
||
profile.root,
|
||
];
|
||
|
||
const position = fullNameParts
|
||
.filter((part) => part !== undefined && part !== null)
|
||
.join("/");
|
||
|
||
return {
|
||
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
||
fullname: profile.prefix + profile.firstName + " " + profile.lastName,
|
||
position: position,
|
||
posLevel: profile.posLevel,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
reason: null,
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05",
|
||
reportName: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
|
||
// /* API แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก
|
||
// *
|
||
// * @summary แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก
|
||
// *
|
||
// * @param {string} rootId Guid, *Id Root
|
||
// * @param {string} salaryPeriodId Guid, *Id Period
|
||
// */
|
||
// @Get("gov-06/{rootId}/{salaryPeriodId}")
|
||
// async SalaryReport6(){
|
||
|
||
// }
|
||
|
||
/**
|
||
* API คำสั่งเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @summary คำสั่งเลื่อนเงินเดือน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov-07/{rootId}/{salaryPeriodId}")
|
||
async SalaryReport7(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
},
|
||
});
|
||
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||
}
|
||
|
||
const salaryProfile = await this.salaryProfileRepository.find({
|
||
where: {
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
salaryPeriod: {
|
||
period: "APR",
|
||
},
|
||
},
|
||
},
|
||
order: {
|
||
type: "DESC",
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root;
|
||
|
||
const formattedData = 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),
|
||
posType: item.posType,
|
||
posLevel: item.posLevel,
|
||
posMasterNo: item.orgShortName + 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)) +
|
||
(item.amountSpecial > 0
|
||
? `(${Extension.ToThaiNumber(String(item.positionSalaryAmount))})`
|
||
: ""),
|
||
remark:
|
||
`${item.type === "FULL" ? "หนึ่งขั้น" : ""}\n` +
|
||
`${item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` +
|
||
`${item.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` +
|
||
`${item.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // ห
|
||
}));
|
||
|
||
return new HttpSuccess({
|
||
template: "gov1-07",
|
||
reportName: "gov1-07",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
yearOld: Extension.ToThaiNumber((salaryPeriod.year + 542).toString()),
|
||
date: Extension.ToThaiNumber(
|
||
Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)),
|
||
),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* APIคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน
|
||
*
|
||
* @summary คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน
|
||
*
|
||
* @param {string} rootId Guid, *Id Root
|
||
* @param {string} salaryPeriodId Guid, *Id Period
|
||
*/
|
||
@Get("gov-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;
|
||
}
|
||
|
||
/**
|
||
* API 00-สรุปรายการเอกสารลูกจ้างที่ต้องส่ง สกจ รอบเมษายน
|
||
*
|
||
* @summary 00-สรุปรายการเอกสารลูกจ้างที่ต้องส่ง สกจ รอบเมษายน
|
||
*
|
||
*/
|
||
@Get("emp-00/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp0(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
where: {
|
||
id: salaryPeriodId,
|
||
},
|
||
});
|
||
if (!salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
|
||
}
|
||
return new HttpSuccess({
|
||
template: "emp1-00",
|
||
reportName: "emp1-00",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* API 01-บัญชีคำนวณโควตา
|
||
*
|
||
* @summary 01-บัญชีคำนวณโควตา
|
||
*
|
||
*/
|
||
@Get("emp-01/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp1(@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.salaryOrgEmployeeRepository.findOne({
|
||
relations: ["salaryPeriod", "salaryProfiles"],
|
||
where: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
});
|
||
|
||
const agency =
|
||
_salaryPeriod == null || _salaryPeriod.salaryProfiles[0] == null
|
||
? ""
|
||
: _salaryPeriod.salaryProfiles[0].root;
|
||
|
||
if (salaryPeriod.period == "APR") {
|
||
return new HttpSuccess({
|
||
template: "emp1-01",
|
||
reportName: "emp1-01",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
total:
|
||
_salaryPeriod == null ? "" : Extension.ToThaiNumber(_salaryPeriod.total.toString()),
|
||
fifteenPercent:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(_salaryPeriod.fifteenPercent.toString()),
|
||
full:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
_salaryPeriod.salaryProfiles.filter((x) => x.type == "FULL").length.toString(),
|
||
),
|
||
haft:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
_salaryPeriod.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(),
|
||
),
|
||
notPromoted:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
_salaryPeriod.salaryProfiles.filter((x) => x.type == "NONE").length.toString(),
|
||
),
|
||
reason: null,
|
||
},
|
||
});
|
||
} else {
|
||
const _salaryPeriodAPR1 = await this.salaryOrgEmployeeRepository.findOne({
|
||
where: {
|
||
snapshot: "SNAP1",
|
||
rootId: rootId,
|
||
salaryPeriod: {
|
||
period: "APR",
|
||
year: salaryPeriod.year,
|
||
},
|
||
},
|
||
});
|
||
const haftSalary =
|
||
_salaryPeriod == null
|
||
? 0
|
||
: _salaryPeriod.salaryProfiles
|
||
.filter((x) => x.type == "HAFT")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
|
||
const fullSalary =
|
||
_salaryPeriod == null
|
||
? 0
|
||
: _salaryPeriod.salaryProfiles
|
||
.filter((x) => x.type == "FULL")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
const fullHaftSalary =
|
||
_salaryPeriod == null
|
||
? 0
|
||
: _salaryPeriod.salaryProfiles
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.reduce((accumulator, object: any) => {
|
||
return (
|
||
accumulator +
|
||
(object.amountUse == null ? 0 : object.amountUse) +
|
||
(object.amountSpecial == null ? 0 : object.amountSpecial)
|
||
);
|
||
}, 0);
|
||
return new HttpSuccess({
|
||
template: "emp2-01",
|
||
reportName: "emp2-01",
|
||
data: {
|
||
date: Extension.ToThaiNumber(
|
||
Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)),
|
||
),
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())),
|
||
agency: agency,
|
||
totalSalary:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(_salaryPeriod.currentAmount.toString()),
|
||
totalUser:
|
||
_salaryPeriod == null ? "" : Extension.ToThaiNumber(_salaryPeriod.total.toString()),
|
||
sixPercentAmount:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(_salaryPeriod.sixPercentAmount.toString()),
|
||
spentAmount:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(_salaryPeriod.spentAmount.toString()),
|
||
remainingAmount:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
(_salaryPeriod.sixPercentAmount - _salaryPeriod.spentAmount).toString(),
|
||
),
|
||
fifteenPercentOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent).toString(),
|
||
),
|
||
totalOld: Extension.ToThaiNumber(
|
||
(_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.total).toString(),
|
||
),
|
||
haft:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
_salaryPeriod.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(),
|
||
),
|
||
full:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
_salaryPeriod.salaryProfiles.filter((x) => x.type == "FULL").length.toString(),
|
||
),
|
||
fullHaft:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
_salaryPeriod.salaryProfiles
|
||
.filter((x) => x.type == "FULLHAFT")
|
||
.length.toString(),
|
||
),
|
||
notPromoted:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
_salaryPeriod.salaryProfiles.filter((x) => x.type == "NONE").length.toString(),
|
||
),
|
||
haftSalary: Extension.ToThaiNumber(haftSalary.toString()),
|
||
fullSalary: Extension.ToThaiNumber(fullSalary.toString()),
|
||
fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toString()),
|
||
total: Extension.ToThaiNumber((haftSalary + fullSalary + fullHaftSalary).toString()),
|
||
summary:
|
||
_salaryPeriod == null
|
||
? ""
|
||
: Extension.ToThaiNumber(
|
||
(
|
||
_salaryPeriod.sixPercentAmount -
|
||
_salaryPeriod.spentAmount -
|
||
haftSalary -
|
||
fullSalary -
|
||
fullHaftSalary
|
||
).toString(),
|
||
),
|
||
reason: null,
|
||
},
|
||
});
|
||
}
|
||
}
|
||
/**
|
||
* API 02-รายชื่อลูกจ้างประจำผู้ครองตำแหน่ง ณ วันที่ 1 มีนาคม
|
||
*
|
||
* @summary 02-รายชื่อลูกจ้างประจำผู้ครองตำแหน่ง ณ วันที่ 1 มีนาคม
|
||
*
|
||
*/
|
||
@Get("emp-02/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp2(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
salaryOrg: {
|
||
snapshot: "SNAP1",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
amount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
reason: null,
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-02" : "emp2-02",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-02" : "emp2-02",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 03-รายชื่อลูกจ้างประจำที่ได้รับการเสนอขอเลื่อนขั้นค่าจ้างหนึ่งขั้น
|
||
*
|
||
* @summary 03-รายชื่อลูกจ้างประจำที่ได้รับการเสนอขอเลื่อนขั้นค่าจ้างหนึ่งขั้น
|
||
*
|
||
*/
|
||
@Get("emp-03/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp3(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
type: "FULL",
|
||
salaryOrg: {
|
||
snapshot: "SNAP1",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
amount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
|
||
const fifteenPercent =
|
||
(_salaryPeriod[0].salaryOrg == null || _salaryPeriod[0].salaryOrg.fifteenPercent == null
|
||
? ""
|
||
: _salaryPeriod[0].salaryOrg.fifteenPercent.toString()) +
|
||
"." +
|
||
(_salaryPeriod[0].salaryOrg == null || _salaryPeriod[0].salaryOrg.fifteenPoint == null
|
||
? "๐๐"
|
||
: _salaryPeriod[0].salaryOrg.fifteenPoint.toString());
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
score: null,
|
||
reason: null,
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-03" : "emp2-03",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-03" : "emp2-03",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
fifteenPercent: Extension.ToThaiNumber(fifteenPercent),
|
||
yearShort: Extension.ToThaiNumber(
|
||
String(Extension.ToThaiYear(salaryPeriod.year)).substr(-2),
|
||
),
|
||
yearShortOld: Extension.ToThaiNumber(
|
||
String(Extension.ToThaiYear(salaryPeriod.year - 1)).substr(-2),
|
||
),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 04-แบบ ลจ.กทม.1-รายชื่อลูกจ้างผู้สมควรได้เลื่อนขั้นค่าจ้าง
|
||
*
|
||
* @summary 04-แบบ ลจ.กทม.1-รายชื่อลูกจ้างผู้สมควรได้เลื่อนขั้นค่าจ้าง
|
||
*
|
||
*/
|
||
@Get("emp-04/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp4(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
type: In(["HAFT", "FULL", "FULLHAFT"]),
|
||
isNext: false,
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
amount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
positionSalaryAmount: profile.positionSalaryAmount
|
||
? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString())
|
||
: null,
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
reason: null,
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-04" : "emp2-04",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-04" : "emp2-04",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 05-แบบ ลจ.กทม.1-1-รายชื่อลูกจ้างผู้สมควรได้รับค่าตอบแทนพิเศษ
|
||
*
|
||
* @summary 05-แบบ ลจ.กทม.1-1-รายชื่อลูกจ้างผู้สมควรได้รับค่าตอบแทนพิเศษ
|
||
*
|
||
*/
|
||
@Get("emp-05/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp5(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
type: In(["HAFT", "FULL", "FULLHAFT"]),
|
||
isNext: true,
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
amount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
positionSalaryAmount: profile.positionSalaryAmount
|
||
? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString())
|
||
: null,
|
||
amountSpecial:
|
||
profile.amountSpecial > 0
|
||
? "(" + Extension.ToThaiNumber(profile.amountSpecial.toString()) + ")"
|
||
: "",
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
reason: null,
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-05" : "emp2-05",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-05" : "emp2-05",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 06-แบบ ลจ.กทม.2-รายชื่อลูกจ้างผู้ไม่สมควรเลื่อนขั้นค่าจ้าง
|
||
*
|
||
* @summary 06-แบบ ลจ.กทม.2-รายชื่อลูกจ้างผู้ไม่สมควรเลื่อนขั้นค่าจ้าง
|
||
*
|
||
*/
|
||
@Get("emp-06/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp6(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
type: In(["NONE"]),
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
amount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
positionSalaryAmount: profile.positionSalaryAmount
|
||
? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString())
|
||
: null,
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
reason: null, //เหตุผลที่ไม่สมควรหรือไม่อาจเลื่อนขั้นค่าจ้าง
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-06" : "emp2-06",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-06" : "emp2-06",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 07-แบบ ลจ.กทม.2-1-รายชื่อลูกจ้างผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ
|
||
*
|
||
* @summary 07-แบบ ลจ.กทม.2-1-รายชื่อลูกจ้างผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ
|
||
*
|
||
*/
|
||
@Get("emp-07/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp7(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
isNext: false,
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
amount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
positionSalaryAmount: profile.positionSalaryAmount
|
||
? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString())
|
||
: null,
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
reason: null, //เหตุผลที่ไม่สมควรหรือไม่อาจเลื่อนขั้นค่าจ้าง
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-07" : "emp2-07",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-07" : "emp2-07",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
// /**
|
||
// * API 08-แบบ ลจ.กทม.3-บัญชีแสดงวันลาในครึ่งปีของลูกจ้าง
|
||
// *
|
||
// * @summary 08-แบบ ลจ.กทม.3-บัญชีแสดงวันลาในครึ่งปีของลูกจ้าง
|
||
// *
|
||
// */
|
||
// @Get("emp-08/{rootId}/{salaryPeriodId}")
|
||
// async SalaryReportEmp8(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
// const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
// where: {
|
||
// id: salaryPeriodId,
|
||
// },
|
||
// });
|
||
// if (!salaryPeriod) {
|
||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
|
||
// }
|
||
// }
|
||
/**
|
||
* API 09-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับเลื่อนขั้นค่าจ้างในวันที่ 1 เมษา ย้อนหลัง 3 ครั้ง
|
||
*
|
||
* @summary 09-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับเลื่อนขั้นค่าจ้างในวันที่ 1 เมษา ย้อนหลัง 3 ครั้ง
|
||
*
|
||
*/
|
||
@Get("emp-09/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp9(@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,
|
||
},
|
||
},
|
||
order: {
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
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 10-รายชื่อลูกจ้างประจำผู้มีผลการประเมินดีเด่น
|
||
// *
|
||
// * @summary 10-รายชื่อลูกจ้างประจำผู้มีผลการประเมินดีเด่น
|
||
// *
|
||
// */
|
||
// @Get("emp-10/{rootId}/{salaryPeriodId}")
|
||
// async SalaryReportEmp10(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||
// const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||
// where: {
|
||
// id: salaryPeriodId,
|
||
// },
|
||
// });
|
||
// if (!salaryPeriod) {
|
||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
|
||
// }
|
||
// }
|
||
/**
|
||
* API 11-คำสั่ง
|
||
*
|
||
* @summary 11-คำสั่ง
|
||
*
|
||
*/
|
||
@Get("emp-11/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp11(@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,
|
||
},
|
||
},
|
||
order: {
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
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 12-บัญชีรายละเอียดผู้ได้รับอัตราค่าจ้างสูงกว่าขั้นสูง (แนบท้ายคำสั่ง)
|
||
*
|
||
* @summary 12-บัญชีรายละเอียดผู้ได้รับอัตราค่าจ้างสูงกว่าขั้นสูง (แนบท้ายคำสั่ง)
|
||
*
|
||
*/
|
||
@Get("emp-12/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp12(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
type: In(["HAFT", "FULL", "FULLHAFT"]),
|
||
isNext: false,
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
positionSalaryAmount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
positionSalaryAmount: profile.positionSalaryAmount
|
||
? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString())
|
||
: null,
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
remark:
|
||
`${profile.type === "FULL" ? "หนึ่งขั้น" : ""}\n` +
|
||
`${profile.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` +
|
||
`${profile.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` +
|
||
`${profile.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-12" : "emp2-12",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-12" : "emp2-12",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 13-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง
|
||
*
|
||
* @summary 13-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง
|
||
*
|
||
*/
|
||
@Get("emp-13/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp13(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
type: In(["NONE"]),
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
positionSalaryAmount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
reason: null, // หมายเหตุ
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-13" : "emp2-13",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-13" : "emp2-13",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 14-คำสั่ง
|
||
*
|
||
* @summary 14-คำสั่ง
|
||
*
|
||
*/
|
||
@Get("emp-14/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp14(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
type: In(["HAFT", "FULL", "FULLHAFT"]),
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
positionSalaryAmount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
positionSalaryAmount: profile.positionSalaryAmount
|
||
? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString())
|
||
: null,
|
||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||
remark:
|
||
`${profile.type === "FULL" ? "หนึ่งขั้น" : ""}\n` +
|
||
`${profile.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` +
|
||
`${profile.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` +
|
||
`${profile.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-14" : "emp2-14",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-14" : "emp2-14",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 15-บัญชีรายละเอียดลูกจ้างประจำที่ได้รับค่าตอบแทนพิเศษ(แนบท้ายคำสั่ง)
|
||
*
|
||
* @summary 15-บัญชีรายละเอียดลูกจ้างประจำที่ได้รับค่าตอบแทนพิเศษ(แนบท้ายคำสั่ง)
|
||
*
|
||
*/
|
||
@Get("emp-15/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp15(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
isNext: true,
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
positionSalaryAmount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.positionSalaryAmount
|
||
? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString())
|
||
: null,
|
||
precentTwo:
|
||
profile.positionSalaryAmountPer == 0.2
|
||
? profile.positionSalaryAmount * profile.positionSalaryAmountPer
|
||
: null, //ร้อยละ 2
|
||
precentFour:
|
||
profile.positionSalaryAmountPer == 0.4
|
||
? profile.positionSalaryAmount * profile.positionSalaryAmountPer
|
||
: null, //ร้อยละ 4
|
||
reason: null, // หมายเหตุ
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-15" : "emp2-15",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-15" : "emp2-15",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 16-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ
|
||
*
|
||
* @summary 16-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ
|
||
*
|
||
*/
|
||
@Get("emp-16/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp16(@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.salaryProfileEmployeeRepository.find({
|
||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||
where: {
|
||
isNext: false,
|
||
salaryOrg: {
|
||
snapshot: "SNAP2",
|
||
rootId: rootId,
|
||
salaryPeriodId: salaryPeriodId,
|
||
},
|
||
},
|
||
order: {
|
||
positionSalaryAmount: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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,
|
||
position: profile.position,
|
||
posLevel: `${profile.posTypeShort} ${profile.posLevel}`,
|
||
posNumber:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
|
||
reason: null, // หมายเหตุ
|
||
};
|
||
});
|
||
|
||
return new HttpSuccess({
|
||
template: salaryPeriod.period == "APR" ? "emp1-16" : "emp2-16",
|
||
reportName: salaryPeriod.period == "APR" ? "emp1-16" : "emp2-16",
|
||
data: {
|
||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||
agency: agency,
|
||
data: formattedData,
|
||
},
|
||
});
|
||
}
|
||
/**
|
||
* API 17-คำสั่ง
|
||
*
|
||
* @summary 17-คำสั่ง
|
||
*
|
||
*/
|
||
@Get("emp-17/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp17(@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,
|
||
},
|
||
},
|
||
order: {
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
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 18-คำสั่ง
|
||
*
|
||
* @summary 18-คำสั่ง
|
||
*
|
||
*/
|
||
@Get("emp-18/{rootId}/{salaryPeriodId}")
|
||
async SalaryReportEmp18(@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,
|
||
},
|
||
},
|
||
order: {
|
||
orgShortName: "ASC",
|
||
posMasterNo: "ASC",
|
||
},
|
||
});
|
||
|
||
if (!_salaryPeriod) {
|
||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||
}
|
||
|
||
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:
|
||
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
|
||
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,
|
||
},
|
||
});
|
||
}
|
||
}
|