fixed #2413 จำนวนวันอายุราชการแสดงไม่ตรงกัน
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s

This commit is contained in:
Warunee Tamkoo 2026-05-12 17:24:15 +07:00
parent e64cd3f384
commit 334ce4f5fc
5 changed files with 528 additions and 52 deletions

View file

@ -595,6 +595,10 @@ export class ProfileSalaryController extends Controller {
_position.length > 1
? _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,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _position[index]?.positionName,
}))
: [];
@ -605,15 +609,23 @@ export class ProfileSalaryController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// Normalize the summed values (convert excess days to months, months to years)
while (existing.day >= 30) {
existing.month += Math.floor(existing.day / 30);
existing.day = existing.day % 30;
}
while (existing.month >= 12) {
existing.year += Math.floor(existing.month / 12);
existing.month = existing.month % 12;
}
return acc;
},
@ -628,6 +640,10 @@ export class ProfileSalaryController extends Controller {
_posLevel.length > 1
? _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,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name:
!_posLevel[index]?.positionType && _posLevel[index]?.positionCee
? `ระดับ ${_posLevel[index]?.positionCee.trim()}`
@ -644,15 +660,23 @@ export class ProfileSalaryController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// Normalize the summed values (convert excess days to months, months to years)
while (existing.day >= 30) {
existing.month += Math.floor(existing.day / 30);
existing.day = existing.day % 30;
}
while (existing.month >= 12) {
existing.year += Math.floor(existing.month / 12);
existing.month = existing.month % 12;
}
return acc;
},
@ -668,6 +692,10 @@ export class ProfileSalaryController extends Controller {
_posExecutive.length > 1
? _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,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _posExecutive[index]?.positionExecutive,
}))
: [];
@ -678,15 +706,23 @@ export class ProfileSalaryController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// Normalize the summed values (convert excess days to months, months to years)
while (existing.day >= 30) {
existing.month += Math.floor(existing.day / 30);
existing.day = existing.day % 30;
}
while (existing.month >= 12) {
existing.year += Math.floor(existing.month / 12);
existing.month = existing.month % 12;
}
return acc;
},
@ -729,9 +765,10 @@ export class ProfileSalaryController extends Controller {
_position.length > 1
? _position.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
// month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
// day: curr.Days ? Math.floor(Number(curr.Days)) : 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,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _position[index]?.positionName,
}))
: [];
@ -742,15 +779,23 @@ export class ProfileSalaryController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// Normalize the summed values (convert excess days to months, months to years)
while (existing.day >= 30) {
existing.month += Math.floor(existing.day / 30);
existing.day = existing.day % 30;
}
while (existing.month >= 12) {
existing.year += Math.floor(existing.month / 12);
existing.month = existing.month % 12;
}
return acc;
},
@ -766,9 +811,10 @@ export class ProfileSalaryController extends Controller {
_posLevel.length > 1
? _posLevel.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
// month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
// day: curr.Days ? Math.floor(Number(curr.Days)) : 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,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name:
!_posLevel[index]?.positionType && _posLevel[index]?.positionCee
? `ระดับ ${_posLevel[index]?.positionCee.trim()}`
@ -785,15 +831,23 @@ export class ProfileSalaryController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// Normalize the summed values (convert excess days to months, months to years)
while (existing.day >= 30) {
existing.month += Math.floor(existing.day / 30);
existing.day = existing.day % 30;
}
while (existing.month >= 12) {
existing.year += Math.floor(existing.month / 12);
existing.month = existing.month % 12;
}
return acc;
},
@ -808,10 +862,11 @@ export class ProfileSalaryController extends Controller {
const mapPosExecutive =
_posExecutive.length > 1
? _posExecutive.slice(1).map((curr: any, index: number) => ({
// year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
// month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
// day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
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,
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
name: _posExecutive[index]?.positionExecutive,
}))
: [];
@ -822,15 +877,23 @@ export class ProfileSalaryController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = { name: curr.name, days: curr.days, year: curr.year, month: curr.month, day: curr.day };
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// Normalize the summed values (convert excess days to months, months to years)
while (existing.day >= 30) {
existing.month += Math.floor(existing.day / 30);
existing.day = existing.day % 30;
}
while (existing.month >= 12) {
existing.year += Math.floor(existing.month / 12);
existing.month = existing.month % 12;
}
return acc;
},

View file

@ -1,23 +1,18 @@
/**
*
* Stored Procedure GetProfileSalaryPosition
* @param totalDays
* @returns { year, month, day }
*/
export function calculateTenure(totalDays: number) {
// 1. แปลงเป็น year เต็ม
// Match stored procedure formula:
// days_diff / 365.2524 AS Years
// (days_diff / 30.4375) % 12 AS Months
// days_diff % 30.4375 AS Days
const year = Math.floor(totalDays / 365.2524);
// 2. วันที่เหลือหลังหัก year ออก
const remainAfterYear = totalDays - year * 365.2524;
// 3. แปลงเป็น month เต็ม
const month = Math.floor(remainAfterYear / 30.4375);
// 4. วันที่เหลือหลังหัก month ออก
const remainAfterMonth = remainAfterYear - month * 30.4375;
// 5. ปัดลง เฉพาะวัน
const day = Math.floor(remainAfterMonth);
const month = Math.floor((totalDays / 30.4375) % 12);
const day = Math.floor(totalDays % 30.4375);
return { year, month, day };
}