@extends('layouts.app')
@section('title','Dashboard')
@section('page_title','Management Dashboard')
@section('content')
<div class="page-head"><div><h1>Business Overview</h1><p>Live figures derived from posted journals and transport operations.</p></div><div class="muted">{{ now()->format('l, d F Y') }}</div></div>
<div class="grid grid-4"><div class="card metric"><div class="metric-label">Cash & Bank</div><div class="metric-value">AED {{ number_format((float)$metrics['cash'],2) }}</div><div class="metric-note">Posted ledger balance</div></div><div class="card metric"><div class="metric-label">Accounts Receivable</div><div class="metric-value">AED {{ number_format((float)$metrics['receivables'],2) }}</div><div class="metric-note">Customer ledger only</div></div><div class="card metric"><div class="metric-label">Accounts Payable</div><div class="metric-value">AED {{ number_format((float)$metrics['payables'],2) }}</div><div class="metric-note">Vendor ledger only</div></div><div class="card metric"><div class="metric-label">Net Working Position</div><div class="metric-value">AED {{ number_format((float)$metrics['cash']+(float)$metrics['receivables']-(float)$metrics['payables'],2) }}</div></div></div>
<div class="grid grid-4" style="margin-top:18px"><div class="card metric"><div class="metric-label">Revenue This Month</div><div class="metric-value">AED {{ number_format((float)$metrics['revenue'],2) }}</div></div><div class="card metric"><div class="metric-label">Costs & Expenses</div><div class="metric-value">AED {{ number_format((float)$metrics['cost'],2) }}</div></div><div class="card metric"><div class="metric-label">Net Profit</div><div class="metric-value">AED {{ number_format((float)$metrics['net_profit'],2) }}</div></div><div class="card metric"><div class="metric-label">Open Jobs</div><div class="metric-value">{{ $metrics['open_jobs'] }}</div><div class="metric-note">{{ $metrics['in_transit'] }} currently in transit</div></div></div>
<div class="grid grid-3" style="margin-top:18px"><div class="card metric"><div class="metric-label">Missing POD</div><div class="metric-value">{{ $metrics['pending_pod'] }}</div><div class="metric-note"><a href="{{ route('jobs.index',['status'=>'delivered']) }}">Review delivered jobs</a></div></div><div class="card metric"><div class="metric-label">Ready to Invoice</div><div class="metric-value">{{ $metrics['ready_to_invoice'] }}</div><div class="metric-note"><a href="{{ route('jobs.index',['status'=>'ready_to_invoice']) }}">Open billing queue</a></div></div><div class="card metric"><div class="metric-label">VAT Estimate</div><div class="metric-value"><a href="{{ route('reports.vat') }}">View Report</a></div><div class="metric-note">Output less recoverable input VAT</div></div></div>
<div class="grid grid-2" style="margin-top:18px"><div class="card"><div class="card-head"><strong>Recent Transport Jobs</strong><a href="{{ route('jobs.index') }}">View all</a></div><div class="table-wrap"><table class="table"><thead><tr><th>Job</th><th>Customer</th><th>Status</th><th>Profit</th></tr></thead><tbody>@forelse($recentJobs as $job)<tr><td><a href="{{ route('jobs.show',$job) }}">{{ $job->job_number }}</a><div class="muted">{{ $job->job_date->format('d M') }}</div></td><td>{{ $job->customer?->legal_name }}</td><td><span class="badge status-{{ $job->status }}">{{ ucwords(str_replace('_',' ',$job->status)) }}</span></td><td>AED {{ number_format((float)$job->profit,2) }}</td></tr>@empty<tr><td colspan="4" class="empty">No jobs yet.</td></tr>@endforelse</tbody></table></div></div>
<div class="card"><div class="card-head"><strong>Overdue Customer Invoices</strong><a href="{{ route('reports.aging','customer') }}">Customer aging</a></div><div class="table-wrap"><table class="table"><thead><tr><th>Invoice</th><th>Customer</th><th>Due</th><th>Balance</th></tr></thead><tbody>@forelse($overdueInvoices as $i)<tr><td><a href="{{ route('invoices.show',$i) }}">{{ $i->invoice_number }}</a></td><td>{{ $i->party?->legal_name }}</td><td>{{ optional($i->due_date)->format('d M Y') }}</td><td>AED {{ number_format((float)$i->grand_total-(float)$i->paid_total-(float)$i->allocated_total,2) }}</td></tr>@empty<tr><td colspan="4" class="empty">No overdue invoices.</td></tr>@endforelse</tbody></table></div></div></div>
<div class="grid grid-2" style="margin-top:18px"><div class="card"><div class="card-head"><strong>Vendor Bills Pending Action</strong><a href="{{ route('bills.index') }}">View bills</a></div><div class="table-wrap"><table class="table"><thead><tr><th>Bill</th><th>Vendor</th><th>Total</th><th>Status</th></tr></thead><tbody>@forelse($pendingBills as $b)@php($s=$b->status instanceof \App\Enums\DocumentStatus?$b->status->value:$b->status)<tr><td><a href="{{ route('bills.show',$b) }}">{{ $b->bill_number }}</a></td><td>{{ $b->party?->legal_name }}</td><td>AED {{ number_format((float)$b->grand_total,2) }}</td><td><span class="badge status-{{ $s }}">{{ ucwords(str_replace('_',' ',$s)) }}</span></td></tr>@empty<tr><td colspan="4" class="empty">Nothing pending.</td></tr>@endforelse</tbody></table></div></div><div class="card"><div class="card-head"><strong>Vehicle Document Alerts</strong><a href="{{ route('masters.index','vehicles') }}">Vehicle register</a></div><div class="table-wrap"><table class="table"><thead><tr><th>Vehicle</th><th>Registration</th><th>Insurance</th><th>Permit</th></tr></thead><tbody>@forelse($expiringVehicles as $v)<tr><td>{{ $v->plate_number }}</td><td>{{ optional($v->registration_expiry)->format('d M Y') }}</td><td>{{ optional($v->insurance_expiry)->format('d M Y') }}</td><td>{{ optional($v->permit_expiry)->format('d M Y') }}</td></tr>@empty<tr><td colspan="4" class="empty">No upcoming expiries.</td></tr>@endforelse</tbody></table></div></div></div>
@endsection
