This commit is contained in:
parent
9bd15c94b3
commit
89773b77ef
4 changed files with 20 additions and 17 deletions
|
|
@ -10154,6 +10154,7 @@ export class ProfileController extends Controller {
|
|||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
remark: "ถึงแก่กรรม",
|
||||
isGovernment: false,
|
||||
};
|
||||
delete data.id;
|
||||
|
||||
|
|
|
|||
|
|
@ -5662,6 +5662,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
remark: "ถึงแก่กรรม",
|
||||
isGovernment: false,
|
||||
};
|
||||
delete data.id;
|
||||
|
||||
|
|
|
|||
|
|
@ -3333,6 +3333,7 @@ export class ProfileEmployeeTempController extends Controller {
|
|||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
remark: "ถึงแก่กรรม",
|
||||
isGovernment: false,
|
||||
};
|
||||
delete data.id;
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue