@php use Illuminate\Support\Str; $run = $detail->payrollRun; $emp = $detail->employee; // Components are stored either as typed objects ({code,name,type,amount}) // or, in some datasets, as a flat {key: amount} map — normalise both here. // The "basic" component is dropped since Basic Salary is shown separately. $comps = collect($detail->components ?? [])->map(function ($v, $k) { $isArr = is_array($v); $key = is_string($k) ? $k : ($isArr ? ($v['code'] ?? $v['name'] ?? '') : ''); return [ 'key' => (string) $key, 'name' => $isArr ? ($v['name'] ?? $k) : Str::headline((string) $k), 'type' => $isArr ? ($v['type'] ?? 'earning') : 'earning', 'amount' => (float) ($isArr ? ($v['amount'] ?? 0) : $v), ]; })->reject(fn ($c) => strtolower($c['name']) === 'basic' || strtolower($c['key']) === 'basic')->values(); $earnings = $comps->filter(fn ($c) => in_array($c['type'], ['earning', 'benefit'], true)); $deductions = $comps->filter(fn ($c) => $c['type'] === 'deduction'); $contributions = $comps->filter(fn ($c) => $c['type'] === 'contributions'); $loanItems = $comps->filter(fn ($c) => ($c['type'] ?? '') === 'loan_installment'); $monogram = strtoupper(substr($run->company?->name ?? 'H', 0, 1)); $periodStart = $run->period_start ?? \Carbon\Carbon::createFromDate($run->year, $run->month, 1); $periodEnd = $run->period_end ?? $periodStart->copy()->endOfMonth(); $fmt = fn($n) => number_format((float) $n, 2); @endphp
{{-- Header --}}
@if($logoData) @else
{{ $monogram }}
@endif
{{ $run->company->name ?? 'HRMS' }}
@if(!empty($run->company->address))
{{ $run->company->address }}
@endif @if(!empty($run->company->phone) || !empty($run->company->email))
{{ collect([$run->company->phone ?? null, $run->company->email ?? null])->filter()->implode(' • ') }}
@endif
PAYSLIP
{{ \Carbon\Carbon::createFromDate($run->year, $run->month, 1)->format('F Y') }}
{{-- Meta strip --}}
Employee Code: {{ $emp->employee_code }} Pay Period: {{ $run->period_start->format('d M') }} – {{ $run->period_end->format('d M Y') }} Generated: {{ now()->format('d M Y') }}
{{-- Employee details --}}
Employee Details
Name{{ $emp->full_name }} Department{{ $emp->department->name ?? '—' }} Designation{{ $emp->designation->name ?? '—' }} Joining Date{{ $emp->joining_date?->format('d M Y') ?? '—' }}
Bank{{ $emp->bank_name ?? '—' }} Account No.{{ $emp->bank_account ?? '—' }}
{{-- Attendance --}}
Attendance Summary
{{ $detail->working_days }}
Working
{{ $detail->present_days }}
Present
{{ $detail->absent_days }}
Absent
{{ $fmt($detail->overtime_hours) }}
OT Hours
{{-- Earnings / Deductions --}}
{{-- Earnings --}} {{-- Deductions --}}
@foreach($earnings as $comp) @endforeach @if($detail->overtime_amount > 0) @endif @if($detail->bonus_amount > 0) @endif
Earnings
ComponentAmount (PKR)
Basic Salary{{ $fmt($detail->basic_salary) }}
{{ $comp['name'] }}{{ $fmt($comp['amount']) }}
Overtime{{ $fmt($detail->overtime_amount) }}
Bonus{{ $fmt($detail->bonus_amount) }}
Gross Salary{{ $fmt($detail->gross_salary) }}
@php $hasDeduction = $deductions->isNotEmpty() || $detail->leave_deduction > 0 || $detail->loan_deduction > 0 || $detail->tax_amount > 0; @endphp @foreach($deductions as $comp) @endforeach @if($detail->leave_deduction > 0) @endif @if($loanItems->isNotEmpty()) @foreach($loanItems as $item) @endforeach @elseif($detail->loan_deduction > 0) @endif @if($detail->tax_amount > 0) @endif @unless($hasDeduction) @endunless
Deductions
DescriptionAmount (PKR)
{{ $comp['name'] }}{{ $fmt($comp['amount']) }}
Leave Deduction{{ $fmt($detail->leave_deduction) }}
{{ $item['name'] }}{{ $fmt($item['amount']) }}
Loan Repayment{{ $fmt($detail->loan_deduction) }}
Income Tax{{ $fmt($detail->tax_amount) }}
No deductions
Total Deductions{{ $fmt($detail->total_deductions) }}
@if($contributions->isNotEmpty() || (float) $detail->pf > 0)
@foreach($contributions as $comp) @endforeach @if((float) $detail->pf > 0) @endif
Employer Contributions
ComponentAmount (PKR)
{{ $comp['name'] }}{{ $fmt($comp['amount']) }}
Total PF (Employee + Employer){{ $fmt($detail->pf) }}
@endif {{-- Net salary --}}
NET SALARY
Gross {{ $fmt($detail->gross_salary) }} − Deductions {{ $fmt($detail->total_deductions) }}
PKR {{ $fmt($detail->net_salary) }}
{{-- Footer --}}