Modern item picker (image, category, stock, keyboard) for deposit, withdraw, history search and shop management; category chips for the stock

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-21 21:31:52 +02:00
parent 11d8e8d819
commit a483ea8712
7 changed files with 472 additions and 56 deletions

View file

@ -4875,3 +4875,87 @@ input[type="file"]::file-selector-button {
.list-toolbar-meta { width: 100%; } .list-toolbar-meta { width: 100%; }
.list-toolbar-meta .members-segment { max-width: 100%; overflow-x: auto; } .list-toolbar-meta .members-segment { max-width: 100%; overflow-x: auto; }
} }
/* ---- Auswahlfeld fuer Gegenstaende (assets/js/item-picker.js) ---- */
.item-picker .search-field input { border-radius: 10px; }
.item-picker-icon { display: contents; }
.item-picker-preview {
width: 24px !important;
height: 24px !important;
left: 0.6rem !important;
border-radius: 5px;
object-fit: contain;
}
.item-picker-list {
position: fixed;
z-index: 1100;
margin: 0;
padding: 0.35rem;
list-style: none;
overflow-y: auto;
background: rgba(30, 30, 30, 0.97);
border: 1px solid rgba(201, 162, 39, 0.35);
border-radius: 12px;
box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
backdrop-filter: blur(10px);
animation: item-picker-in 0.12s ease-out;
}
.item-picker-list[hidden] { display: none; }
@keyframes item-picker-in {
from { opacity: 0; transform: translateY(-4px); }
to { opacity: 1; transform: none; }
}
.item-picker-option {
display: flex;
align-items: center;
gap: 0.7rem;
padding: 0.45rem 0.6rem;
border-radius: 8px;
cursor: pointer;
}
.item-picker-option:hover { background: rgba(255, 255, 255, 0.05); }
.item-picker-option.active { background: rgba(201, 162, 39, 0.16); }
.item-picker-thumb {
flex-shrink: 0;
width: 34px;
height: 34px;
border-radius: 7px;
object-fit: contain;
background: rgba(255, 255, 255, 0.04);
border: 1px solid var(--border);
}
.item-picker-thumb-empty {
display: grid;
place-items: center;
color: var(--gold);
font-weight: 700;
border-style: dashed;
}
.item-picker-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.item-picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-picker-name mark { background: none; color: var(--gold); font-weight: 700; }
.item-picker-meta { font-size: 0.78rem; color: var(--text-muted); }
.item-picker-qty {
flex-shrink: 0;
padding: 0.1rem 0.55rem;
border-radius: 999px;
background: rgba(76, 175, 80, 0.14);
color: #8fd392;
font-size: 0.75rem;
white-space: nowrap;
}
.item-picker-note { padding: 0.55rem 0.7rem; color: var(--text-muted); font-size: 0.85rem; }
/* Bestand: Suche und Kategorie-Chips */
.warehouse-filters.list-toolbar { margin: 1rem 0; }

273
assets/js/item-picker.js Normal file
View file

