@extends('layouts.finance') @section('title', 'Dashboard') @section('subtitle', 'Consolidated view across US, Pakistan & Australia') @section('content') @php $settings = $data['settings']; $dateFilter = $data['date_filter'] ?? ['active' => false, 'from' => null, 'to' => null, 'label' => null]; $filterActive = (bool) ($dateFilter['active'] ?? false); $periodLabel = $filterActive ? 'Filtered' : 'Mo.'; $todayLabel = $filterActive ? 'Filtered' : 'Today'; $accounts = $data['bank_accounts']; $walletAccounts = $accounts->filter(fn($account) => trim((string) ($account->transaction_category ?? '')) === 'Wallets'); $usAccounts = $accounts ->where('currency', 'USD') ->reject(fn($account) => trim((string) ($account->transaction_category ?? '')) === 'Wallets'); $pkAccounts = $accounts->where('currency', 'PKR'); $auAccounts = $accounts->where('currency', 'AUD'); $cards = $data['credit_cards']; $inventoryProducts = $data['inventory_products'] ?? collect(); $inventoryUnits = $inventoryProducts->sum(fn($p) => $p->stock); $kpis = $data['kpis']; $kuickpayToday = $data['kuickpay_today'] ?? ['total' => 0, 'count' => 0, 'fee' => 0, 'payout_date' => null, 'received' => false]; $kuickpayPendingYesterday = $data['kuickpay_pending_yesterday'] ?? ['date' => null, 'remaining' => 0, 'net' => 0, 'fee' => 0, 'gross' => 0, 'status' => null]; $kuickpayBacklog = $data['kuickpay_pending_backlog'] ?? ['total' => 0, 'count' => 0]; $verification = $data['verification'] ?? [ 'currency' => 'PKR', 'business_total' => 0, 'business_total_before_liabilities' => 0, 'inventory_amount' => 0, 'lent_amount' => 0, 'transit_amount' => 0, 'credit_card_debt' => 0, 'loan_debt' => 0, 'liabilities_total' => 0, 'bank_balance' => 0, 'kuickpay_today_amount' => 0, 'kuickpay_today_fee' => 0, 'kuickpay_today_net' => 0, 'store_credit_amount' => 0, 'store_credit_source' => null, 'kuickpay_pending_balance' => 0, 'kuickpay_pending_gross' => 0, ]; $displayCurrency = 'PKR'; $displayMoney = fn($amount) => $metrics->moneyIn($amount, 'USD', $displayCurrency); $agentPointCards = app(\App\Support\AgentPointsReportService::class)->dashboardCards(); $kuickpayPendingTotal = (float) ($verification['kuickpay_pending_balance'] ?? (($kuickpayPendingYesterday['remaining'] ?? 0) + ($kuickpayBacklog['total'] ?? 0))); $kuickpayPendingGross = (float) ($verification['kuickpay_pending_gross'] ?? 0); // Before-fee (gross) equivalent of yesterday's unsettled remaining, proportional. $kuickpayYesterdayGross = (($kuickpayPendingYesterday['net'] ?? 0) > 0) ? (float) ($kuickpayPendingYesterday['gross'] ?? 0) * (($kuickpayPendingYesterday['remaining'] ?? 0) / $kuickpayPendingYesterday['net']) : 0.0; $kuickpayPendingDayCount = (int) ($kuickpayBacklog['count'] ?? 0) + (((float) ($kuickpayPendingYesterday['remaining'] ?? 0)) > 0 ? 1 : 0); // PayFast settlement mirror (same shape as KuickPay). $payfastToday = $data['payfast_today'] ?? ['total' => 0, 'count' => 0, 'fee' => 0, 'payout_date' => null, 'received' => false]; $payfastPendingYesterday = $data['payfast_pending_yesterday'] ?? ['date' => null, 'remaining' => 0, 'net' => 0, 'fee' => 0, 'gross' => 0, 'status' => null]; $payfastBacklog = $data['payfast_pending_backlog'] ?? ['total' => 0, 'count' => 0]; $payfastTodayNet = max(0.0, (float) ($payfastToday['total'] ?? 0) - (float) ($payfastToday['fee'] ?? 0)); $payfastPendingTotal = (float) ($verification['payfast_pending_balance'] ?? (($payfastPendingYesterday['remaining'] ?? 0) + ($payfastBacklog['total'] ?? 0))); $payfastPendingGross = (float) ($verification['payfast_pending_gross'] ?? 0); $payfastPendingDayCount = (int) ($payfastBacklog['count'] ?? 0) + (((float) ($payfastPendingYesterday['remaining'] ?? 0)) > 0 ? 1 : 0); $kuickpayProviderRows = collect($verification['kuickpay_provider_verification'] ?? [])->keyBy('key'); $kuickpayProviderCards = collect($metrics->kuickpayProviders())->map(function ($provider, $key) use ($metrics, $kuickpayProviderRows) { $row = $kuickpayProviderRows->get($key, []); $today = [ 'total' => (float) ($row['today_gross'] ?? 0), 'fee' => (float) ($row['today_fee'] ?? 0), 'count' => (int) ($row['today_count'] ?? 0), ]; return [ 'key' => $key, 'label' => $provider['label'], 'prefix' => $provider['prefix'], 'today' => $today, 'net' => (float) ($row['today_net'] ?? max(0.0, (float) ($today['total'] ?? 0) - (float) ($today['fee'] ?? 0))), // This provider's own outstanding net, not the gateway-wide total. 'pending' => (float) ($row['pending'] ?? 0), ]; }); $usSubtotal = $usAccounts->sum(fn($a) => $a->current_balance); $walletSubtotal = $walletAccounts->sum(fn($a) => $a->current_balance); $pkSubtotal = $pkAccounts->sum(fn($a) => $a->current_balance); $auSubtotal = $auAccounts->sum(fn($a) => $a->current_balance); $cardPayable = $cards->sum(fn($c) => $metrics->usd($c->payable_balance, $c->currency)); $cardLimit = $cards->sum(fn($c) => $metrics->usd($c->credit_limit, $c->currency)); $runningProfit = $data['running_profit'] ?? ['years' => [], 'current_year_profit' => 0]; $currentYearExpense = $filterActive ? (float) ($kpis['expenses'] ?? 0) : (float) ($runningProfit['years'][0]['expenses'] ?? 0); $currentYearProfit = $filterActive ? (float) ($kpis['profit'] ?? 0) : (float) ($runningProfit['current_year_profit'] ?? ($kpis['running_profit_year'] ?? 0)); $bankLogo = fn($account) => strtoupper(substr($account->bank_name ?: $account->name, 0, 4)); $bankColor = fn($currency) => $currency === 'PKR' ? '#1e3a8a' : ($currency === 'AUD' ? '#0d9488' : '#6366f1'); $gatewayDateParams = [ 'mode' => 'date', 'from' => $filterActive ? $dateFilter['from'] : now()->toDateString(), 'to' => $filterActive ? $dateFilter['to'] : now()->toDateString(), ]; $dashboardCardParams = $filterActive ? ['from' => $dateFilter['from'], 'to' => $dateFilter['to']] : []; $dashboardDateModeParams = $filterActive ? ['mode' => 'date'] + $dashboardCardParams : []; @endphp
Core business cards and live monthly / yearly totals
Giving and obligation estimates
Provider collections, fees, and pending balances
{{ $todayLabel }} collections and unsettled pending balance
{{ $filterActive ? 'Filtered' : 'Current month' }} factory expense and revenue cards
Live balances across all wallet and gateway accounts
{{ $group['subtitle'] }}
Limits, balances payable, and due dates