Files
2026-07-06 22:17:16 +02:00

140 lines
6.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?= $this->extend('layout/main') ?>
<?= $this->section('content') ?>
<?php $fmt = static fn ($v) => number_format((float) $v, 2, ',', ' ') . ' zł'; ?>
<style>
.col-desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
</style>
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h4 mb-0">Operacje</h1>
<a href="<?= site_url('operations/new') ?>" class="btn btn-primary">+ Nowa operacja</a>
</div>
<div class="card shadow-sm mb-3">
<div class="card-body">
<?= form_open('operations', ['method' => 'get', 'class' => 'row g-2 align-items-end']) ?>
<div class="col-6 col-md-3">
<label class="form-label small mb-1">Od</label>
<input type="date" name="from" class="form-control" value="<?= esc($filter['from'] ?? '') ?>">
</div>
<div class="col-6 col-md-3">
<label class="form-label small mb-1">Do</label>
<input type="date" name="to" class="form-control" value="<?= esc($filter['to'] ?? '') ?>">
</div>
<div class="col-6 col-md-3">
<label class="form-label small mb-1">Kategoria</label>
<select name="category_id" class="form-select">
<option value="">— wszystkie —</option>
<?php foreach ($categories as $c): ?>
<option value="<?= $c['id'] ?>" <?= (string) ($filter['category_id'] ?? '') === (string) $c['id'] ? 'selected' : '' ?>>
<?= esc($c['indent_label']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-6 col-md-2">
<label class="form-label small mb-1">Typ</label>
<select name="type" class="form-select">
<option value="">— oba —</option>
<option value="income" <?= ($filter['type'] ?? '') === 'income' ? 'selected' : '' ?>>Przychód</option>
<option value="expense" <?= ($filter['type'] ?? '') === 'expense' ? 'selected' : '' ?>>Wydatek</option>
</select>
</div>
<div class="col-md-1">
<button class="btn btn-outline-primary w-100">Filtruj</button>
</div>
<?= form_close() ?>
</div>
</div>
<div class="row g-3 mb-3">
<div class="col-md-4"><div class="card stat-card shadow-sm"><div class="card-body">
<div class="text-muted small">Przychody</div>
<div class="value amount-income"><?= $fmt($totals['income']) ?></div>
</div></div></div>
<div class="col-md-4"><div class="card stat-card shadow-sm"><div class="card-body">
<div class="text-muted small">Wydatki</div>
<div class="value amount-expense"><?= $fmt($totals['expense']) ?></div>
</div></div></div>
<div class="col-md-4"><div class="card stat-card shadow-sm"><div class="card-body">
<div class="text-muted small">Saldo</div>
<div class="value <?= $totals['balance'] >= 0 ? 'amount-income' : 'amount-expense' ?>"><?= $fmt($totals['balance']) ?></div>
</div></div></div>
</div>
<div class="card shadow-sm">
<div class="table-responsive">
<table class="table table-hover mb-0 align-middle">
<thead class="table-light">
<tr>
<th class="text-nowrap">Data</th>
<th class="text-nowrap">Kategoria</th>
<th>Opis</th>
<th class="text-end text-nowrap">Kwota</th>
<th class="text-end">Akcje</th>
</tr>
</thead>
<tbody>
<?php if (empty($operations)): ?>
<tr><td colspan="5" class="text-center text-muted py-4">Brak operacji dla wybranych filtrów.</td></tr>
<?php else: foreach ($operations as $o): ?>
<tr>
<td class="text-nowrap"><?= esc($o['date']) ?></td>
<td class="text-nowrap">
<?php
if (! empty($o['category_name'])) {
echo esc(! empty($o['parent_name'])
? $o['parent_name'] . ' → ' . $o['category_name']
: $o['category_name']);
} else {
echo '(bez kategorii)';
}
?>
</td>
<td class="text-muted col-desc" title="<?= esc($o['description'] ?? '') ?>"><?= esc($o['description'] ?? '') ?></td>
<td class="text-end text-nowrap <?= $o['type'] === 'income' ? 'amount-income' : 'amount-expense' ?>">
<?= $o['type'] === 'income' ? '+' : '' ?><?= $fmt($o['amount']) ?>
</td>
<td class="text-end text-nowrap">
<a href="<?= site_url('operations/' . $o['id'] . '/edit') ?>" class="btn btn-sm btn-outline-secondary">Edytuj</a>
<a href="<?= site_url('operations/' . $o['id'] . '/delete') ?>" class="btn btn-sm btn-outline-danger"
onclick="return confirm('Usunąć operację?')">Usuń</a>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
<?php if ($pages > 1): ?>
<?php
$qs = array_filter([
'from' => $filter['from'] ?? '',
'to' => $filter['to'] ?? '',
'category_id' => $filter['category_id'] ?? '',
'type' => $filter['type'] ?? '',
], static fn ($v) => $v !== '' && $v !== null);
$link = static fn (int $p) => site_url('operations') . '?' . http_build_query($qs + ['page' => $p]);
?>
<div class="card-footer d-flex justify-content-between align-items-center flex-wrap gap-2">
<span class="text-muted small">Strona <?= $page ?> z <?= $pages ?> (<?= $total ?> operacji)</span>
<nav>
<ul class="pagination pagination-sm mb-0">
<li class="page-item <?= $page <= 1 ? 'disabled' : '' ?>">
<a class="page-link" href="<?= $link(max(1, $page - 1)) ?>"></a>
</li>
<?php for ($p = 1; $p <= $pages; $p++): ?>
<li class="page-item <?= $p === $page ? 'active' : '' ?>">
<a class="page-link" href="<?= $link($p) ?>"><?= $p ?></a>
</li>
<?php endfor; ?>
<li class="page-item <?= $page >= $pages ? 'disabled' : '' ?>">
<a class="page-link" href="<?= $link(min($pages, $page + 1)) ?>"></a>
</li>
</ul>
</nav>
</div>
<?php endif; ?>
</div>
<?= $this->endSection() ?>