160 lines
6.5 KiB
PHP
160 lines
6.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../src/config.php';
|
|
require_once __DIR__ . '/../src/auth.php';
|
|
require_once __DIR__ . '/../src/db.php';
|
|
require_once __DIR__ . '/../src/journal_functions.php';
|
|
require_once __DIR__ . '/../src/icons.php';
|
|
require_login();
|
|
|
|
$q = trim($_GET['q'] ?? '');
|
|
$from = trim($_GET['from'] ?? '');
|
|
$to = trim($_GET['to'] ?? '');
|
|
$year_id = isset($_GET['year_id']) ? (int)$_GET['year_id'] : 0;
|
|
|
|
$years = get_journal_years();
|
|
|
|
$entries = [];
|
|
$searched = false;
|
|
|
|
if ($q !== '' || $from !== '' || $to !== '' || $year_id) {
|
|
$searched = true;
|
|
$pdo = get_db();
|
|
|
|
$sql = "SELECT e.id, e.entry_date, e.month, e.description, e.attachment_note,
|
|
e.amount, e.year_id, y.year AS journal_year,
|
|
s.name AS supplier_name
|
|
FROM journal_entries e
|
|
JOIN journal_years y ON y.id = e.year_id
|
|
LEFT JOIN journal_suppliers s ON s.id = e.supplier_id
|
|
WHERE 1=1";
|
|
$params = [];
|
|
|
|
if ($q !== '') {
|
|
$sql .= " AND (e.description ILIKE :q OR e.attachment_note ILIKE :q2)";
|
|
$params[':q'] = '%' . $q . '%';
|
|
$params[':q2'] = '%' . $q . '%';
|
|
}
|
|
if ($from !== '') {
|
|
$sql .= " AND e.entry_date >= :from";
|
|
$params[':from'] = $from;
|
|
}
|
|
if ($to !== '') {
|
|
$sql .= " AND e.entry_date <= :to";
|
|
$params[':to'] = $to;
|
|
}
|
|
if ($year_id) {
|
|
$sql .= " AND e.year_id = :year_id";
|
|
$params[':year_id'] = $year_id;
|
|
}
|
|
|
|
$sql .= " ORDER BY e.entry_date DESC, e.id DESC LIMIT 200";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
$entries = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Journal-Suche</title>
|
|
<link rel="stylesheet" href="assets/style.css">
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1>PIRP</h1>
|
|
<nav>
|
|
<a href="<?= url_for('index.php') ?>"><?= icon_dashboard() ?>Dashboard</a>
|
|
<a href="<?= url_for('invoices.php') ?>"><?= icon_invoices() ?>Rechnungen</a>
|
|
<a href="<?= url_for('customers.php') ?>"><?= icon_customers() ?>Kunden</a>
|
|
<a href="<?= url_for('expenses.php') ?>"><?= icon_expenses() ?>Ausgaben</a>
|
|
<a href="<?= url_for('belegarchiv.php') ?>"><?= icon_archive() ?>Belege</a>
|
|
<a href="<?= url_for('journal.php') ?>" class="active"><?= icon_journal() ?>Journal</a>
|
|
<a href="<?= url_for('euer.php') ?>"><?= icon_euer() ?>EÜR</a>
|
|
<a href="<?= url_for('settings.php') ?>"><?= icon_settings() ?>Einstellungen</a>
|
|
<a href="<?= url_for('logout.php') ?>"><?= icon_logout() ?>Logout (<?= htmlspecialchars($_SESSION['username'] ?? '') ?>)</a>
|
|
<span class="cmd-k-hint" onclick="document.dispatchEvent(new KeyboardEvent('keydown',{key:'k',ctrlKey:true}))"><kbd>Ctrl+K</kbd></span>
|
|
</nav>
|
|
</header>
|
|
<main>
|
|
<div class="journal-subnav">
|
|
<a href="<?= url_for('journal.php') ?>">Monatsansicht</a>
|
|
<a href="<?= url_for('journal_summary.php') ?>">Jahressummen</a>
|
|
<a href="<?= url_for('journal_search.php') ?>" class="active">Suche</a>
|
|
</div>
|
|
|
|
<form method="get" class="filters">
|
|
<label>Suche:
|
|
<input type="text" name="q" value="<?= htmlspecialchars($q) ?>" placeholder="Beschreibung, Beleg..." autofocus>
|
|
</label>
|
|
<label>Von:
|
|
<input type="date" name="from" value="<?= htmlspecialchars($from) ?>">
|
|
</label>
|
|
<label>Bis:
|
|
<input type="date" name="to" value="<?= htmlspecialchars($to) ?>">
|
|
</label>
|
|
<?php if ($years): ?>
|
|
<label>Jahr:
|
|
<select name="year_id">
|
|
<option value="">Alle Jahre</option>
|
|
<?php foreach ($years as $y): ?>
|
|
<option value="<?= $y['id'] ?>" <?= $y['id'] == $year_id ? 'selected' : '' ?>><?= (int)$y['year'] ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</label>
|
|
<?php endif; ?>
|
|
<button type="submit">Suchen</button>
|
|
<a href="<?= url_for('journal_search.php') ?>">Zurücksetzen</a>
|
|
</form>
|
|
|
|
<?php if ($searched): ?>
|
|
<section>
|
|
<h2>Suchergebnisse <?php if ($entries): ?><span style="font-weight:normal;font-size:12px;color:var(--text-muted);">(<?= count($entries) ?> Treffer<?= count($entries) >= 200 ? ', max. 200' : '' ?>)</span><?php endif; ?></h2>
|
|
|
|
<?php if (empty($entries)): ?>
|
|
<p style="color:var(--text-muted);">Keine Buchungen gefunden.</p>
|
|
<?php else: ?>
|
|
<div class="journal-table-wrap">
|
|
<table class="journal-table">
|
|
<thead>
|
|
<tr>
|
|
<th class="journal-col-date">Datum</th>
|
|
<th class="journal-col-att">B</th>
|
|
<th class="journal-col-text">Beschreibung</th>
|
|
<th class="journal-col-betrag">Betrag</th>
|
|
<th>Jahr / Monat</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($entries as $e): ?>
|
|
<tr>
|
|
<td class="journal-col-date"><?= date('d.m.Y', strtotime($e['entry_date'])) ?></td>
|
|
<td class="journal-col-att"><?= htmlspecialchars($e['attachment_note'] ?? '') ?></td>
|
|
<td class="journal-col-text">
|
|
<a href="<?= url_for('journal_entry.php?id=' . $e['id']) ?>" style="color:inherit;">
|
|
<?= htmlspecialchars($e['description']) ?>
|
|
</a>
|
|
<?php if ($e['supplier_name']): ?>
|
|
<span style="color:var(--text-dim);font-size:10px;"> · <?= htmlspecialchars($e['supplier_name']) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="journal-col-betrag"><?= number_format((float)$e['amount'], 2, ',', '.') ?></td>
|
|
<td>
|
|
<a href="<?= url_for('journal.php?year_id=' . $e['year_id'] . '&month=' . $e['month']) ?>"
|
|
style="font-size:11px;color:var(--text-muted);">
|
|
<?= (int)$e['journal_year'] ?> / <?= journal_month_name_full((int)$e['month']) ?>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</section>
|
|
<?php endif; ?>
|
|
</main>
|
|
<script src="assets/command-palette.js"></script>
|
|
</body>
|
|
</html>
|