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>
This commit is contained in:
Maaxxs 2026-09-21 10:56:59 +02:00
parent ebc9e2367e
commit 17dea6d41f
12 changed files with 187 additions and 46 deletions

View file

@ -470,7 +470,7 @@ Herzform (`assets/images/lumipunkt.svg`).
- **Rangliste:** alle aktiven Mitglieder mit ihrem Punktestand als Karten, höchster zuerst. - **Rangliste:** alle aktiven Mitglieder mit ihrem Punktestand als Karten, höchster zuerst.
Platz 1 bis 3 sind gold, silber und bronze umrandet, die eigene Karte hervorgehoben. Ein Platz 1 bis 3 sind gold, silber und bronze umrandet, die eigene Karte hervorgehoben. Ein
Klick auf eine Karte zeigt nur die Vergaben dieses Mitglieds. Den eigenen Stand zeigt die Klick auf eine Karte zeigt nur die Vergaben dieses Mitglieds. Den eigenen Stand zeigt die
Seite oben und die Seitenleiste unter dem Namen. Seite oben, das Dashboard und ein Kästchen in der Seitenleiste über dem Profil.
- **Punkte vergeben** (`contributions_award.php`): Anlass (Raid, Event, Sonstiges), Grund, - **Punkte vergeben** (`contributions_award.php`): Anlass (Raid, Event, Sonstiges), Grund,
Datum, Punkte pro Mitglied und optional eine Bemerkung. Die Mitglieder wählt man per Häkchen Datum, Punkte pro Mitglied und optional eine Bemerkung. Die Mitglieder wählt man per Häkchen
aus, mit Suche und „Alle/Keine“. Beim Anlass Raid lässt sich ein Raid aus der Raid-API aus, mit Suche und „Alle/Keine“. Beim Anlass Raid lässt sich ein Raid aus der Raid-API
@ -507,12 +507,17 @@ Im **Lumishop** (`shop.php`) tauschen Mitglieder Lumipunkte gegen Gegenstände.
- **Angebot** als Kacheln mit Bild, Kategorie, Beschreibung, Preis und verfügbarer Menge, dazu - **Angebot** als Kacheln mit Bild, Kategorie, Beschreibung, Preis und verfügbarer Menge, dazu
Suche und Kategoriefilter. Oben steht, wie viele Punkte man ausgeben kann: der Punktestand Suche und Kategoriefilter. Oben steht, wie viele Punkte man ausgeben kann: der Punktestand
abzüglich der Punkte in eigenen offenen Anträgen. abzüglich der Punkte in eigenen offenen Anträgen.
- **Beantragen:** Anzahl und optional eine Bemerkung (z.B. der Charaktername). Die Website - **Beantragen:** Anzahl und optional eine Bemerkung (z.B. der Charaktername). Man darf mehr
prüft, ob Punkte und Bestand reichen, wobei offene Anträge schon abgezogen sind. Abgezogen beantragen, als gerade verfügbar ist. Die Punkte müssen aber für die ganze Anzahl reichen,
wird aber noch nichts, und offene Anträge lassen sich unter **Meine Anträge** zurückziehen. wobei offene Anträge schon abgezogen sind. Abgezogen wird noch nichts, und offene Anträge
lassen sich unter **Meine Anträge** zurückziehen.
- **Anträge** (`shop_orders.php`, mit `shop.manage`), aufgeteilt in Offen, Zur Übergabe und - **Anträge** (`shop_orders.php`, mit `shop.manage`), aufgeteilt in Offen, Zur Übergabe und
Erledigt. Bei offenen Anträgen steht der Punktestand des Mitglieds dabei. Erledigt. Bei offenen Anträgen stehen der Punktestand des Mitglieds und der aktuelle Bestand
- **Bewilligen** zieht die Lumipunkte ab. Das ist eine Buchung „Lumishop: …“ im dabei.
- **Bewilligen** zieht die Lumipunkte ab. Neben dem Knopf steht die Anzahl, vorbelegt mit
der beantragten Menge bzw. dem, was da ist. So lässt sich auch nur ein Teil bewilligen:
Abgezogen werden dann nur die Punkte für diesen Teil, und das Mitglied sieht „3 von 10
bewilligt“. Das ist eine Buchung „Lumishop: …“ im
Lumipunkte-Verlauf. Gleichzeitig verringert es den Bestand bzw. bucht im Lagerhaus eine Lumipunkte-Verlauf. Gleichzeitig verringert es den Bestand bzw. bucht im Lagerhaus eine
Entnahme an das Mitglied. Entnahme an das Mitglied.
- **Ablehnen** geht mit einem optionalen Grund, den das Mitglied sieht. - **Ablehnen** geht mit einem optionalen Grund, den das Mitglied sieht.

