From 17dea6d41f2978f2842322ba92c290d0dd141650 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Mon, 21 Sep 2026 10:56:59 +0200 Subject: [PATCH] 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 --- README.md | 17 +++++++++------ assets/css/style.css | 43 ++++++++++++++++++++++++++++++++----- assets/js/shop.js | 15 +++++++++++++ dashboard.php | 32 +++++++++++++++++++++++++++ includes/header.php | 14 +++++++----- includes/schema.php | 13 +++++++++-- includes/shop.php | 9 +++++++- includes/shop_order_row.php | 33 ++++++++++++++++++++++++---- shop.php | 10 +++++---- shop_action.php | 39 +++++++++++++++++---------------- shop_orders.php | 6 ++++++ sql/schema.sql | 2 ++ 12 files changed, 187 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index fec4a36..f6db80f 100644 --- a/README.md +++ b/README.md @@ -470,7 +470,7 @@ Herzform (`assets/images/lumipunkt.svg`). - **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 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, 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 @@ -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 Suche und Kategoriefilter. Oben steht, wie viele Punkte man ausgeben kann: der Punktestand abzüglich der Punkte in eigenen offenen Anträgen. -- **Beantragen:** Anzahl und optional eine Bemerkung (z.B. der Charaktername). Die Website - prüft, ob Punkte und Bestand reichen, wobei offene Anträge schon abgezogen sind. Abgezogen - wird aber noch nichts, und offene Anträge lassen sich unter **Meine Anträge** zurückziehen. +- **Beantragen:** Anzahl und optional eine Bemerkung (z.B. der Charaktername). Man darf mehr + beantragen, als gerade verfügbar ist. Die Punkte müssen aber für die ganze Anzahl reichen, + 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 - Erledigt. Bei offenen Anträgen steht der Punktestand des Mitglieds dabei. - - **Bewilligen** zieht die Lumipunkte ab. Das ist eine Buchung „Lumishop: …“ im + Erledigt. Bei offenen Anträgen stehen der Punktestand des Mitglieds und der aktuelle Bestand + 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 Entnahme an das Mitglied. - **Ablehnen** geht mit einem optionalen Grund, den das Mitglied sieht. diff --git a/assets/css/style.css b/assets/css/style.css index a9abed2..a4eebfa 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -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-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 { - display: inline-flex; + display: flex; align-items: center; - gap: 0.25rem; - margin-top: 0.15rem; - font-weight: 700; - color: var(--gold); + gap: 0.7rem; + margin-top: 1rem; + padding: 0.6rem 0.8rem; + 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) { .contribution-form-grid { grid-template-columns: 1fr; } @@ -2848,3 +2864,20 @@ input.shop-import-row-price { width: 100px; } } #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%; } +} diff --git a/assets/js/shop.js b/assets/js/shop.js index 03dfafb..53d86c1 100644 --- a/assets/js/shop.js +++ b/assets/js/shop.js @@ -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 ---- var itemModal = document.getElementById('shop-item-modal'); if (itemModal) { diff --git a/dashboard.php b/dashboard.php index f733fe9..3452e74 100644 --- a/dashboard.php +++ b/dashboard.php @@ -1,6 +1,7 @@ prepare( @@ -42,6 +45,22 @@ if ($canViewRaids) { } $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; $roleCount = $canManageRoles ? (int) db()->query('SELECT COUNT(*) FROM roles')->fetchColumn() : null; @@ -103,6 +122,19 @@ include __DIR__ . '/includes/header.php';
+ +
+ +
+

+

Lumipunkte · Platz

