diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index ccb231a4..0eaf5a1f 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -32,7 +32,7 @@ import { UpdateProfileCouple, UpdatePrivacyDto, } 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 { PosMaster } from "../entities/PosMaster"; import { PosLevel } from "../entities/PosLevel"; @@ -1499,8 +1499,8 @@ export class ProfileController extends Controller { const position_raw = await this.salaryRepo.find({ where: { profileId: id, - commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), - isEntry: false, + commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]), + // isEntry: false, }, order: { order: "ASC" }, }); @@ -1529,7 +1529,7 @@ export class ProfileController extends Controller { 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))}`) + 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 inRetirePeriod = false; - let currentRetire = null; + const currentDate = new Date(); + 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++) { - const item = position_raw[i]; - - if (retireCodes.includes(item.commandCode)) { - // เริ่มพ้นจากราชการ - currentRetire = { - commandName: item.commandName ?? "-", - startDate: item.commandDateAffect - }; - inRetirePeriod = true; + 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)); } - else if (inRetirePeriod && currentRetire) { - // เจอคำสั่งถัดไปที่ไม่ใช่การพ้นจากราชการ = วันกลับเข้า - const endDate = item.commandDateAffect; - let daysCount = 0; - if (currentRetire.startDate && endDate) { - const start = new Date(currentRetire.startDate); - const end = new Date(endDate); - daysCount = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24)); - } + const startDateStr = startDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate)) + : "-"; - const startDateStr = currentRetire.startDate - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentRetire.startDate)) - : "-"; - const endDateStr = endDate - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(endDate)) - : "-"; - - retires.push({ - date: `${startDateStr} - ${endDateStr}`, - detail: currentRetire.commandName, - day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-" - }); - - inRetirePeriod = false; - currentRetire = null; - } + retires.push({ + date: `${startDateStr}`, + detail: retire_raw.commandName ?? "-", + day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-" + }); } // กรณีไม่มีข้อมูล @@ -1620,11 +1605,7 @@ export class ProfileController extends Controller { commandExcecuteDate, } = await getPosNumCodeSit(item.commandId, "REPORTED"); - _document = Extension.ToThaiNumber( - `คำสั่ง ${posNumCodeSitAbb} - ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} - ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}` - ) + _document = Extension.ToThaiNumber(`คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`) _commandTypename = commandTypeName; } // ค้นหาหน่วยงานที่รักษาการ @@ -1656,7 +1637,7 @@ export class ProfileController extends Controller { } _actpositions.push({ - data: + date: item.dateStart && item.dateEnd ? Extension.ToThaiNumber( `${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`, @@ -1689,14 +1670,14 @@ export class ProfileController extends Controller { // ช่วยราชการ const assistance_raw = await this.profileAssistanceRepository.find({ select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"], - where: { profileId: id, status: "PENDING", isDeleted: false }, + where: { profileId: id, /*status: "PENDING",*/ isDeleted: false }, order: { createdAt: "ASC" }, }); let _assistances = [] if (assistance_raw.length > 0) { for (const item of assistance_raw) { 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) : "-"; if (item.commandId) { @@ -1708,15 +1689,11 @@ export class ProfileController extends Controller { commandExcecuteDate, } = await getPosNumCodeSit(item.commandId); - _document = Extension.ToThaiNumber(` - คำสั่ง ${posNumCodeSitAbb} - ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} - ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))} - `) + _document = Extension.ToThaiNumber(`คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`) _commandTypename = commandTypeName; } _assistances.push({ - data: + date: item.dateStart && item.dateEnd ? Extension.ToThaiNumber( `${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`, @@ -1860,7 +1837,7 @@ export class ProfileController extends Controller { ? 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))}`) + 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" }, }); const data = { + currentDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentDate)), fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, prefix: profiles?.prefix != null ? profiles.prefix : "", firstName: profiles?.firstName != null ? profiles.firstName : "", diff --git a/src/controllers/ProfileEmployeeAbsentLateController.ts b/src/controllers/ProfileEmployeeAbsentLateController.ts index 37ce4994..a5e32fa1 100644 --- a/src/controllers/ProfileEmployeeAbsentLateController.ts +++ b/src/controllers/ProfileEmployeeAbsentLateController.ts @@ -106,8 +106,8 @@ export class ProfileEmployeeAbsentLateController extends Controller { } /** - * API สร้างข้อมูลการมาสาย/ขาดราชการ (Batch) - * @summary API สร้างข้อมูลการมาสาย/ขาดราชการ (Batch) สำหรับ Job + * API สร้างข้อมูลการมาสาย/ขาดราชการ (สำหรับ Job) + * @summary API สร้างข้อมูลการมาสาย/ขาดราชการ (สำหรับ Job) */ @Post("batch") public async newAbsentLateBatch( diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 89293c5d..39b6ea46 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1493,8 +1493,8 @@ export class ProfileEmployeeController extends Controller { const position_raw = await this.salaryRepo.find({ where: { profileEmployeeId: id, - commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16", "20"]), - isEntry: false, + commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]), + // isEntry: false, }, order: { order: "ASC" }, }); @@ -1523,7 +1523,7 @@ export class ProfileEmployeeController extends Controller { 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))}`) + 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) : 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))}`) + 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 inRetirePeriod = false; - let currentRetire = null; + const currentDate = new Date(); + 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++) { - const item = position_raw[i]; + if (retire_raw) { + const startDate = retire_raw.commandDateAffect; - if (retireCodes.includes(item.commandCode)) { - // เริ่มพ้นจากราชการ - currentRetire = { - commandName: item.commandName ?? "-", - startDate: item.commandDateAffect - }; - inRetirePeriod = true; + // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน + let daysCount = 0; + if (startDate) { + const start = new Date(startDate); + daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24)); } - else if (inRetirePeriod && currentRetire) { - // เจอคำสั่งถัดไปที่ไม่ใช่การพ้นจากราชการ = วันกลับเข้า - const endDate = item.commandDateAffect; - let daysCount = 0; - if (currentRetire.startDate && endDate) { - const start = new Date(currentRetire.startDate); - const end = new Date(endDate); - daysCount = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24)); - } + const startDateStr = startDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate)) + : "-"; - const startDateStr = currentRetire.startDate - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentRetire.startDate)) - : "-"; - const endDateStr = endDate - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(endDate)) - : "-"; - - retires.push({ - date: `${startDateStr} - ${endDateStr}`, - detail: currentRetire.commandName, - day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-" - }); - - inRetirePeriod = false; - currentRetire = null; - } + retires.push({ + date: `${startDateStr} - ปัจจุบัน`, + detail: retire_raw.commandName ?? "-", + day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-" + }); } // กรณีไม่มีข้อมูล @@ -1865,6 +1850,7 @@ export class ProfileEmployeeController extends Controller { ) : ""; const data = { + currentDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentDate)), fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, prefix: profiles?.prefix != null ? profiles.prefix : "", firstName: profiles?.firstName != null ? profiles.firstName : "",