Mache OTC-Produktliste dynamisch

This commit is contained in:
gitea_admin committed 2026-09-06 08:15:01 +02:00
1 parent ee03fd70b9
commit 4ccc0c528f
2 files changed
+27 -17

No files matched your search

+10 -12
View File
@@ -258,17 +258,22 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
foreach ($otcProducts as $product) {
$productId = (int) ($product['id'] ?? 0);
$productName = auth_escape_html((string) ($product['name'] ?? ''));
$productSku = auth_escape_html((string) ($product['sku'] ?? ''));
$availableQty = (int) max(0, (int) round((float) ($product['available_qty'] ?? 0)));
$hasSellableMapping = (bool) ($product['has_sellable_mapping'] ?? false);
$inputId = 'otc-product-' . $productId;
$mappingNote = $hasSellableMapping ? '' : ' (Artikel-Mapping fehlt)';
$disabledAttribute = $hasSellableMapping ? '' : ' disabled aria-disabled="true"';
$otcProductRows .= '<div class="sg-form-sections-card__field-group">';
$otcProductRows .= '<label class="sg-label" for="' . $inputId . '">' . $productName . '</label>';
$otcProductRows .= '<input class="sg-interaction-element sg-input-single-line" type="number" id="' . $inputId . '" min="0" max="' . $availableQty . '" step="1" data-otc-order-product data-product-id="' . $productId . '" data-title="' . $productName . '" data-available-qty="' . $availableQty . '">';
$otcProductRows .= '<label class="sg-label" for="' . $inputId . '">' . $productName . ($productSku !== '' ? ' (' . $productSku . ')' : '') . $mappingNote . '</label>';
$otcProductRows .= '<input class="sg-interaction-element sg-input-single-line" type="number" id="' . $inputId . '" min="0" step="1" data-otc-order-product data-product-id="' . $productId . '" data-title="' . $productName . '" data-available-qty="' . $availableQty . '"' . $disabledAttribute . '>';
$otcProductRows .= '<p class="sg-body sg-form-sections-card__sentence">Physischer Bestand: ' . $availableQty . '</p>';
$otcProductRows .= '</div>';
}
if ($otcProductRows === '') {
$otcProductRows = '<p class="sg-body sg-form-sections-card__sentence">Keine verfügbaren Produkte im Lager.</p>';
$otcProductRows = '<p class="sg-body sg-form-sections-card__sentence">Keine aktiven OTC-Produkte erfasst.</p>';
}
$moduleNavigation = json_encode(
@@ -1053,10 +1058,6 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
echo " const updateFormState = () => {";
echo " const totalQty = productInputs.reduce((sum, input) => sum + getInputValue(input), 0);";
echo " const totalPrice = parseFloat(totalPriceInput.value || '0') || 0;";
echo " const overstockInput = productInputs.find((input) => {";
echo " const maxQty = parseInt(input.max || '0', 10);";
echo " return Number.isFinite(maxQty) && maxQty >= 0 && getInputValue(input) > maxQty;";
echo " });";
echo " const isValid = totalQty > 0";
echo " && totalPrice > 0";
echo " && !!getFieldValue(orderDateInput)";
@@ -1066,12 +1067,9 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best
echo " && !!getFieldValue(streetInput)";
echo " && !!getFieldValue(houseNumberInput)";
echo " && !!getFieldValue(zipInput)";
echo " && !!getFieldValue(cityInput)";
echo " && overstockInput === undefined;";
echo " && !!getFieldValue(cityInput);";
echo " let errorMsg = '';";
echo " if (overstockInput) {";
echo " errorMsg = 'Menge für ' + overstockInput.dataset.title + ' überschreitet den Lagerbestand.';";
echo " } else if (totalQty === 0) {";
echo " if (totalQty === 0) {";
echo " errorMsg = 'Mindestens ein Produkt mit Menge > 0 erforderlich.';";
echo " } else if (totalPrice <= 0) {";
echo " errorMsg = 'Preis muss größer als 0 sein.';";