From 48387a994523e5ecd5c7b79839bddb55b7cbe9b4 Mon Sep 17 00:00:00 2001 From: "r.mubarakzyanov" Date: Tue, 17 Mar 2026 15:43:12 +0300 Subject: [PATCH] cliente fornitore --- public/userarea/import_edit2.php | 129 +++++++++++++++++++++++----- public/userarea/save_edited_row.php | 7 ++ 2 files changed, 114 insertions(+), 22 deletions(-) diff --git a/public/userarea/import_edit2.php b/public/userarea/import_edit2.php index a1d041d..3b3217d 100644 --- a/public/userarea/import_edit2.php +++ b/public/userarea/import_edit2.php @@ -174,9 +174,13 @@ $desiredOrder = [ // se ci sono altri campi fixed li mettiamo dopo ]; +// ClienteFornitore is rendered as a standalone column (like idclient), skip it in fixed fields +$excludeFromFixed = ['ClienteFornitore']; + $fixedFields = []; $tempMap = []; foreach ($fixedFieldsRaw as $f) { + if (in_array($f['fixed_field_key'], $excludeFromFixed, true)) continue; $tempMap[$f['fixed_field_key']] = $f; } @@ -946,17 +950,24 @@ function fixedDefaultValue(array $f): string $topColIndex = $mainFieldMapping ? 2 : 1; ?> -
+
+ +
-
+
+ + +
-
Client
+
Status
-
Status
+
Client
+
+
Cliente Fornitore
" . htmlspecialchars($mapping['field_label']) . "
"; @@ -1211,12 +1224,7 @@ function fixedDefaultValue(array $f): string
-
- -
-
+
@@ -1225,8 +1233,18 @@ function fixedDefaultValue(array $f): string
+
+ +
+
+ +
$d['datadb_id'] == $row['iddatadb']); $autoIndex = 0; foreach ($allMappings as $mapping) { @@ -1544,6 +1562,11 @@ function fixedDefaultValue(array $f): string formData.append('idclient', idclientSelect.value); } + const fornitoreSelect = row.querySelector(`select[name="rows[${rowIndex}][cliente_fornitore_id]"]`); + if (fornitoreSelect) { + formData.append('cliente_fornitore_id', fornitoreSelect.value); + } + // ---- FIXED FIELDS (NEW) ---- const fixedInputs = row.querySelectorAll(`input[name^="rows[${rowIndex}]["], select[name^="rows[${rowIndex}]["]`); fixedInputs.forEach(inp => { @@ -1689,6 +1712,10 @@ function fixedDefaultValue(array $f): string if (idclientSelect) { formData.append('idclient', idclientSelect.value); } + const fornitoreSelect = row.querySelector(`select[name="rows[${rowIndex}][cliente_fornitore_id]"]`); + if (fornitoreSelect) { + formData.append('cliente_fornitore_id', fornitoreSelect.value); + } // ---- FIXED FIELDS ---- const fixedInputs = row.querySelectorAll(`input[name^="rows[${rowIndex}]["], select[name^="rows[${rowIndex}]["]`); fixedInputs.forEach(inp => { @@ -1856,6 +1883,7 @@ function fixedDefaultValue(array $f): string }); populateClientDropdowns(); + populateFornitoreDropdowns(); clientLoadingStatus.textContent = "Clienti caricati."; // ✅ force refresh of header dependent fixed fields $('#clientSelect').trigger('change'); @@ -1908,6 +1936,45 @@ function fixedDefaultValue(array $f): string }); } + // Funzione per popolare i dropdown ClienteFornitore (header + rows) + function populateFornitoreDropdowns() { + // Header + const headerSelect = document.getElementById("clienteFornitoreSelect"); + if (headerSelect) { + headerSelect.innerHTML = ''; + clientData.forEach(client => { + const nome = client.Nominativo || "Nome non disponibile"; + const id = client.IdCliente || "ID non disponibile"; + const codiceCliente = (client.CodiceCliente || '').toString().trim(); + const suffix = (codiceCliente.split('_')[1] || '').trim(); + const shortCode = suffix || (codiceCliente ? codiceCliente.charAt(0) : '--'); + headerSelect.add(new Option(`${nome.trim()} - ${shortCode} (ID: ${id})`, id)); + }); + } + + // Row dropdowns + const fornitoreDropdowns = document.querySelectorAll('select[name^="rows"][name$="[cliente_fornitore_id]"]'); + fornitoreDropdowns.forEach(dropdown => { + const currentValue = dropdown.getAttribute('data-current-value') || ''; + dropdown.innerHTML = ''; + clientData.forEach(client => { + const nome = client.Nominativo || "Nome non disponibile"; + const id = client.IdCliente || "ID non disponibile"; + const codiceCliente = (client.CodiceCliente || '').toString().trim(); + const suffix = (codiceCliente.split('_')[1] || '').trim(); + const shortCode = suffix || (codiceCliente ? codiceCliente.charAt(0) : '--'); + const option = new Option(`${nome.trim()} - ${shortCode} (ID: ${id})`, id); + if (String(id) === String(currentValue)) { + option.selected = true; + } + dropdown.add(option); + }); + if (currentValue) { + dropdown.value = currentValue; + } + }); + } + // Carica i client all'avvio loadClients(); @@ -2381,6 +2448,13 @@ function fixedDefaultValue(array $f): string }); gridCell.dispatchEvent(event); } + if (e.target.matches('select[name^="rows"][name$="[cliente_fornitore_id]"]')) { + const gridCell = e.target.closest('.grid-cell'); + const event = new Event('change', { + bubbles: true + }); + gridCell.dispatchEvent(event); + } }); }); @@ -2397,11 +2471,10 @@ function fixedDefaultValue(array $f): string // Ensure Select2 dropdowns trigger change events for unsaved changes tracking $('.searchable-client').on('select2:select select2:clear', function(e) { - const gridCell = this.closest('.grid-cell'); - const event = new Event('change', { - bubbles: true - }); - gridCell.dispatchEvent(event); + // Trigger native change on the real