= 2; $can_undo = lookupUserPermission('module_financial') >= 3; $types = accountTypes(); $kinds = accountLedgerKinds(); $open_accounts = accountsList(false); $account_id = intval($_GET['account'] ?? 0); $account = $account_id ? accountRow($account_id) : null; $missing_account = $account_id && !$account; if (!$account) { $pick = 0; foreach ($open_accounts as $id => $option) { if ($option['reconciling_id']) { $pick = $id; break; } } if (!$pick && isset($open_accounts[intval($config_default_payment_account)])) { $pick = intval($config_default_payment_account); } if (!$pick && $open_accounts) { $pick = array_key_first($open_accounts); } $account = $pick ? $open_accounts[$pick] : null; } $account_id = $account ? intval($account['account_id']) : 0; $is_card = $account && $account['type'] === 3; $currency = $account ? (string) $account['account_currency_code'] : (string) $session_company_currency; $money = function ($amount) use ($currency) { return escapeHtml(billingMoney($amount, $currency)); }; // A balance as the statement reads it - a card's as what is owed $statement_money = function ($balance) use ($account, $money) { return $account ? escapeHtml(reconcileBalanceText($account, $balance)) : $money($balance); }; $open = $account ? reconcileOpen($account_id) : null; $last = $account ? reconcileLast($account_id) : null; $history = $account && !$open ? reconcileHistory($account_id) : []; $starting = $account ? reconcileStartingBalance($account_id) : 0.0; // Brought forward from the bank's balance - and how far ITFlow was from it that day $opening = $account ? reconcileOpening($account_id) : null; $opening_totals = $opening ? reconcileTotals($opening) : null; $opening_gap = $opening ? round($opening_totals['difference'], 2) : 0.0; // The next statement most likely ends at the end of last month $suggest = date('Y-m-t', strtotime('first day of last month')); if ($last && $suggest <= $last['reconciliation_statement_date']) { $suggest = date('Y-m-d'); } if ($open) { $totals = reconcileTotals($open); $lines = reconcileLines($open, $later); $statement_date = $open['reconciliation_statement_date']; } else { $uncleared = $account ? mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*), COALESCE(SUM(ledger.txn_amount), 0) FROM (" . accountLedgerSql($account_id, false) . ") AS ledger WHERE ledger.txn_cleared_id IS NULL")) : [0, 0]; } $statement_form = function ($row) use ($mysqli, $account, $is_card, $suggest, $last, $starting, $money, $statement_money) { $date = $row ? $row['reconciliation_statement_date'] : $suggest; $ending = $row ? floatval($row['reconciliation_ending_balance']) * ($is_card ? -1 : 1) : null; $first = !$row && !$last; if ($first) { // An account with history before the statement most likely starts from the bank's balance $start = date('Y-m-01', strtotime($date)); $account_id = intval($account['account_id']); $earlier = mysqli_fetch_row(mysqli_query($mysqli, "SELECT EXISTS (SELECT 1 FROM payments WHERE payment_account_id = $account_id AND payment_date < '$start') OR EXISTS (SELECT 1 FROM revenues WHERE revenue_account_id = $account_id AND revenue_date < '$start') OR EXISTS (SELECT 1 FROM expenses WHERE expense_account_id = $account_id AND expense_date < '$start')"))[0]; $from_statement = intval($earlier) === 1; ?>
| Cleared | Date | Who or what | In | Out |
|---|---|---|---|---|
| = $can_edit ? '' : 'disabled' ?> aria-label="Cleared"> | = escapeHtml($line['txn_date']) ?>= escapeHtml($line['txn_date']) ?> |
= escapeHtml($what) ?> - = escapeHtml($description) ?>
= escapeHtml(implode(' ยท ', $meta)) ?>
|
= $amount > 0 ? $money($amount) : '' ?> | = $amount < 0 ? $money(-$amount) : '' ?> |
| Statement to | = $is_card ? 'Owed' : 'Ending balance' ?> | Cleared | In | Out | Reconciled | |
|---|---|---|---|---|---|---|
| = escapeHtml(date('M j, Y', strtotime($row['reconciliation_statement_date']))) ?>
Brought forward - everything before = escapeHtml(date('M j, Y', strtotime($row['reconciliation_statement_date'] . ' +1 day'))) ?>
= escapeHtml($row['reconciliation_notes']) ?>
|
= $statement_money($row['reconciliation_ending_balance']) ?>
= 0.005) { ?>
opening balance corrected by = $money($row['reconciliation_adjustment']) ?>
= 0.005) { ?>
= $money(abs($t['difference'])) ?> off ITFlow's = $statement_money($t['cleared']) ?>
|
= $t['count'] ?> line= $t['count'] === 1 ? '' : 's' ?>
from = $statement_money($t['starting']) ?>
|
= $money($t['in']) ?> | = $money($t['out']) ?> |
= escapeHtml($row['finished_by_name'] ?? 'Someone since removed') ?>
= escapeHtml(timeAgo($row['reconciliation_finished_at'])) ?>
|
Undo |