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(),
|
createdAt: new Date(),
|
||||||
lastUpdatedAt: new Date(),
|
lastUpdatedAt: new Date(),
|
||||||
remark: "ถึงแก่กรรม",
|
remark: "ถึงแก่กรรม",
|
||||||
|
isGovernment: false,
|
||||||
};
|
};
|
||||||
delete data.id;
|
delete data.id;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 =
|
||||||
|
|
@ -152,12 +151,12 @@ export async function calculateGovAge(profileId: string, type: string) {
|
||||||
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) {
|
||||||
|
|
@ -174,12 +173,13 @@ export async function calculateGovAge(profileId: string, type: string) {
|
||||||
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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue