fix report kk1
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m4s

This commit is contained in:
harid 2026-03-25 15:53:26 +07:00
parent 702eb13782
commit effc782460
2 changed files with 332 additions and 187 deletions

View file

@ -87,6 +87,7 @@ import { OrgChild4 } from "../entities/OrgChild4";
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
import { ProfileAssistance } from "../entities/ProfileAssistance";
import { CommandRecive } from "../entities/CommandRecive";
import { CommandCode } from "../entities/CommandCode";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService";
@ -146,6 +147,7 @@ export class ProfileController extends Controller {
private permissionProflileRepository = AppDataSource.getRepository(PermissionProfile);
private profileAssistanceRepository = AppDataSource.getRepository(ProfileAssistance);
private commandReciveRepository = AppDataSource.getRepository(CommandRecive);
private commandCodeRepository = AppDataSource.getRepository(CommandCode);
// Services
private profileLeaveService = new ProfileLeaveService();
@ -1370,26 +1372,26 @@ export class ProfileController extends Controller {
yearData = { year };
for (let i = 1; i <= 11; i++) {
yearData[`leaveTypeCodeLv${i}`] = "-";
yearData[`totalLeaveDaysLv${i}`] = "-";
yearData[`leaveTypeNameLv${i}`] = "-";
yearData[`leaveTypeCodeLv${i}`] = "";
yearData[`totalLeaveDaysLv${i}`] = "";
yearData[`leaveTypeNameLv${i}`] = "";
}
leaves.push(yearData);
}
yearData[leaveTypeCodeKey] = item.code ? item.code : "-";
yearData[leaveTypeCodeKey] = item.code ? item.code : "";
yearData[totalLeaveDaysKey] = item.totalLeaveDays
? Extension.ToThaiNumber(item.totalLeaveDays.toString())
: "-";
yearData[leaveTypeNameKey] = item.name ? item.name : "-";
yearData[leaveTypeNameKey] = item.name ? item.name : "";
}
}
});
if (leaves.length === 0) {
leaves.push({year:""});
}
// if (leaves.length === 0) {
// leaves.push({year:""});
// }
// Query มาสาย/ขาดราชการ และ merge ตามปี
const absentLate_raw = await this.profileAbsentLateRepo
@ -1417,9 +1419,9 @@ export class ProfileController extends Controller {
if (!yearData) {
yearData = { year };
for (let i = 1; i <= 11; i++) {
yearData[`leaveTypeCodeLv${i}`] = "-";
yearData[`totalLeaveDaysLv${i}`] = "-";
yearData[`leaveTypeNameLv${i}`] = "-";
yearData[`leaveTypeCodeLv${i}`] = "";
yearData[`totalLeaveDaysLv${i}`] = "";
yearData[`leaveTypeNameLv${i}`] = "";
}
leaves.push(yearData);
}
@ -1428,18 +1430,18 @@ export class ProfileController extends Controller {
if (item.status === "LATE") {
yearData.late = item.totalAmount
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
: "-";
: "";
} else if (item.status === "ABSENT") {
yearData.absent = item.totalAmount
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
: "-";
: "";
}
});
// เติมค่า "-" ถ้าไม่มีข้อมูลมาสาย/ขาดราชการ
// เติมค่า "" ถ้าไม่มีข้อมูลมาสาย/ขาดราชการ
leaves.forEach((yearData) => {
if (!yearData.late) yearData.late = "-";
if (!yearData.absent) yearData.absent = "-";
if (!yearData.late) yearData.late = "";
if (!yearData.absent) yearData.absent = "";
});
const leave2_raw = await this.profileLeaveRepository
@ -1568,39 +1570,78 @@ export class ProfileController extends Controller {
];
const position_raw = await this.salaryRepo.find({
where: {
where: [{
profileId: id,
commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
// isEntry: false,
},
{ profileId: id, commandCode: IsNull() }],
order: { order: "ASC" },
});
let _commandName:any = "";
let _commandDateAffect:any = ""
const positionList =
position_raw.length > 0
? position_raw.map((item) => ({
commandName: item.commandName ?? "",
commandDateAffect: item.commandDateAffect
? await Promise.all(position_raw.map(async(item, idx, arr) => {
const isLast = idx === arr.length - 1;
if (isLast) {
_commandDateAffect = item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "",
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "",
posNo:
item.posNoAbb && item.posNo
? Extension.ToThaiNumber(`${item.posNoAbb} ${item.posNo}`)
: "";
}
const _code = item.commandCode ? Number(item.commandCode) : null;
if (_code != null) {
_commandName = await this.commandCodeRepository.findOne({
select: { name: true, code: true },
where: { code: _code }
});
}
const codeSitAbb = item.posNumCodeSitAbb ?? "-"
const commandNo = item.commandNo && item.commandYear
? item.commandNo+"/"+(item.commandYear > 2500 ? item.commandYear : item.commandYear + 543)
: "-"
const dateAffect = item.commandDateAffect
? `${Extension.ToThaiFullDate2(item.commandDateAffect)}`
: "-"
return {
commandName: _commandName && _commandName.name
? _commandName.name
: item.commandName,
commandDateAffect: item.commandDateAffect
? Extension.ToThaiNumber(
Extension.ToThaiFullDate2(item.commandDateAffect)
)
: "",
position: item.positionName,
posType: item.positionType,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(
Extension.ToThaiFullDate2(item.commandDateSign)
)
: "",
posNo:
item.posNoAbb && item.posNo
? Extension.ToThaiNumber(`${item.posNoAbb} ${item.posNo}`)
: "",
position: item.positionName,
posType: item.positionType,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString())
: "",
refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
amount: item.amount
? Extension.ToThaiNumber(
Number(item.amount).toLocaleString()
)
: "",
positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(
Number(item.positionSalaryAmount).toLocaleString()
)
: "",
refDoc: Extension.ToThaiNumber(
`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`
),
};
}))
: [
{
@ -1620,34 +1661,35 @@ export class ProfileController extends Controller {
// ประวัติพ้นจากราชการ
let retires = [];
const currentDate = new Date();
const retire_raw = await this.salaryRepo.findOne({
where: {
profileId: id,
commandCode: In(["12", "15", "16"]),
},
order: { order: "desc" },
});
// todo: รอข้อสรุป
// const retire_raw = await this.salaryRepo.findOne({
// where: {
// profileId: id,
// commandCode: In(["12", "15", "16"]),
// },
// order: { order: "desc" },
// });
if (retire_raw) {
const startDate = retire_raw.commandDateAffect;
// if (retire_raw) {
// const startDate = retire_raw.commandDateAffect;
// คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
let daysCount = 0;
if (startDate) {
const start = new Date(startDate);
daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
}
// // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
// let daysCount = 0;
// if (startDate) {
// const start = new Date(startDate);
// daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
// }
const startDateStr = startDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
: "-";
// const startDateStr = startDate
// ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
// : "-";
retires.push({
date: `${startDateStr}`,
detail: retire_raw.commandName ?? "-",
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
});
}
// retires.push({
// date: `${startDateStr}`,
// detail: retire_raw.commandName ?? "-",
// day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
// });
// }
// กรณีไม่มีข้อมูล
if (retires.length === 0) {
@ -1782,7 +1824,7 @@ export class ProfileController extends Controller {
});
}
}
// Merge รักษาการ และ ช่วยราชาร
// Merge รักษาการ และ ช่วยราชาร
const actposition = [..._actpositions, ..._assistances];
const duty_raw = await this.dutyRepository.find({
@ -1892,23 +1934,33 @@ export class ProfileController extends Controller {
});
const otherIncome =
otherIncome_raw.length > 0
? otherIncome_raw.map((item) => ({
commandName: item.commandName ?? "",
commandDateAffect: item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "",
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "",
commandNo: item.commandNo ? Extension.ToThaiNumber(item.commandNo) : "",
position: item.positionName,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
? await Promise.all(
otherIncome_raw.map(async(item) => {
const codeSitAbb = item.posNumCodeSitAbb ?? "-"
const commandNo = item.commandNo && item.commandYear
? item.commandNo+"/"+(item.commandYear > 2500 ? item.commandYear : item.commandYear + 543)
: "-"
const dateAffect = item.commandDateAffect
? `${Extension.ToThaiFullDate2(item.commandDateAffect)}`
: "-"
return {
commandName: item.commandName ?? "",
commandDateAffect: item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "",
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "",
commandNo: item.commandNo ? Extension.ToThaiNumber(item.commandNo) : "",
position: item.positionName,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
refDoc: Extension.ToThaiNumber(`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`)
}
}))
: [
{
@ -2042,8 +2094,7 @@ export class ProfileController extends Controller {
appointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "",
positionDate:
positionList.length > 0 ? positionList[positionList.length - 1].commandDateAffect : "",
positionDate: _commandDateAffect ?? "",
citizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
fatherFullName: