Files
kaffeekasse-saas/resources/views/tenant/bookings.php
T
2026-06-23 00:06:31 +02:00

130 lines
5.7 KiB
PHP

<?php
$tenantRole = (string) ($authState['tenant_role'] ?? 'member');
$isSelfService = $tenantRole === 'member';
$selectedMemberId = (string) old('member_id');
$selectedProductId = (string) old('product_id');
$selectedSourceCode = (string) old('source_code', 'digital_self');
$sourceLabels = [
'digital_self' => 'Selbst gebucht',
'paper_sheet' => 'Papierliste',
'admin_backoffice' => 'Nachgetragen durch Verwaltung',
'rfid_reader' => 'Kartenleser',
];
require __DIR__ . '/../partials/layout-top.php';
?>
<section class="page-head">
<span class="eyebrow"><?= e($isSelfService ? 'Mein Kaffee' : 'Kaffeekasse') ?></span>
<h1>Kaffee buchen</h1>
<?php if ($isSelfService): ?>
<p>Wählen Sie, was Sie genommen haben. Die Buchung landet direkt auf Ihrem Kaffeekonto.</p>
<?php else: ?>
<p>Wählen Sie Mitglied, Produkt und Menge. Die Kaffeekasse berechnet den Betrag sofort mit dem hinterlegten Preis.</p>
<?php endif; ?>
</section>
<section class="section-actions">
<a class="button button-secondary" href="<?= e(tenant_url($tenant['slug'], 'bookings/export')) ?>">Buchungen als CSV exportieren</a>
</section>
<div class="two-column">
<form class="card form-card" method="post" action="<?= e(tenant_url($tenant['slug'], 'bookings')) ?>">
<?= csrf_field($csrf) ?>
<?php if ($isSelfService): ?>
<?php if (is_array($currentMember)): ?>
<p class="form-note">Buchung für <?= e($currentMember['display_name']) ?></p>
<?php endif; ?>
<?php else: ?>
<label>
<span>Mitglied</span>
<select name="member_id" required>
<?php foreach ($members as $member): ?>
<option value="<?= e((string) $member['id']) ?>" <?= $selectedMemberId === (string) $member['id'] ? 'selected' : '' ?>><?= e($member['display_name']) ?></option>
<?php endforeach; ?>
</select>
</label>
<?php endif; ?>
<label>
<span>Produkt</span>
<select name="product_id" required>
<?php foreach ($products as $product): ?>
<option value="<?= e((string) $product['id']) ?>" <?= $selectedProductId === (string) $product['id'] ? 'selected' : '' ?>><?= e($product['name']) ?> (<?= e(money_from_cents((int) $product['price_cents'])) ?>)</option>
<?php endforeach; ?>
</select>
</label>
<?php if ($isSelfService): ?>
<input type="hidden" name="source_code" value="digital_self">
<?php else: ?>
<label>
<span>Buchungsart</span>
<select name="source_code">
<option value="digital_self" <?= $selectedSourceCode === 'digital_self' ? 'selected' : '' ?>>Selbst gebucht</option>
<option value="admin_backoffice" <?= $selectedSourceCode === 'admin_backoffice' ? 'selected' : '' ?>>Nachgetragen durch Verwaltung</option>
</select>
</label>
<?php endif; ?>
<label>
<span>Menge</span>
<input type="number" name="quantity" min="0.25" step="0.25" value="<?= e((string) old('quantity', '1')) ?>" required>
</label>
<label>
<span>Wann genommen?</span>
<input type="datetime-local" name="effective_at" value="<?= e((string) old('effective_at', gmdate('Y-m-d\TH:i'))) ?>" required>
</label>
<label>
<span>Notiz, falls nötig</span>
<input type="text" name="notes" value="<?= e((string) old('notes')) ?>">
</label>
<button class="button button-primary" type="submit">Auf Kaffeekonto buchen</button>
</form>
<?php if ($isSelfService): ?>
<section class="card">
<span class="eyebrow">Hinweise</span>
<ul class="stack-list">
<li>
<strong>Ihr Verlauf</strong>
<small>Ihre Buchungen können Sie als Tabelle exportieren.</small>
</li>
<li>
<strong>Korrekturen</strong>
<small>Falsche Buchungen bitte direkt an die verantwortliche Person melden.</small>
</li>
</ul>
</section>
<?php else: ?>
<section class="table-card">
<table>
<thead>
<tr>
<th>Zeit</th>
<th>Mitglied</th>
<th>Produkt</th>
<th>Buchungsart</th>
<th>Betrag</th>
</tr>
</thead>
<tbody>
<?php if ($bookings === []): ?>
<tr>
<td class="table-empty" colspan="5">Noch keine Kaffee-Buchungen. Die erste Buchung können Sie links erfassen.</td>
</tr>
<?php endif; ?>
<?php foreach ($bookings as $booking): ?>
<?php $sourceLabel = $sourceLabels[(string) ($booking['source_code'] ?? '')] ?? (string) $booking['source_name']; ?>
<tr>
<td><?= e($booking['recorded_at']) ?></td>
<td><?= e($booking['member_name']) ?></td>
<td><?= e($booking['product_name']) ?></td>
<td><?= e($sourceLabel) ?></td>
<td><?= e(money_from_cents((int) $booking['total_cents'])) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</section>
<?php endif; ?>
</div>
<?php require __DIR__ . '/../partials/layout-bottom.php'; ?>