LuminaWebsite/includes/shop_order_row.php
Maaxxs 17dea6d41f Lumishop partial approval, Lumipunkte on dashboard and in sidebar box
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>
2026-09-21 10:56:59 +02:00

130 lines
8.1 KiB
PHP
Raw 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.

<?php
/**
* Eine Bestellung als Zeile - fuer "Meine Antraege" (shop.php) und die Antragsliste der
* Verwaltung (shop_orders.php, dort mit $orderView = 'manage' und den Bearbeitungsknoepfen).
*
* @var array $order
* @var string|null $orderView
* @var string|null $orderReturn Ruecksprung nach einer Aktion
* @var array<int, int|null>|null $itemStocks Bestand je Shop-Gegenstand (Verwaltung, null = unbegrenzt)
*/
$isManageView = ($orderView ?? 'member') === 'manage';
$status = (string) $order['status'];
$badgeClass = [
'pending' => 'badge-pending',
'approved' => 'shop-badge-approved',
'delivered' => 'badge-active',
'rejected' => 'badge-disabled',
'cancelled' => '',
][$status] ?? '';
$return = $orderReturn ?? '/shop.php#antraege';
$requested = shop_requested_quantity($order);
$quantity = (int) $order['quantity'];
// Bestand fuer die Bewilligung: vorbelegt wird hoechstens, was da ist.
$stockNow = null;
$hasStockInfo = $isManageView && $status === 'pending' && $order['item_id'] !== null && array_key_exists((int) $order['item_id'], $itemStocks ?? []);
if ($hasStockInfo) {
$stockNow = $itemStocks[(int) $order['item_id']];
}
$approveDefault = $stockNow !== null ? max(1, min($quantity, $stockNow)) : $quantity;
?>
<article class="shop-order shop-order-<?= e($status) ?>">
<span class="shop-order-icon"><?= warehouse_icon_html($order['icon'] ?? null, (string) $order['item_name'], 44) ?></span>
<div class="shop-order-body">
<div class="shop-order-title">
<strong><?= e(shop_order_label($order)) ?></strong>
<span class="badge <?= e($badgeClass) ?>"><?= e(shop_status_label($status)) ?></span>
<span class="text-muted">#<?= (int) $order['id'] ?></span>
</div>
<div class="shop-order-meta text-muted">
<?php if ($isManageView): ?>
<strong class="shop-order-buyer"><?= e((string) $order['buyer']) ?></strong> ·
<?php endif; ?>
beantragt am <?= e(contribution_format_time($order['created_at'])) ?>
<?php if ($quantity > 1): ?>
· <?= $quantity ?> × <?= contribution_format((int) $order['unit_price']) ?>
<?php endif; ?>
<?php if ($requested > $quantity): ?>
· <strong class="shop-order-partial"><?= $quantity ?> von <?= $requested ?> bewilligt</strong>
<?php endif; ?>
</div>
<?php if ($hasStockInfo): ?>
<div class="shop-order-meta shop-order-stock<?= $stockNow !== null && $stockNow < $quantity ? ' is-short' : '' ?>">
Bestand: <?= $stockNow === null ? 'unbegrenzt' : number_format($stockNow, 0, ',', '.') ?>
<?= $stockNow !== null && $stockNow < $quantity ? ' – reicht nicht für alle, nur einen Teil bewilligen' : '' ?>
</div>
<?php endif; ?>
<?php if (!empty($order['note'])): ?>
<div class="shop-order-note"><span class="text-muted">Bemerkung:</span> <?= e((string) $order['note']) ?></div>
<?php endif; ?>
<?php if ($order['decided_at'] !== null): ?>
<div class="shop-order-meta text-muted">
<?= $status === 'rejected' ? 'Abgelehnt' : ($status === 'cancelled' ? 'Storniert' : 'Bewilligt') ?>
am <?= e(contribution_format_time($order['decided_at'])) ?>
<?php if (!empty($order['decider'])): ?>von <?= e((string) $order['decider']) ?><?php endif; ?>
<?php if ($order['delivered_at'] !== null): ?>
· übergeben am <?= e(contribution_format_time($order['delivered_at'])) ?>
<?php if (!empty($order['deliverer'])): ?>von <?= e((string) $order['deliverer']) ?><?php endif; ?>
<?php endif; ?>
</div>
<?php elseif ($status === 'cancelled'): ?>
<div class="shop-order-meta text-muted">Vom Mitglied zurückgezogen.</div>
<?php endif; ?>
<?php if (!empty($order['decision_note'])): ?>
<div class="shop-order-note"><span class="text-muted">Grund:</span> <?= e((string) $order['decision_note']) ?></div>
<?php endif; ?>
</div>
<div class="shop-order-price<?= in_array($status, ['approved', 'delivered'], true) ? ' is-paid' : '' ?>" data-order-price="<?= (int) $order['id'] ?>" title="<?= in_array($status, ['approved', 'delivered'], true) ? 'Abgezogen' : ($status === 'pending' ? 'Vorgemerkt' : 'Nicht abgezogen') ?>">
<?= contribution_coin(18) ?> <?= contribution_format((int) $order['total_price']) ?>
</div>
<div class="shop-order-actions">
<?php if ($isManageView): ?>
<?php if ($status === 'pending'): ?>
<form method="post" action="/shop_action.php" class="shop-approve-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="approve">
<input type="hidden" name="order_id" value="<?= (int) $order['id'] ?>">
<input type="hidden" name="return" value="<?= e($return) ?>">
<?php if ($quantity > 1): ?>
<input type="number" name="approve_quantity" min="1" max="<?= $quantity ?>" value="<?= $approveDefault ?>"
class="shop-approve-quantity" title="Anzahl, die bewilligt wird (höchstens <?= $quantity ?>)"
aria-label="Anzahl bewilligen" data-unit-price="<?= (int) $order['unit_price'] ?>">
<span class="text-muted shop-approve-of">von <?= $quantity ?></span>
<?php endif; ?>
<button type="submit" class="button-success button-small" title="Lumipunkte abziehen und zur Übergabe freigeben"><?= icon('check') ?> Bewilligen</button>
</form>
<form method="post" action="/shop_action.php" data-prompt="Grund für die Ablehnung (optional, sieht das Mitglied):">
<?= csrf_field() ?>
<input type="hidden" name="action" value="reject">
<input type="hidden" name="order_id" value="<?= (int) $order['id'] ?>">
<input type="hidden" name="reason" value="">
<input type="hidden" name="return" value="<?= e($return) ?>">
<button type="submit" class="button-secondary button-small"><?= icon('x') ?> Ablehnen</button>
</form>
<?php elseif ($status === 'approved'): ?>
<form method="post" action="/shop_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="deliver">
<input type="hidden" name="order_id" value="<?= (int) $order['id'] ?>">
<input type="hidden" name="return" value="<?= e($return) ?>">
<button type="submit" class="button-small" title="Im Spiel übergeben"><?= icon('check') ?> Übergeben</button>
</form>
<form method="post" action="/shop_action.php" data-prompt="Bestellung stornieren? Die Lumipunkte gehen zurück an das Mitglied und der Bestand wird wieder aufgefüllt.&#10;&#10;Grund (optional):">
<?= csrf_field() ?>
<input type="hidden" name="action" value="revoke">
<input type="hidden" name="order_id" value="<?= (int) $order['id'] ?>">
<input type="hidden" name="reason" value="">
<input type="hidden" name="return" value="<?= e($return) ?>">
<button type="submit" class="icon-button icon-button-danger" title="Stornieren" aria-label="Stornieren"><?= icon('restore') ?></button>
</form>
<?php endif; ?>
<?php elseif ($status === 'pending'): ?>
<form method="post" action="/shop_action.php" onsubmit="return confirm('Antrag zurückziehen?');">
<?= csrf_field() ?>
<input type="hidden" name="action" value="cancel">
<input type="hidden" name="order_id" value="<?= (int) $order['id'] ?>">
<button type="submit" class="button-secondary button-small">Zurückziehen</button>
</form>
<?php endif; ?>
</div>
</article>