@ -0,0 +1,273 @@
/**
* Auswahlfeld fuer Lagerhaus-Gegenstaende: Suchfeld mit aufklappender Liste (Bild, Name,
* Kategorie, Bestand) statt Datalist oder Dropdown. Tastatur: Pfeile, Enter, Escape.
*
* Markup: <div class="item-picker" data-picker-items="<id eines JSON-Scripts>" data-picker-mode="name|id|submit">
* name - der Text selbst wird gesendet (freie Eingabe erlaubt, z.B. neue Gegenstaende)
* id - ein verstecktes Feld bekommt die ID; nur Eintraege aus der Liste sind gueltig
* submit - wie name, schickt nach der Auswahl das Formular ab (Suche im Verlauf)
* Optional data-picker-empty: Text, wenn nichts passt.
* Von aussen: element.itemPicker.set(idOderName) und element.itemPicker.refresh().
*/
(function () {
'use strict';
var MAX_SHOWN = 60;
function norm(value) {
return String(value || '').toLowerCase().normalize('NFD').replace(/[̀-ͯ]/g, '');
}
function formatQty(qty) {
return Number(qty).toLocaleString('de-DE');
}
// Name mit hervorgehobenem Suchbegriff (als Textknoten, kein innerHTML mit Benutzerdaten)
function highlighted(name, query) {
var span = document.createElement('span');
span.className = 'item-picker-name';
var at = query ? norm(name).indexOf(query) : -1;
if (at === -1) {
span.textContent = name;
return span;
}
var mark = document.createElement('mark');
mark.textContent = name.slice(at, at + query.length);
span.appendChild(document.createTextNode(name.slice(0, at)));
span.appendChild(mark);
span.appendChild(document.createTextNode(name.slice(at + query.length)));
return span;
}
function thumb(item) {
if (item.icon) {
var img = document.createElement('img');
img.className = 'item-picker-thumb';
img.src = item.icon;
img.alt = '';
img.loading = 'lazy';
return img;
}
var empty = document.createElement('span');
empty.className = 'item-picker-thumb item-picker-thumb-empty';
empty.textContent = item.name.charAt(0).toUpperCase();
return empty;
}
function ItemPicker(root) {
var source = document.getElementById(root.dataset.pickerItems);
var input = root.querySelector('.item-picker-input');
if (!source || !input) return;
var items = JSON.parse(source.textContent || '[]');
items.forEach(function (item) { item.key = norm(item.name); item.catKey = norm(item.category); });
var mode = root.dataset.pickerMode || 'name';
var hidden = root.querySelector('input[type="hidden"]');
var iconSlot = root.querySelector('.item-picker-icon');
var searchIcon = iconSlot ? iconSlot.innerHTML : '';
var emptyText = root.dataset.pickerEmpty || 'Kein Gegenstand gefunden.';
var list = document.createElement('ul');
list.className = 'item-picker-list';
list.id = (input.id || 'item-picker-' + Math.random().toString(36).slice(2)) + '-list';
list.setAttribute('role', 'listbox');
list.hidden = true;
document.body.appendChild(list);
input.setAttribute('role', 'combobox');
input.setAttribute('aria-autocomplete', 'list');
input.setAttribute('aria-expanded', 'false');
input.setAttribute('aria-controls', list.id);
input.setAttribute('autocomplete', 'off');
var matches = [];
var active = -1;
function findItem(value) {
var key = norm(String(value).trim());
for (var i = 0; i < items.length; i++) {
if (String(items[i].id) === String(value) || items[i].key === key) return items[i];
}
return null;
}
function refresh() {
var item = findItem(input.value);
if (iconSlot) {
iconSlot.innerHTML = '';
if (item && item.icon) {
var img = document.createElement('img');
img.className = 'icon item-picker-preview';
img.src = item.icon;
img.alt = '';
iconSlot.appendChild(img);
} else {
iconSlot.innerHTML = searchIcon;
}
}
if (mode === 'id' && hidden) {
var id = item ? String(item.id) : '';
if (hidden.value !== id) {
hidden.value = id;
hidden.dataset.max = item && item.qty != null ? item.qty : '';
hidden.dispatchEvent(new Event('change'));
}
input.setCustomValidity(id || !input.required ? '' : 'Bitte einen Gegenstand aus der Liste wählen.');
}
}
function position() {
var rect = input.getBoundingClientRect();
var below = window.innerHeight - rect.bottom;
list.style.left = rect.left + 'px';
list.style.width = rect.width + 'px';
if (below < 240 && rect.top > below) {
list.style.top = 'auto';
list.style.bottom = (window.innerHeight - rect.top + 6) + 'px';
list.style.maxHeight = Math.min(340, rect.top - 12) + 'px';
} else {
list.style.bottom = 'auto';
list.style.top = (rect.bottom + 6) + 'px';
list.style.maxHeight = Math.min(340, below - 12) + 'px';
}
}
function render() {
var query = norm(input.value.trim());
var starts = [];
var contains = [];
items.forEach(function (item) {
if (!query) contains.push(item);
else if (item.key.indexOf(query) === 0) starts.push(item);
else if (item.key.indexOf(query) !== -1 || item.catKey.indexOf(query) !== -1) contains.push(item);
});
var all = starts.concat(contains);
matches = all.slice(0, MAX_SHOWN);
active = matches.length && query ? 0 : -1;
list.innerHTML = '';
matches.forEach(function (item, index) {
var li = document.createElement('li');
li.className = 'item-picker-option';
li.id = list.id + '-' + index;
li.setAttribute('role', 'option');
li.appendChild(thumb(item));
var text = document.createElement('span');
text.className = 'item-picker-text';
text.appendChild(highlighted(item.name, query));
var meta = document.createElement('span');
meta.className = 'item-picker-meta';
meta.textContent = item.category;
text.appendChild(meta);
li.appendChild(text);
if (item.qty != null) {
var qty = document.createElement('span');
qty.className = 'item-picker-qty';
qty.textContent = formatQty(item.qty) + ' auf Lager';
li.appendChild(qty);
}
li.addEventListener('mousedown', function (event) { event.preventDefault(); });
li.addEventListener('click', function () { choose(item); });
list.appendChild(li);
});
if (!matches.length) {
var none = document.createElement('li');
none.className = 'item-picker-note';
none.textContent = emptyText;
list.appendChild(none);
} else if (all.length > matches.length) {
var more = document.createElement('li');
more.className = 'item-picker-note';
more.textContent = '… und ' + (all.length - matches.length) + ' weitere - weiter tippen zum Eingrenzen';
list.appendChild(more);
}
highlight();
}
function highlight() {
Array.prototype.forEach.call(list.querySelectorAll('.item-picker-option'), function (li, index) {
var on = index === active;
li.classList.toggle('active', on);
li.setAttribute('aria-selected', String(on));
if (on) li.scrollIntoView({ block: 'nearest' });
});
if (active >= 0) input.setAttribute('aria-activedescendant', list.id + '-' + active);
else input.removeAttribute('aria-activedescendant');
}
function open() {
render();
list.hidden = false;
input.setAttribute('aria-expanded', 'true');
position();
window.addEventListener('scroll', position, true);
window.addEventListener('resize', position);
}
function close() {
list.hidden = true;
input.setAttribute('aria-expanded', 'false');
window.removeEventListener('scroll', position, true);
window.removeEventListener('resize', position);
}
function choose(item, silent) {
input.value = item.name;
refresh();
close();
input.dispatchEvent(new Event('change', { bubbles: true }));
if (!silent && mode === 'submit' && input.form) input.form.submit();
}
input.addEventListener('input', function () {
refresh();
open();
});
input.addEventListener('click', function () {
if (list.hidden) open();
});
input.addEventListener('change', refresh);
input.addEventListener('blur', close);
input.addEventListener('keydown', function (event) {
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
event.preventDefault();
if (list.hidden) { open(); return; }
if (!matches.length) return;
active = event.key === 'ArrowDown'
? (active + 1) % matches.length
: (active <= 0 ? matches.length - 1 : active - 1);
highlight();
} else if (event.key === 'Enter' && !list.hidden && active >= 0) {
event.preventDefault();
choose(matches[active]);
} else if (event.key === 'Escape' && !list.hidden) {
// Nur die Liste schliessen, nicht gleich den ganzen Dialog
event.stopPropagation();
close();
} else if (event.key === 'Tab') {
close();
}
});
// Vorbelegung (z.B. nach einem Fehler): ID im versteckten Feld -> Name anzeigen
if (mode === 'id' && hidden && hidden.value && !input.value) {
var initial = findItem(hidden.value);
if (initial) input.value = initial.name;
}
refresh();
root.itemPicker = {
set: function (value) {
var item = findItem(value);
if (item) choose(item, true);
else { input.value = value; refresh(); }
},
refresh: refresh
};
}
document.querySelectorAll('.item-picker').forEach(ItemPicker);
})();

