= 2; $open_accounts = accountsList(false); $account_filter = intval($_GET['account'] ?? 0); $account = $account_filter ? accountRow($account_filter) : null; $missing_account = $account_filter && !$account; if (!$account) { $account_filter = 0; } $all = !$account; $types = accountTypes(); $kinds = accountLedgerKinds(); $shows = accountLedgerShows($all); $show = (string) ($_GET['show'] ?? ''); $show = isset($shows[$show]) ? $show : ''; $kind_filter = (string) ($_GET['kind'] ?? ''); if ($kind_filter === '' && isset(accountLedgerTypeNames()[(string) ($_GET['type'] ?? '')])) { $kind_filter = accountLedgerTypeNames()[(string) $_GET['type']]; } $category_filter = intval($_GET['category'] ?? 0); $client_filter = intval($_GET['client'] ?? 0); $method_filter = (string) ($_GET['method'] ?? ($_GET['payment_method'] ?? '')); $amount_min = (string) ($_GET['amount_min'] ?? ''); $amount_max = (string) ($_GET['amount_max'] ?? ''); $more_filters = ($kind_filter !== '' && isset($kinds[$kind_filter])) || $method_filter !== '' || $amount_min !== '' || $amount_max !== ''; $reconciliation_filter = intval($_GET['reconciliation'] ?? 0); $reconciliation = $reconciliation_filter ? reconcileRow($reconciliation_filter) : null; // Only these sort - filter_header.php hands through any lowercase word $sortable_columns = ['txn_date' => null, 'txn_amount' => 'ledger.txn_amount', 'category_name' => 'ledger.category_name', 'client_name' => 'ledger.client_name', 'txn_what' => 'ledger.txn_what', 'account_name' => 'ledger.account_name']; if (!array_key_exists($sort, $sortable_columns)) { $sort = 'txn_date'; } $order_sql = $sort === 'txn_date' ? "ledger.txn_date $order, ledger.txn_created_at $order, ledger.txn_order $order, ledger.txn_id $order" : "{$sortable_columns[$sort]} $order, ledger.txn_date DESC, ledger.txn_id DESC"; $balance_visible = !$all && $sort === 'txn_date'; $filter_src = array_merge($_GET, ['dtf' => $dtf, 'dtt' => $dtt, 'kind' => $kind_filter, 'show' => $show]); $where = accountLedgerFiltersSql($filter_src, $summary, false, $all); $show_query = $show !== '' ? 'AND ' . $shows[$show]['where'] : ''; // The balance after each line only where it shows - one account, in date order $ledger = accountLedgerSql($account_filter, $balance_visible); $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS ledger.* FROM ($ledger) AS ledger WHERE $where $show_query ORDER BY $order_sql LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $rows = []; while ($row = mysqli_fetch_assoc($sql)) { $rows[] = accountLedgerVisible($row); } // The pills, and the money in and out of what is listed - and, on every account's // transfers, what was moved, what paid off cards and what payment processors paid out. // One pass over the ledger, without the balance after each line. $transfer_cards = $all && $show === 'transfers'; $count_sql = []; foreach ($shows as $key => $s) { $count_sql[] = $key === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)"; } // Across every account a transfer is money moved between them, so Money in and Money out // leave it out (accountLedgerShows()) - except on Transfers, where it is what is listed $not_transfer = $all && $show !== 'transfers' ? "AND ledger.txn_kind NOT IN ('transfer_in', 'transfer_out')" : ''; $count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query $not_transfer AND ledger.txn_amount > 0 THEN ledger.txn_amount END), 0)"; $count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query $not_transfer AND ledger.txn_amount < 0 THEN -ledger.txn_amount END), 0)"; if ($transfer_cards) { $count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query THEN -ledger.txn_amount END), 0)"; $count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.other_account_type = 3 THEN -ledger.txn_amount END), 0)"; $count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.other_account_type = 3 THEN 1 END), 0)"; $count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.account_type = 5 THEN -ledger.txn_amount END), 0)"; $count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.account_type = 5 THEN 1 END), 0)"; } $row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " FROM (" . accountLedgerSql($account_filter, false) . ") AS ledger WHERE $where")); $counts = []; foreach (array_keys($shows) as $i => $key) { $counts[$key] = intval($row[$i]); } $n = count($shows); $total_in = round(floatval($row[$n]), 2); $total_out = round(floatval($row[$n + 1]), 2); if ($transfer_cards) { $moved = ['count' => $counts['transfers'], 'total' => round(floatval($row[$n + 2]), 2), 'cards' => round(floatval($row[$n + 3]), 2), 'card_count' => intval($row[$n + 4]), 'payouts' => round(floatval($row[$n + 5]), 2), 'payout_count' => intval($row[$n + 6])]; } $currency = $account ? (string) $account['account_currency_code'] : (string) $session_company_currency; $money = function ($amount, $code = null) use ($currency) { return escapeHtml(billingMoney($amount, $code ?? $currency)); }; $filter_url = function ($changes) { $params = array_merge($_GET, $changes); unset($params['page'], $params['type'], $params['payment_method']); return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null && $v !== 0; })); }; $any_filter = $q || $category_filter || $client_filter || $more_filters || $reconciliation_filter || $show !== '' || $dtf !== '1970-01-01'; $dated = $dtf !== '1970-01-01' || $dtt !== '2099-12-31'; $cash = 0.0; $cash_accounts = 0; foreach ($open_accounts as $open) { if ($open['type'] !== 3) { $cash += $open['balance']; $cash_accounts++; } } $is_card = $account && $account['type'] === 3; ?>
That account no longer exists - here is every account's.
· ·
In the accounts
Across account
Moved
transfer
Paid onto cards
Paid out by processors
Money in
Money out
Difference

The lines on brought forward as reconciled - everything before The lines cleared on Show every line
Date Account Who or what Category Client In Out Balance
-
Transfer
-
Another client
-
0 ? $money($amount, $row_currency) : '' ?>
line count($rows) ? ' - the totals are for all of them, not just this page' : '' ?>
'transactions', 'icon' => $show === 'transfers' ? 'fa-exchange-alt' : 'fa-list-alt', 'filtered' => $q || $category_filter || $client_filter || $more_filters || $reconciliation_filter || $dtf !== '1970-01-01', 'views' => ['show', 'account'], 'view' => emptyStatePill($shows, $show, '', ['uncleared']), 'title' => $account ? 'Nothing on ' . escapeHtml($account['account_name']) . ' yet' : 'No transactions yet', 'text' => 'Payments, other income, expenses and transfers show here as they are recorded.', 'actions' => $can_edit ? [['label' => $is_card ? 'Pay the Card' : 'New Transfer', 'modal' => 'modals/transfer/transfer_add.php' . ($account ? ($is_card ? '?to=' : '?from=') . $account_filter : ''), 'size' => 'lg', 'icon' => $is_card ? 'fa-credit-card' : 'fa-exchange-alt']] : [], ]; require_once "../includes/filter_footer.php"; ?>