0"); $current_year = $year === intval(date('Y')); $from = "$year-01-01"; $to = $current_year ? date('Y-m-d') : "$year-12-31"; $prev_from = ($year - 1) . '-01-01'; $prev_to = $current_year ? dashboardShiftMonths(date('Y-m-d'), -12) : ($year - 1) . '-12-31'; $compare = $current_year ? 'the same time last year' : (string) ($year - 1); $grid = reportExpensesByCategory($from, $to); $categories = reportCategoriesWithAmounts(reportCategoryRows('Expense', $grid), $grid); $totals = reportGridTotals($grid); $prev_total = reportGridTotals(reportExpensesByCategory($prev_from, $prev_to))['total']; if (reportExporting()) { reportCategoryYearCsv($categories, $grid, $year, "Expenses $year", 'Total expenses'); } $months_elapsed = reportMonthsElapsed($year); $average = $months_elapsed ? $totals['total'] / $months_elapsed : 0; $biggest = null; foreach ($categories as $cat => $category) { if (!$biggest || $grid[$cat]['total'] > $grid[$biggest]['total']) { $biggest = $cat; } } // What is already committed every month $recurring = recurringExpenseMonthlyTotal(); $prev_full = reportGridTotals(reportExpensesByCategory(($year - 1) . '-01-01', ($year - 1) . '-12-31'))['months']; require_once "includes/inc_report_layout.php"; ?>
[$year, $years], 'subtitle' => $current_year ? "$year to date" : (string) $year, ]); ?> 'Spending', 'value' => reportMoney($totals['total']), 'sub' => reportChangeHtml($totals['total'], $prev_total, 'down', $compare), 'url' => "/agent/expenses.php?canned_date=custom&dtf=$from&dtt=$to"], ['label' => 'Monthly average', 'value' => reportMoney($average), 'sub' => escapeHtml("Over $months_elapsed month" . ($months_elapsed === 1 ? '' : 's'))], ['label' => 'Biggest category', 'value' => $biggest !== null ? $categories[$biggest]['category_name'] : '-', 'sub' => $biggest !== null ? reportMoney($grid[$biggest]['total']) . ' ยท ' . reportPercent(reportShare($grid[$biggest]['total'], $totals['total'])) . '' : ''], ['label' => 'Recurring', 'value' => reportMoney($recurring), 'sub' => 'Per month, committed now', 'url' => '/agent/recurring_expenses.php'], ]) ?>
(string) ($year - 1), 'data' => array_map(function ($v) { return round($v, 2); }, array_values($prev_full)), 'tone' => 'muted', 'type' => 'line', 'dashed' => true]; echo reportChart([ 'type' => 'bar', 'labels' => array_map(function ($m) { return date('M', mktime(0, 0, 0, $m, 1)); }, range(1, 12)), 'series' => $series, 'stacked' => true, 'format' => 'money', ], 'lg', 'Spending per month by category, with last year as a line'); ?>