fixed cron job

This commit is contained in:
Warunee Tamkoo 2026-05-18 21:51:23 +07:00
parent d093953fbe
commit 5ea111a3c5

View file

@ -84,19 +84,31 @@ export class ProfileSalaryController extends Controller {
? _position.slice(1).map((curr: any, index: number) => ({
positionName: _position[index]?.positionName,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
year:
curr.Years !== null && curr.Years !== undefined
? Math.floor(Number(curr.Years))
: 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day:
curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
}))
: [];
const currentTenure = mapPosition.find((curr: any) => curr.positionName == x.position);
if (currentTenure) {
const normalized = normalizeDurationSumSimple(
currentTenure.year,
currentTenure.month,
currentTenure.day,
);
const mapData: any = {
profileId: x.id,
positionName: currentTenure.positionName,
year: currentTenure.year,
month: currentTenure.month,
day: currentTenure.day,
Years: normalized.years,
Months: normalized.months,
Days: normalized.days,
};
data.push(mapData);
}
@ -129,19 +141,31 @@ export class ProfileSalaryController extends Controller {
? _position.slice(1).map((curr: any, index: number) => ({
positionName: _position[index]?.positionName,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
year:
curr.Years !== null && curr.Years !== undefined
? Math.floor(Number(curr.Years))
: 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day:
curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
}))
: [];
const currentTenure = mapPosition.find((curr: any) => curr.positionName == x.position);
if (currentTenure) {
const normalized = normalizeDurationSumSimple(
currentTenure.year,
currentTenure.month,
currentTenure.day,
);
const mapData: any = {
profileEmployeeId: x.id,
positionName: currentTenure.positionName,
year: currentTenure.year,
month: currentTenure.month,
day: currentTenure.day,
Years: normalized.years,
Months: normalized.months,
Days: normalized.days,
};
data.push(mapData);
}
@ -175,6 +199,16 @@ export class ProfileSalaryController extends Controller {
positionType: _positionLevel[index]?.positionType,
positionLevel: _positionLevel[index]?.positionLevel,
positionCee: _positionLevel[index]?.positionCee,
year:
curr.Years !== null && curr.Years !== undefined
? Math.floor(Number(curr.Years))
: 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day:
curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
}))
: [];
const calDayDiff = mapPositionLevel
@ -189,21 +223,35 @@ export class ProfileSalaryController extends Controller {
acc.positionType = curr.positionType;
acc.positionLevel = curr.positionLevel;
acc.positionCee = curr.positionCee;
acc.year += curr.year;
acc.month += curr.month;
acc.day += curr.day;
return acc;
},
{ days_diff: 0, positionType: null, positionLevel: null, positionCee: null },
{
days_diff: 0,
positionType: null,
positionLevel: null,
positionCee: null,
year: 0,
month: 0,
day: 0,
},
);
const years = calDayDiff.days_diff / 365;
const normalized = normalizeDurationSumSimple(years, 0, 0);
const normalized = normalizeDurationSumSimple(
calDayDiff.year,
calDayDiff.month,
calDayDiff.day,
);
const mapData: any = {
profileId: x.id,
positionType: calDayDiff.positionType,
positionLevel: calDayDiff.positionLevel,
positionCee: calDayDiff.positionCee,
days_diff: calDayDiff.days_diff,
Years: x.posLevel == null ? 0 : normalized.years.toFixed(4),
Months: x.posLevel == null ? 0 : normalized.months.toFixed(4),
Days: x.posLevel == null ? 0 : normalized.days.toFixed(4),
Years: x.posLevel == null ? 0 : normalized.years,
Months: x.posLevel == null ? 0 : normalized.months,
Days: x.posLevel == null ? 0 : normalized.days,
};
data.push(mapData);
}
@ -236,6 +284,16 @@ export class ProfileSalaryController extends Controller {
positionType: _positionLevel[index]?.positionType,
positionLevel: _positionLevel[index]?.positionLevel,
positionCee: _positionLevel[index]?.positionCee,
year:
curr.Years !== null && curr.Years !== undefined
? Math.floor(Number(curr.Years))
: 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day:
curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
}))
: [];
const calDayDiff = mapPositionLevel
@ -250,21 +308,35 @@ export class ProfileSalaryController extends Controller {
acc.positionType = curr.positionType;
acc.positionLevel = curr.positionLevel;
acc.positionCee = curr.positionCee;
acc.year += curr.year;
acc.month += curr.month;
acc.day += curr.day;
return acc;
},
{ days_diff: 0, positionType: null, positionLevel: null, positionCee: null },
{
days_diff: 0,
positionType: null,
positionLevel: null,
positionCee: null,
year: 0,
month: 0,
day: 0,
},
);
const years = calDayDiff.days_diff / 365;
const normalized = normalizeDurationSumSimple(years, 0, 0);
const normalized = normalizeDurationSumSimple(
calDayDiff.year,
calDayDiff.month,
calDayDiff.day,
);
const mapData: any = {
profileEmployeeId: x.id,
positionType: calDayDiff.positionType,
positionLevel: calDayDiff.positionLevel,
positionCee: calDayDiff.positionCee,
days_diff: calDayDiff.days_diff,
Years: x.posLevel == null ? 0 : normalized.years.toFixed(4),
Months: x.posLevel == null ? 0 : normalized.months.toFixed(4),
Days: x.posLevel == null ? 0 : normalized.days.toFixed(4),
Years: x.posLevel == null ? 0 : normalized.years,
Months: x.posLevel == null ? 0 : normalized.months,
Days: x.posLevel == null ? 0 : normalized.days,
};
data.push(mapData);
}
@ -316,6 +388,16 @@ export class ProfileSalaryController extends Controller {
? _position.slice(1).map((curr: any, index: number) => ({
days_diff: curr.days_diff,
positionExecutive: _position[index]?.positionExecutive,
year:
curr.Years !== null && curr.Years !== undefined
? Math.floor(Number(curr.Years))
: 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day:
curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
}))
: [];
const _posExecutiveName = position?.posExecutive?.posExecutiveName;
@ -325,19 +407,25 @@ export class ProfileSalaryController extends Controller {
(acc: any, curr: any) => {
acc.days_diff += Number(curr.days_diff) || 0;
acc.positionExecutive = curr.positionExecutive;
acc.year += curr.year;
acc.month += curr.month;
acc.day += curr.day;
return acc;
},
{ days_diff: 0, positionExecutive: null },
{ days_diff: 0, positionExecutive: null, year: 0, month: 0, day: 0 },
);
const years = calDayDiff.days_diff / 365;
const normalized = normalizeDurationSumSimple(years, 0, 0);
const normalized = normalizeDurationSumSimple(
calDayDiff.year,
calDayDiff.month,
calDayDiff.day,
);
const mapData: any = {
profileId: x.id,
positionExecutiveName: calDayDiff.positionExecutive,
days_diff: calDayDiff.days_diff,
Years: normalized.years.toFixed(4),
Months: normalized.months.toFixed(4),
Days: normalized.days.toFixed(4),
Years: normalized.years,
Months: normalized.months,
Days: normalized.days,
};
data.push(mapData);
}
@ -589,8 +677,12 @@ export class ProfileSalaryController extends Controller {
? _position.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
year:
curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _position[index]?.positionName,
}))
@ -606,16 +698,18 @@ export class ProfileSalaryController extends Controller {
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
// Normalize the summed values using calendar arithmetic
const normalized = normalizeDurationSumSimple(
existing.year,
existing.month,
existing.day
);
const normalized = normalizeDurationSumSimple(existing.year, existing.month, existing.day);
existing.year = normalized.years;
existing.month = normalized.months;
existing.day = normalized.days;
@ -634,8 +728,12 @@ export class ProfileSalaryController extends Controller {
? _posLevel.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
year:
curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name:
!_posLevel[index]?.positionType && _posLevel[index]?.positionCee
@ -657,16 +755,18 @@ export class ProfileSalaryController extends Controller {
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
// Normalize the summed values using calendar arithmetic
const normalized = normalizeDurationSumSimple(
existing.year,
existing.month,
existing.day
);
const normalized = normalizeDurationSumSimple(existing.year, existing.month, existing.day);
existing.year = normalized.years;
existing.month = normalized.months;
existing.day = normalized.days;
@ -686,8 +786,12 @@ export class ProfileSalaryController extends Controller {
? _posExecutive.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
year:
curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _posExecutive[index]?.positionExecutive,
}))
@ -703,16 +807,18 @@ export class ProfileSalaryController extends Controller {
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
// Normalize the summed values using calendar arithmetic
const normalized = normalizeDurationSumSimple(
existing.year,
existing.month,
existing.day
);
const normalized = normalizeDurationSumSimple(existing.year, existing.month, existing.day);
existing.year = normalized.years;
existing.month = normalized.months;
existing.day = normalized.days;
@ -759,8 +865,12 @@ export class ProfileSalaryController extends Controller {
? _position.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
year:
curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _position[index]?.positionName,
}))
@ -776,16 +886,18 @@ export class ProfileSalaryController extends Controller {
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
// Normalize the summed values using calendar arithmetic
const normalized = normalizeDurationSumSimple(
existing.year,
existing.month,
existing.day
);
const normalized = normalizeDurationSumSimple(existing.year, existing.month, existing.day);
existing.year = normalized.years;
existing.month = normalized.months;
existing.day = normalized.days;
@ -805,8 +917,12 @@ export class ProfileSalaryController extends Controller {
? _posLevel.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
year:
curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name:
!_posLevel[index]?.positionType && _posLevel[index]?.positionCee
@ -828,16 +944,18 @@ export class ProfileSalaryController extends Controller {
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
// Normalize the summed values using calendar arithmetic
const normalized = normalizeDurationSumSimple(
existing.year,
existing.month,
existing.day
);
const normalized = normalizeDurationSumSimple(existing.year, existing.month, existing.day);
existing.year = normalized.years;
existing.month = normalized.months;
existing.day = normalized.days;
@ -857,8 +975,12 @@ export class ProfileSalaryController extends Controller {
? _posExecutive.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// Use stored procedure's calculated values (calendar arithmetic)
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
year:
curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
month:
curr.Months !== null && curr.Months !== undefined
? Math.floor(Number(curr.Months))
: 0,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _posExecutive[index]?.positionExecutive,
}))
@ -874,16 +996,18 @@ export class ProfileSalaryController extends Controller {
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
// Normalize the summed values using calendar arithmetic
const normalized = normalizeDurationSumSimple(
existing.year,
existing.month,
existing.day
);
const normalized = normalizeDurationSumSimple(existing.year, existing.month, existing.day);
existing.year = normalized.years;
existing.month = normalized.months;
existing.day = normalized.days;