View file

@ -2497,14 +2497,30 @@ button.contribution-chip-remove:hover { background: none; color: var(--danger);
.contribution-pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .contribution-pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contribution-pick-points { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.8rem; color: var(--text-muted); } .contribution-pick-points { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.8rem; color: var(--text-muted); }
/* Lumipunkte als Kaestchen ueber dem Profil (ueber dem Strich der Fusszeile) */
.sidebar-points { .sidebar-points {
display: inline-flex; display: flex;
align-items: center; align-items: center;
gap: 0.25rem; gap: 0.7rem;
margin-top: 0.15rem; margin-top: 1rem;
font-weight: 700; padding: 0.6rem 0.8rem;
color: var(--gold); border: 1px solid rgba(201, 162, 39, 0.45);
border-radius: 10px;
background: linear-gradient(135deg, rgba(201, 162, 39, 0.16), rgba(201, 162, 39, 0.04));
color: var(--text);
transition: border-color 0.15s, background 0.15s;
} }
.sidebar-points:hover {
border-color: var(--gold);
background: linear-gradient(135deg, rgba(201, 162, 39, 0.24), rgba(201, 162, 39, 0.06));
color: var(--text);
text-decoration: none;
}
.sidebar-points img { flex-shrink: 0; filter: drop-shadow(0 2px 5px rgba(201, 162, 39, 0.35)); }
.sidebar-points > span { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-points-label { font-size: 0.72rem; color: var(--text-muted); }
.sidebar-points strong { font-size: 1.2rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.sidebar-points + .sidebar-footer { margin-top: 0.85rem; }
@media (max-width: 700px) { @media (max-width: 700px) {
.contribution-form-grid { grid-template-columns: 1fr; } .contribution-form-grid { grid-template-columns: 1fr; }
@ -2848,3 +2864,20 @@ input.shop-import-row-price { width: 100px; }
} }
#shop-item-description { font-family: inherit; } #shop-item-description { font-family: inherit; }
/* Lumishop: Teilbewilligung */
.shop-order-actions .shop-approve-form { display: inline-flex; flex-direction: row; align-items: center; gap: 0.35rem; }
input.shop-approve-quantity { width: 72px; padding: 0.3rem 0.45rem; font-size: 0.9rem; }
.shop-approve-of { font-size: 0.8rem; white-space: nowrap; }
.shop-order-partial { color: var(--gold); font-weight: 600; }
.shop-order-stock { color: var(--text-muted); }
.shop-order-stock.is-short { color: var(--danger); }
/* Dashboard: eigene Lumipunkte */
.stat-card-points { border-color: rgba(201, 162, 39, 0.45); background: linear-gradient(135deg, rgba(201, 162, 39, 0.14), var(--bg-panel) 70%); }
.stat-card-points img { flex-shrink: 0; filter: drop-shadow(0 3px 8px rgba(201, 162, 39, 0.35)); }
.stat-card-points h3 { color: var(--gold); font-size: 1.35rem; }
.stat-card-links { margin-top: 0.2rem !important; font-size: 0.8rem; }
@media (max-width: 700px) {
.shop-order-actions { flex-wrap: wrap; justify-content: flex-end; width: 100%; }
}

View file

@ -95,6 +95,21 @@
}); });
}); });
// ---- Antraege: Teilbewilligung - Kosten passend zur eingegebenen Anzahl anzeigen ----
document.querySelectorAll('.shop-approve-quantity').forEach(function (input) {
var form = input.closest('form');
var orderId = form.querySelector('input[name="order_id"]').value;
var price = document.querySelector('[data-order-price="' + orderId + '"]');
var amount = price ? price.lastChild : null;
var unit = parseInt(input.dataset.unitPrice, 10) || 0;
var update = function () {
var qty = Math.min(parseInt(input.value, 10) || 0, parseInt(input.max, 10));
if (amount) amount.textContent = ' ' + formatPoints(Math.max(0, qty) * unit);
};
input.addEventListener('input', update);
update();
});
// ---- Verwaltung: Gegenstand anlegen / bearbeiten ---- // ---- Verwaltung: Gegenstand anlegen / bearbeiten ----
var itemModal = document.getElementById('shop-item-modal'); var itemModal = document.getElementById('shop-item-modal');
if (itemModal) { if (itemModal) {

View file

@ -1,6 +1,7 @@
<?php <?php
require_once __DIR__ . '/includes/bootstrap.php'; require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raids_api.php'; require_once __DIR__ . '/includes/raids_api.php';
require_once __DIR__ . '/includes/contributions.php';
require_permission('dashboard.view'); require_permission('dashboard.view');
$user = current_user(); $user = current_user();
@ -8,6 +9,8 @@ $canViewUsers = user_has_permission('users.view');
$canManageRoles = user_has_permission('roles.manage'); $canManageRoles = user_has_permission('roles.manage');
$canViewRaids = user_has_permission('raids.view'); $canViewRaids = user_has_permission('raids.view');
$canViewPremades = user_has_permission('premades.view'); $canViewPremades = user_has_permission('premades.view');
$canViewContributions = user_has_permission('contributions.view');
$canViewShop = user_has_permission('shop.view');
$discordId = $user['discord_id'] ? (int) $user['discord_id'] : null; $discordId = $user['discord_id'] ? (int) $user['discord_id'] : null;
$roleStmt = db()->prepare( $roleStmt = db()->prepare(
@ -42,6 +45,22 @@ if ($canViewRaids) {
} }
$nextRaids = array_slice($upcomingRaids, 0, 3); $nextRaids = array_slice($upcomingRaids, 0, 3);
// Eigene Lumipunkte mit Platz in der Rangliste (gleiche Punktzahl = gleicher Platz).
$myPoints = null;
$myRank = null;
if ($canViewContributions) {
$myPoints = contribution_user_balance((int) $user['id']);
$rankStmt = db()->prepare(
"SELECT COUNT(*) + 1 FROM (
SELECT u.id, COALESCE(SUM(e.points), 0) AS points FROM users u
LEFT JOIN contribution_entries e ON e.user_id = u.id
WHERE u.status = 'active' GROUP BY u.id
) balances WHERE points > ?"
);
$rankStmt->execute([$myPoints]);
$myRank = (int) $rankStmt->fetchColumn();
}
$memberCount = $canViewUsers ? (int) db()->query("SELECT COUNT(*) FROM users WHERE status = 'active'")->fetchColumn() : null; $memberCount = $canViewUsers ? (int) db()->query("SELECT COUNT(*) FROM users WHERE status = 'active'")->fetchColumn() : null;
$roleCount = $canManageRoles ? (int) db()->query('SELECT COUNT(*) FROM roles')->fetchColumn() : null; $roleCount = $canManageRoles ? (int) db()->query('SELECT COUNT(*) FROM roles')->fetchColumn() : null;
@ -103,6 +122,19 @@ include __DIR__ . '/includes/header.php';
<div class="panel"> <div class="panel">
<div class="card-grid"> <div class="card-grid">
<?php if ($myPoints !== null): ?>
<div class="panel stat-card stat-card-points">
<img src="/assets/images/lumipunkt.svg" alt="" width="44" height="44">
<div>
<h3><?= e(contribution_format($myPoints)) ?></h3>
<p class="text-muted">Lumipunkte · Platz <?= (int) $myRank ?></p>
<p class="stat-card-links">
<a href="/contributions.php">Rangliste</a>
<?php if ($canViewShop): ?>· <a href="/shop.php">Lumishop</a><?php endif; ?>
</p>
</div>
</div>
<?php endif; ?>
<?php if ($canViewRaids): ?> <?php if ($canViewRaids): ?>
<div class="panel stat-card"> <div class="panel stat-card">
<div class="icon-badge"><?= icon('calendar') ?></div> <div class="icon-badge"><?= icon('calendar') ?></div>

View file

@ -204,16 +204,20 @@ $otherFlashes = array_values(array_filter($allFlashes, fn (array $f): bool => ($
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
</nav> </nav>
<?php if ($sidebarPoints !== null): ?>
<a class="sidebar-points" href="/contributions.php" title="Deine Lumipunkte - zur Rangliste">
<img src="/assets/images/lumipunkt.svg" alt="" width="30" height="30">
<span>
<span class="sidebar-points-label">Deine Lumipunkte</span>
<strong><?= e(number_format($sidebarPoints, 0, ',', '.')) ?></strong>
</span>
</a>
<?php endif; ?>
<div class="sidebar-footer"> <div class="sidebar-footer">
<div class="sidebar-user"> <div class="sidebar-user">
<?= avatar_html($currentUser, 36) ?> <?= avatar_html($currentUser, 36) ?>
<div> <div>
Angemeldet als<br><strong><?= e($currentUser['display_name'] !== '' ? $currentUser['display_name'] : $currentUser['username']) ?></strong> Angemeldet als<br><strong><?= e($currentUser['display_name'] !== '' ? $currentUser['display_name'] : $currentUser['username']) ?></strong>
<?php if ($sidebarPoints !== null): ?>
<a class="sidebar-points" href="/contributions.php" title="Deine Lumipunkte">
<img src="/assets/images/lumipunkt.svg" alt="" width="14" height="14"> <?= e(number_format($sidebarPoints, 0, ',', '.')) ?>
</a>
<?php endif; ?>
</div> </div>
</div> </div>
<a href="/logout.php" class="sidebar-link" title="Abmelden"> <a href="/logout.php" class="sidebar-link" title="Abmelden">

View file

@ -11,7 +11,7 @@ declare(strict_types=1);
*/ */
// Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu. // Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu.
const SCHEMA_VERSION = 9; const SCHEMA_VERSION = 10;
/** /**
* Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql). * Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql).
@ -125,7 +125,9 @@ CREATE TABLE IF NOT EXISTS shop_orders (
-- Name und Preis zum Zeitpunkt der Bestellung (bleiben, auch wenn der Gegenstand spaeter -- Name und Preis zum Zeitpunkt der Bestellung (bleiben, auch wenn der Gegenstand spaeter
-- geaendert oder geloescht wird) -- geaendert oder geloescht wird)
item_name VARCHAR(150) NOT NULL, item_name VARCHAR(150) NOT NULL,
-- Anzahl (nach einer Teilbewilligung die bewilligte) und die urspruenglich beantragte
quantity INT UNSIGNED NOT NULL, quantity INT UNSIGNED NOT NULL,
requested_quantity INT UNSIGNED NOT NULL,
unit_price INT UNSIGNED NOT NULL, unit_price INT UNSIGNED NOT NULL,
total_price INT UNSIGNED NOT NULL, total_price INT UNSIGNED NOT NULL,
-- Bemerkung des Mitglieds (z.B. Charaktername) -- Bemerkung des Mitglieds (z.B. Charaktername)
@ -208,6 +210,9 @@ function schema_column_upgrades(): array
'roles' => [ 'roles' => [
'discord_role_id' => "ALTER TABLE roles ADD COLUMN discord_role_id BIGINT UNSIGNED NULL AFTER roster_order", 'discord_role_id' => "ALTER TABLE roles ADD COLUMN discord_role_id BIGINT UNSIGNED NULL AFTER roster_order",
], ],
'shop_orders' => [
'requested_quantity' => "ALTER TABLE shop_orders ADD COLUMN requested_quantity INT UNSIGNED NOT NULL DEFAULT 0 AFTER quantity",
],
]; ];
} }
@ -222,7 +227,7 @@ function ensure_schema(): void
$stmt = $pdo->query( $stmt = $pdo->query(
"SELECT LOWER(table_name) AS t, LOWER(column_name) AS c FROM information_schema.columns "SELECT LOWER(table_name) AS t, LOWER(column_name) AS c FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name IN ('users', 'roles')" WHERE table_schema = DATABASE() AND table_name IN ('" . implode("', '", array_keys($upgrades)) . "')"
); );
$existing = []; $existing = [];
foreach ($stmt->fetchAll() as $row) { foreach ($stmt->fetchAll() as $row) {
@ -246,6 +251,10 @@ function ensure_schema(): void
} }
foreach ($upgrades as $table => $columns) { foreach ($upgrades as $table => $columns) {
// Tabellen, die es noch nicht gibt, entstehen oben schon mit allen Spalten.
if (!in_array($table, $tables, true)) {
continue;
}
foreach ($columns as $column => $sql) { foreach ($columns as $column => $sql) {
if (empty($existing[$table][$column])) { if (empty($existing[$table][$column])) {
$statements[] = $sql; $statements[] = $sql;

View file

@ -39,7 +39,8 @@ const SHOP_STOCK_MODES = [
const SHOP_MAX_PRICE = 1000000; const SHOP_MAX_PRICE = 1000000;
const SHOP_MAX_STOCK = 1000000; const SHOP_MAX_STOCK = 1000000;
const SHOP_MAX_ORDER_QUANTITY = 1000; // Nur gegen Tippfehler - der Bestand begrenzt Antraege nicht, erst die Bewilligung.
const SHOP_MAX_ORDER_QUANTITY = 1000000;
function shop_status_label(string $status): string function shop_status_label(string $status): string
{ {
@ -200,6 +201,12 @@ function shop_order_label(array $order): string
return ((int) $order['quantity'] > 1 ? (int) $order['quantity'] . '× ' : '') . $order['item_name']; return ((int) $order['quantity'] > 1 ? (int) $order['quantity'] . '× ' : '') . $order['item_name'];
} }
/** Urspruenglich beantragte Anzahl (aeltere Antraege ohne eigene Spalte: die Anzahl selbst). */
function shop_requested_quantity(array $order): int
{
return max((int) ($order['requested_quantity'] ?? 0), (int) $order['quantity']);
}
function shop_format_availability(?int $available): string function shop_format_availability(?int $available): string
{ {
if ($available === null) { if ($available === null) {

View file

@ -6,6 +6,7 @@
* @var array $order * @var array $order
* @var string|null $orderView * @var string|null $orderView
* @var string|null $orderReturn Ruecksprung nach einer Aktion * @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'; $isManageView = ($orderView ?? 'member') === 'manage';
$status = (string) $order['status']; $status = (string) $order['status'];
@ -17,6 +18,15 @@ $badgeClass = [
'cancelled' => '', 'cancelled' => '',
][$status] ?? ''; ][$status] ?? '';
$return = $orderReturn ?? '/shop.php#antraege'; $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) ?>"> <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> <span class="shop-order-icon"><?= warehouse_icon_html($order['icon'] ?? null, (string) $order['item_name'], 44) ?></span>
@ -31,10 +41,19 @@ $return = $orderReturn ?? '/shop.php#antraege';
<strong class="shop-order-buyer"><?= e((string) $order['buyer']) ?></strong> · <strong class="shop-order-buyer"><?= e((string) $order['buyer']) ?></strong> ·
<?php endif; ?> <?php endif; ?>
beantragt am <?= e(contribution_format_time($order['created_at'])) ?> beantragt am <?= e(contribution_format_time($order['created_at'])) ?>
<?php if ((int) $order['quantity'] > 1): ?> <?php if ($quantity > 1): ?>
· <?= (int) $order['quantity'] ?> × <?= contribution_format((int) $order['unit_price']) ?> · <?= $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; ?> <?php endif; ?>
</div> </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'])): ?> <?php if (!empty($order['note'])): ?>
<div class="shop-order-note"><span class="text-muted">Bemerkung:</span> <?= e((string) $order['note']) ?></div> <div class="shop-order-note"><span class="text-muted">Bemerkung:</span> <?= e((string) $order['note']) ?></div>
<?php endif; ?> <?php endif; ?>
@ -55,17 +74,23 @@ $return = $orderReturn ?? '/shop.php#antraege';
<div class="shop-order-note"><span class="text-muted">Grund:</span> <?= e((string) $order['decision_note']) ?></div> <div class="shop-order-note"><span class="text-muted">Grund:</span> <?= e((string) $order['decision_note']) ?></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="shop-order-price<?= in_array($status, ['approved', 'delivered'], true) ? ' is-paid' : '' ?>" title="<?= in_array($status, ['approved', 'delivered'], true) ? 'Abgezogen' : ($status === 'pending' ? 'Vorgemerkt' : 'Nicht abgezogen') ?>"> <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']) ?> <?= contribution_coin(18) ?> <?= contribution_format((int) $order['total_price']) ?>
</div> </div>
<div class="shop-order-actions"> <div class="shop-order-actions">
<?php if ($isManageView): ?> <?php if ($isManageView): ?>
<?php if ($status === 'pending'): ?> <?php if ($status === 'pending'): ?>
<form method="post" action="/shop_action.php"> <form method="post" action="/shop_action.php" class="shop-approve-form">
<?= csrf_field() ?> <?= csrf_field() ?>
<input type="hidden" name="action" value="approve"> <input type="hidden" name="action" value="approve">
<input type="hidden" name="order_id" value="<?= (int) $order['id'] ?>"> <input type="hidden" name="order_id" value="<?= (int) $order['id'] ?>">
<input type="hidden" name="return" value="<?= e($return) ?>"> <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> <button type="submit" class="button-success button-small" title="Lumipunkte abziehen und zur Übergabe freigeben"><?= icon('check') ?> Bewilligen</button>
</form> </form>
<form method="post" action="/shop_action.php" data-prompt="Grund für die Ablehnung (optional, sieht das Mitglied):"> <form method="post" action="/shop_action.php" data-prompt="Grund für die Ablehnung (optional, sieht das Mitglied):">

View file

@ -83,10 +83,12 @@ include __DIR__ . '/includes/header.php';
$price = (int) $item['price']; $price = (int) $item['price'];
$soldOut = $available !== null && $available < 1; $soldOut = $available !== null && $available < 1;
$affordable = $price === 0 ? SHOP_MAX_ORDER_QUANTITY : intdiv($spendable, $price); $affordable = $price === 0 ? SHOP_MAX_ORDER_QUANTITY : intdiv($spendable, $price);
$max = min(SHOP_MAX_ORDER_QUANTITY, $affordable, $available ?? SHOP_MAX_ORDER_QUANTITY); // Mehr als verfuegbar darf beantragt werden (die Bewilligung kann kuerzen) - nur die
$reason = $soldOut ? 'Ausverkauft' : ($max < 1 ? 'Nicht genug Lumipunkte' : ''); // Punkte muessen reichen.
$max = min(SHOP_MAX_ORDER_QUANTITY, $affordable);
$reason = $max < 1 ? 'Nicht genug Lumipunkte' : '';
?> ?>
<div class="shop-card<?= $soldOut ? ' sold-out' : '' ?>" data-name="<?= e(mb_strtolower((string) $item['name'])) ?>" data-category="<?= (int) ($item['category_id'] ?? 0) ?>"> <div class="shop-card" data-name="<?= e(mb_strtolower((string) $item['name'])) ?>" data-category="<?= (int) ($item['category_id'] ?? 0) ?>">
<span class="shop-card-image"><?= shop_icon_html($item, 72) ?></span> <span class="shop-card-image"><?= shop_icon_html($item, 72) ?></span>
<span class="shop-card-name"><?= e((string) $item['name']) ?></span> <span class="shop-card-name"><?= e((string) $item['name']) ?></span>
<?php if ($item['category_name'] !== null): ?> <?php if ($item['category_name'] !== null): ?>
@ -153,7 +155,7 @@ include __DIR__ . '/includes/header.php';
<label for="shop-buy-note">Bemerkung <span class="text-muted">(optional, z.B. Name deines Charakters)</span></label> <label for="shop-buy-note">Bemerkung <span class="text-muted">(optional, z.B. Name deines Charakters)</span></label>
<input type="text" id="shop-buy-note" name="note" maxlength="255" value="<?= e((string) ($old['note'] ?? '')) ?>"> <input type="text" id="shop-buy-note" name="note" maxlength="255" value="<?= e((string) ($old['note'] ?? '')) ?>">
</div> </div>
<p class="text-muted shop-buy-hint">Die Lumipunkte werden erst abgezogen, wenn dein Antrag bewilligt ist. Bis dahin kannst du ihn zurückziehen.</p> <p class="text-muted shop-buy-hint">Du kannst auch mehr beantragen, als gerade verfügbar ist – dann wird eventuell nur ein Teil bewilligt. Die Lumipunkte werden erst bei der Bewilligung abgezogen, und nur für die bewilligte Anzahl. Bis dahin kannst du den Antrag zurückziehen.</p>
<div class="actions"> <div class="actions">
<button type="submit" class="button-success">Antrag stellen</button> <button type="submit" class="button-success">Antrag stellen</button>
</div> </div>

View file

@ -76,15 +76,9 @@ switch ($action) {
shop_fail('Die Bemerkung darf höchstens 255 Zeichen lang sein.', '/shop.php'); shop_fail('Die Bemerkung darf höchstens 255 Zeichen lang sein.', '/shop.php');
} }
// Mehr als verfuegbar darf beantragt werden - wie viel es wirklich gibt, entscheidet die
// Bewilligung (auch teilweise).
$pdo->beginTransaction(); $pdo->beginTransaction();
// Gegenstand sperren, damit zwei gleichzeitige Antraege nicht beide das letzte Stueck bekommen.
$pdo->prepare('SELECT id FROM shop_items WHERE id = ? FOR UPDATE')->execute([$itemId]);
$available = shop_available($item);
if ($available !== null && $quantity > $available) {
shop_fail($available > 0
? 'Von „' . $item['name'] . '“ sind nur noch ' . $available . ' verfügbar.'
: '„' . $item['name'] . '“ ist leider ausverkauft.', '/shop.php');
}
$total = (int) $item['price'] * $quantity; $total = (int) $item['price'] * $quantity;
$spendable = contribution_user_balance($userId) - shop_reserved_points($userId); $spendable = contribution_user_balance($userId) - shop_reserved_points($userId);
if ($total > $spendable) { if ($total > $spendable) {
@ -93,8 +87,9 @@ switch ($action) {
} }
$pdo->prepare( $pdo->prepare(
'INSERT INTO shop_orders (user_id, item_id, item_name, quantity, unit_price, total_price, note) VALUES (?, ?, ?, ?, ?, ?, ?)' 'INSERT INTO shop_orders (user_id, item_id, item_name, quantity, requested_quantity, unit_price, total_price, note)
)->execute([$userId, $itemId, $item['name'], $quantity, (int) $item['price'], $total, $note !== '' ? $note : null]); VALUES (?, ?, ?, ?, ?, ?, ?, ?)'
)->execute([$userId, $itemId, $item['name'], $quantity, $quantity, (int) $item['price'], $total, $note !== '' ? $note : null]);
$pdo->commit(); $pdo->commit();
unset($_SESSION['shop_form']); unset($_SESSION['shop_form']);
@ -124,13 +119,18 @@ if (!user_has_permission('shop.manage')) {
$url = shop_return_url(); $url = shop_return_url();
switch ($action) { switch ($action) {
// ---- Bewilligen: Punkte abziehen, Bestand verringern / aus dem Lagerhaus entnehmen ---- // ---- Bewilligen (auf Wunsch nur einen Teil): Punkte abziehen, Bestand verringern / aus dem Lagerhaus entnehmen ----
case 'approve': case 'approve':
$pdo->beginTransaction(); $pdo->beginTransaction();
$order = shop_lock_order($orderId, 'pending', $url); $order = shop_lock_order($orderId, 'pending', $url);
$buyerId = (int) $order['user_id']; $buyerId = (int) $order['user_id'];
$quantity = (int) $order['quantity']; $requested = (int) $order['quantity'];
$total = (int) $order['total_price']; $quantity = filter_var($_POST['approve_quantity'] ?? $requested, FILTER_VALIDATE_INT);
if ($quantity === false || $quantity < 1 || $quantity > $requested) {
shop_fail('Bitte zwischen 1 und ' . $requested . ' Stück bewilligen.', $url);
}
$total = (int) $order['unit_price'] * $quantity;
$order['quantity'] = $quantity; // fuer die Beschriftung der Buchung
$buyerStmt = $pdo->prepare("SELECT COALESCE(NULLIF(display_name, ''), username) FROM users WHERE id = ?"); $buyerStmt = $pdo->prepare("SELECT COALESCE(NULLIF(display_name, ''), username) FROM users WHERE id = ?");
$buyerStmt->execute([$buyerId]); $buyerStmt->execute([$buyerId]);
@ -153,7 +153,7 @@ switch ($action) {
$movementId = null; $movementId = null;
if ($item && $item['stock_mode'] === 'manual') { if ($item && $item['stock_mode'] === 'manual') {
if ((int) $item['stock'] < $quantity) { if ((int) $item['stock'] < $quantity) {
shop_fail('Von „' . $item['name'] . '“ sind nur noch ' . (int) $item['stock'] . ' im Shop-Bestand.', $url); shop_fail('Von „' . $item['name'] . '“ sind nur noch ' . (int) $item['stock'] . ' im Shop-Bestand - bitte eine kleinere Anzahl bewilligen.', $url);
} }
$pdo->prepare('UPDATE shop_items SET stock = stock - ? WHERE id = ?')->execute([$quantity, (int) $item['id']]); $pdo->prepare('UPDATE shop_items SET stock = stock - ? WHERE id = ?')->execute([$quantity, (int) $item['id']]);
$stockTaken = 1; $stockTaken = 1;
@ -165,7 +165,7 @@ switch ($action) {
$pdo->prepare('SELECT id FROM warehouse_items WHERE id = ? FOR UPDATE')->execute([$warehouseId]); $pdo->prepare('SELECT id FROM warehouse_items WHERE id = ? FOR UPDATE')->execute([$warehouseId]);
$inStock = warehouse_item_stock($warehouseId); $inStock = warehouse_item_stock($warehouseId);
if ($inStock < $quantity) { if ($inStock < $quantity) {
shop_fail('Im Lagerhaus sind nur noch ' . $inStock . '× „' . $item['name'] . '“.', $url); shop_fail('Im Lagerhaus sind nur noch ' . $inStock . '× „' . $item['name'] . '“ - bitte eine kleinere Anzahl bewilligen.', $url);
} }
$pdo->prepare( $pdo->prepare(
"INSERT INTO warehouse_movements (item_id, direction, quantity, occurred_at, counterpart_user_id, note, created_by) "INSERT INTO warehouse_movements (item_id, direction, quantity, occurred_at, counterpart_user_id, note, created_by)
@ -184,12 +184,13 @@ switch ($action) {
} }
$pdo->prepare( $pdo->prepare(
"UPDATE shop_orders SET status = 'approved', decided_by = ?, decided_at = NOW(), award_id = ?, "UPDATE shop_orders SET status = 'approved', quantity = ?, total_price = ?, decided_by = ?, decided_at = NOW(),
warehouse_movement_id = ?, stock_taken = ? WHERE id = ?" award_id = ?, warehouse_movement_id = ?, stock_taken = ? WHERE id = ?"
)->execute([$userId, $awardId, $movementId, $stockTaken, $orderId]); )->execute([$quantity, $total, $userId, $awardId, $movementId, $stockTaken, $orderId]);
$pdo->commit(); $pdo->commit();
set_flash('success', 'Bewilligt: ' . shop_order_label($order) . ' für ' . $buyerName . '. ' set_flash('success', 'Bewilligt: ' . shop_order_label($order) . ($quantity < $requested ? ' (von ' . $requested . ' beantragt)' : '')
. ' für ' . $buyerName . '. '
. contribution_format($total) . ' Lumipunkte abgezogen' . ($movementId ? ', Entnahme im Lagerhaus gebucht' : '') . '.'); . contribution_format($total) . ' Lumipunkte abgezogen' . ($movementId ? ', Entnahme im Lagerhaus gebucht' : '') . '.');
redirect($url); redirect($url);

View file

@ -26,6 +26,12 @@ foreach ($orders as $order) {
$balances[(int) $order['user_id']] ??= contribution_user_balance((int) $order['user_id']); $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'; $orderView = 'manage';
$orderReturn = '/shop_orders.php?tab=' . $tab . ($page > 1 ? '&page=' . $page : ''); $orderReturn = '/shop_orders.php?tab=' . $tab . ($page > 1 ? '&page=' . $page : '');

View file

@ -222,7 +222,9 @@ CREATE TABLE IF NOT EXISTS shop_orders (
-- Name und Preis zum Zeitpunkt der Bestellung (bleiben, auch wenn der Gegenstand spaeter -- Name und Preis zum Zeitpunkt der Bestellung (bleiben, auch wenn der Gegenstand spaeter
-- geaendert oder geloescht wird) -- geaendert oder geloescht wird)
item_name VARCHAR(150) NOT NULL, item_name VARCHAR(150) NOT NULL,
-- Anzahl (nach einer Teilbewilligung die bewilligte) und die urspruenglich beantragte
quantity INT UNSIGNED NOT NULL, quantity INT UNSIGNED NOT NULL,
requested_quantity INT UNSIGNED NOT NULL,
unit_price INT UNSIGNED NOT NULL, unit_price INT UNSIGNED NOT NULL,
total_price INT UNSIGNED NOT NULL, total_price INT UNSIGNED NOT NULL,
-- Bemerkung des Mitglieds (z.B. Charaktername) -- Bemerkung des Mitglieds (z.B. Charaktername)