fix: remove obsolete attendancePolicy relationship calls and update 13th month calculation rules

This commit is contained in:
2026-08-11 09:13:42 +08:00
parent a77fd9a575
commit ec3c00ffff
4 changed files with 16 additions and 17 deletions

View File

@@ -41,7 +41,7 @@ class AttendanceRecordController extends Controller
}
if (Auth::user()->can('manage-attendance-records')) {
$query = AttendanceRecord::with(['employee.employee.branch', 'shift', 'attendancePolicy', 'creator'])
$query = AttendanceRecord::with(['employee.employee.branch', 'shift', 'creator'])
->where(function ($q) {
if (Auth::user()->can('manage-any-attendance-records')) {
$q->whereIn('created_by', getCompanyAndUsersId());
@@ -442,7 +442,7 @@ class AttendanceRecordController extends Controller
$attendanceRecord->update($validated);
// Reload necessary relationships if not already fresh
$attendanceRecord->loadMissing(['shift', 'attendancePolicy']);
$attendanceRecord->loadMissing(['shift']);
$attendanceRecord->processAttendance(false);
return redirect()->back()->with('success', __('Attendance record updated successfully'));
@@ -735,7 +735,7 @@ class AttendanceRecordController extends Controller
{
if (Auth::user()->can('export-attendance-record')) {
try {
$attendanceRecords = AttendanceRecord::with(['employee', 'shift', 'attendancePolicy'])
$attendanceRecords = AttendanceRecord::with(['employee', 'shift'])
->where(function ($q) {
if (Auth::user()->can('manage-any-attendance-records')) {
$q->whereIn('created_by', getCompanyAndUsersId());
@@ -758,7 +758,6 @@ class AttendanceRecordController extends Controller
'Employee',
'Date',
'Shift',
'Attedance Policy',
'Clock In',
'Clock Out',
'Break Hours',
@@ -775,7 +774,6 @@ class AttendanceRecordController extends Controller
$record->employee->name ?? '',
$record->date ? date('Y-m-d', strtotime($record->date)) : '',
$record->shift->name ?? '',
$record->attendancePolicy->name ?? '',
$record->clock_in ?? '',
$record->clock_out ?? '',
$record->break_hours ?? '',

View File

@@ -462,7 +462,7 @@ class EmployeeController extends Controller
}
// Load user with employee relationships
$user = User::with(['employee.branch', 'employee.department', 'employee.designation', 'employee.shift', 'employee.attendancePolicy', 'employee.documents.documentType'])
$user = User::with(['employee.branch', 'employee.department', 'employee.designation', 'employee.shift', 'employee.documents.documentType'])
->where('id', $employee->user_id)
->first();
@@ -1149,7 +1149,7 @@ class EmployeeController extends Controller
{
if (Auth::user()->can('export-employee')) {
try {
$employees = User::with(['employee.branch', 'employee.department', 'employee.designation', 'employee.shift', 'employee.attendancePolicy'])
$employees = User::with(['employee.branch', 'employee.department', 'employee.designation', 'employee.shift'])
->where('type', 'employee')
->where(function ($q) {
if (Auth::user()->can('manage-any-employees')) {
@@ -1182,7 +1182,6 @@ class EmployeeController extends Controller
'Gender',
'Shift',
'Basic Salary',
'Attedance Policy',
'Employement Type',
'Employement Status',
'City',
@@ -1212,7 +1211,6 @@ class EmployeeController extends Controller
$employee->gender ?? '',
$employee->shift->name ?? '',
$employee->base_salary ?? '',
$employee->attendancePolicy->name ?? '',
$employee->employment_type ?? '',
$employee->employee_status ?? 'active',
$employee->city ?? '',

View File

@@ -50,19 +50,22 @@ class ThirteenthMonthService
$key = $periodDate->format('Y-m');
if (array_key_exists($key, $monthlyEarnings)) {
// Actual Basic Salary Earned (net of absences/tardiness)
$basic = (float) ($entry->basic_salary ?? 0);
$extraBase = 0.00;
// Add Paid Leaves (Sick Leave, Vacation Leave, Birthday Leave)
// Excludes: LWOP (Unpaid Leaves), Holiday Pay, Overtime, Night Differential, COLA
$paidLeaves = 0.00;
if (is_array($entry->earnings_breakdown)) {
foreach ($entry->earnings_breakdown as $item) {
$category = strtolower($item['name'] ?? '');
if (str_contains($category, 'paid leave') || str_contains($category, 'holiday')) {
$extraBase += (float) ($item['amount'] ?? 0);
if (str_contains($category, 'paid leave')) {
$paidLeaves += (float) ($item['amount'] ?? 0);
}
}
}
$monthlyEarnings[$key] += ($basic + $extraBase);
$monthlyEarnings[$key] += ($basic + $paidLeaves);
}
}
} else {

View File

@@ -8,10 +8,10 @@ Implement a comprehensive **13th Month Pay Module** compliant with Philippine La
## 2. Requirements & Business Rules
### A. Calculation Formula (DOLE Standard)
$$\text{13th Month Pay} = \frac{\sum (\text{Basic Salary Earned} + \text{Paid Leave Pay} + \text{Holiday Pay})}{12}$$
$$\text{13th Month Pay} = \frac{\sum (\text{Actual Basic Salary Earned} + \text{Paid Leave Pay})}{12}$$
* **Included Base:** Basic pay earned + Approved paid leave pay (VL/SL) + Holiday pay from processed `PayrollEntry` records in the selected year/range.
* **Excluded Base:** Overtime pay, Night Differential pay, allowances, incentives, and reimbursements.
* **Included Base:** Actual basic salary earned (after tardiness/absence deductions) + Approved Paid Leaves (Sick Leave, Vacation Leave, Birthday Leave) from processed `PayrollEntry` records.
* **Excluded Base:** Unpaid Leaves (LWOP), Holiday Pay (Regular & Special Non-Working), Overtime Pay, Night Differential Pay, COLA, allowances, incentives, and reimbursements.
* **Deductions Policy:** Completely free of statutory (SSS, PhilHealth, Pag-IBIG) and loan deductions.
* **Tax Exemption:** Automatically applies TRAIN Law ₱90,000 bonus tax-exemption threshold (amounts above ₱90k flagged for tax evaluation).
* **Pro-rating:** Automatically pro-rates for employees hired during the year or resigned mid-year based on actual payroll records.