<x-app-layout><x-slot name="header"><div class="d-flex flex-wrap justify-content-between align-items-center gap-2"><div><h2 class="h4 mb-0">Account Statement</h2><p class="text-muted mb-0">Customer collections, other income and business expenses</p></div><div class="d-flex gap-2"><a class="btn btn-outline-success" href="{{ route('admin.accounts.statement.export', request()->query()) }}">Export CSV</a><button onclick="window.print()" class="btn btn-outline-secondary">Print</button>@can('accounts.manage')<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#accountEntry">Add entry</button>@endcan</div></div></x-slot>
<form class="card border-0 shadow-sm mb-4 d-print-none"><div class="card-body row g-3 align-items-end"><div class="col-md-3"><label class="form-label">From</label><input type="date" name="from" value="{{ $filters['from'] ?? '' }}" class="form-control"></div><div class="col-md-3"><label class="form-label">To</label><input type="date" name="to" value="{{ $filters['to'] ?? '' }}" class="form-control"></div><div class="col-md-2"><label class="form-label">Type</label><select name="type" class="form-select"><option value="">All</option><option value="income" @selected(($filters['type']??'')==='income')>Income</option><option value="expense" @selected(($filters['type']??'')==='expense')>Expense</option></select></div><div class="col-md-2"><label class="form-label">Method</label><select name="method" class="form-select"><option value="">All</option>@foreach(['cash','bank','bkash','nagad','other'] as $m)<option value="{{ $m }}" @selected(($filters['method']??'')===$m)>{{ ucfirst($m) }}</option>@endforeach</select></div><div class="col-md-2"><button class="btn btn-dark w-100">Filter</button></div></div></form>
<div class="row g-3 mb-4"><div class="col-6 col-lg-3"><div class="card border-0 shadow-sm"><div class="card-body"><small>Opening</small><h3>@money($opening)</h3></div></div></div><div class="col-6 col-lg-3"><div class="card border-0 shadow-sm"><div class="card-body"><small>Income</small><h3 class="text-success">@money($income)</h3></div></div></div><div class="col-6 col-lg-3"><div class="card border-0 shadow-sm"><div class="card-body"><small>Expense</small><h3 class="text-danger">@money($expense)</h3></div></div></div><div class="col-6 col-lg-3"><div class="card border-0 shadow-sm"><div class="card-body"><small>Closing</small><h3>@money($opening+$income-$expense)</h3></div></div></div></div>
<div class="card border-0 shadow-sm"><div class="table-responsive"><table class="table table-hover align-middle mb-0" style="min-width:900px"><thead><tr><th>Date</th><th>Source</th><th>Category / Description</th><th>Method</th><th>Reference</th><th class="text-end">Income</th><th class="text-end">Expense</th><th class="text-end">Balance</th><th class="d-print-none"></th></tr></thead><tbody>@php($balance=$opening) @if(($filters['from']??null))<tr class="table-light"><td>{{ $filters['from'] }}</td><td>Opening</td><td>Opening balance</td><td></td><td></td><td></td><td></td><td class="text-end fw-bold">{{ number_format($balance,2) }}</td><td></td></tr>@endif @forelse($rows as $row) @php($balance += $row['income']-$row['expense'])<tr><td>{{ $row['date']?->format('d M Y') }}</td><td><span class="badge {{ $row['source']==='billing'?'bg-info text-dark':'bg-secondary' }}">{{ ucfirst($row['source']) }}</span></td><td><strong>{{ $row['category'] }}</strong><div class="small text-muted">{{ $row['description'] }}</div></td><td>{{ ucfirst($row['method']) }}</td><td>{{ $row['reference'] ?: '-' }}</td><td class="text-end text-success">{{ $row['income'] ? number_format($row['income'],2):'-' }}</td><td class="text-end text-danger">{{ $row['expense'] ? number_format($row['expense'],2):'-' }}</td><td class="text-end fw-bold">{{ number_format($balance,2) }}</td><td class="d-print-none">@if($row['source']==='manual' && auth()->user()->can('accounts.manage'))<form method="post" action="{{ route('admin.accounts.transactions.destroy',$row['id']) }}" onsubmit="return confirm('Delete this entry?')">@csrf @method('DELETE')<button class="btn btn-sm btn-outline-danger">Delete</button></form>@endif</td></tr>@empty<tr><td colspan="9" class="text-center py-4">No transactions found.</td></tr>@endforelse</tbody></table></div></div>
@can('accounts.manage')<div class="modal fade" id="accountEntry" tabindex="-1"><div class="modal-dialog"><form method="post" action="{{ route('admin.accounts.transactions.store') }}" class="modal-content">@csrf<div class="modal-header"><h5 class="modal-title">Add account entry</h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body row g-3"><div class="col-6"><label class="form-label">Type *</label><select name="type" class="form-select" required><option value="income">Income</option><option value="expense">Expense</option></select></div><div class="col-6"><label class="form-label">Date *</label><input type="date" name="transaction_date" value="{{ now()->toDateString() }}" class="form-control" required></div><div class="col-7"><label class="form-label">Category *</label><input name="category" list="accountCategories" class="form-control" required><datalist id="accountCategories"><option>Office Rent</option><option>Staff Salary</option><option>Electricity</option><option>Bandwidth Purchase</option><option>Equipment Sale</option><option>Other Income</option><option>Maintenance</option></datalist></div><div class="col-5"><label class="form-label">Amount *</label><input type="number" name="amount" step="0.01" min="0.01" class="form-control" required></div><div class="col-6"><label class="form-label">Method *</label><select name="payment_method" class="form-select" required>@foreach(['cash','bank','bkash','nagad','other'] as $m)<option value="{{ $m }}">{{ ucfirst($m) }}</option>@endforeach</select></div><div class="col-6"><label class="form-label">Reference</label><input name="reference" class="form-control"></div><div class="col-12"><label class="form-label">Description</label><textarea name="description" class="form-control"></textarea></div></div><div class="modal-footer"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button><button class="btn btn-primary">Save</button></div></form></div></div>@endcan
</x-app-layout>
