fixed #2413 จำนวนวันอายุราชการแสดงไม่ตรงกัน
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s
This commit is contained in:
parent
e64cd3f384
commit
334ce4f5fc
5 changed files with 528 additions and 52 deletions
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue