= 2; $can_delete = lookupUserPermission('module_financial') >= 3; $vendor_filter = intval($_GET['vendor'] ?? 0); $category_filter = intval($_GET['category'] ?? 0); $account_filter = intval($_GET['account'] ?? 0); $client_filter = intval($_GET['client'] ?? 0); $method_filter = trim((string) ($_GET['method'] ?? '')); $shows = expenseShows(); $show = isset($shows[$_GET['show'] ?? '']) ? (string) ($_GET['show'] ?? '') : ''; // Only these sort - filter_header.php hands through any lowercase word $sortable_columns = ['expense_date' => 'expense_date', 'vendor_name' => 'vendor_name', 'category_name' => 'category_name', 'client_name' => 'client_name', 'account_name' => 'account_name', 'expense_amount' => 'expense_amount', 'expense_created_at' => 'expense_created_at']; if (!isset($sortable_columns[$sort])) { $sort = 'expense_date'; } // Everything but the pill, then the pill - the pill counts are over what the rest leave $filter_src = array_merge($_GET, ['dtf' => $dtf, 'dtt' => $dtt, 'show' => '']); $where = expenseFiltersSql($filter_src); $show_query = $shows[$show]['where'] ? "AND {$shows[$show]['where']}" : ''; $joins = expenseJoinsSql(); $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS expenses.*, vendor_name, vendor_archived_at, category_name, category_color, account_name, client_name, user_name FROM expenses $joins WHERE $where $show_query ORDER BY {$sortable_columns[$sort]} $order, expense_id DESC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $expenses = []; while ($row = mysqli_fetch_assoc($sql)) { $expenses[] = $row; } // The pills, and the total 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 THEN expense_amount END), 0) FROM expenses $joins WHERE $where")); $counts = []; foreach (array_keys($shows) as $i => $key) { $counts[$key] = intval($row[$i]); } $listed_total = floatval($row[count($shows)]); $stats = expenseStats(); $filter_url = function ($changes) { $params = array_merge($_GET, $changes); unset($params['page']); return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null; })); }; $date_url = function ($from, $to, $changes = []) use ($filter_url) { return $filter_url(array_merge(['canned_date' => 'custom', 'dtf' => $from, 'dtt' => $to], $changes)); }; $stat_money = function ($amount) use ($session_company_currency) { return escapeHtml(billingMoney($amount, $session_company_currency)); }; // More filters open when one of them is set $more_filters = $account_filter || $method_filter !== ''; $any_filter = $q || $vendor_filter || $category_filter || $account_filter || $client_filter || $method_filter !== '' || $show !== '' || $dtf !== '1970-01-01'; // This month against the same days of last month $month_change = $stats['last_to_date'] > 0 ? round(($stats['month'] - $stats['last_to_date']) / $stats['last_to_date'] * 100) : null; ?>
This month
% on the same days of in
so far
expense · a month
Recurring
a month from running · a year
No receipt, 90 days

Expenses

Date Vendor Category Client Paid from Amount
> true, 'archived' => !empty($row['vendor_archived_at'])]) ?>
-
Refund
expense count($expenses) ? ' - the total is for all of them, not just this page' : '' ?>