diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index d13a9061..e73837c2 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -10154,6 +10154,7 @@ export class ProfileController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), remark: "ถึงแก่กรรม", + isGovernment: false, }; delete data.id; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 04afb47b..6dd79359 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -5662,6 +5662,7 @@ export class ProfileEmployeeController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), remark: "ถึงแก่กรรม", + isGovernment: false, }; delete data.id; diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 8766017f..7e726cbe 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -3333,6 +3333,7 @@ export class ProfileEmployeeTempController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), remark: "ถึงแก่กรรม", + isGovernment: false, }; delete data.id; diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 0223a185..6a49c1b7 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -104,7 +104,6 @@ export async function calculateGovAge(profileId: string, type: string) { // const firstStartDate = new Date(records[0].date); const firstStartDate = profile?.dateAppoint ? profile?.dateAppoint : new Date(); const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date(); - const { years: totalYears1, months: totalMonths1, @@ -124,11 +123,11 @@ export async function calculateGovAge(profileId: string, type: string) { if (!records_middle || records_middle.length === 0) { return { year: totalYears1, month: totalMonths1, day: totalDays1 }; } - let totalYears2 = 0, totalMonths2 = 0, totalDays2 = 0; + // case ที่เข้าออกราชการหลายครั้ง for (let i = 0; i < records_middle.length; i++) { const startDate = new Date(records_middle[i].dateGovernment); const endDate = @@ -151,35 +150,36 @@ export async function calculateGovAge(profileId: string, type: string) { totalMonths2 += months_mid; totalDays2 += days_mid; } - - const adjustTotal = (years: any, months: any, days: any) => { - if (days >= new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate()) { - months += Math.floor( - days / new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate(), - ); - days %= new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate(); + + //ตั้งแต่วันที่กลับมารับราขการไปจนถึงรวมถึงวันที่ปัจจุบัน + const adjustTotal = (years:number, months:number, days:number) => { + const daysInThisMonth = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate(); + if (days >= daysInThisMonth) { + months += Math.floor(days / daysInThisMonth); + days %= daysInThisMonth; } - + if (months >= 12) { years += Math.floor(months / 12); months %= 12; } - + return { years, months, days }; }; const adjustedTotal = adjustTotal(totalYears2, totalMonths2, totalDays2); - + let sumYears = totalYears1 + adjustedTotal.years; let sumMonths = totalMonths1 + adjustedTotal.months; let sumDays = totalDays1 + adjustedTotal.days; - if (sumMonths >= 12) { - sumYears += Math.floor(sumMonths / 12); - sumMonths %= 12; - } + const finalAdjusted = adjustTotal(sumYears, sumMonths, sumDays); - return { year: sumYears, month: sumMonths, day: sumDays }; + return { + year: finalAdjusted.years, + month: finalAdjusted.months, + day: finalAdjusted.days, +}; } export function calculateRetireDate(birthDate: Date) {