@extends('layouts.app')
@section('page_title','Payroll')
@section('page_subtitle','Create Canadian payroll records, deductions and payslips for staff.')
@section('content')
<div class="card"><h3>Create Payroll</h3><form method="POST" action="{{ route('admin.payrolls.store') }}">@csrf<div class="form-row"><div class="field"><label>Employee</label><select name="user_id" required>@foreach($employees as $employee)<option value="{{ $employee->id }}">{{ $employee->name }} - {{ $employee->staff_id }}</option>@endforeach</select></div><div class="field"><label>Status</label><select name="status"><option>draft</option><option>approved</option><option>paid</option></select></div><div class="field"><label>Period Start</label><input class="input" type="date" name="pay_period_start" required></div><div class="field"><label>Period End</label><input class="input" type="date" name="pay_period_end" required></div><div class="field"><label>Basic Salary</label><input class="input" type="number" step="0.01" name="basic_salary" value="0"></div><div class="field"><label>Allowances</label><input class="input" type="number" step="0.01" name="allowances" value="0"></div><div class="field"><label>Deductions</label><input class="input" type="number" step="0.01" name="deductions" value="0"></div><div class="field"><label>Tax / CPP / EI</label><input class="input" type="number" step="0.01" name="tax" value="0"></div><div class="field"><label>Paid At</label><input class="input" type="date" name="paid_at"></div></div><div class="field"><label>Notes</label><textarea name="notes"></textarea></div><button class="btn">Create Payslip</button></form></div>
<div class="card"><h3>Payroll Records</h3><table class="table"><tr><th>Employee</th><th>Period</th><th>Gross</th><th>Deductions / Tax / CPP / EI</th><th>Net Pay</th><th>Status</th><th>Update</th></tr>@forelse($payrolls as $payroll)<tr><td>{{ $payroll->user?->name }}</td><td>{{ $payroll->pay_period_start?->format('d M Y') }} - {{ $payroll->pay_period_end?->format('d M Y') }}</td><td>C${{ number_format($payroll->basic_salary + $payroll->allowances,2) }}</td><td>C${{ number_format($payroll->deductions + $payroll->tax,2) }}</td><td><strong>C${{ number_format($payroll->net_pay,2) }}</strong></td><td><span class="badge {{ $payroll->status==='paid'?'green':'yellow' }}">{{ ucfirst($payroll->status) }}</span></td><td><form method="POST" action="{{ route('admin.payrolls.update',$payroll) }}">@csrf @method('PUT')<input type="hidden" name="basic_salary" value="{{ $payroll->basic_salary }}"><input type="hidden" name="allowances" value="{{ $payroll->allowances }}"><input type="hidden" name="deductions" value="{{ $payroll->deductions }}"><input type="hidden" name="tax" value="{{ $payroll->tax }}"><input type="hidden" name="notes" value="{{ $payroll->notes }}"><select name="status"><option @selected($payroll->status==='draft')>draft</option><option @selected($payroll->status==='approved')>approved</option><option @selected($payroll->status==='paid')>paid</option></select><input class="input" type="date" name="paid_at" value="{{ optional($payroll->paid_at)->format('Y-m-d') }}"><button class="btn secondary">Save</button></form></td></tr>@empty<tr><td colspan="7"><div class="empty">No payroll yet.</div></td></tr>@endforelse</table><div class="pagination">{{ $payrolls->links() }}</div></div>
@endsection
