@extends('layouts.app') @section('title', 'Cash Flow Ledger — Financial OS') @push('styles') {{-- Tom Select CSS for searchable dropdowns --}} @endpush @section('content') @php $user = Auth::user(); $canModify = $canModify ?? true; $userCurrency = $user->base_currency ?? 'USD'; $currencySymbols = [ 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'OMR' => 'ر.ع.', 'AED' => 'د.إ', 'SAR' => 'ر.س', 'PKR' => '₨', 'INR' => '₹' ]; $currencySymbol = $currencySymbols[$userCurrency] ?? $userCurrency; $totalIncome = $incomeTransactions->sum('amount') ?? 0; $totalExpenses = $expenseTransactions->sum('amount') ?? 0; $totalLiabilities= $liabilityTransactions->sum('amount') ?? 0; $netCashFlow = $totalIncome - $totalExpenses; $savingsRate = $totalIncome > 0 ? (($totalIncome - $totalExpenses) / $totalIncome) * 100 : 0; $defaultCategoryId = $defaultCategoryId ?? null; $defaultAccountId = $defaultAccountId ?? null; $defaultAmount = $defaultAmount ?? ''; $defaultDescription= $defaultDescription?? ''; $defaultMerchant = $defaultMerchant ?? ''; $activeTab = $activeTab ?? 'expense'; $prevMonth = ''; // ── FIX 4: Build a correct running balance per-account lookup ── // We load the transactions once; the table iterates them in DESC date order. // We calculate the running balance going BACKWARDS from current_balance. // current_balance already reflects all transactions up to NOW. // As we walk backwards (newest → oldest), we un-apply each transaction // to get the balance BEFORE that transaction. // We display the balance AFTER the transaction (i.e. the running total at that point). // Group current balances by account id $accountBalances = $financialAccounts->pluck('current_balance', 'id')->toArray(); // We'll track per-account running balance in a plain PHP array (no static) $runningBalances = []; // [ account_id => float ] $balanceInitialized = []; // [ account_id => bool ] @endphp @php $isEditing = request()->has('edit') || (isset($editMode) && $editMode && isset($editTransactionId)); $editingId = request()->get('edit') ?? ($editTransactionId ?? null); @endphp {{-- TOASTS --}} @if(session('success'))
| Date | Ref | Category | Account | Type | Outflow | Inflow | Liability | Transfer | Balance | Actions |
|---|---|---|---|---|---|---|---|---|---|---|
| {{ $mon }} | ||||||||||
| {{ $tx->transaction_date->format('d M Y') }} | #{{ str_pad($tx->id,6,'0',STR_PAD_LEFT) }} |
{{ $tx->category?->name ?? '—' }}
@if($tx->description) {{ Str::limit(e($tx->description),35) }} @endif
|
{{ $account->account_name ?? '—' }}
{{ $txSymbol }}{{ number_format($account->current_balance ?? 0, 2) }}
|
{{ $displayType }} | {{ (!$isIncome && !$isTransfer && !$isLiability) ? $txSymbol.number_format($tx->amount,2) : '—' }} | {{ $isIncome ? $txSymbol.number_format($tx->amount,2) : '—' }} | {{ $isLiability ? $txSymbol.number_format($tx->amount,2) : '—' }} | {{ $isTransfer ? $txSymbol.number_format($tx->amount,2) : '—' }} | {{ $txSymbol }}{{ number_format($displayBalance,2) }} | |
|
No transactions found. |
||||||||||