diff --git a/public/userarea/lookup_values.php b/public/userarea/lookup_values.php index 1025711..fd1cd02 100644 --- a/public/userarea/lookup_values.php +++ b/public/userarea/lookup_values.php @@ -496,14 +496,41 @@ function h($v) } }); - // Select2 for category filter + modal selects - $('#categoryFilter, #add_category, #edit_category').select2({ + // Select2 solo per il filtro categoria (fuori dai modali) + $('#categoryFilter').select2({ theme: 'bootstrap4', width: '100%', placeholder: '-- Seleziona --', allowClear: true }); + // Select2 per il modale ADD: inizializza quando il modale è visibile + // e aggancia il dropdown dentro il modale (altrimenti le opzioni non si vedono) + $('#addModal').on('shown.bs.modal', function() { + if (!$('#add_category').data('select2')) { + $('#add_category').select2({ + theme: 'bootstrap4', + width: '100%', + placeholder: '-- Seleziona --', + allowClear: true, + dropdownParent: $('#addModal') + }); + } + }); + + // Select2 per il modale EDIT: stessa logica + $('#editModal').on('shown.bs.modal', function() { + if (!$('#edit_category').data('select2')) { + $('#edit_category').select2({ + theme: 'bootstrap4', + width: '100%', + placeholder: '-- Seleziona --', + allowClear: true, + dropdownParent: $('#editModal') + }); + } + }); + // Filter redirect $('#categoryFilter').on('change', function() { const v = $(this).val() || ''; diff --git a/public/userarea/manage-worksheet.php b/public/userarea/manage-worksheet.php index 3eaa1e7..ea5e554 100644 --- a/public/userarea/manage-worksheet.php +++ b/public/userarea/manage-worksheet.php @@ -365,18 +365,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) { } } -// Load packaging items from dedicated table -$packagingLookup = [ - 'PACKAGING_TYPE' => [], - 'BOX' => [], - 'PALLET' => [] -]; +// Load ALL packaging items (tutte le categorie, distinct via GROUP nel dropdown) +$packagingByCategory = []; // categoria => [ {value, label}, ... ] $stmt = $pdo->prepare(" - SELECT category, item_name, item_code + SELECT id, category, item_name, item_code FROM packaging_items WHERE is_active = 1 - AND category IN ('PACKAGING_TYPE', 'BOX', 'PALLET') ORDER BY category ASC, item_name ASC "); $stmt->execute(); @@ -387,12 +382,20 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) { $label .= ' — ' . $r['item_code']; } - $packagingLookup[$r['category']][] = [ - 'value' => $r['item_code'], + $packagingByCategory[$r['category']][] = [ + 'value' => (int)$r['id'], // salviamo l'ID 'label' => $label ]; } +// Elenco categorie distinte (per il primo dropdown) +$packagingCategories = array_keys($packagingByCategory); +sort($packagingCategories); + +// Questi verranno calcolati DOPO il caricamento del worksheet +$savedPackageCode = ''; +$savedPackageCategory = ''; + // Load mescole dropdown for modal $mescole = $pdo->query(" SELECT id, nome, nomeuscita @@ -432,6 +435,19 @@ if ($worksheet_id > 0) { } } +// Ora che $worksheet è caricato, ricava categoria + codice salvati per l'imballo +$savedPackageCode = $worksheet['requested_package_code'] ?? ''; +if ($savedPackageCode !== '' && $savedPackageCode !== null) { + foreach ($packagingByCategory as $cat => $items) { + foreach ($items as $it) { + if ((string)$it['value'] === (string)$savedPackageCode) { + $savedPackageCategory = $cat; + break 2; + } + } + } +} + // Helpers function h($v) { @@ -1045,14 +1061,28 @@ $isEdit = ($worksheet_id > 0);
Packaging
-
Compila prima la confezione, poi eventuali dettagli di scatola e bancale
+
Seleziona prima la categoria, poi lo specifico elemento di imballo
- - + + + + +
Es. PACKAGING_TYPE, BOX, PALLET…
+
+ +
+ + +
Il valore salvato è il codice dell'elemento
@@ -1074,13 +1104,6 @@ $isEdit = ($worksheet_id > 0); value="">
-
- - -
-
0); value="">
-
- - -
-
0); }); } + // ---- Imballo: categoria -> elemento filtrato ---- + const packagingData = ; + const savedPackageCode = ; + + function fillPackagingItems(category, selectedValue) { + const $items = $('#requested_package_code'); + $items.empty(); + + if (!category || !packagingData[category]) { + $items.append(''); + return; + } + + $items.append(''); + packagingData[category].forEach(function(it) { + const sel = (String(it.value) === String(selectedValue)) ? ' selected' : ''; + $items.append(''); + }); + } + + // Al cambio categoria, ricarica gli elementi (svuota selezione) + $('#packaging_category').on('change', function() { + fillPackagingItems($(this).val(), ''); + }); + + // Popola all'avvio se in modifica c'è già una categoria selezionata + // Usiamo il valore direttamente dal PHP, non dal .val() del select + const initialCat = ; + if (initialCat) { + $('#packaging_category').val(initialCat); + fillPackagingItems(initialCat, savedPackageCode); + } + $('#mixModal').on('shown.bs.modal', function() { if (!$('#idmescola').data('select2')) { $('#idmescola').select2({ diff --git a/public/userarea/packaging_items.php b/public/userarea/packaging_items.php index e95778f..f7f5bc7 100644 --- a/public/userarea/packaging_items.php +++ b/public/userarea/packaging_items.php @@ -272,6 +272,13 @@ {$qtyTot} {$badge} +
+ +