/** * คำนวณอายุงานจากจำนวนวันรวม * ใช้สูตรเดียวกับ Stored Procedure GetProfileSalaryPosition * @param totalDays จำนวนวันรวม * @returns { year, month, day } ปี เดือน วัน */ export function calculateTenure(totalDays: number) { // 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); const month = Math.floor((totalDays / 30.4375) % 12); const day = Math.floor(totalDays % 30.4375); return { year, month, day }; }