@section('page-title', 'Payroll Details') @push('styles') @endpush

{{ __('Payroll Details') }}

{{ $payroll->name }}

{{ $payroll->period_start ? $payroll->period_start->format('d M Y') : 'N/A' }} - {{ $payroll->period_end ? $payroll->period_end->format('d M Y') : 'N/A' }}

@if($payroll->status === 'draft')
@csrf
@endif @if($payroll->status === 'draft')
@csrf
@endif {{ __('CSV') }} {{ __('Excel') }} {{ __('PDF') }}

{{ __('Gross Salary') }}

{{ number_format($payroll->total_gross, 2) }}

{{ __('Total Deductions') }}

{{ number_format($payroll->total_deductions, 2) }}

{{ __('Net Payment') }}

{{ number_format($payroll->total_net, 2) }}

@php // Collect all unique allowances and deductions across all employees $allAllowances = []; $allDeductions = []; foreach($payroll->items as $item) { $breakdown = $item->breakdown ?? []; $allowances = $breakdown['allowances'] ?? []; $socialFunds = $breakdown['social_funds'] ?? []; foreach($allowances as $allowance) { if (!in_array($allowance['name'], $allAllowances)) { $allAllowances[] = $allowance['name']; } } foreach($socialFunds as $fund) { if (!in_array($fund['name'], $allDeductions)) { $allDeductions[] = $fund['name']; } } } // Add Other Deductions (from deductions system) foreach($payroll->items as $item) { $breakdown = $item->breakdown ?? []; $otherDeds = $breakdown['other_deductions'] ?? []; foreach($otherDeds as $ded) { if (!in_array($ded['name'], $allDeductions)) { $allDeductions[] = $ded['name']; } } } // Add Loans to deductions if any exist $hasLoans = false; foreach($payroll->items as $item) { $breakdown = $item->breakdown ?? []; if (($breakdown['total_loan_deductions'] ?? 0) > 0) { $hasLoans = true; break; } } if ($hasLoans) { $allDeductions[] = 'Loans'; } @endphp
{{ __('Scroll horizontally to view all columns') }}
@forelse($allAllowances as $allowanceName) @empty @endforelse @foreach($allDeductions as $deductionName) @if(strtoupper($deductionName) !== 'NSSF') @endif @endforeach @forelse($payroll->items as $index => $item) @php $breakdown = $item->breakdown ?? []; $basicPayUSD = $breakdown['basic_pay_usd'] ?? 0; $grossTZS = $breakdown['gross_salary_tzs'] ?? $item->gross; $allowances = $breakdown['allowances'] ?? []; $socialFunds = $breakdown['social_funds'] ?? []; $otherDeductions = $breakdown['other_deductions'] ?? []; $paye = $breakdown['paye'] ?? 0; $totalLoanDed = $breakdown['total_loan_deductions'] ?? 0; // Create lookup arrays for this employee's data $empAllowances = []; foreach($allowances as $allowance) { $empAllowances[$allowance['name']] = $allowance['amount']; } $empDeductions = []; foreach($socialFunds as $fund) { $empDeductions[$fund['name']] = $fund['employee_amount']; } foreach($otherDeductions as $deduction) { $empDeductions[$deduction['name']] = $deduction['amount']; } if ($totalLoanDed > 0) { $empDeductions['Loans'] = $totalLoanDed; } @endphp @forelse($allAllowances as $allowanceName) @empty @endforelse @foreach($allDeductions as $deductionName) @if(strtoupper($deductionName) !== 'NSSF') @endif @endforeach @empty @endforelse
{{ __('Employee') }} {{ __('Basic Pay (USD)') }} {{ __('Gross Pay (TZS)') }} {{ $allowanceName }}{{ __('Allowances') }} {{ __('NSSF Employee (10%)') }} {{ __('NSSF Employer (10%)') }} {{ $deductionName }}{{ __('PAYE') }} {{ __('Net Pay') }} {{ __('Actions') }}
{{ strtoupper(substr($item->employee->first_name, 0, 1) . substr($item->employee->last_name, 0, 1)) }}
{{ $item->employee->first_name }} {{ $item->employee->last_name }}
{{ $item->employee->position ?? 'N/A' }}
${{ number_format($basicPayUSD, 2) }} {{ number_format($grossTZS, 2) }} {{ isset($empAllowances[$allowanceName]) ? number_format($empAllowances[$allowanceName], 2) : '-' }} - {{ $item->nssf_employee > 0 ? number_format($item->nssf_employee, 2) : '-' }} {{ $item->nssf_employer > 0 ? number_format($item->nssf_employer, 2) : '-' }} {{ isset($empDeductions[$deductionName]) ? number_format($empDeductions[$deductionName], 2) : '-' }} {{ $paye > 0 ? number_format($paye, 2) : '-' }} {{ number_format($item->net, 2) }}
@if($payroll->status === 'draft')
@csrf
@endif

{{ __('No employees in this payroll summary') }}