@extends('layouts.app')
@section('title',$entry->payslip_number)
@section('content')
<style>@media print{.payslip-actions,.mf-sidebar,header{display:none!important}main{margin:0!important;padding:0!important}.payslip-sheet{border:0!important;box-shadow:none!important}}</style>
@php($period=$entry->period)
@php($business=$period->branch->business)
<div class="payslip-actions mb-4 flex justify-between gap-2"><a class="mf-btn" href="{{ route('payroll.show',$period) }}">Back to Payroll</a><div class="flex gap-2"><button class="mf-btn" onclick="window.print()">Print</button><a class="mf-btn mf-btn-primary" href="{{ route('payroll.payslip.pdf',[$period,$entry]) }}">Download PDF</a></div></div>
<div class="payslip-sheet mf-card mf-card-body max-w-4xl mx-auto">
    <div class="border-b pb-4 mb-4 flex justify-between gap-4"><div class="flex gap-3">@if($business->logo_path)<img src="{{ route('document-branding.asset',[$business,'logo']) }}" alt="Company logo" class="h-14 w-20 object-contain">@endif<div><div class="text-xl font-semibold">{{ $business->name }}</div><div class="text-sm text-muted-foreground">Employee Payslip · {{ $entry->payslip_number }}</div><div class="text-xs text-muted-foreground">{{ collect([$business->address,$business->phone,$business->email])->filter()->join(' · ') }}</div></div></div><div class="text-right text-xs text-muted-foreground">Reg {{ $business->registration_number ?: 'N/A' }}<br>TIN {{ $business->tin ?: 'N/A' }}</div></div>
    <div class="grid gap-3 md:grid-cols-2 text-sm mb-5">
        <div><div class="text-muted-foreground">Employee</div><div class="font-medium">{{ $entry->employee_name_snapshot }}</div><div>{{ $entry->employee_number_snapshot ?: 'N/A' }} · {{ $entry->position_snapshot ?: 'No position' }}</div></div>
        <div><div class="text-muted-foreground">Payroll period</div><div class="font-medium">{{ $period->name }} · {{ $period->period_number }}</div><div>{{ $period->start_date->format('d M Y') }} – {{ $period->end_date->format('d M Y') }}</div></div>
        <div><div class="text-muted-foreground">Branch</div><div class="font-medium">{{ $period->branch->name }}</div></div>
        <div><div class="text-muted-foreground">Paid</div><div class="font-medium">{{ $entry->paid_at?->format('d M Y H:i') }}</div><div>From {{ $entry->financialAccount?->name ?? 'N/A' }}</div></div>
    </div>
    <div class="grid gap-4 md:grid-cols-2">
        <div class="border p-3"><div class="font-semibold mb-2">Earnings</div><div class="space-y-1 text-sm"><div class="flex justify-between"><span>Basic salary</span><span>{{ number_format((float)$entry->basic_salary,2) }}</span></div><div class="flex justify-between"><span>Allowances</span><span>{{ number_format((float)$entry->allowances,2) }}</span></div><div class="flex justify-between"><span>Bonus</span><span>{{ number_format((float)$entry->bonus,2) }}</span></div><div class="flex justify-between"><span>Commission</span><span>{{ number_format((float)$entry->commission,2) }}</span></div><div class="flex justify-between"><span>Overtime</span><span>{{ number_format((float)$entry->overtime,2) }}</span></div><div class="flex justify-between border-t pt-2 font-semibold"><span>Gross</span><span>{{ number_format((float)$entry->gross,2) }}</span></div></div></div>
        <div class="border p-3"><div class="font-semibold mb-2">Deductions</div><div class="space-y-1 text-sm"><div class="flex justify-between"><span>Deductions</span><span>{{ number_format((float)$entry->deductions,2) }}</span></div><div class="flex justify-between"><span>Advances</span><span>{{ number_format((float)$entry->advances,2) }}</span></div><div class="flex justify-between"><span>Other deductions</span><span>{{ number_format((float)$entry->other_deductions,2) }}</span></div><div class="flex justify-between border-t pt-2 font-semibold"><span>Total deductions</span><span>{{ number_format((float)$entry->total_deductions,2) }}</span></div></div></div>
    </div>
    <div class="mt-4 border-y py-4 flex justify-between text-lg font-semibold"><span>NET PAY</span><span>{{ ($business->currency_symbol ?: $business->currency) }} {{ number_format((float)$entry->net,2) }}</span></div>
    <div class="mt-4 text-xs text-muted-foreground">Transaction: {{ $entry->accountTransaction?->transaction_number ?? 'N/A' }} · Journal: {{ $entry->accounting_journal_number ?? 'N/A' }} · Processed by {{ $entry->payer?->name ?? 'N/A' }}</div>
    @if($business->stamp_path)<div class="mt-4 flex justify-end"><img src="{{ route('document-branding.asset',[$business,'stamp']) }}" alt="Company stamp" class="max-h-20 max-w-28 object-contain"></div>@endif
</div>
@endsection