View file

@ -137,6 +137,10 @@
mode.value = data.stock_mode || 'manual'; mode.value = data.stock_mode || 'manual';
form.elements.stock.value = data.stock !== undefined ? data.stock : 0; form.elements.stock.value = data.stock !== undefined ? data.stock : 0;
form.elements.warehouse_item.value = data.warehouse_item || ''; form.elements.warehouse_item.value = data.warehouse_item || '';
// Bild in den Auswahlfeldern passend zum eingetragenen Gegenstand
form.querySelectorAll('.item-picker').forEach(function (picker) {
if (picker.itemPicker) picker.itemPicker.refresh();
});
form.elements.active.checked = data.active === undefined ? true : !!data.active; form.elements.active.checked = data.active === undefined ? true : !!data.active;
title.textContent = data.id ? 'Gegenstand bearbeiten' : 'Gegenstand anlegen'; title.textContent = data.id ? 'Gegenstand bearbeiten' : 'Gegenstand anlegen';
applyMode(); applyMode();

View file

@ -8,19 +8,14 @@
modal.hidden = false; modal.hidden = false;
// Aus einer Bestandszeile heraus: Gegenstand gleich vorauswaehlen. // Aus einer Bestandszeile heraus: Gegenstand gleich vorauswaehlen.
if (trigger && trigger.dataset.itemId) { var picker = modal.querySelector('.item-picker');
var select = modal.querySelector('select[name="item_id"]'); var preset = trigger ? (trigger.dataset.itemId || trigger.dataset.itemName) : '';
if (select) { if (picker && picker.itemPicker && preset) {
select.value = trigger.dataset.itemId; picker.itemPicker.set(preset);
select.dispatchEvent(new Event('change'));
}
}
if (trigger && trigger.dataset.itemName) {
var input = modal.querySelector('input[name="item"]');
if (input) input.value = trigger.dataset.itemName;
} }
var first = modal.querySelector('input:not([type="hidden"]):not([value]), select, input[type="text"]'); // Vorausgewaehlt: gleich zur Anzahl, sonst ins Suchfeld
var first = preset ? modal.querySelector('input[type="number"]') : modal.querySelector('.item-picker-input, input[type="text"]');
if (first) first.focus(); if (first) first.focus();
} }
@ -50,8 +45,7 @@
var outQuantity = document.getElementById('out-quantity'); var outQuantity = document.getElementById('out-quantity');
if (outItem && outQuantity) { if (outItem && outQuantity) {
var applyMax = function () { var applyMax = function () {
var option = outItem.options[outItem.selectedIndex]; var max = outItem.dataset.max;
var max = option ? option.getAttribute('data-max') : null;
if (max) { if (max) {
outQuantity.max = max; outQuantity.max = max;
if (parseInt(outQuantity.value, 10) > parseInt(max, 10)) outQuantity.value = max; if (parseInt(outQuantity.value, 10) > parseInt(max, 10)) outQuantity.value = max;
@ -81,11 +75,11 @@
var category = document.getElementById('warehouse-category'); var category = document.getElementById('warehouse-category');
var table = document.getElementById('warehouse-stock'); var table = document.getElementById('warehouse-stock');
var noMatch = document.getElementById('warehouse-no-match'); var noMatch = document.getElementById('warehouse-no-match');
if (!search || !category || !table) return; var cat = '';
if (!search || !table) return;
function filter() { function filter() {
var term = search.value.trim().toLowerCase(); var term = search.value.trim().toLowerCase();
var cat = category.value;
var visible = 0; var visible = 0;
table.querySelectorAll('.warehouse-card').forEach(function (row) { table.querySelectorAll('.warehouse-card').forEach(function (row) {
var show = (term === '' || row.dataset.name.indexOf(term) !== -1) var show = (term === '' || row.dataset.name.indexOf(term) !== -1)
@ -97,5 +91,17 @@
} }
search.addEventListener('input', filter); search.addEventListener('input', filter);
category.addEventListener('change', filter); if (category) {
category.addEventListener('click', function (event) {
var chip = event.target.closest('button');
if (!chip) return;
cat = chip.dataset.value;
category.querySelectorAll('button').forEach(function (b) {
var on = b === chip;
b.classList.toggle('active', on);
b.setAttribute('aria-pressed', String(on));
});
filter();
});
}
})(); })();

View file

@ -258,6 +258,30 @@ function warehouse_icon_html(?string $icon, string $name, int $size): string
. icon('box') . '</span>'; . icon('box') . '</span>';
} }
/**
* Gegenstaende als JSON fuer die Auswahlliste (assets/js/item-picker.js), direkt in ein
* <script type="application/json"> ausgebbar. Bestand aus 'quantity' oder $stockById.
*
* @param array<int, array<string, mixed>> $rows id, name, category, icon (optional quantity)
* @param array<int, int> $stockById
*/
function warehouse_picker_json(array $rows, array $stockById = []): string
{
$items = [];
foreach ($rows as $row) {
$icon = (string) ($row['icon'] ?? '');
$id = (int) $row['id'];
$items[] = [
'id' => $id,
'name' => (string) $row['name'],
'category' => warehouse_category_label((string) $row['category']),
'icon' => preg_match('/^[a-z0-9_]+\.webp$/', $icon) ? '/assets/images/warehouse/' . $icon : null,
'qty' => isset($row['quantity']) ? (int) $row['quantity'] : ($stockById[$id] ?? null),
];
}
return (string) json_encode($items, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP);
}
/** Jetzt in deutscher Zeit, passend fuer ein datetime-local-Feld. */ /** Jetzt in deutscher Zeit, passend fuer ein datetime-local-Feld. */
function warehouse_now_input(): string function warehouse_now_input(): string
{ {

View file

@ -11,10 +11,11 @@ $pendingCount = shop_pending_count();
// Lagerhaus-Gegenstaende fuer die Vorschlagsliste (Bild/Verknuepfung) und zum Uebernehmen: // Lagerhaus-Gegenstaende fuer die Vorschlagsliste (Bild/Verknuepfung) und zum Uebernehmen:
// alles, was auf Lager ist und noch nicht im Shop steht (ohne Kina). // alles, was auf Lager ist und noch nicht im Shop steht (ohne Kina).
$warehouseNames = db()->query('SELECT name FROM warehouse_items ORDER BY name')->fetchAll(PDO::FETCH_COLUMN); $warehouseItems = db()->query('SELECT id, name, category, icon FROM warehouse_items ORDER BY name')->fetchAll();
$linkedIds = array_filter(array_map(static fn (array $i): int => (int) $i['warehouse_item_id'], $items)); $linkedIds = array_filter(array_map(static fn (array $i): int => (int) $i['warehouse_item_id'], $items));
$warehouseStock = warehouse_stock();
$importable = array_values(array_filter( $importable = array_values(array_filter(
warehouse_stock(), $warehouseStock,
static fn (array $row): bool => $row['category'] !== 'currency' && !in_array((int) $row['id'], $linkedIds, true) static fn (array $row): bool => $row['category'] !== 'currency' && !in_array((int) $row['id'], $linkedIds, true)
)); ));
@ -188,7 +189,12 @@ include __DIR__ . '/includes/header.php';
<input type="hidden" name="item_id" value=""> <input type="hidden" name="item_id" value="">
<div> <div>
<label for="shop-item-name">Name</label> <label for="shop-item-name">Name</label>
<input type="text" id="shop-item-name" name="name" maxlength="150" required list="shop-warehouse-list" autocomplete="off"> <div class="item-picker" data-picker-items="shop-warehouse-list" data-picker-empty="Kein Lagerhaus-Gegenstand mit diesem Namen - der Name ist frei wählbar.">
<label class="search-field">
<span class="item-picker-icon"><?= icon('search') ?></span>
<input type="text" class="item-picker-input" id="shop-item-name" name="name" maxlength="150" required placeholder="Name eingeben oder aus dem Lagerhaus wählen …">
</label>
</div>
</div> </div>
<div class="warehouse-row"> <div class="warehouse-row">
<div> <div>
@ -225,8 +231,13 @@ include __DIR__ . '/includes/header.php';
</div> </div>
<div> <div>
<label for="shop-item-warehouse">Lagerhaus-Gegenstand <span class="text-muted" data-mode-hint>(optional, für das Bild)</span></label> <label for="shop-item-warehouse">Lagerhaus-Gegenstand <span class="text-muted" data-mode-hint>(optional, für das Bild)</span></label>
<input type="text" id="shop-item-warehouse" name="warehouse_item" maxlength="150" list="shop-warehouse-list" autocomplete="off" <div class="item-picker" data-picker-items="shop-warehouse-list" data-picker-empty="Kein Lagerhaus-Gegenstand mit diesem Namen.">
placeholder="Leer lassen = gleicher Name wie oben, falls es ihn im Lagerhaus gibt"> <label class="search-field">
<span class="item-picker-icon"><?= icon('search') ?></span>
<input type="text" class="item-picker-input" id="shop-item-warehouse" name="warehouse_item" maxlength="150"
placeholder="Leer lassen = gleicher Name wie oben, falls es ihn im Lagerhaus gibt">
</label>
</div>
<div class="field-hint" data-mode-field="warehouse">Der Bestand im Shop ist der Lagerbestand dieses Gegenstands. Beim Bewilligen wird die Entnahme automatisch im Lagerhaus gebucht.</div> <div class="field-hint" data-mode-field="warehouse">Der Bestand im Shop ist der Lagerbestand dieses Gegenstands. Beim Bewilligen wird die Entnahme automatisch im Lagerhaus gebucht.</div>
</div> </div>
<label class="checkbox-label"> <label class="checkbox-label">
@ -238,11 +249,7 @@ include __DIR__ . '/includes/header.php';
</form> </form>
</div> </div>
</div> </div>
<datalist id="shop-warehouse-list"> <script type="application/json" id="shop-warehouse-list"><?= warehouse_picker_json($warehouseItems, array_map('intval', array_column($warehouseStock, 'quantity', 'id'))) ?></script>
<?php foreach ($warehouseNames as $name): ?>
<option value="<?= e((string) $name) ?>">
<?php endforeach; ?>
</datalist>
<!-- Aus dem Lagerhaus uebernehmen --> <!-- Aus dem Lagerhaus uebernehmen -->
<?php if (!empty($importable)): ?> <?php if (!empty($importable)): ?>
@ -296,5 +303,6 @@ include __DIR__ . '/includes/header.php';
</div> </div>
<?php endif; ?> <?php endif; ?>
<script src="<?= e(asset_url('/assets/js/item-picker.js')) ?>"></script>
<script src="<?= e(asset_url('/assets/js/shop.js')) ?>"></script> <script src="<?= e(asset_url('/assets/js/shop.js')) ?>"></script>
<?php include __DIR__ . '/includes/footer.php'; ?> <?php include __DIR__ . '/includes/footer.php'; ?>

View file

@ -63,7 +63,13 @@ $page = min($pageCount, max(1, (int) ($_GET['page'] ?? 1)));
$movements = warehouse_movements($historyFilter, $perPage, ($page - 1) * $perPage, $historySort); $movements = warehouse_movements($historyFilter, $perPage, ($page - 1) * $perPage, $historySort);
// Fuer die Formulare: alle Gegenstaende (Vorschlagsliste) und die Konten der Website. // Fuer die Formulare: alle Gegenstaende (Vorschlagsliste) und die Konten der Website.
$allItems = $canManage ? db()->query('SELECT name FROM warehouse_items ORDER BY name')->fetchAll(PDO::FETCH_COLUMN) : []; $allItems = $canManage ? db()->query('SELECT id, name, category, icon FROM warehouse_items ORDER BY name')->fetchAll() : [];
$stockById = array_map('intval', array_column($stock, 'quantity', 'id'));
// Vorschlaege fuer die Suche im Verlauf: nur Gegenstaende, die schon einmal bewegt wurden.
$historyItems = db()->query(
'SELECT i.id, i.name, i.category, i.icon FROM warehouse_items i
WHERE EXISTS (SELECT 1 FROM warehouse_movements m WHERE m.item_id = i.id) ORDER BY i.name'
)->fetchAll();
$members = $canManage ? db()->query( $members = $canManage ? db()->query(
"SELECT id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users "SELECT id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users
WHERE status = 'active' ORDER BY name" WHERE status = 'active' ORDER BY name"
@ -75,8 +81,10 @@ unset($_SESSION['warehouse_form']);
$openForm = (string) ($old['form'] ?? ''); $openForm = (string) ($old['form'] ?? '');
$categoriesInStock = []; $categoriesInStock = [];
$categoryCounts = [];
foreach ($itemStock as $row) { foreach ($itemStock as $row) {
$categoriesInStock[$row['category']] = warehouse_category_label((string) $row['category']); $categoriesInStock[$row['category']] = warehouse_category_label((string) $row['category']);
$categoryCounts[$row['category']] = ($categoryCounts[$row['category']] ?? 0) + 1;
} }
asort($categoriesInStock); asort($categoriesInStock);
@ -149,14 +157,19 @@ include __DIR__ . '/includes/header.php';
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="warehouse-filters"> <div class="list-toolbar warehouse-filters">
<input type="search" id="warehouse-search" placeholder="Gegenstand suchen …" autocomplete="off"> <label class="search-field">
<select id="warehouse-category"> <?= icon('search') ?>
<option value="">Alle Kategorien</option> <input type="search" id="warehouse-search" placeholder="Gegenstand suchen …" autocomplete="off" aria-label="Bestand durchsuchen">
<?php foreach ($categoriesInStock as $key => $label): ?> </label>
<option value="<?= e((string) $key) ?>"><?= e($label) ?></option> <?php if (count($categoriesInStock) > 1): ?>
<?php endforeach; ?> <div class="members-chips" id="warehouse-category" role="group" aria-label="Nach Kategorie filtern">
</select> <button type="button" class="members-chip active" data-value="" aria-pressed="true">Alle <span class="chip-count"><?= count($itemStock) ?></span></button>
<?php foreach ($categoriesInStock as $key => $label): ?>
<button type="button" class="members-chip" data-value="<?= e((string) $key) ?>" aria-pressed="false"><?= e($label) ?> <span class="chip-count"><?= (int) $categoryCounts[$key] ?></span></button>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div> </div>
<?php if (empty($itemStock)): ?> <?php if (empty($itemStock)): ?>
@ -206,10 +219,13 @@ include __DIR__ . '/includes/header.php';
<?php if ($filterItemId !== null): ?><input type="hidden" name="item" value="<?= (int) $filterItemId ?>"><?php endif; ?> <?php if ($filterItemId !== null): ?><input type="hidden" name="item" value="<?= (int) $filterItemId ?>"><?php endif; ?>
<input type="hidden" name="dir" value="<?= e($historyDirection) ?>"> <input type="hidden" name="dir" value="<?= e($historyDirection) ?>">
<input type="hidden" name="sort" value="<?= e($historySort) ?>"> <input type="hidden" name="sort" value="<?= e($historySort) ?>">
<label class="search-field"> <div class="item-picker" data-picker-items="warehouse-picker-history" data-picker-mode="submit" data-picker-empty="Kein Gegenstand - Enter sucht auch in Personen und Bemerkungen.">
<?= icon('search') ?> <label class="search-field">
<input type="search" name="q" value="<?= e($historyQuery) ?>" placeholder="Gegenstand, Person oder Bemerkung suchen …" aria-label="Verlauf durchsuchen"> <span class="item-picker-icon"><?= icon('search') ?></span>
</label> <input type="search" class="item-picker-input" id="history-search" name="q" value="<?= e($historyQuery) ?>" placeholder="Gegenstand, Person oder Bemerkung suchen …" aria-label="Verlauf durchsuchen">
</label>
</div>
<script type="application/json" id="warehouse-picker-history"><?= warehouse_picker_json($historyItems) ?></script>
<div class="list-toolbar-row"> <div class="list-toolbar-row">
<div class="members-chips" role="group" aria-label="Nach Art filtern"> <div class="members-chips" role="group" aria-label="Nach Art filtern">
<?php foreach (['' => 'Alle', 'in' => 'Eingelagert', 'out' => 'Entnommen'] as $value => $label): ?> <?php foreach (['' => 'Alle', 'in' => 'Eingelagert', 'out' => 'Entnommen'] as $value => $label): ?>
@ -312,13 +328,14 @@ include __DIR__ . '/includes/header.php';
<input type="hidden" name="action" value="deposit"> <input type="hidden" name="action" value="deposit">
<div> <div>
<label for="in-item">Gegenstand</label> <label for="in-item">Gegenstand</label>
<input type="text" id="in-item" name="item" list="warehouse-item-list" required autocomplete="off" <div class="item-picker" data-picker-items="warehouse-picker-all" data-picker-empty="Nicht im Katalog - wird beim Einlagern als neuer Gegenstand angelegt.">
value="<?= e((string) ($oldIn['item'] ?? '')) ?>" placeholder="Namen eintippen, Vorschläge erscheinen"> <label class="search-field">
<datalist id="warehouse-item-list"> <span class="item-picker-icon"><?= icon('search') ?></span>
<?php foreach ($allItems as $name): ?> <input type="text" class="item-picker-input" id="in-item" name="item" required
<option value="<?= e((string) $name) ?>"> value="<?= e((string) ($oldIn['item'] ?? '')) ?>" placeholder="Gegenstand suchen …">
<?php endforeach; ?> </label>
</datalist> </div>
<script type="application/json" id="warehouse-picker-all"><?= warehouse_picker_json($allItems, $stockById) ?></script>
</div> </div>
<?php if (!empty($oldIn['unknown_item'])): ?> <?php if (!empty($oldIn['unknown_item'])): ?>
<div class="warehouse-new-item"> <div class="warehouse-new-item">
@ -367,16 +384,15 @@ include __DIR__ . '/includes/header.php';
<?= csrf_field() ?> <?= csrf_field() ?>
<input type="hidden" name="action" value="withdraw"> <input type="hidden" name="action" value="withdraw">
<div> <div>
<label for="out-item">Gegenstand</label> <label for="out-item-search">Gegenstand</label>
<select id="out-item" name="item_id" required> <div class="item-picker" data-picker-items="warehouse-picker-stock" data-picker-mode="id" data-picker-empty="Nicht auf Lager.">
<option value="">– aus dem Bestand wählen –</option> <input type="hidden" id="out-item" name="item_id" value="<?= e((string) ($oldOut['item_id'] ?? '')) ?>">
<?php foreach ($stock as $row): ?> <label class="search-field">
<option value="<?= (int) $row['id'] ?>" data-max="<?= (int) $row['quantity'] ?>" <span class="item-picker-icon"><?= icon('search') ?></span>
<?= (string) ($oldOut['item_id'] ?? '') === (string) $row['id'] ? 'selected' : '' ?>> <input type="text" class="item-picker-input" id="out-item-search" required placeholder="Aus dem Bestand wählen …" aria-label="Gegenstand">
<?= e((string) $row['name']) ?> (<?= number_format((int) $row['quantity'], 0, ',', '.') ?> auf Lager) </label>
</option> </div>
<?php endforeach; ?> <script type="application/json" id="warehouse-picker-stock"><?= warehouse_picker_json($stock) ?></script>
</select>
</div> </div>
<div class="warehouse-row"> <div class="warehouse-row">
<div> <div>
@ -404,5 +420,6 @@ include __DIR__ . '/includes/header.php';
</div> </div>
<?php endif; ?> <?php endif; ?>
<script src="<?= e(asset_url('/assets/js/item-picker.js')) ?>"></script>
<script src="<?= e(asset_url('/assets/js/warehouse.js')) ?>"></script> <script src="<?= e(asset_url('/assets/js/warehouse.js')) ?>"></script>
<?php include __DIR__ . '/includes/footer.php'; ?> <?php include __DIR__ . '/includes/footer.php'; ?>