Members may now request more than is in stock (or items that are sold out); only their points have to cover the full request. When approving, the manager can approve fewer than requested. The quantity field is prefilled with what is in stock, the cost updates as you type, and only the approved part is charged and taken from stock. The order keeps the requested quantity, so the member sees e.g. "3 von 10 bewilligt". The order list also shows the current stock and flags when it isn't enough. The column upgrade check now covers every table that has upgrades, instead of only users and roles. Tables that are about to be created fresh are skipped. The dashboard gets a card with your Lumipunkte and your rank. In the sidebar, the points move from under your name into a gold box above the profile. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
87 lines
3.8 KiB
PHP
87 lines
3.8 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']);
|
||
}
|
||
|
||
// Aktueller Bestand je Gegenstand - damit man sieht, ob ein Antrag ganz bewilligt werden kann.
|
||
$itemStocks = [];
|
||
foreach (shop_items(false) as $shopItem) {
|
||
$itemStocks[(int) $shopItem['id']] = shop_stock($shopItem);
|
||
}
|
||
|
||
$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'; ?>
|