This commit is contained in:
AdisakKanthawilang 2025-06-11 14:30:44 +07:00
parent 9bd15c94b3
commit 89773b77ef
4 changed files with 20 additions and 17 deletions

View file

@ -10154,6 +10154,7 @@ export class ProfileController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
remark: "ถึงแก่กรรม", remark: "ถึงแก่กรรม",
isGovernment: false,
}; };
delete data.id; delete data.id;

View file

@ -5662,6 +5662,7 @@ export class ProfileEmployeeController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
remark: "ถึงแก่กรรม", remark: "ถึงแก่กรรม",
isGovernment: false,
}; };
delete data.id; delete data.id;

View file

@ -3333,6 +3333,7 @@ export class ProfileEmployeeTempController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
remark: "ถึงแก่กรรม", remark: "ถึงแก่กรรม",
isGovernment: false,
}; };
delete data.id; delete data.id;

View file

@ -104,7 +104,6 @@ export async function calculateGovAge(profileId: string, type: string) {
// const firstStartDate = new Date(records[0].date); // const firstStartDate = new Date(records[0].date);
const firstStartDate = profile?.dateAppoint ? profile?.dateAppoint : new Date(); const firstStartDate = profile?.dateAppoint ? profile?.dateAppoint : new Date();
const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date(); const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date();
const { const {
years: totalYears1, years: totalYears1,
months: totalMonths1, months: totalMonths1,
@ -124,11 +123,11 @@ export async function calculateGovAge(profileId: string, type: string) {
if (!records_middle || records_middle.length === 0) { if (!records_middle || records_middle.length === 0) {
return { year: totalYears1, month: totalMonths1, day: totalDays1 }; return { year: totalYears1, month: totalMonths1, day: totalDays1 };
} }
let totalYears2 = 0, let totalYears2 = 0,
totalMonths2 = 0, totalMonths2 = 0,
totalDays2 = 0; totalDays2 = 0;
// case ที่เข้าออกราชการหลายครั้ง
for (let i = 0; i < records_middle.length; i++) { for (let i = 0; i < records_middle.length; i++) {
const startDate = new Date(records_middle[i].dateGovernment); const startDate = new Date(records_middle[i].dateGovernment);
const endDate = const endDate =
@ -151,35 +150,36 @@ export async function calculateGovAge(profileId: string, type: string) {
totalMonths2 += months_mid; totalMonths2 += months_mid;
totalDays2 += days_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()) { const adjustTotal = (years:number, months:number, days:number) => {
months += Math.floor( const daysInThisMonth = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate();
days / new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate(), if (days >= daysInThisMonth) {
); months += Math.floor(days / daysInThisMonth);
days %= new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate(); days %= daysInThisMonth;
} }
if (months >= 12) { if (months >= 12) {
years += Math.floor(months / 12); years += Math.floor(months / 12);
months %= 12; months %= 12;
} }
return { years, months, days }; return { years, months, days };
}; };
const adjustedTotal = adjustTotal(totalYears2, totalMonths2, totalDays2); const adjustedTotal = adjustTotal(totalYears2, totalMonths2, totalDays2);
let sumYears = totalYears1 + adjustedTotal.years; let sumYears = totalYears1 + adjustedTotal.years;
let sumMonths = totalMonths1 + adjustedTotal.months; let sumMonths = totalMonths1 + adjustedTotal.months;
let sumDays = totalDays1 + adjustedTotal.days; let sumDays = totalDays1 + adjustedTotal.days;
if (sumMonths >= 12) { const finalAdjusted = adjustTotal(sumYears, sumMonths, sumDays);
sumYears += Math.floor(sumMonths / 12);
sumMonths %= 12;
}
return { year: sumYears, month: sumMonths, day: sumDays }; return {
year: finalAdjusted.years,
month: finalAdjusted.months,
day: finalAdjusted.days,
};
} }
export function calculateRetireDate(birthDate: Date) { export function calculateRetireDate(birthDate: Date) {