@extends('layouts.master') @section('content')
{{-- PAGE HEADER + DATE FILTER --}}

Home

{{ $rangeLabel }} ({{ $fromDate }} to {{ $toDate }})
{{-- ═══════════════════════════════════════════════════════════════ EXECUTIVE SCORECARD RIBBON (replaces the old 4-card row) Kept: Net Cash Position · Net Tax Liability Added: Gross Profit · A/R Health ════════════════════════════════════════════════════════════════ --}}
{{-- Net Cash Position --}}
Net Cash Position
{{ number_format($netCashPosition, 2) }}
Cash less supplier payments due (7 days)
{{-- Net Tax Liability --}}
Net Tax Liability (Range)
{{ number_format($netTaxLiability, 2) }}
Collected: {{ number_format($vatCollected, 2) }}  |  Paid: {{ number_format($vatPaid, 2) }}
{{-- Gross Profit (new) --}}
Gross Profit (Range)
{{ number_format($grossProfitThisRange, 2) }}
Rev: {{ number_format($revenueThisRange, 2) }}  |  @php $gpMargin = $revenueThisRange > 0 ? round(($grossProfitThisRange / $revenueThisRange) * 100, 1) : 0; @endphp Margin: {{ $gpMargin }}%
{{-- A/R Health (new) --}}
{{-- ═══════════════════════════════════════════════════════════════ CASH FLOW CHART + QUICK ACTIONS + BANK BREAKDOWN ════════════════════════════════════════════════════════════════ --}}
Cash Flow Trend (Last 12 Months)
Bank Account Breakdown
Balances as at {{ $toDate }}
{{-- ═══════════════════════════════════════════════════════════════ RECEIVABLES + PAYABLES ════════════════════════════════════════════════════════════════ --}}
Receivables
Outstanding
{{ number_format($totalOutstandingReceivables, 2) }}
Overdue
{{ number_format($overdueReceivables, 2) }}
Collected This Month
{{ number_format($collectedThisMonth, 2) }}
Payables
Outstanding
{{ number_format($totalOutstandingPayables, 2) }}
Overdue
{{ number_format($overduePayables, 2) }}
Paid This Month
{{ number_format($paidToSuppliersThisMonth, 2) }}
{{-- ═══════════════════════════════════════════════════════════════ REVENUE & EXPENSES ════════════════════════════════════════════════════════════════ --}}
Revenue & Expenses
Revenue (Range)
{{ number_format($revenueThisRange, 2) }}
Expenses (Range)
{{ number_format($expensesThisRange, 2) }}
Gross Profit (Range)
{{ number_format($grossProfitThisRange, 2) }}
Net Profit / (Loss)
{{ number_format($netProfitThisRange, 2) }}
Expense Breakdown (Top Accounts)
{{-- ═══════════════════════════════════════════════════════════════ DOCUMENT PIPELINE (enhanced) ════════════════════════════════════════════════════════════════ --}}
Document Pipeline
{{-- ── Rich KPI cards ── --}} {{-- /row KPI cards --}} {{-- ── Animated Conversion Funnel ── --}}
Sales Conversion Funnel
@php $funnelStages = [ ['label' => 'Quotations', 'icon' => 'fa-file-alt', 'color' => 'primary', 'key' => 'Quotations'], ['label' => 'Sales Orders', 'icon' => 'fa-shopping-bag', 'color' => 'success', 'key' => 'Sales Orders'], ['label' => 'Invoices', 'icon' => 'fa-file-invoice', 'color' => 'warning', 'key' => 'Invoices'], ['label' => 'Receipts', 'icon' => 'fa-money-bill', 'color' => 'info', 'key' => 'Receipts'], ]; $maxFunnel = max(1, max($funnel)); @endphp @foreach($funnelStages as $i => $stage) @php $count = $funnel[$stage['key']] ?? 0; $prevCount = $i > 0 ? ($funnel[$funnelStages[$i-1]['key']] ?? 0) : $count; $convRate = $prevCount > 0 ? round(($count / $prevCount) * 100, 1) : 0; $barWidth = $maxFunnel > 0 ? round(($count / $maxFunnel) * 100) : 0; @endphp
{{ $stage['label'] }} {{ number_format($count) }} @if($i > 0) {{ $convRate }}% conversion @endif
@if($i < count($funnelStages) - 1)
@endif @endforeach
{{-- ── Recent Documents ── --}}
Recent Documents
@forelse($recentDocuments as $doc) @empty @endforelse
Type Reference Customer / Supplier Date Status Total
{{ $doc['type'] }} {{ $doc['document_number'] }} @if($doc['side'] === 'customer') {{ $customerAccountNames[$doc['party_id']] ?? ('Customer #'.$doc['party_id']) }} @else {{ $supplierAccountNames[$doc['party_id']] ?? ('Supplier #'.$doc['party_id']) }} @endif {{ $doc['document_date'] }} {{ $doc['status'] }} {{ number_format((float) $doc['inclusive_total'], 2) }}
No recent documents found.
{{-- /col-lg-8 --}} {{-- ── ALERTS + ACTIVITY ── --}}
Smart Alerts
{{-- Overdue invoices 30+ days --}}
Invoices Overdue 30+ Days {{ $overdueInvoices30->count() }}
@if($overdueInvoices30->isEmpty())
No overdue invoices.
@else
    @foreach($overdueInvoices30->take(4) as $inv)
  • {{ $customerAccountNames[$inv['customer_account_id']] ?? ('Customer #'.$inv['customer_account_id']) }} — {{ $inv['document_number'] }} ({{ number_format($inv['outstanding'], 2) }})
  • @endforeach @if($overdueInvoices30->count() > 4)
  • + {{ $overdueInvoices30->count() - 4 }} more
  • @endif
