Members request items from the shop. Their points and the stock are earmarked but not taken until someone with shop.manage approves. Approving books a negative "Lumishop" entry in the Lumipunkte history and takes the stock. For warehouse-backed items it also books a withdrawal to the member in the warehouse. Approved orders are then marked as handed over in the game, or can be reversed, which restores points, stock and the warehouse withdrawal. The management page handles categories and items (price, description, stock). Stock is either the shop's own count, unlimited, or live from a linked warehouse item. Items in stock can be imported from the warehouse, and an item's own stock can be moved into the warehouse to link it there. Warehouse cards show when an item is sold in the shop. Shop bookings can't be deleted from the Lumipunkte page, only reversed in the shop, so orders and points stay in sync. The new permissions go to the Administrator group only, so the shop stays hidden until it is assigned. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
81 lines
3.6 KiB
PHP
81 lines
3.6 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/shop.php';
|
||
require_permission('shop.manage');
|
||
|
||
$tabs = [
|
||
'open' => ['label' => 'Offen', 'statuses' => ['pending']],
|
||
'delivery' => ['label' => 'Zur Übergabe', 'statuses' => ['approved']],
|
||
'done' => ['label' => 'Erledigt', 'statuses' => ['delivered', 'rejected', 'cancelled']],
|
||
];
|
||
$tab = isset($tabs[$_GET['tab'] ?? '']) ? (string) $_GET['tab'] : 'open';
|
||
$counts = [];
|
||
foreach ($tabs as $key => $def) {
|
||
$counts[$key] = shop_order_count($def['statuses'], null);
|
||
}
|
||
|
||
$perPage = 25;
|
||
$total = $counts[$tab];
|
||
$pageCount = max(1, (int) ceil($total / $perPage));
|
||
$page = min($pageCount, max(1, (int) ($_GET['page'] ?? 1)));
|
||
$orders = shop_orders($tabs[$tab]['statuses'], null, $perPage, ($page - 1) * $perPage);
|
||
|
||
// Punktestand der Antragsteller - zeigt schon vor dem Bewilligen, ob es reicht.
|
||
$balances = [];
|
||
foreach ($orders as $order) {
|
||
$balances[(int) $order['user_id']] ??= contribution_user_balance((int) $order['user_id']);
|
||
}
|
||
|
||
$orderView = 'manage';
|
||
$orderReturn = '/shop_orders.php?tab=' . $tab . ($page > 1 ? '&page=' . $page : '');
|
||
|
||
$pageTitle = 'Lumishop-Anträge';
|
||
$containerWide = true;
|
||
include __DIR__ . '/includes/header.php';
|
||
?>
|
||
<div class="panel">
|
||
<div class="warehouse-head">
|
||
<div>
|
||
<h1>Lumishop-Anträge</h1>
|
||
<p class="text-muted">Bewilligen zieht die Lumipunkte ab und bucht bei Lagerhaus-Gegenständen die Entnahme. Danach den Gegenstand im Spiel überreichen und als übergeben markieren.</p>
|
||
</div>
|
||
<div class="actions">
|
||
<a class="button button-secondary" href="/shop.php">Zum Shop</a>
|
||
<a class="button button-secondary" href="/shop_manage.php">Shop verwalten</a>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="filter-tabs">
|
||
<?php foreach ($tabs as $key => $def): ?>
|
||
<a class="filter-tab<?= $tab === $key ? ' active' : '' ?>" href="/shop_orders.php?tab=<?= e($key) ?>">
|
||
<?= e($def['label']) ?><?= $key !== 'done' ? ' (' . $counts[$key] . ')' : '' ?>
|
||
</a>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
|
||
<?php if (empty($orders)): ?>
|
||
<p class="text-muted"><?= $tab === 'open' ? 'Keine offenen Anträge.' : ($tab === 'delivery' ? 'Nichts wartet auf die Übergabe.' : 'Noch keine erledigten Anträge.') ?></p>
|
||
<?php else: ?>
|
||
<div class="shop-orders">
|
||
<?php foreach ($orders as $order): ?>
|
||
<?php if ($order['status'] === 'pending'): ?>
|
||
<?php $buyerBalance = $balances[(int) $order['user_id']]; ?>
|
||
<div class="shop-order-balance<?= $buyerBalance < (int) $order['total_price'] ? ' is-short' : '' ?>">
|
||
Punktestand von <?= e((string) $order['buyer']) ?>: <?= contribution_coin(14) ?> <?= contribution_format($buyerBalance) ?>
|
||
<?= $buyerBalance < (int) $order['total_price'] ? ' – reicht nicht für diesen Antrag' : '' ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php include __DIR__ . '/includes/shop_order_row.php'; ?>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<div class="warehouse-pages">
|
||
<span class="text-muted">
|
||
Anträge <?= ($page - 1) * $perPage + 1 ?>–<?= min($page * $perPage, $total) ?> von <?= number_format($total, 0, ',', '.') ?>
|
||
</span>
|
||
<?php render_pagination('/shop_orders.php?tab=' . $tab . '&', $page, $pageCount, ''); ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<script src="<?= e(asset_url('/assets/js/shop.js')) ?>"></script>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|