@extends('layouts.app')
@section('title',$bank->bank_name)
@section('page_title','Bank Statement')
@section('content')
<div class="page-head"><div><h1>{{ $bank->bank_name }} · {{ $bank->account_name }}</h1><p>{{ $bank->account_number }} · Book balance AED {{ number_format((float)$bookBalance,2) }}</p></div><div class="actions"><a class="btn btn-primary" href="{{ route('bank.reconcile.create',$bank) }}">Start Reconciliation</a><a class="btn btn-secondary" href="{{ route('bank.index') }}">Back</a></div></div>
<div class="grid grid-2"><div class="card"><div class="card-head"><strong>Import CSV Statement</strong></div><div class="card-body"><form method="post" enctype="multipart/form-data" action="{{ route('bank.import',$bank) }}">@csrf<div class="field"><label>CSV columns: Date, Reference, Description, Debit, Credit, Balance (optional)</label><input class="control" type="file" name="file" accept=".csv,.txt" required></div><label class="checkbox"><input type="checkbox" name="has_header" value="1" checked> First row is a header</label><button class="btn btn-primary">Import</button></form></div></div><div class="card"><div class="card-head"><strong>Add Manual Statement Line</strong></div><div class="card-body"><form class="form-grid" method="post" action="{{ route('bank.transactions.store',$bank) }}">@csrf<div class="field"><label>Date</label><input class="control" type="date" name="transaction_date" value="{{ date('Y-m-d') }}"></div><div class="field"><label>Reference</label><input class="control" name="reference"></div><div class="field full"><label>Description</label><input class="control" name="description"></div><div class="field"><label>Debit / Money In</label><input class="control" type="number" step="0.01" name="debit" value="0"></div><div class="field"><label>Credit / Money Out</label><input class="control" type="number" step="0.01" name="credit" value="0"></div><button class="btn btn-primary">Add Line</button></form></div></div></div>
<div class="card" style="margin-top:18px"><div class="table-wrap"><table class="table"><thead><tr><th>Date</th><th>Reference</th><th>Description</th><th>Debit</th><th>Credit</th><th>Balance</th><th>Status</th><th></th></tr></thead><tbody>@forelse($transactions as $t)<tr><td>{{ $t->transaction_date->format('d M Y') }}</td><td>{{ $t->reference }}</td><td>{{ $t->description }}</td><td>{{ number_format((float)$t->debit,2) }}</td><td>{{ number_format((float)$t->credit,2) }}</td><td>{{ $t->running_balance!==null?number_format((float)$t->running_balance,2):'—' }}</td><td><span class="badge">{{ ucfirst($t->match_status) }}</span></td><td>@if($t->match_status!=='cleared')<form method="post" action="{{ route('bank.transactions.destroy',[$bank,$t]) }}">@csrf @method('delete')<button class="btn btn-danger btn-sm">Delete</button></form>@endif</td></tr>@empty<tr><td colspan="8" class="empty">No statement transactions.</td></tr>@endforelse</tbody></table></div>{{ $transactions->links() }}</div>
@endsection