@endif
{{-- Quotations expiring --}}
Quotations Expiring (7 Days) {{ $quotationsExpiring->count() }}
@if($quotationsExpiring->isEmpty())
No expiring quotations.
@else
    @foreach($quotationsExpiring->take(4) as $q)
  • {{ $q->document_number }} — {{ $customerAccountNames[$q->customer_account_id] ?? ('Customer #'.$q->customer_account_id) }}
  • @endforeach
@endif
{{-- Supplier payments due --}}
Supplier Payments Due (7 Days) {{ count($supplierPaymentsDue) }}
@if(empty($supplierPaymentsDue) || $supplierPaymentsDue->isEmpty())
No supplier payments due.
@else
    @foreach($supplierPaymentsDue->take(4) as $p)
  • {{ $supplierAccountNames[$p['supplier_account_id']] ?? ('Supplier #'.$p['supplier_account_id']) }} — {{ $p['document_number'] }} ({{ number_format($p['outstanding'], 2) }})
  • @endforeach
@endif
{{-- Overdue POs --}} @if(isset($overduePurchaseOrders) && $overduePurchaseOrders > 0)
Overdue Purchase Orders {{ $overduePurchaseOrders }}
@endif {{-- Delayed GRVs --}} @if(isset($delayedReceipts) && $delayedReceipts > 0)
GRVs Pending Over 3 Days {{ $delayedReceipts }}
@endif {{-- Below reorder level --}} @if(isset($belowReorderCount) && $belowReorderCount > 0)
Products Below Reorder Level {{ $belowReorderCount }}
@endif
{{-- Recent Activity --}}
Recent Activity
@if($activityLog->isEmpty())
No activity yet.
@else
    @foreach($activityLog as $a)
  • {{ \Carbon\Carbon::parse($a->created_at)->format('Y-m-d H:i') }} — {{ $a->user_name ?? 'System' }} {{ $a->action }} {{ $a->document_type }} #{{ $a->document_id }} ({{ $a->from_status ?? '-' }} → {{ $a->to_status }})
  • @endforeach
@endif
{{-- /col-lg-4 --}}
{{-- ═══════════════════════════════════════════════════════════════ QUOTATION ANALYTICS ════════════════════════════════════════════════════════════════ --}}
Quotation Analytics
@php $totalQuotes = ($quotationStats['total'] ?? 0); $convertedQuotes = ($quotationStats['converted'] ?? 0); $notConverted = ($quotationStats['not_converted']?? 0); $expiredQuotes = ($quotationStats['expired'] ?? 0); $rejectedQuotes = ($quotationStats['rejected'] ?? 0); $convPct = $totalQuotes > 0 ? round(($convertedQuotes / $totalQuotes) * 100, 1) : 0; $avgConvDays = $quotationStats['avg_days_to_convert'] ?? 0; $avgQuoteVal = $quotationStats['avg_quote_value'] ?? 0; @endphp
Total Quotations
{{ number_format($totalQuotes) }}
Converted
{{ number_format($convertedQuotes) }}
Conversion %
{{ $convPct }}%
Expired
{{ number_format($expiredQuotes) }}
Avg Quote Value
{{ number_format($avgQuoteVal, 2) }}
Converted vs Not Converted
Monthly Quotation & Conversion Trend
{{-- ═══════════════════════════════════════════════════════════════ PERIOD COMPARISON ════════════════════════════════════════════════════════════════ --}}
Period Comparison
Metric This Month Last Month This Year Last Year
Revenue {{ number_format($periodSummary['this_month']['revenue'] ?? 0, 2) }} {{ number_format($periodSummary['last_month']['revenue'] ?? 0, 2) }} {{ number_format($periodSummary['this_year']['revenue'] ?? 0, 2) }} {{ number_format($periodSummary['last_year']['revenue'] ?? 0, 2) }}
Expenses {{ number_format($periodSummary['this_month']['expenses'] ?? 0, 2) }} {{ number_format($periodSummary['last_month']['expenses'] ?? 0, 2) }} {{ number_format($periodSummary['this_year']['expenses'] ?? 0, 2) }} {{ number_format($periodSummary['last_year']['expenses'] ?? 0, 2) }}
Net Profit {{ number_format($periodSummary['this_month']['net_profit'] ?? 0, 2) }} {{ number_format($periodSummary['last_month']['net_profit'] ?? 0, 2) }} {{ number_format($periodSummary['this_year']['net_profit'] ?? 0, 2) }} {{ number_format($periodSummary['last_year']['net_profit'] ?? 0, 2) }}
Receivables (Outstanding) {{ number_format($periodSummary['this_month']['receivables'] ?? 0, 2) }} {{ number_format($periodSummary['last_month']['receivables'] ?? 0, 2) }} {{ number_format($periodSummary['this_year']['receivables'] ?? 0, 2) }} {{ number_format($periodSummary['last_year']['receivables'] ?? 0, 2) }}
Payables (Outstanding) {{ number_format($periodSummary['this_month']['payables'] ?? 0, 2) }} {{ number_format($periodSummary['last_month']['payables'] ?? 0, 2) }} {{ number_format($periodSummary['this_year']['payables'] ?? 0, 2) }} {{ number_format($periodSummary['last_year']['payables'] ?? 0, 2) }}
{{-- /container-fluid --}} @endsection @section('scripts') @endsection