fix report kk1
This commit is contained in:
parent
702eb13782
commit
dcf1a6b1c8
2 changed files with 332 additions and 187 deletions
|
|
@ -87,6 +87,7 @@ import { OrgChild4 } from "../entities/OrgChild4";
|
||||||
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
||||||
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
||||||
import { CommandRecive } from "../entities/CommandRecive";
|
import { CommandRecive } from "../entities/CommandRecive";
|
||||||
|
import { CommandCode } from "../entities/CommandCode";
|
||||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
|
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
|
||||||
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
||||||
|
|
@ -146,6 +147,7 @@ export class ProfileController extends Controller {
|
||||||
private permissionProflileRepository = AppDataSource.getRepository(PermissionProfile);
|
private permissionProflileRepository = AppDataSource.getRepository(PermissionProfile);
|
||||||
private profileAssistanceRepository = AppDataSource.getRepository(ProfileAssistance);
|
private profileAssistanceRepository = AppDataSource.getRepository(ProfileAssistance);
|
||||||
private commandReciveRepository = AppDataSource.getRepository(CommandRecive);
|
private commandReciveRepository = AppDataSource.getRepository(CommandRecive);
|
||||||
|
private commandCodeRepository = AppDataSource.getRepository(CommandCode);
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
private profileLeaveService = new ProfileLeaveService();
|
private profileLeaveService = new ProfileLeaveService();
|
||||||
|
|
@ -1370,26 +1372,26 @@ export class ProfileController extends Controller {
|
||||||
yearData = { year };
|
yearData = { year };
|
||||||
|
|
||||||
for (let i = 1; i <= 11; i++) {
|
for (let i = 1; i <= 11; i++) {
|
||||||
yearData[`leaveTypeCodeLv${i}`] = "-";
|
yearData[`leaveTypeCodeLv${i}`] = "";
|
||||||
yearData[`totalLeaveDaysLv${i}`] = "-";
|
yearData[`totalLeaveDaysLv${i}`] = "";
|
||||||
yearData[`leaveTypeNameLv${i}`] = "-";
|
yearData[`leaveTypeNameLv${i}`] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
leaves.push(yearData);
|
leaves.push(yearData);
|
||||||
}
|
}
|
||||||
|
|
||||||
yearData[leaveTypeCodeKey] = item.code ? item.code : "-";
|
yearData[leaveTypeCodeKey] = item.code ? item.code : "";
|
||||||
yearData[totalLeaveDaysKey] = item.totalLeaveDays
|
yearData[totalLeaveDaysKey] = item.totalLeaveDays
|
||||||
? Extension.ToThaiNumber(item.totalLeaveDays.toString())
|
? Extension.ToThaiNumber(item.totalLeaveDays.toString())
|
||||||
: "-";
|
: "-";
|
||||||
yearData[leaveTypeNameKey] = item.name ? item.name : "-";
|
yearData[leaveTypeNameKey] = item.name ? item.name : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (leaves.length === 0) {
|
// if (leaves.length === 0) {
|
||||||
leaves.push({year:""});
|
// leaves.push({year:""});
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Query มาสาย/ขาดราชการ และ merge ตามปี
|
// Query มาสาย/ขาดราชการ และ merge ตามปี
|
||||||
const absentLate_raw = await this.profileAbsentLateRepo
|
const absentLate_raw = await this.profileAbsentLateRepo
|
||||||
|
|
@ -1417,9 +1419,9 @@ export class ProfileController extends Controller {
|
||||||
if (!yearData) {
|
if (!yearData) {
|
||||||
yearData = { year };
|
yearData = { year };
|
||||||
for (let i = 1; i <= 11; i++) {
|
for (let i = 1; i <= 11; i++) {
|
||||||
yearData[`leaveTypeCodeLv${i}`] = "-";
|
yearData[`leaveTypeCodeLv${i}`] = "";
|
||||||
yearData[`totalLeaveDaysLv${i}`] = "-";
|
yearData[`totalLeaveDaysLv${i}`] = "";
|
||||||
yearData[`leaveTypeNameLv${i}`] = "-";
|
yearData[`leaveTypeNameLv${i}`] = "";
|
||||||
}
|
}
|
||||||
leaves.push(yearData);
|
leaves.push(yearData);
|
||||||
}
|
}
|
||||||
|
|
@ -1428,18 +1430,18 @@ export class ProfileController extends Controller {
|
||||||
if (item.status === "LATE") {
|
if (item.status === "LATE") {
|
||||||
yearData.late = item.totalAmount
|
yearData.late = item.totalAmount
|
||||||
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
||||||
: "-";
|
: "";
|
||||||
} else if (item.status === "ABSENT") {
|
} else if (item.status === "ABSENT") {
|
||||||
yearData.absent = item.totalAmount
|
yearData.absent = item.totalAmount
|
||||||
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
||||||
: "-";
|
: "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// เติมค่า "-" ถ้าไม่มีข้อมูลมาสาย/ขาดราชการ
|
// เติมค่า "" ถ้าไม่มีข้อมูลมาสาย/ขาดราชการ
|
||||||
leaves.forEach((yearData) => {
|
leaves.forEach((yearData) => {
|
||||||
if (!yearData.late) yearData.late = "-";
|
if (!yearData.late) yearData.late = "";
|
||||||
if (!yearData.absent) yearData.absent = "-";
|
if (!yearData.absent) yearData.absent = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
const leave2_raw = await this.profileLeaveRepository
|
const leave2_raw = await this.profileLeaveRepository
|
||||||
|
|
@ -1568,22 +1570,52 @@ export class ProfileController extends Controller {
|
||||||
];
|
];
|
||||||
|
|
||||||
const position_raw = await this.salaryRepo.find({
|
const position_raw = await this.salaryRepo.find({
|
||||||
where: {
|
where: [{
|
||||||
profileId: id,
|
profileId: id,
|
||||||
commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
|
commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
|
||||||
// isEntry: false,
|
// isEntry: false,
|
||||||
},
|
},
|
||||||
|
{ profileId: id, commandCode: IsNull() }],
|
||||||
order: { order: "ASC" },
|
order: { order: "ASC" },
|
||||||
});
|
});
|
||||||
|
let _commandName:any = "";
|
||||||
|
let _commandDateAffect:any = ""
|
||||||
const positionList =
|
const positionList =
|
||||||
position_raw.length > 0
|
position_raw.length > 0
|
||||||
? position_raw.map((item) => ({
|
? await Promise.all(position_raw.map(async(item, idx, arr) => {
|
||||||
commandName: item.commandName ?? "",
|
const isLast = idx === arr.length - 1;
|
||||||
commandDateAffect: item.commandDateAffect
|
if (isLast) {
|
||||||
|
_commandDateAffect = item.commandDateAffect
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
)
|
||||||
: "",
|
: "",
|
||||||
commandDateSign: item.commandDateSign
|
commandDateSign: item.commandDateSign
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
|
? Extension.ToThaiNumber(
|
||||||
|
Extension.ToThaiFullDate2(item.commandDateSign)
|
||||||
|
)
|
||||||
: "",
|
: "",
|
||||||
posNo:
|
posNo:
|
||||||
item.posNoAbb && item.posNo
|
item.posNoAbb && item.posNo
|
||||||
|
|
@ -1596,11 +1628,20 @@ export class ProfileController extends Controller {
|
||||||
: item.positionCee
|
: item.positionCee
|
||||||
? Extension.ToThaiNumber(item.positionCee)
|
? Extension.ToThaiNumber(item.positionCee)
|
||||||
: null,
|
: null,
|
||||||
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
|
amount: item.amount
|
||||||
positionSalaryAmount: item.positionSalaryAmount
|
? Extension.ToThaiNumber(
|
||||||
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString())
|
Number(item.amount).toLocaleString()
|
||||||
|
)
|
||||||
: "",
|
: "",
|
||||||
refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
|
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 = [];
|
let retires = [];
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const retire_raw = await this.salaryRepo.findOne({
|
// todo: รอข้อสรุป
|
||||||
where: {
|
// const retire_raw = await this.salaryRepo.findOne({
|
||||||
profileId: id,
|
// where: {
|
||||||
commandCode: In(["12", "15", "16"]),
|
// profileId: id,
|
||||||
},
|
// commandCode: In(["12", "15", "16"]),
|
||||||
order: { order: "desc" },
|
// },
|
||||||
});
|
// order: { order: "desc" },
|
||||||
|
// });
|
||||||
|
|
||||||
if (retire_raw) {
|
// if (retire_raw) {
|
||||||
const startDate = retire_raw.commandDateAffect;
|
// const startDate = retire_raw.commandDateAffect;
|
||||||
|
|
||||||
// คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
|
// // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
|
||||||
let daysCount = 0;
|
// let daysCount = 0;
|
||||||
if (startDate) {
|
// if (startDate) {
|
||||||
const start = new Date(startDate);
|
// const start = new Date(startDate);
|
||||||
daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
// daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
||||||
}
|
// }
|
||||||
|
|
||||||
const startDateStr = startDate
|
// const startDateStr = startDate
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
|
// ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
|
||||||
: "-";
|
// : "-";
|
||||||
|
|
||||||
retires.push({
|
// retires.push({
|
||||||
date: `${startDateStr}`,
|
// date: `${startDateStr}`,
|
||||||
detail: retire_raw.commandName ?? "-",
|
// detail: retire_raw.commandName ?? "-",
|
||||||
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
|
// day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
// กรณีไม่มีข้อมูล
|
// กรณีไม่มีข้อมูล
|
||||||
if (retires.length === 0) {
|
if (retires.length === 0) {
|
||||||
|
|
@ -1782,7 +1824,7 @@ export class ProfileController extends Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Merge รักษาการ และ ช่วยราชาร
|
// Merge รักษาการ และ ช่วยราชการ
|
||||||
const actposition = [..._actpositions, ..._assistances];
|
const actposition = [..._actpositions, ..._assistances];
|
||||||
|
|
||||||
const duty_raw = await this.dutyRepository.find({
|
const duty_raw = await this.dutyRepository.find({
|
||||||
|
|
@ -1892,7 +1934,16 @@ export class ProfileController extends Controller {
|
||||||
});
|
});
|
||||||
const otherIncome =
|
const otherIncome =
|
||||||
otherIncome_raw.length > 0
|
otherIncome_raw.length > 0
|
||||||
? otherIncome_raw.map((item) => ({
|
? 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 ?? "",
|
commandName: item.commandName ?? "",
|
||||||
commandDateAffect: item.commandDateAffect
|
commandDateAffect: item.commandDateAffect
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
||||||
|
|
@ -1908,7 +1959,8 @@ export class ProfileController extends Controller {
|
||||||
? Extension.ToThaiNumber(item.positionCee)
|
? Extension.ToThaiNumber(item.positionCee)
|
||||||
: null,
|
: null,
|
||||||
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
|
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))}`)
|
refDoc: Extension.ToThaiNumber(`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`)
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
: [
|
: [
|
||||||
{
|
{
|
||||||
|
|
@ -2042,8 +2094,7 @@ export class ProfileController extends Controller {
|
||||||
appointDate: profiles?.dateAppoint
|
appointDate: profiles?.dateAppoint
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
|
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
|
||||||
: "",
|
: "",
|
||||||
positionDate:
|
positionDate: _commandDateAffect ?? "",
|
||||||
positionList.length > 0 ? positionList[positionList.length - 1].commandDateAffect : "",
|
|
||||||
citizenId:
|
citizenId:
|
||||||
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
|
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
|
||||||
fatherFullName:
|
fatherFullName:
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ import { ProfileDuty } from "../entities/ProfileDuty";
|
||||||
import { getTopDegrees } from "../services/PositionService";
|
import { getTopDegrees } from "../services/PositionService";
|
||||||
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
||||||
import { PostRetireToExprofile } from "./ExRetirementController";
|
import { PostRetireToExprofile } from "./ExRetirementController";
|
||||||
|
import { CommandCode } from "../entities/CommandCode";
|
||||||
@Route("api/v1/org/profile-employee")
|
@Route("api/v1/org/profile-employee")
|
||||||
@Tags("ProfileEmployee")
|
@Tags("ProfileEmployee")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -136,6 +137,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
|
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
|
||||||
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
|
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
|
||||||
private profileAssistanceRepository = AppDataSource.getRepository(ProfileAssistance);
|
private profileAssistanceRepository = AppDataSource.getRepository(ProfileAssistance);
|
||||||
|
private commandCodeRepository = AppDataSource.getRepository(CommandCode);
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
private profileLeaveService = new ProfileLeaveService();
|
private profileLeaveService = new ProfileLeaveService();
|
||||||
|
|
@ -808,27 +810,68 @@ export class ProfileEmployeeController extends Controller {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const leave_raw = await this.profileLeaveRepository.find({
|
const leave_raw = await this.profileLeaveRepository
|
||||||
relations: { leaveType: true },
|
.createQueryBuilder("profileLeave")
|
||||||
where: { profileEmployeeId: id, isDeleted: false },
|
.leftJoinAndSelect("profileLeave.leaveType", "leaveType")
|
||||||
order: { dateLeaveStart: "ASC" },
|
.select([
|
||||||
|
"profileLeave.isDeleted",
|
||||||
|
"profileLeave.leaveTypeId",
|
||||||
|
"leaveType.name as name",
|
||||||
|
"leaveType.code as code",
|
||||||
|
"profileLeave.status",
|
||||||
|
"profileLeave.profileEmployeeId",
|
||||||
|
"MAX(profileLeave.dateLeaveStart) as maxDateLeaveStart",
|
||||||
|
])
|
||||||
|
.addSelect("SUM(profileLeave.leaveDays)", "totalLeaveDays")
|
||||||
|
.where("profileLeave.profileEmployeeId = :profileId", { profileId: id })
|
||||||
|
.andWhere("profileLeave.isDeleted = :isDeleted", { isDeleted: false })
|
||||||
|
.andWhere("profileLeave.status = :status", { status: "approve" })
|
||||||
|
.groupBy("profileLeave.leaveTypeId")
|
||||||
|
.orderBy("code", "ASC")
|
||||||
|
.addOrderBy("maxDateLeaveStart", "ASC")
|
||||||
|
.getRawMany();
|
||||||
|
|
||||||
|
const leaves: any[] = [];
|
||||||
|
|
||||||
|
leave_raw.forEach((item) => {
|
||||||
|
const leaveTypeCode = item.code ? item.code.trim().toUpperCase() : "";
|
||||||
|
if (leaveTypeCode.startsWith("LV-")) {
|
||||||
|
const lvIndex = parseInt(leaveTypeCode.split("-")[1], 10);
|
||||||
|
|
||||||
|
if (lvIndex >= 1 && lvIndex <= 11) {
|
||||||
|
const leaveTypeCodeKey = `leaveTypeCodeLv${lvIndex}`;
|
||||||
|
const totalLeaveDaysKey = `totalLeaveDaysLv${lvIndex}`;
|
||||||
|
const leaveTypeNameKey = `leaveTypeNameLv${lvIndex}`;
|
||||||
|
|
||||||
|
const leaveDate = item.maxDateLeaveStart ? new Date(item.maxDateLeaveStart) : null;
|
||||||
|
const year = leaveDate
|
||||||
|
? Extension.ToThaiNumber(Extension.ToThaiShortYear(leaveDate))
|
||||||
|
: "";
|
||||||
|
|
||||||
|
let yearData = leaves.find((data) => data.year === year);
|
||||||
|
if (!yearData) {
|
||||||
|
yearData = { year };
|
||||||
|
|
||||||
|
for (let i = 1; i <= 11; i++) {
|
||||||
|
yearData[`leaveTypeCodeLv${i}`] = "-";
|
||||||
|
yearData[`totalLeaveDaysLv${i}`] = "-";
|
||||||
|
yearData[`leaveTypeNameLv${i}`] = "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
leaves.push(yearData);
|
||||||
|
}
|
||||||
|
|
||||||
|
yearData[leaveTypeCodeKey] = item.code ? item.code : "-";
|
||||||
|
yearData[totalLeaveDaysKey] = item.totalLeaveDays
|
||||||
|
? Extension.ToThaiNumber(item.totalLeaveDays.toString())
|
||||||
|
: "-";
|
||||||
|
yearData[leaveTypeNameKey] = item.name ? item.name : "-";
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const leaves =
|
|
||||||
leave_raw.length > 0
|
// กรองเอา object ที่ไม่มี year ออก
|
||||||
? leave_raw.map((item) => ({
|
const filteredLeaves = leaves.filter(item => item.year && item.year !== "");
|
||||||
LeaveTypeName: item.leaveType.name,
|
|
||||||
DateLeaveStart: item.dateLeaveStart
|
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart))
|
|
||||||
: "",
|
|
||||||
LeaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "",
|
|
||||||
}))
|
|
||||||
: [
|
|
||||||
{
|
|
||||||
LeaveTypeName: "-",
|
|
||||||
DateLeaveStart: "-",
|
|
||||||
LeaveDays: "-",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
|
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
|
||||||
|
|
@ -917,7 +960,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[6].createdAt))
|
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[6].createdAt))
|
||||||
: null,
|
: null,
|
||||||
insignias,
|
insignias,
|
||||||
leaves,
|
leaves: filteredLeaves,
|
||||||
certs,
|
certs,
|
||||||
trainings,
|
trainings,
|
||||||
disciplines,
|
disciplines,
|
||||||
|
|
@ -943,6 +986,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
|
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
|
||||||
const profiles = await this.profileRepo.findOne({
|
const profiles = await this.profileRepo.findOne({
|
||||||
relations: [
|
relations: [
|
||||||
|
"posType",
|
||||||
"posLevel",
|
"posLevel",
|
||||||
"currentSubDistrict",
|
"currentSubDistrict",
|
||||||
"currentDistrict",
|
"currentDistrict",
|
||||||
|
|
@ -1364,26 +1408,26 @@ export class ProfileEmployeeController extends Controller {
|
||||||
yearData = { year };
|
yearData = { year };
|
||||||
|
|
||||||
for (let i = 1; i <= 11; i++) {
|
for (let i = 1; i <= 11; i++) {
|
||||||
yearData[`leaveTypeCodeLv${i}`] = "-";
|
yearData[`leaveTypeCodeLv${i}`] = "";
|
||||||
yearData[`totalLeaveDaysLv${i}`] = "-";
|
yearData[`totalLeaveDaysLv${i}`] = "";
|
||||||
yearData[`leaveTypeNameLv${i}`] = "-";
|
yearData[`leaveTypeNameLv${i}`] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
leaves.push(yearData);
|
leaves.push(yearData);
|
||||||
}
|
}
|
||||||
|
|
||||||
yearData[leaveTypeCodeKey] = item.code ? item.code : "-";
|
yearData[leaveTypeCodeKey] = item.code ? item.code : "";
|
||||||
yearData[totalLeaveDaysKey] = item.totalLeaveDays
|
yearData[totalLeaveDaysKey] = item.totalLeaveDays
|
||||||
? Extension.ToThaiNumber(item.totalLeaveDays.toString())
|
? Extension.ToThaiNumber(item.totalLeaveDays.toString())
|
||||||
: "-";
|
: "";
|
||||||
yearData[leaveTypeNameKey] = item.name ? item.name : "-";
|
yearData[leaveTypeNameKey] = item.name ? item.name : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (leaves.length === 0) {
|
// if (leaves.length === 0) {
|
||||||
leaves.push({year:""});
|
// leaves.push({year:""});
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Query มาสาย/ขาดราชการ และ merge ตามปี
|
// Query มาสาย/ขาดราชการ และ merge ตามปี
|
||||||
const absentLate_raw = await this.profileEmployeeAbsentLateRepo
|
const absentLate_raw = await this.profileEmployeeAbsentLateRepo
|
||||||
|
|
@ -1411,9 +1455,9 @@ export class ProfileEmployeeController extends Controller {
|
||||||
if (!yearData) {
|
if (!yearData) {
|
||||||
yearData = { year };
|
yearData = { year };
|
||||||
for (let i = 1; i <= 11; i++) {
|
for (let i = 1; i <= 11; i++) {
|
||||||
yearData[`leaveTypeCodeLv${i}`] = "-";
|
yearData[`leaveTypeCodeLv${i}`] = "";
|
||||||
yearData[`totalLeaveDaysLv${i}`] = "-";
|
yearData[`totalLeaveDaysLv${i}`] = "";
|
||||||
yearData[`leaveTypeNameLv${i}`] = "-";
|
yearData[`leaveTypeNameLv${i}`] = "";
|
||||||
}
|
}
|
||||||
leaves.push(yearData);
|
leaves.push(yearData);
|
||||||
}
|
}
|
||||||
|
|
@ -1422,18 +1466,18 @@ export class ProfileEmployeeController extends Controller {
|
||||||
if (item.status === "LATE") {
|
if (item.status === "LATE") {
|
||||||
yearData.lateAmount = item.totalAmount
|
yearData.lateAmount = item.totalAmount
|
||||||
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
||||||
: "-";
|
: "";
|
||||||
} else if (item.status === "ABSENT") {
|
} else if (item.status === "ABSENT") {
|
||||||
yearData.absentAmount = item.totalAmount
|
yearData.absentAmount = item.totalAmount
|
||||||
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
? Extension.ToThaiNumber(parseFloat(item.totalAmount).toFixed(1))
|
||||||
: "-";
|
: "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// เติมค่า "-" ถ้าไม่มีข้อมูลมาสาย/ขาดราชการ
|
// เติมค่า "" ถ้าไม่มีข้อมูลมาสาย/ขาดราชการ
|
||||||
leaves.forEach((yearData) => {
|
leaves.forEach((yearData) => {
|
||||||
if (!yearData.lateAmount) yearData.lateAmount = "-";
|
if (!yearData.lateAmount) yearData.lateAmount = "";
|
||||||
if (!yearData.absentAmount) yearData.absentAmount = "-";
|
if (!yearData.absentAmount) yearData.absentAmount = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
const leave2_raw = await this.profileLeaveRepository
|
const leave2_raw = await this.profileLeaveRepository
|
||||||
|
|
@ -1562,22 +1606,52 @@ export class ProfileEmployeeController extends Controller {
|
||||||
];
|
];
|
||||||
|
|
||||||
const position_raw = await this.salaryRepo.find({
|
const position_raw = await this.salaryRepo.find({
|
||||||
where: {
|
where: [{
|
||||||
profileEmployeeId: id,
|
profileEmployeeId: id,
|
||||||
commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
|
commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
|
||||||
// isEntry: false,
|
// isEntry: false,
|
||||||
},
|
},
|
||||||
|
{ profileEmployeeId: id, commandCode: IsNull() }],
|
||||||
order: { order: "ASC" },
|
order: { order: "ASC" },
|
||||||
});
|
});
|
||||||
|
let _commandName:any = "";
|
||||||
|
let _commandDateAffect:any = ""
|
||||||
const positionList =
|
const positionList =
|
||||||
position_raw.length > 0
|
position_raw.length > 0
|
||||||
? position_raw.map((item) => ({
|
? await Promise.all(position_raw.map(async(item, idx, arr) => {
|
||||||
commandName: item.commandName ?? "",
|
const isLast = idx === arr.length - 1;
|
||||||
commandDateAffect: item.commandDateAffect
|
if (isLast) {
|
||||||
|
_commandDateAffect = item.commandDateAffect
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
)
|
||||||
: "",
|
: "",
|
||||||
commandDateSign: item.commandDateSign
|
commandDateSign: item.commandDateSign
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
|
? Extension.ToThaiNumber(
|
||||||
|
Extension.ToThaiFullDate2(item.commandDateSign)
|
||||||
|
)
|
||||||
: "",
|
: "",
|
||||||
posNo:
|
posNo:
|
||||||
item.posNoAbb && item.posNo
|
item.posNoAbb && item.posNo
|
||||||
|
|
@ -1590,11 +1664,20 @@ export class ProfileEmployeeController extends Controller {
|
||||||
: item.positionCee
|
: item.positionCee
|
||||||
? Extension.ToThaiNumber(item.positionCee)
|
? Extension.ToThaiNumber(item.positionCee)
|
||||||
: null,
|
: null,
|
||||||
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
|
amount: item.amount
|
||||||
positionSalaryAmount: item.positionSalaryAmount
|
? Extension.ToThaiNumber(
|
||||||
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString())
|
Number(item.amount).toLocaleString()
|
||||||
|
)
|
||||||
: "",
|
: "",
|
||||||
refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
|
positionSalaryAmount: item.positionSalaryAmount
|
||||||
|
? Extension.ToThaiNumber(
|
||||||
|
Number(item.positionSalaryAmount).toLocaleString()
|
||||||
|
)
|
||||||
|
: "",
|
||||||
|
refDoc: Extension.ToThaiNumber(
|
||||||
|
`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`
|
||||||
|
),
|
||||||
|
};
|
||||||
}))
|
}))
|
||||||
: [
|
: [
|
||||||
{
|
{
|
||||||
|
|
@ -1610,6 +1693,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
refDoc: ""
|
refDoc: ""
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// ลูกจ้างยังไม่มีรักษาการและช่วยราชการ
|
// ลูกจ้างยังไม่มีรักษาการและช่วยราชการ
|
||||||
// const actposition_raw = await this.profileActpositionRepo.find({
|
// const actposition_raw = await this.profileActpositionRepo.find({
|
||||||
// select: ["dateStart", "dateEnd", "position", "isDeleted"],
|
// select: ["dateStart", "dateEnd", "position", "isDeleted"],
|
||||||
|
|
@ -1789,7 +1873,16 @@ export class ProfileEmployeeController extends Controller {
|
||||||
});
|
});
|
||||||
const otherIncome =
|
const otherIncome =
|
||||||
otherIncome_raw.length > 0
|
otherIncome_raw.length > 0
|
||||||
? otherIncome_raw.map((item) => ({
|
? 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 ?? "",
|
commandName: item.commandName ?? "",
|
||||||
commandDateAffect: item.commandDateAffect
|
commandDateAffect: item.commandDateAffect
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
|
||||||
|
|
@ -1805,7 +1898,8 @@ export class ProfileEmployeeController extends Controller {
|
||||||
? Extension.ToThaiNumber(item.positionCee)
|
? Extension.ToThaiNumber(item.positionCee)
|
||||||
: null,
|
: null,
|
||||||
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
|
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))}`)
|
refDoc: Extension.ToThaiNumber(`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`)
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
: [
|
: [
|
||||||
{
|
{
|
||||||
|
|
@ -1823,34 +1917,35 @@ export class ProfileEmployeeController extends Controller {
|
||||||
// ประวัติพ้นจากราชการ
|
// ประวัติพ้นจากราชการ
|
||||||
let retires = [];
|
let retires = [];
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const retire_raw = await this.salaryRepo.findOne({
|
// todo: รอข้อสรุป
|
||||||
where: {
|
// const retire_raw = await this.salaryRepo.findOne({
|
||||||
profileEmployeeId: id,
|
// where: {
|
||||||
commandCode: In(["12", "15", "16"]),
|
// profileEmployeeId: id,
|
||||||
},
|
// commandCode: In(["12", "15", "16"]),
|
||||||
order: { order: "desc" },
|
// },
|
||||||
});
|
// order: { order: "desc" },
|
||||||
|
// });
|
||||||
|
|
||||||
if (retire_raw) {
|
// if (retire_raw) {
|
||||||
const startDate = retire_raw.commandDateAffect;
|
// const startDate = retire_raw.commandDateAffect;
|
||||||
|
|
||||||
// คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
|
// // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
|
||||||
let daysCount = 0;
|
// let daysCount = 0;
|
||||||
if (startDate) {
|
// if (startDate) {
|
||||||
const start = new Date(startDate);
|
// const start = new Date(startDate);
|
||||||
daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
// daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
||||||
}
|
// }
|
||||||
|
|
||||||
const startDateStr = startDate
|
// const startDateStr = startDate
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
|
// ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
|
||||||
: "-";
|
// : "-";
|
||||||
|
|
||||||
retires.push({
|
// retires.push({
|
||||||
date: `${startDateStr} - ปัจจุบัน`,
|
// date: `${startDateStr} - ปัจจุบัน`,
|
||||||
detail: retire_raw.commandName ?? "-",
|
// detail: retire_raw.commandName ?? "-",
|
||||||
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
|
// day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
// กรณีไม่มีข้อมูล
|
// กรณีไม่มีข้อมูล
|
||||||
if (retires.length === 0) {
|
if (retires.length === 0) {
|
||||||
|
|
@ -1863,11 +1958,11 @@ export class ProfileEmployeeController extends Controller {
|
||||||
(_child2 == null ? "" : _child2 + " ") +
|
(_child2 == null ? "" : _child2 + " ") +
|
||||||
(_child1 == null ? "" : _child1 + " ") +
|
(_child1 == null ? "" : _child1 + " ") +
|
||||||
(_root == null ? "" : _root).trim()
|
(_root == null ? "" : _root).trim()
|
||||||
const _position = profiles?.position != null ?
|
const _position = (profiles?.position != null ?
|
||||||
profiles?.posLevel != null
|
profiles.posType != null && profiles?.posLevel != null
|
||||||
? Extension.ToThaiNumber(`${profiles.position}${profiles.posLevel.posLevelName}`)
|
? Extension.ToThaiNumber(`${profiles.position} ${profiles.posType.posTypeShortName} ${profiles.posLevel.posLevelName}`)
|
||||||
: profiles.position
|
: profiles.position
|
||||||
: ""
|
: "").trim()
|
||||||
const ocAssistance = await this.profileAssistanceRepository.findOne({
|
const ocAssistance = await this.profileAssistanceRepository.findOne({
|
||||||
select: ["agency", "profileEmployeeId", "commandName", "status", "isDeleted"],
|
select: ["agency", "profileEmployeeId", "commandName", "status", "isDeleted"],
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -1960,8 +2055,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
appointDate: profiles?.dateAppoint
|
appointDate: profiles?.dateAppoint
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
|
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
|
||||||
: "",
|
: "",
|
||||||
positionDate:
|
positionDate: _commandDateAffect ?? "",
|
||||||
positionList.length > 0 ? positionList[positionList.length - 1].commandDateAffect : "",
|
|
||||||
citizenId:
|
citizenId:
|
||||||
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
|
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
|
||||||
fatherFullName:
|
fatherFullName:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue