@extends('layouts.app')
@section('title',$receipt->receipt_number)
@section('page_title','Receipt Voucher')
@section('content')
@php($s=$receipt->status instanceof \App\Enums\DocumentStatus?$receipt->status->value:$receipt->status)
<div class="page-head"><div><h1>{{ $receipt->receipt_number }}</h1><p>{{ $receipt->party->legal_name }} · <span class="badge status-{{ $s }}">{{ ucwords(str_replace('_',' ',$s)) }}</span></p></div><div class="actions"><a class="btn btn-secondary" href="{{ route('receipts.index') }}">Back</a><a class="btn btn-secondary" target="_blank" href="{{ route('receipts.print',$receipt) }}">Print</a><a class="btn btn-secondary" href="{{ route('receipts.pdf',$receipt) }}">PDF</a>@if(in_array($s,['draft','rejected'])&&auth()->user()->hasPermission('receipts.edit_draft'))<a class="btn btn-primary" href="{{ route('receipts.edit',$receipt) }}">Edit</a>@endif</div></div>
<div class="grid grid-3"><div class="card metric"><div class="metric-label">Receipt Amount</div><div class="metric-value">{{ $receipt->currency_code }} {{ number_format((float)$receipt->amount,2) }}</div></div><div class="card metric"><div class="metric-label">Allocated</div><div class="metric-value">{{ number_format((float)$receipt->allocations->sum('amount'),2) }}</div></div><div class="card metric"><div class="metric-label">Unallocated / Advance</div><div class="metric-value">{{ number_format((float)$receipt->amount-(float)$receipt->allocations->sum('amount'),2) }}</div></div></div>
<div class="card" style="margin-top:18px"><div class="detail-grid" style="border:0"><div class="detail"><div class="detail-label">Type</div><div class="detail-value">{{ ucwords(str_replace('_',' ',$receipt->receipt_type)) }}</div></div><div class="detail"><div class="detail-label">Date</div><div class="detail-value">{{ $receipt->receipt_date->format('d M Y') }}</div></div><div class="detail"><div class="detail-label">Method</div><div class="detail-value">{{ ucwords(str_replace('_',' ',$receipt->payment_method)) }}</div></div><div class="detail"><div class="detail-label">Reference</div><div class="detail-value">{{ $receipt->reference_number?:'—' }}</div></div><div class="detail"><div class="detail-label">Description</div><div class="detail-value">{{ $receipt->description?:'—' }}</div></div><div class="detail"><div class="detail-label">Branch</div><div class="detail-value">{{ $receipt->branch->name }}</div></div></div></div>
@if($receipt->allocations->isNotEmpty())<div class="card" style="margin-top:18px"><div class="card-head"><strong>Invoice Allocations</strong></div><div class="table-wrap"><table class="table"><thead><tr><th>Invoice</th><th>Invoice Total</th><th>Allocated</th></tr></thead><tbody>@foreach($receipt->allocations as $a)<tr><td><a href="{{ route('invoices.show',$a->invoice) }}">{{ $a->invoice->invoice_number }}</a></td><td>{{ number_format((float)$a->invoice->grand_total,2) }}</td><td>{{ number_format((float)$a->amount,2) }}</td></tr>@endforeach</tbody></table></div></div>@endif
@include('components.workflow-actions',['document'=>$receipt,'routePrefix'=>'receipts','permissionPrefix'=>'receipts','status'=>$s,'postLabel'=>'Post Receipt'])
@endsection
