fix report kk1

This commit is contained in:
harid 2026-03-23 17:44:11 +07:00
parent a76bda34b4
commit fba751a5f9
3 changed files with 66 additions and 102 deletions

View file

@ -32,7 +32,7 @@ import {
UpdateProfileCouple, UpdateProfileCouple,
UpdatePrivacyDto, UpdatePrivacyDto,
} from "../entities/Profile"; } from "../entities/Profile";
import { Brackets, In, IsNull, Like, Not } from "typeorm"; import { Brackets, In, IsNull, Like, Not, MoreThan } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision"; import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
@ -1499,8 +1499,8 @@ 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(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
isEntry: false, // isEntry: false,
}, },
order: { order: "ASC" }, order: { order: "ASC" },
}); });
@ -1529,7 +1529,7 @@ export class ProfileController extends Controller {
positionSalaryAmount: item.positionSalaryAmount positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString()) ? 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))}`) refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
})) }))
: [ : [
{ {
@ -1547,50 +1547,35 @@ export class ProfileController extends Controller {
]; ];
// ประวัติพ้นจากราชการ // ประวัติพ้นจากราชการ
const retireCodes = ['C-PM-12','C-PM-13','C-PM-17','C-PM-18','C-PM-19','C-PM-20','C-PM-23','C-PM-43'];
let retires = []; let retires = [];
let inRetirePeriod = false; const currentDate = new Date();
let currentRetire = null; const retire_raw = await this.salaryRepo.findOne({
where: {
profileId: id,
commandCode: In(["16"]),
},
order: { order: "desc" },
});
for (let i = 0; i < position_raw.length; i++) { if (retire_raw) {
const item = position_raw[i]; const startDate = retire_raw.commandDateAffect;
if (retireCodes.includes(item.commandCode)) { // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
// เริ่มพ้นจากราชการ let daysCount = 0;
currentRetire = { if (startDate) {
commandName: item.commandName ?? "-", const start = new Date(startDate);
startDate: item.commandDateAffect daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
};
inRetirePeriod = true;
} }
else if (inRetirePeriod && currentRetire) {
// เจอคำสั่งถัดไปที่ไม่ใช่การพ้นจากราชการ = วันกลับเข้า
const endDate = item.commandDateAffect;
let daysCount = 0;
if (currentRetire.startDate && endDate) { const startDateStr = startDate
const start = new Date(currentRetire.startDate); ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
const end = new Date(endDate); : "-";
daysCount = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
}
const startDateStr = currentRetire.startDate retires.push({
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentRetire.startDate)) date: `${startDateStr}`,
: "-"; detail: retire_raw.commandName ?? "-",
const endDateStr = endDate day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(endDate)) });
: "-";
retires.push({
date: `${startDateStr} - ${endDateStr}`,
detail: currentRetire.commandName,
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
});
inRetirePeriod = false;
currentRetire = null;
}
} }
// กรณีไม่มีข้อมูล // กรณีไม่มีข้อมูล
@ -1620,11 +1605,7 @@ export class ProfileController extends Controller {
commandExcecuteDate, commandExcecuteDate,
} = await getPosNumCodeSit(item.commandId, "REPORTED"); } = await getPosNumCodeSit(item.commandId, "REPORTED");
_document = Extension.ToThaiNumber( _document = Extension.ToThaiNumber(`คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`)
`คำสั่ง ${posNumCodeSitAbb}
${commandNo}/${commandYear>2500?commandYear:commandYear+543}
. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`
)
_commandTypename = commandTypeName; _commandTypename = commandTypeName;
} }
// ค้นหาหน่วยงานที่รักษาการ // ค้นหาหน่วยงานที่รักษาการ
@ -1656,7 +1637,7 @@ export class ProfileController extends Controller {
} }
_actpositions.push({ _actpositions.push({
data: date:
item.dateStart && item.dateEnd item.dateStart && item.dateEnd
? Extension.ToThaiNumber( ? Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`, `${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`,
@ -1689,14 +1670,14 @@ export class ProfileController extends Controller {
// ช่วยราชการ // ช่วยราชการ
const assistance_raw = await this.profileAssistanceRepository.find({ const assistance_raw = await this.profileAssistanceRepository.find({
select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"], select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"],
where: { profileId: id, status: "PENDING", isDeleted: false }, where: { profileId: id, /*status: "PENDING",*/ isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
let _assistances = [] let _assistances = []
if (assistance_raw.length > 0) { if (assistance_raw.length > 0) {
for (const item of assistance_raw) { for (const item of assistance_raw) {
let _commandTypename: string = item.commandName ?? "ให้ช่วยราชการ"; let _commandTypename: string = item.commandName ?? "ให้ช่วยราชการ";
let _document: string = "-"; let _document: string = item.document ? Extension.ToThaiNumber(item.document) : "-";
let _org: string = item.agency ? Extension.ToThaiNumber(item.agency) : "-"; let _org: string = item.agency ? Extension.ToThaiNumber(item.agency) : "-";
if (item.commandId) { if (item.commandId) {
@ -1708,15 +1689,11 @@ export class ProfileController extends Controller {
commandExcecuteDate, commandExcecuteDate,
} = await getPosNumCodeSit(item.commandId); } = await getPosNumCodeSit(item.commandId);
_document = Extension.ToThaiNumber(` _document = Extension.ToThaiNumber(`คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`)
${posNumCodeSitAbb}
${commandNo}/${commandYear>2500?commandYear:commandYear+543}
. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}
`)
_commandTypename = commandTypeName; _commandTypename = commandTypeName;
} }
_assistances.push({ _assistances.push({
data: date:
item.dateStart && item.dateEnd item.dateStart && item.dateEnd
? Extension.ToThaiNumber( ? Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`, `${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`,
@ -1860,7 +1837,7 @@ 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(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
})) }))
: [ : [
{ {
@ -1955,6 +1932,7 @@ export class ProfileController extends Controller {
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const data = { const data = {
currentDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentDate)),
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
prefix: profiles?.prefix != null ? profiles.prefix : "", prefix: profiles?.prefix != null ? profiles.prefix : "",
firstName: profiles?.firstName != null ? profiles.firstName : "", firstName: profiles?.firstName != null ? profiles.firstName : "",

View file

@ -106,8 +106,8 @@ export class ProfileEmployeeAbsentLateController extends Controller {
} }
/** /**
* API / (Batch) * API / ( Job)
* @summary API / (Batch) Job * @summary API / ( Job)
*/ */
@Post("batch") @Post("batch")
public async newAbsentLateBatch( public async newAbsentLateBatch(

View file

@ -1493,8 +1493,8 @@ 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(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
isEntry: false, // isEntry: false,
}, },
order: { order: "ASC" }, order: { order: "ASC" },
}); });
@ -1523,7 +1523,7 @@ export class ProfileEmployeeController extends Controller {
positionSalaryAmount: item.positionSalaryAmount positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString()) ? 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))}`) refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
})) }))
: [ : [
{ {
@ -1734,7 +1734,7 @@ 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(`คำสั่ง ${item.posNumCodeSitAbb ?? "-"} ที่ ${item.commandNo ?? "-"}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
})) }))
: [ : [
{ {
@ -1750,50 +1750,35 @@ export class ProfileEmployeeController extends Controller {
]; ];
// ประวัติพ้นจากราชการ // ประวัติพ้นจากราชการ
const retireCodes = ['C-PM-12','C-PM-13','C-PM-17','C-PM-18','C-PM-19','C-PM-20','C-PM-23','C-PM-43'];
let retires = []; let retires = [];
let inRetirePeriod = false; const currentDate = new Date();
let currentRetire = null; const retire_raw = await this.salaryRepo.findOne({
where: {
profileEmployeeId: id,
commandCode: In(["16"]),
},
order: { order: "desc" },
});
for (let i = 0; i < position_raw.length; i++) { if (retire_raw) {
const item = position_raw[i]; const startDate = retire_raw.commandDateAffect;
if (retireCodes.includes(item.commandCode)) { // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
// เริ่มพ้นจากราชการ let daysCount = 0;
currentRetire = { if (startDate) {
commandName: item.commandName ?? "-", const start = new Date(startDate);
startDate: item.commandDateAffect daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
};
inRetirePeriod = true;
} }
else if (inRetirePeriod && currentRetire) {
// เจอคำสั่งถัดไปที่ไม่ใช่การพ้นจากราชการ = วันกลับเข้า
const endDate = item.commandDateAffect;
let daysCount = 0;
if (currentRetire.startDate && endDate) { const startDateStr = startDate
const start = new Date(currentRetire.startDate); ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
const end = new Date(endDate); : "-";
daysCount = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
}
const startDateStr = currentRetire.startDate retires.push({
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentRetire.startDate)) date: `${startDateStr} - ปัจจุบัน`,
: "-"; detail: retire_raw.commandName ?? "-",
const endDateStr = endDate day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(endDate)) });
: "-";
retires.push({
date: `${startDateStr} - ${endDateStr}`,
detail: currentRetire.commandName,
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
});
inRetirePeriod = false;
currentRetire = null;
}
} }
// กรณีไม่มีข้อมูล // กรณีไม่มีข้อมูล
@ -1865,6 +1850,7 @@ export class ProfileEmployeeController extends Controller {
) )
: ""; : "";
const data = { const data = {
currentDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentDate)),
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
prefix: profiles?.prefix != null ? profiles.prefix : "", prefix: profiles?.prefix != null ? profiles.prefix : "",
firstName: profiles?.firstName != null ? profiles.firstName : "", firstName: profiles?.firstName != null ? profiles.firstName : "",