@extends('layouts.app')
@section('title',$account->name)
@section('content')
<x-ui.page-toolbar :title="$account->name" :description="str($account->account_type)->replace('_',' ')->title().' · '.$account->branch->name" :breadcrumbs="[['label'=>'Dashboard','url'=>route('dashboard')],['label'=>'Financial Accounts','url'=>route('accounts.index')],['label'=>$account->name]]">
<x-slot:actions><div class="flex gap-2">@if(auth()->user()->can('accounts.capital') && $account->status==='active')<a class="mf-btn" href="{{ route('capital-injections.create',['account'=>$account->id]) }}">Add Capital</a>@endif @if(auth()->user()->can('accounts.transfer') && $account->status==='active')<a class="mf-btn" href="{{ route('account-transfers.create',['source'=>$account->id]) }}">Transfer</a>@endif @if(auth()->user()->can('accounts.manage'))<a class="mf-btn mf-btn-primary" href="{{ route('accounts.edit',$account) }}">Edit Account</a>@endif</div></x-slot:actions>
</x-ui.page-toolbar>
<div class="grid gap-4 md:grid-cols-4 mb-4"><div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Current balance</div><div class="mt-1 text-lg font-semibold">{{ number_format((float)$account->current_balance,2) }}</div></div><div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Opening balance</div><div class="mt-1 font-semibold">{{ number_format((float)$account->opening_balance,2) }}</div></div><div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Type</div><div class="mt-1 font-medium">{{ str($account->account_type)->replace('_',' ')->title() }}</div></div><div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Status</div><div class="mt-1"><span class="mf-badge {{ $account->status==='active'?'mf-badge-success':'mf-badge-muted' }}">{{ ucfirst($account->status) }}</span></div></div></div>
<div class="mf-card mb-4"><div class="border-b p-4"><h2 class="font-semibold">Account details</h2></div><div class="p-4 grid gap-4 md:grid-cols-3 text-sm"><div><div class="text-xs text-muted-foreground">Branch</div><div class="font-medium">{{ $account->branch->name }}</div></div><div><div class="text-xs text-muted-foreground">Reference details</div><div>{{ $account->reference_details ?: '—' }}</div></div><div><div class="text-xs text-muted-foreground">Created</div><div>{{ $account->created_at->format('d M Y H:i') }}</div></div></div></div>
<div class="mb-3"><h2 class="text-base font-semibold">Account Statement</h2><p class="mt-1 text-sm text-muted-foreground">Permanent posting-order history showing branch, source record, money movement and the running balance after each event.</p></div>
<div class="mf-table-frame"><table class="mf-table"><thead><tr><th>Date</th><th>Transaction</th><th>Branch</th><th>Reference</th><th>Type</th><th>Related Record</th><th>Description</th><th>User</th><th class="text-right">Money In</th><th class="text-right">Money Out</th><th class="text-right">Running Balance</th></tr></thead><tbody>@forelse($transactions as $transaction)@php($related=$transaction->related) <tr><td>{{ $transaction->transaction_date->format('d M Y H:i') }}</td><td class="font-medium">{{ $transaction->transaction_number }}</td><td>{{ $transaction->branch->name }}</td><td>{{ $transaction->reference ?: '—' }}</td><td>{{ str($transaction->type)->replace('_',' ')->title() }}</td><td>@if($related){{ $related->capital_number ?? $related->transfer_number ?? $related->name ?? class_basename($transaction->related_type).' #'.$transaction->related_id }}@else—@endif</td><td>{{ $transaction->description }}</td><td>{{ $transaction->user?->name ?? 'System' }}</td><td class="text-right">{{ (float)$transaction->money_in>0?number_format((float)$transaction->money_in,2):'—' }}</td><td class="text-right">{{ (float)$transaction->money_out>0?number_format((float)$transaction->money_out,2):'—' }}</td><td class="text-right font-medium">{{ number_format((float)$transaction->running_balance,2) }}</td></tr>@empty<tr><td colspan="11" class="text-center text-muted-foreground">No transactions posted to this account yet.</td></tr>@endforelse</tbody></table></div><div class="mt-4">{{ $transactions->links() }}</div>
@endsection
