@extends('layouts.app')
@section('title','Payroll '.$run->payroll_no)
@section('crumbs', '<a href="'.route('payroll-runs.index').'">Payroll Runs</a> · <b>'.$run->payroll_no.'</b>')
@section('content')
<div class="card"><div class="card-h"><h2>Payroll {{ $run->payroll_no }} — {{ fdate($run->payroll_month,'M Y') }}</h2>
<span class="bdg b-{{ statusClass($run->status) }}">{{ $run->status }}</span>
<div class="sp no-print">
<a class="btn btn-sm btn-ghost" href="{{ route('payroll-runs.index') }}">← Back</a>
@if($run->status==='draft' && perm('payroll.approve'))<form method="POST" action="{{ route('payroll-runs.approve',$run->id) }}" style="display:inline" data-confirm="Approve this payroll?">@csrf<button class="btn btn-sm btn-ok">✓ Approve</button></form>@endif
@if($run->status==='draft' && perm('payroll.delete'))<form method="POST" action="{{ route('payroll-runs.destroy',$run->id) }}" style="display:inline" data-confirm="Delete this run?" >@csrf @method('DELETE')<button class="btn btn-sm btn-danger">Delete</button></form>@endif
</div></div>
<div class="card-b">
<div class="grid g4" style="margin-bottom:14px">
<div class="kpi g"><div class="lb">Gross</div><div class="vl">{{ cmoney($run->total_gross,0) }}</div></div>
<div class="kpi red"><div class="lb">Deductions</div><div class="vl">{{ cmoney($run->total_deductions,0) }}</div><div class="sb">PAYE {{ money($run->total_payee) }} · SSNIT(ee) {{ money($run->total_ssnit_employee) }}</div></div>
<div class="kpi b"><div class="lb">Net pay</div><div class="vl">{{ cmoney($run->total_net,0) }}</div></div>
<div class="kpi y"><div class="lb">Employer SSNIT</div><div class="vl">{{ cmoney($run->total_ssnit_employer,0) }}</div></div>
</div>
@if($run->status==='approved' && perm('payroll.approve'))
<div class="card" style="border-left:5px solid var(--ok)"><div class="card-b"><form method="POST" action="{{ route('payroll-runs.pay',$run->id) }}" data-confirm="Pay {{ cmoney($run->total_net) }} in salaries?">@csrf
<div class="frow"><div class="fld c6"><label>Pay from *</label><select name="bank_account_id" required><option value="">—</option>@foreach(\App\Models\BankAccount::where('is_active',true)->orderBy('bank_name')->get() as $b)<option value="{{ $b->id }}">{{ $b->display_name }} ({{ money($b->current_balance) }})</option>@endforeach</select></div>
<div class="fld c6"><label>&nbsp;</label><button class="btn btn-pri">💰 Pay salaries & post</button></div></div>
</form></div></div>
@endif
<div class="twrap"><table class="tbl"><thead><tr><th>Employee</th><th class="r">Basic</th><th class="r">Allow</th><th class="r">Gross</th><th class="r">SSNIT</th><th class="r">PAYE</th><th class="r">Adv</th><th class="r">Net</th><th class="no-print"></th></tr></thead>
<tbody>@foreach($run->lines as $l)<tr>
<td><b>{{ $l->employee->full_name ?? '' }}</b><br><span class="small muted">{{ $l->employee->employee_no ?? '' }} · {{ $l->employee->department->name ?? '' }}</span></td>
<td class="r">{{ money($l->basic_salary) }}</td><td class="r">{{ money($l->allowances_total) }}</td><td class="r"><b>{{ money($l->gross_pay) }}</b></td>
<td class="r">{{ money($l->ssnit_employee) }}</td><td class="r">{{ money($l->paye) }}</td><td class="r">{{ money($l->advances_deduction) }}</td>
<td class="r"><b>{{ money($l->net_pay) }}</b></td>
<td class="no-print"><a class="btn btn-sm btn-ghost" href="{{ route('payroll-runs.payslip',[$run->id,$l->id]) }}" target="_blank">Payslip</a></td>
</tr>@endforeach</tbody>
<tfoot><tr><td>Total</td><td></td><td></td><td class="r">{{ money($run->total_gross) }}</td><td class="r">{{ money($run->total_ssnit_employee) }}</td><td class="r">{{ money($run->total_payee) }}</td><td></td><td class="r">{{ money($run->total_net) }}</td><td></td></tr></tfoot>
</table></div>
</div></div>
@endsection