+ +
+
+
diff --git a/includes/header.php b/includes/header.php index d0f2cf2..abdecd2 100644 --- a/includes/header.php +++ b/includes/header.php @@ -204,16 +204,20 @@ $otherFlashes = array_values(array_filter($allFlashes, fn (array $f): bool => ($ + + + + + Deine Lumipunkte + + + + + +
+ Bestand: + +
+
Bemerkung:
@@ -55,17 +74,23 @@ $return = $orderReturn ?? '/shop.php#antraege';
Grund:
-
+
-
+ + 1): ?> + + von +
diff --git a/shop.php b/shop.php index 24c847b..6f56eaa 100644 --- a/shop.php +++ b/shop.php @@ -83,10 +83,12 @@ include __DIR__ . '/includes/header.php'; $price = (int) $item['price']; $soldOut = $available !== null && $available < 1; $affordable = $price === 0 ? SHOP_MAX_ORDER_QUANTITY : intdiv($spendable, $price); - $max = min(SHOP_MAX_ORDER_QUANTITY, $affordable, $available ?? SHOP_MAX_ORDER_QUANTITY); - $reason = $soldOut ? 'Ausverkauft' : ($max < 1 ? 'Nicht genug Lumipunkte' : ''); + // Mehr als verfuegbar darf beantragt werden (die Bewilligung kann kuerzen) - nur die + // Punkte muessen reichen. + $max = min(SHOP_MAX_ORDER_QUANTITY, $affordable); + $reason = $max < 1 ? 'Nicht genug Lumipunkte' : ''; ?> -
+
@@ -153,7 +155,7 @@ include __DIR__ . '/includes/header.php';
-

Die Lumipunkte werden erst abgezogen, wenn dein Antrag bewilligt ist. Bis dahin kannst du ihn zurückziehen.

+

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.

diff --git a/shop_action.php b/shop_action.php index cab15a9..3fd200d 100644 --- a/shop_action.php +++ b/shop_action.php @@ -76,15 +76,9 @@ switch ($action) { 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(); - // 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; $spendable = contribution_user_balance($userId) - shop_reserved_points($userId); if ($total > $spendable) { @@ -93,8 +87,9 @@ switch ($action) { } $pdo->prepare( - 'INSERT INTO shop_orders (user_id, item_id, item_name, quantity, unit_price, total_price, note) VALUES (?, ?, ?, ?, ?, ?, ?)' - )->execute([$userId, $itemId, $item['name'], $quantity, (int) $item['price'], $total, $note !== '' ? $note : null]); + 'INSERT INTO shop_orders (user_id, item_id, item_name, quantity, requested_quantity, unit_price, total_price, note) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)' + )->execute([$userId, $itemId, $item['name'], $quantity, $quantity, (int) $item['price'], $total, $note !== '' ? $note : null]); $pdo->commit(); unset($_SESSION['shop_form']); @@ -124,13 +119,18 @@ if (!user_has_permission('shop.manage')) { $url = shop_return_url(); 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': $pdo->beginTransaction(); $order = shop_lock_order($orderId, 'pending', $url); $buyerId = (int) $order['user_id']; - $quantity = (int) $order['quantity']; - $total = (int) $order['total_price']; + $requested = (int) $order['quantity']; + $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->execute([$buyerId]); @@ -153,7 +153,7 @@ switch ($action) { $movementId = null; if ($item && $item['stock_mode'] === 'manual') { 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']]); $stockTaken = 1; @@ -165,7 +165,7 @@ switch ($action) { $pdo->prepare('SELECT id FROM warehouse_items WHERE id = ? FOR UPDATE')->execute([$warehouseId]); $inStock = warehouse_item_stock($warehouseId); 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( "INSERT INTO warehouse_movements (item_id, direction, quantity, occurred_at, counterpart_user_id, note, created_by) @@ -184,12 +184,13 @@ switch ($action) { } $pdo->prepare( - "UPDATE shop_orders SET status = 'approved', decided_by = ?, decided_at = NOW(), award_id = ?, - warehouse_movement_id = ?, stock_taken = ? WHERE id = ?" - )->execute([$userId, $awardId, $movementId, $stockTaken, $orderId]); + "UPDATE shop_orders SET status = 'approved', quantity = ?, total_price = ?, decided_by = ?, decided_at = NOW(), + award_id = ?, warehouse_movement_id = ?, stock_taken = ? WHERE id = ?" + )->execute([$quantity, $total, $userId, $awardId, $movementId, $stockTaken, $orderId]); $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' : '') . '.'); redirect($url); diff --git a/shop_orders.php b/shop_orders.php index 75866fa..1810c8e 100644 --- a/shop_orders.php +++ b/shop_orders.php @@ -26,6 +26,12 @@ 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 : ''); diff --git a/sql/schema.sql b/sql/schema.sql index e5924d2..2e5bb5f 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -222,7 +222,9 @@ CREATE TABLE IF NOT EXISTS shop_orders ( -- Name und Preis zum Zeitpunkt der Bestellung (bleiben, auch wenn der Gegenstand spaeter -- geaendert oder geloescht wird) item_name VARCHAR(150) NOT NULL, + -- Anzahl (nach einer Teilbewilligung die bewilligte) und die urspruenglich beantragte quantity INT UNSIGNED NOT NULL, + requested_quantity INT UNSIGNED NOT NULL, unit_price INT UNSIGNED NOT NULL, total_price INT UNSIGNED NOT NULL, -- Bemerkung des Mitglieds (z.B. Charaktername)