= 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'] : ''; $ledger = accountLedgerSql($account_filter); $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[] = $row; } // The pills, and the money in and out of what is listed $count_sql = []; foreach ($shows as $key => $s) { $count_sql[] = $key === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)"; } $row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . ", COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.txn_amount > 0 THEN ledger.txn_amount END), 0), COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.txn_amount < 0 THEN -ledger.txn_amount END), 0) FROM ($ledger) AS ledger WHERE $where")); $counts = []; foreach (array_keys($shows) as $i => $key) { $counts[$key] = intval($row[$i]); } $total_in = round(floatval($row[count($shows)]), 2); $total_out = round(floatval($row[count($shows) + 1]), 2); $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; // Every account's transfers: what was moved, what paid off cards and what payment processors paid out $transfer_cards = $all && $show === 'transfers'; if ($transfer_cards) { $row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*), COALESCE(SUM(-ledger.txn_amount), 0), COALESCE(SUM(CASE WHEN ledger.other_account_type = 3 THEN -ledger.txn_amount END), 0), COALESCE(SUM(CASE WHEN ledger.other_account_type = 3 THEN 1 END), 0), COALESCE(SUM(CASE WHEN ledger.account_type = 5 THEN -ledger.txn_amount END), 0), COALESCE(SUM(CASE WHEN ledger.account_type = 5 THEN 1 END), 0) FROM ($ledger) AS ledger WHERE $where $show_query")); $moved = ['count' => intval($row[0]), 'total' => round(floatval($row[1]), 2), 'cards' => round(floatval($row[2]), 2), 'card_count' => intval($row[3]), 'payouts' => round(floatval($row[4]), 2), 'payout_count' => intval($row[5])]; } ?>
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 cleared on Show every line
Date Account Who or what Category Client In Out Balance
-
Transfer
-
-
0 ? $money($amount, $row_currency) : '' ?>
line count($rows) ? ' - the totals are for all of them, not just this page' : '' ?>