Files
budget/views/comparisons.php
T
Ty Clifford b7eaa81501 -
2026-06-14 15:25:31 -04:00

64 lines
4.5 KiB
PHP

<?php
$totals = $yearly['totals'];
$bestMonth = null;
foreach ($yearly['months'] as $row) {
if ($bestMonth === null || $row['remaining'] > $bestMonth['remaining']) {
$bestMonth = $row;
}
}
?>
<section class="hero-grid comparison-metrics">
<article class="metric-card card"><div class="metric-icon blue">Σ</div><p><?= (int) $yearly['year'] ?> resources</p><strong><?= h(Support::money($totals['gross_resources'], $symbol)) ?></strong><small>Across all twelve months</small></article>
<article class="metric-card card"><div class="metric-icon pink">↗</div><p><?= (int) $yearly['year'] ?> expenses</p><strong><?= h(Support::money($totals['expenses'], $symbol)) ?></strong><small><?= $totals['gross_resources'] > 0 ? number_format($totals['expenses'] / $totals['gross_resources'] * 100, 1) : '0.0' ?>% of resources</small></article>
<article class="metric-card card"><div class="metric-icon orange">◇</div><p>Moved dormant</p><strong><?= h(Support::money($totals['dead_movement'], $symbol)) ?></strong><small>Net dormant deposits</small></article>
<article class="metric-card card"><div class="metric-icon green">★</div><p>Strongest remainder</p><strong><?= h(Support::money($bestMonth['remaining'] ?? 0, $symbol)) ?></strong><small><?= $bestMonth ? h(date('F', strtotime($bestMonth['month'] . '-01'))) : 'No data' ?></small></article>
</section>
<section class="content-grid comparison-grid">
<article class="card span-2">
<div class="card-heading"><div><p class="eyebrow">Month-to-month</p><h2>Resources vs. expenses</h2></div></div>
<canvas class="trend-chart large" data-trend-chart='<?= h(json_encode($comparison)) ?>' data-symbol="<?= h($symbol) ?>" height="280"></canvas>
</article>
<article class="card">
<div class="card-heading"><div><p class="eyebrow"><?= h(date('F', strtotime($month . '-01'))) ?></p><h2>Category share</h2></div></div>
<?php if ($categoryStats === []): ?>
<div class="empty-state compact"><strong>No category data</strong><p>Record categorized expenses to build this view.</p></div>
<?php else: ?>
<?php $categoryTotal = array_sum(array_column($categoryStats, 'spent')); ?>
<div class="category-bars">
<?php foreach ($categoryStats as $category): $width = $categoryTotal > 0 ? (float) $category['spent'] / $categoryTotal * 100 : 0; ?>
<div>
<p><span><i style="--dot:<?= h($category['color']) ?>"></i><?= h($category['category_name']) ?></span><strong><?= h(Support::money($category['spent'], $symbol)) ?></strong></p>
<div class="progress-track"><span style="width:<?= h((string) $width) ?>%;--bar:<?= h($category['color']) ?>"></span></div>
<?php if ((float) $category['monthly_limit'] > 0): ?><small><?= number_format($category['spent'] / $category['monthly_limit'] * 100, 0) ?>% of <?= h(Support::money($category['monthly_limit'], $symbol)) ?> category limit</small><?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</article>
</section>
<article class="card">
<div class="card-heading">
<div><p class="eyebrow">Statistical table</p><h2><?= (int) $yearly['year'] ?> monthly breakdown</h2></div>
<label class="search-box"><span>⌕</span><input type="search" placeholder="Find a month…" data-table-search="year-table"></label>
</div>
<div class="table-wrap">
<table id="year-table">
<thead><tr><th>Month</th><th>Resources</th><th>Planned</th><th>Expenses</th><th>Dormant</th><th>Remainder</th></tr></thead>
<tbody>
<?php foreach ($yearly['months'] as $row): ?>
<tr>
<td><a class="text-link" href="<?= h(url('comparisons', ['month' => $row['month']])) ?>"><?= h(date('F Y', strtotime($row['month'] . '-01'))) ?></a></td>
<td><?= h(Support::money($row['gross_resources'], $symbol)) ?></td>
<td><?= h(Support::money($row['planned'], $symbol)) ?></td>
<td><?= h(Support::money($row['expenses'], $symbol)) ?></td>
<td><?= h(Support::money($row['dead_movement'], $symbol)) ?></td>
<td class="<?= $row['remaining'] >= 0 ? 'green' : 'red' ?>"><strong><?= h(Support::money($row['remaining'], $symbol)) ?></strong></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</article>