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

@ -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 };
}