$from, 'end' => $to]));
$from_other = $totals['total'] - $from_invoices;
$months_elapsed = reportMonthsElapsed($year);
$average = $months_elapsed ? $totals['total'] / $months_elapsed : 0;
$best_month = 0;
foreach ($totals['months'] as $m => $v) {
if ($v > ($totals['months'][$best_month] ?? 0)) {
$best_month = $m;
}
}
// Last year month by month, as a line behind this year's bars
$prev_full = reportGridTotals(reportIncomeByCategory(($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,
]); ?>
= reportStats([
['label' => 'Income', 'value' => reportMoney($totals['total']), 'sub' => reportChangeHtml($totals['total'], $prev_total, 'up', $compare),
'url' => "/agent/income.php?canned_date=custom&dtf=$from&dtt=$to"],
['label' => 'Invoice payments', 'value' => reportMoney($from_invoices), 'sub' => escapeHtml(reportPercent(reportShare($from_invoices, $totals['total']))) . '
of income',
'url' => "/agent/income.php?show=payments&canned_date=custom&dtf=$from&dtt=$to"],
['label' => 'Other income', 'value' => reportMoney($from_other), 'sub' => escapeHtml(reportPercent(reportShare($from_other, $totals['total']))) . '
of income',
'url' => "/agent/income.php?show=other&canned_date=custom&dtf=$from&dtt=$to"],
['label' => 'Monthly average', 'value' => reportMoney($average), 'sub' => $best_month ? 'Best month
' . date('F', mktime(0, 0, 0, $best_month, 1)) . '' : ''],
]) ?>
= reportSectionOpen('Income by month', escapeHtml("$year, with " . ($year - 1) . ' as a line')) ?>
(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', 'Income per month by category, with last year as a line');
?>
= reportSectionOpen('By category', 'Click an amount to see the payments and other income behind it', 'itflow-report-long') ?>
= reportCategoryYearTable($categories, $grid, $year, 'income.php', 'Total income', 'show=uncategorised') ?>
Payments are filed under the category of the invoice they paid, other income under its own - No category when it has none. Transfers between your own accounts are left out.