diff --git a/app/Models/PayrollRun.php b/app/Models/PayrollRun.php index ac612272f..c641ffe6b 100644 --- a/app/Models/PayrollRun.php +++ b/app/Models/PayrollRun.php @@ -165,7 +165,13 @@ class PayrollRun extends BaseModel 'per_day_salary' => $salaryBreakdown['daily_rate'], 'unpaid_leave_deduction' => $summary['absence_amount'] ?? 0, - 'earnings_breakdown' => $salaryBreakdown['earnings'], + 'earnings_breakdown' => array_merge($salaryBreakdown['earnings'], [ + 'meta' => [ + 'daily_rate' => $salaryBreakdown['daily_rate'], + 'pay_type' => $salaryBreakdown['pay_type'], + ], + 'summary' => $summary + ]), 'deductions_breakdown' => $salaryBreakdown['deductions'], 'created_by' => $this->created_by, ]); diff --git a/resources/views/payslips/template.blade.php b/resources/views/payslips/template.blade.php index d29b2e10e..32d0fa6f9 100755 --- a/resources/views/payslips/template.blade.php +++ b/resources/views/payslips/template.blade.php @@ -179,41 +179,18 @@ $summary = $rawEarnings['summary'] ?? []; unset($rawEarnings['meta'], $rawEarnings['summary']); - $earnings = array_values($rawEarnings); - $deductions = array_values($payrollEntry->deductions_breakdown ?? []); + // Filter out zero values (except Basic Salary) so they don't clutter the payslip + $earnings = array_filter(array_values($rawEarnings), function($item) { + return strtolower($item['name']) === 'basic salary' || (float)$item['amount'] > 0; + }); + + $deductions = array_filter(array_values($payrollEntry->deductions_breakdown ?? []), function($item) { + return (float)$item['amount'] > 0; + }); - if (!function_exists('extractAmount')) { - function extractAmount($array, $keywords) { - $keywords = (array) $keywords; - foreach ($array as $item) { - if (!isset($item['name'])) continue; - foreach ($keywords as $keyword) { - if (stripos($item['name'], $keyword) !== false) { - return $item['amount']; - } - } - } - return 0; - } - } - - // Map dynamic earnings natively - $basicSalary = extractAmount($earnings, 'Basic Salary') ?: $payrollEntry->basic_salary; - $nightDiff = extractAmount($earnings, 'Night Diff'); - $overtime = extractAmount($earnings, ['Overtime', 'Reg. OT']); - $holidayPay = extractAmount($earnings, 'Holiday'); - $adjustment = extractAmount($earnings, 'Adjustment'); - - // Map explicit deductions natively - $undertimeDed = extractAmount($deductions, 'Undertime'); - $sss = extractAmount($deductions, 'SSS'); - $phic = extractAmount($deductions, 'PhilHealth'); - $hdmf = extractAmount($deductions, 'Pag-IBIG'); - $tax = extractAmount($deductions, ['Tax', 'Withholding']); - - // Explicit penalties - $tardiness = extractAmount($deductions, ['Late', 'Tardiness']); - $absences = extractAmount($deductions, 'Absence'); + // Re-index after filtering + $earnings = array_values($earnings); + $deductions = array_values($deductions); $payType = $meta['pay_type'] ?? 'Monthly'; @@ -264,36 +241,21 @@ DEDUCTIONS AMOUNT - - Basic Salary - {{ formatCurrency($basicSalary) }} - Undertime Deduction - {{ formatCurrency($undertimeDed) }} - - - Night Differential - {{ formatCurrency($nightDiff) }} - SSS Contribution (EE) - {{ formatCurrency($sss) }} - - - Overtime - {{ formatCurrency($overtime) }} - PhilHealth Contribution (EE) - {{ formatCurrency($phic) }} - - - Holiday Pay - {{ formatCurrency($holidayPay) }} - Pag-IBIG Contribution (EE) - {{ formatCurrency($hdmf) }} - - - Adjustment + - {{ formatCurrency($adjustment) }} - Withholding Tax - {{ formatCurrency($tax) }} - + @php + $maxRows = max(count($earnings), count($deductions)); + @endphp + @for ($i = 0; $i < $maxRows; $i++) + @php + $earn = $earnings[$i] ?? null; + $ded = $deductions[$i] ?? null; + @endphp + + {{ $earn ? $earn['name'] : '' }} + {{ $earn ? formatCurrency($earn['amount']) : '' }} + {{ $ded ? $ded['name'] : '' }} + {{ $ded ? formatCurrency($ded['amount']) : '' }} + + @endfor Total Earnings {{ formatCurrency($payrollEntry->gross_pay) }} @@ -302,20 +264,6 @@ - - - - - - - - - - - - -
Tardiness{{ formatCurrency($tardiness) }}
Undertime{{ formatCurrency($undertimeDed) }}
-
Attendance Summary