added fatturazione avanzata to template and imported

This commit is contained in:
2026-07-02 15:20:55 +02:00
parent 1476160a38
commit bef600ae11
6 changed files with 146 additions and 63 deletions
+18 -22
View File
@@ -23,19 +23,17 @@ if ((int)$stmt->fetchColumn() > 0) {
} }
/** /**
* FIXED FIELDS STANDARD (no UI selection) * FIXED FIELDS STANDARD
* is_manual always 1
* is_visible_import default 1
*/ */
$fixedFields = [ $fixedFields = [
// fixed_field_key, data_type ['ClienteResponsabile', 'INT'],
['ClienteResponsabile', 'INT'], ['ClienteFornitore', 'INT'],
['ClienteFornitore', 'INT'], ['ClienteAnalisi', 'INT'],
['ClienteAnalisi', 'INT'], ['ClienteFatturazione', 'INT'], // ← NUOVO
['MoltiplicatorePrezzo', 'INT'], ['MoltiplicatorePrezzo', 'INT'],
['AnagraficaCertestObject', 'INT'], ['AnagraficaCertestObject', 'INT'],
['AnagraficaCertestService', 'INT'], ['AnagraficaCertestService', 'INT'],
['ConsegnaRichiesta', 'DATE'], ['ConsegnaRichiesta', 'DATE'],
]; ];
@@ -43,12 +41,11 @@ try {
$pdo->beginTransaction(); $pdo->beginTransaction();
$ins = $pdo->prepare(" $ins = $pdo->prepare("
INSERT INTO template_fixed_mapping INSERT INTO template_fixed_mapping
(template_id, fixed_field_key, is_manual, data_type, is_required, default_value, is_visible_import) (template_id, fixed_field_key, is_manual, data_type, is_required, default_value, is_visible_import)
VALUES VALUES
(:template_id, :fixed_field_key, 1, :data_type, 1, NULL, 1) (:template_id, :fixed_field_key, 1, :data_type, 1, NULL, 1)
"); ");
foreach ($fixedFields as $f) { foreach ($fixedFields as $f) {
$ins->execute([ $ins->execute([
@@ -58,16 +55,15 @@ try {
]); ]);
} }
$pdo->commit(); $pdo->commit();
// Return rows (for client render) // Return rows (for client render)
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT id, template_id, fixed_field_key, is_manual, data_type, is_required, default_value, is_visible_import SELECT id, template_id, fixed_field_key, is_manual, data_type, is_required, default_value, is_visible_import
FROM template_fixed_mapping FROM template_fixed_mapping
WHERE template_id = ? WHERE template_id = ?
ORDER BY id ASC ORDER BY id ASC
"); ");
$stmt->execute([$templateId]); $stmt->execute([$templateId]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
+56 -32
View File
@@ -110,6 +110,9 @@
ids.add(String(val)); ids.add(String(val));
} }
} }
if (row.fixedFields && row.fixedFields.ClienteFatturazione) {
ids.add(String(row.fixedFields.ClienteFatturazione));
}
}); });
// Batch resolve via single request per ID // Batch resolve via single request per ID
@@ -156,33 +159,50 @@
return textA.localeCompare(textB, "it", { sensitivity: "base" }); return textA.localeCompare(textB, "it", { sensitivity: "base" });
}); });
} }
// Select2 AJAX config for client selects // Mappa: quale filtro Inattivo applicare per ogni campo cliente
const clientSelect2Config = { const clientFieldTipoMap = {
placeholder: "Search client...", ClienteFornitore: "attivo",
allowClear: true, ClienteAnalisi: "attivo",
width: "100%", ClienteFatturazione: "inattivo",
minimumInputLength: 0,
sorter: sortSelect2ResultsByStart,
dropdownCssClass: "select2-dropdown-smaller",
ajax: {
url: "search_clienti.php",
dataType: "json",
delay: 150,
data: function (params) {
return { q: params.term || "", limit: 20 };
},
processResults: function (data) {
const results = (data.results || []).map((item) => ({
...item,
text: formatClientLabel(item),
}));
return { results: results };
},
cache: true,
},
}; };
// Select2 AJAX config factory for client selects (parametrizzata su "tipo")
function clientSelect2ConfigFor(tipo) {
return {
placeholder: "Search client...",
allowClear: true,
width: "100%",
minimumInputLength: 0,
sorter: sortSelect2ResultsByStart,
dropdownCssClass: "select2-dropdown-smaller",
ajax: {
url: "search_clienti.php",
dataType: "json",
delay: 150,
data: function (params) {
const d = { q: params.term || "", limit: 20 };
if (tipo) d.tipo = tipo;
return d;
},
processResults: function (data) {
const results = (data.results || []).map((item) => ({
...item,
text: formatClientLabel(item),
}));
return { results: results };
},
cache: true,
},
};
}
// Helper: inizializza Select2 su un elemento leggendo il tipo da data-client-tipo
function initClientSelect2(el) {
const tipo = el.dataset.clientTipo || "";
$(el).select2(clientSelect2ConfigFor(tipo));
}
async function loadClientData() { async function loadClientData() {
// No longer loads all clients — AJAX Select2 handles search // No longer loads all clients — AJAX Select2 handles search
// Just resolve names for pre-selected values // Just resolve names for pre-selected values
@@ -215,6 +235,7 @@
getParams: (cid) => ({ id_cliente: cid }), getParams: (cid) => ({ id_cliente: cid }),
}, },
ClienteFornitore: { source: "clients" }, ClienteFornitore: { source: "clients" },
ClienteFatturazione: { source: "clients" },
ClienteAnalisi: { source: "clients" }, ClienteAnalisi: { source: "clients" },
}; };
@@ -536,6 +557,7 @@
sel.className = sel.className =
"cell-input dropdown-select client-select searchable-client fornitore-select"; "cell-input dropdown-select client-select searchable-client fornitore-select";
sel.dataset.currentValue = row.cliente_fornitore_id || ""; sel.dataset.currentValue = row.cliente_fornitore_id || "";
sel.dataset.clientTipo = "attivo";
sel.innerHTML = buildClientOptionsHTML( sel.innerHTML = buildClientOptionsHTML(
row.cliente_fornitore_id, row.cliente_fornitore_id,
); );
@@ -631,12 +653,13 @@
if (config && config.source === "clients") { if (config && config.source === "clients") {
const reqCls = col.isRequired ? " required-input" : ""; const reqCls = col.isRequired ? " required-input" : "";
const req = col.isRequired ? " required" : ""; const req = col.isRequired ? " required" : "";
const tipo = clientFieldTipoMap[col.key] || "";
let opts = '<option value="">Select...</option>'; let opts = '<option value="">Select...</option>';
if (value) { if (value) {
const label = clientNameCache[value] || value; const label = clientNameCache[value] || value;
opts += `<option value="${esc(String(value))}" selected>${esc(String(label))}</option>`; opts += `<option value="${esc(String(value))}" selected>${esc(String(label))}</option>`;
} }
return `<select class="cell-input manual-input fixed-input searchable-client api-fixed-select${reqCls}" data-fixed-key="${escAttr(col.key)}" data-current-value="${escAttr(value)}"${req}>${opts}</select>`; return `<select class="cell-input manual-input fixed-input searchable-client api-fixed-select${reqCls}" data-fixed-key="${escAttr(col.key)}" data-current-value="${escAttr(value)}" data-client-tipo="${escAttr(tipo)}"${req}>${opts}</select>`;
} }
// Select — build from cache // Select — build from cache
@@ -1070,7 +1093,7 @@
`<button type="button" class="propagate-btn" data-column="idclient" data-col-index="${colIdx}"><i class="fas fa-arrow-down"></i></button>`; `<button type="button" class="propagate-btn" data-column="idclient" data-col-index="${colIdx}"><i class="fas fa-arrow-down"></i></button>`;
} else if (col.type === "cliente_fornitore_id") { } else if (col.type === "cliente_fornitore_id") {
cell.innerHTML = cell.innerHTML =
`<select class="custom-field dropdown-select client-select searchable-client" data-column="cliente_fornitore_id" id="clienteFornitoreSelect"><option value="">Select a supplier...</option></select>` + `<select class="custom-field dropdown-select client-select searchable-client" data-column="cliente_fornitore_id" data-client-tipo="attivo" id="clienteFornitoreSelect"><option value="">Select a supplier...</option></select>` +
`<button type="button" class="propagate-btn" data-column="cliente_fornitore_id" data-col-index="${colIdx}"><i class="fas fa-arrow-down"></i></button>`; `<button type="button" class="propagate-btn" data-column="cliente_fornitore_id" data-col-index="${colIdx}"><i class="fas fa-arrow-down"></i></button>`;
} else if (col.type === "fixed" && col.dataType === "DATE") { } else if (col.type === "fixed" && col.dataType === "DATE") {
cell.innerHTML = cell.innerHTML =
@@ -1079,8 +1102,9 @@
} else if (col.type === "fixed") { } else if (col.type === "fixed") {
const isApiField = !!fixedFieldApiConfig[col.key]; const isApiField = !!fixedFieldApiConfig[col.key];
if (isApiField) { if (isApiField) {
const tipo = clientFieldTipoMap[col.key] || "";
cell.innerHTML = cell.innerHTML =
`<select class="custom-field dropdown-select api-fixed-select fixed-top" data-column="fixed_${col.key}" data-fixed-key="${col.key}"><option value="">Seleziona...</option></select>` + `<select class="custom-field dropdown-select api-fixed-select fixed-top" data-column="fixed_${col.key}" data-fixed-key="${col.key}" data-client-tipo="${tipo}"><option value="">Seleziona...</option></select>` +
`<button type="button" class="propagate-btn" data-column="fixed_${col.key}" data-col-index="${colIdx}"><i class="fas fa-arrow-down"></i></button>`; `<button type="button" class="propagate-btn" data-column="fixed_${col.key}" data-col-index="${colIdx}"><i class="fas fa-arrow-down"></i></button>`;
} else { } else {
cell.innerHTML = cell.innerHTML =
@@ -1115,12 +1139,12 @@
const clientSel = document.getElementById("clientSelect"); const clientSel = document.getElementById("clientSelect");
if (clientSel) { if (clientSel) {
clientSel.innerHTML = buildClientOptionsHTML(meta.defaultIdclient); clientSel.innerHTML = buildClientOptionsHTML(meta.defaultIdclient);
$(clientSel).select2(clientSelect2Config); initClientSelect2(clientSel);
} }
const fornitSel = document.getElementById("clienteFornitoreSelect"); const fornitSel = document.getElementById("clienteFornitoreSelect");
if (fornitSel) { if (fornitSel) {
fornitSel.innerHTML = buildClientOptionsHTML(""); fornitSel.innerHTML = buildClientOptionsHTML("");
$(fornitSel).select2(clientSelect2Config); initClientSelect2(fornitSel);
} }
// Fixed field selects in top row // Fixed field selects in top row
@@ -1130,7 +1154,7 @@
// Client-sourced → init as AJAX Select2 // Client-sourced → init as AJAX Select2
if (config && config.source === "clients") { if (config && config.source === "clients") {
$(sel).select2(clientSelect2Config); initClientSelect2(sel);
return; return;
} }
@@ -1583,7 +1607,7 @@
$(this) $(this)
.find(".searchable-client:not(.select2-hidden-accessible)") .find(".searchable-client:not(.select2-hidden-accessible)")
.each(function () { .each(function () {
$(this).select2(clientSelect2Config); initClientSelect2(this);
}); });
$(this) $(this)
.find(".searchable-dropdown:not(.select2-hidden-accessible)") .find(".searchable-dropdown:not(.select2-hidden-accessible)")
+30 -1
View File
@@ -147,6 +147,7 @@ $desiredOrder = [
'ClienteResponsabile', 'ClienteResponsabile',
'ClienteFornitore', 'ClienteFornitore',
'ClienteAnalisi', 'ClienteAnalisi',
'ClienteFatturazione',
'AnagraficaCertestObject', 'AnagraficaCertestObject',
'AnagraficaCertestService', 'AnagraficaCertestService',
'MoltiplicatorePrezzo', 'MoltiplicatorePrezzo',
@@ -181,6 +182,7 @@ $fixedAliasMap = [
'ClienteResponsabile' => 'cliente_responsabile_id', 'ClienteResponsabile' => 'cliente_responsabile_id',
'ClienteFornitore' => 'cliente_fornitore_id', 'ClienteFornitore' => 'cliente_fornitore_id',
'ClienteAnalisi' => 'clienteAnalisi', 'ClienteAnalisi' => 'clienteAnalisi',
'ClienteFatturazione' => 'ClienteFatturazione',
'MoltiplicatorePrezzo' => 'moltiplicatore_prezzo_id', 'MoltiplicatorePrezzo' => 'moltiplicatore_prezzo_id',
'AnagraficaCertestObject' => 'anagrafica_certest_object_id', 'AnagraficaCertestObject' => 'anagrafica_certest_object_id',
'AnagraficaCertestService' => 'anagrafica_certest_service_id', 'AnagraficaCertestService' => 'anagrafica_certest_service_id',
@@ -285,6 +287,21 @@ $gridColumns[] = ['type' => 'idclient', 'key' => 'idclient', 'label' => 'Client'
// 4. Cliente Fornitore // 4. Cliente Fornitore
$gridColumns[] = ['type' => 'cliente_fornitore_id', 'key' => 'cliente_fornitore_id', 'label' => $slugMapping['ClienteFornitore'] ?? 'ClienteFornitore', 'width' => 300]; $gridColumns[] = ['type' => 'cliente_fornitore_id', 'key' => 'cliente_fornitore_id', 'label' => $slugMapping['ClienteFornitore'] ?? 'ClienteFornitore', 'width' => 300];
// 4b. Fatturazione Avanzata — subito dopo Cliente Fornitore
foreach ($fixedFields as $f) {
if ($f['fixed_field_key'] === 'ClienteFatturazione') {
$gridColumns[] = [
'type' => 'fixed',
'key' => 'ClienteFatturazione',
'label' => 'Fatturazione avanzata',
'dataType' => $f['data_type'],
'isRequired' => (bool)$f['is_required'],
'width' => 180,
];
break;
}
}
// 5. Other custom fields in schema order // 5. Other custom fields in schema order
foreach ($allMappings as $mapping) { foreach ($allMappings as $mapping) {
if ( if (
@@ -321,7 +338,18 @@ $gridColumns[] = ['type' => 'tracking', 'key' => 'tracking', 'label' => 'Trackin
// 10. Fixed fields (with importreferencecode/filename/importdate after ConsegnaRichiesta) // 10. Fixed fields (with importreferencecode/filename/importdate after ConsegnaRichiesta)
foreach ($fixedFields as $f) { foreach ($fixedFields as $f) {
$key = $f['fixed_field_key']; $key = $f['fixed_field_key'];
$label = $slugMapping[$key] ?? $key;
if ($key === 'ClienteFatturazione') continue; // già renderizzata al punto 4b
// Cambia solo il titolo della colonna ClienteAnalisi
if ($key === 'ClienteAnalisi') {
$label = 'Buyer';
} elseif ($key === 'ClienteFatturazione') {
$label = 'Fatturazione avanzata';
} else {
$label = $slugMapping[$key] ?? $key;
}
$gridColumns[] = [ $gridColumns[] = [
'type' => 'fixed', 'type' => 'fixed',
'key' => $key, 'key' => $key,
@@ -330,6 +358,7 @@ foreach ($fixedFields as $f) {
'isRequired' => (bool)$f['is_required'], 'isRequired' => (bool)$f['is_required'],
'width' => 180, 'width' => 180,
]; ];
if ($key === 'ConsegnaRichiesta') { if ($key === 'ConsegnaRichiesta') {
$gridColumns[] = ['type' => 'static', 'key' => 'importreferencecode', 'label' => $slugMapping['importreferencecode'] ?? 'Import Reference Code', 'width' => 150, 'editable' => false]; $gridColumns[] = ['type' => 'static', 'key' => 'importreferencecode', 'label' => $slugMapping['importreferencecode'] ?? 'Import Reference Code', 'width' => 150, 'editable' => false];
$gridColumns[] = ['type' => 'static', 'key' => 'filename_import', 'label' => $slugMapping['filename_import'] ?? 'File', 'width' => 150, 'editable' => false]; $gridColumns[] = ['type' => 'static', 'key' => 'filename_import', 'label' => $slugMapping['filename_import'] ?? 'File', 'width' => 150, 'editable' => false];
@@ -627,6 +627,7 @@ $apiSampleJson = $template['api_sample_json'] ?? '';
'ClienteResponsabile', 'ClienteResponsabile',
'ClienteFornitore', 'ClienteFornitore',
'ClienteAnalisi', 'ClienteAnalisi',
'ClienteFatturazione',
'MoltiplicatorePrezzo', 'MoltiplicatorePrezzo',
'AnagraficaCertestObject', 'AnagraficaCertestObject',
'AnagraficaCertestService' 'AnagraficaCertestService'
@@ -2183,11 +2184,11 @@ $apiSampleJson = $template['api_sample_json'] ?? '';
'ClienteResponsabile', 'ClienteResponsabile',
'ClienteFornitore', 'ClienteFornitore',
'ClienteAnalisi', 'ClienteAnalisi',
'ClienteFatturazione', // ← AGGIUNGI QUESTA RIGA
'MoltiplicatorePrezzo', 'MoltiplicatorePrezzo',
'AnagraficaCertestObject', 'AnagraficaCertestObject',
'AnagraficaCertestService' 'AnagraficaCertestService'
]; ];
tbody.innerHTML = rows.map(r => { tbody.innerHTML = rows.map(r => {
const type = String(r.data_type || '').toUpperCase(); const type = String(r.data_type || '').toUpperCase();
const dv = r.default_value ?? ''; const dv = r.default_value ?? '';
@@ -2491,11 +2492,22 @@ $apiSampleJson = $template['api_sample_json'] ?? '';
})).filter(x => x.id != null && x.label); })).filter(x => x.id != null && x.label);
} }
if (key === 'ClienteFornitore' || key === 'ClienteAnalisi') { if (key === 'ClienteFornitore' || key === 'ClienteAnalisi' || key === 'ClienteFatturazione') {
const j = await fetchJson('get_clienti.php'); const j = await fetchJson('get_clienti.php');
const list = normalizeList(j, key); const list = normalizeList(j, key);
return list.map(x => ({ const isInattivo = (x) => {
const v = x.Inattivo;
return v === true || v === 1 || v === '1' || v === 'true';
};
// Fornitore e Analisi: solo clienti ATTIVI (Inattivo = false)
// Fatturazione: solo clienti INATTIVI (Inattivo = true)
const filtered = (key === 'ClienteFatturazione') ?
list.filter(isInattivo) :
list.filter(x => !isInattivo(x));
return filtered.map(x => ({
id: x.IdCliente ?? x.Id ?? x.id, id: x.IdCliente ?? x.Id ?? x.id,
label: formatClientLabel(x) label: formatClientLabel(x)
})).filter(x => x.id != null && x.label); })).filter(x => x.id != null && x.label);
+9 -3
View File
@@ -730,8 +730,8 @@
{ {
"IdSchemaCustomFields": 177, "IdSchemaCustomFields": 177,
"ConteggioClienti": 0, "ConteggioClienti": 0,
"Nome": "Phoebe philo ACC", "Nome": "Phoebe Philo ",
"Descrizione": "(scarpe, borse, cinture, occhiali, gioielleria)\r\n" "Descrizione": "\r\n\r\n"
}, },
{ {
"IdSchemaCustomFields": 178, "IdSchemaCustomFields": 178,
@@ -815,7 +815,7 @@
"IdSchemaCustomFields": 191, "IdSchemaCustomFields": 191,
"ConteggioClienti": 0, "ConteggioClienti": 0,
"Nome": "KIABI", "Nome": "KIABI",
"Descrizione": "Schema per il cliente Kiabi\r\n" "Descrizione": "Schema per il cliente Kiabi\r\n\r\n"
}, },
{ {
"IdSchemaCustomFields": 192, "IdSchemaCustomFields": 192,
@@ -900,6 +900,12 @@
"ConteggioClienti": 0, "ConteggioClienti": 0,
"Nome": "Chanel Flammability", "Nome": "Chanel Flammability",
"Descrizione": "Schema per Chanel Flammability\r\n" "Descrizione": "Schema per Chanel Flammability\r\n"
},
{
"IdSchemaCustomFields": 206,
"ConteggioClienti": 0,
"Nome": "COLDWATER CREEK",
"Descrizione": "\r\n"
} }
] ]
} }
+18 -2
View File
@@ -19,6 +19,14 @@ $q = mb_strtolower(trim($_GET['q'] ?? ''));
$limit = max(1, min(50, intval($_GET['limit'] ?? 20))); $limit = max(1, min(50, intval($_GET['limit'] ?? 20)));
$id = isset($_GET['id']) ? intval($_GET['id']) : null; $id = isset($_GET['id']) ? intval($_GET['id']) : null;
$tipo = $_GET['tipo'] ?? ''; // 'attivo' | 'inattivo' | '' (nessun filtro)
function isInattivo(array $c): bool
{
$v = $c['Inattivo'] ?? false;
return $v === true || $v === 1 || $v === '1' || $v === 'true';
}
function formatClientLabel(array $client): string function formatClientLabel(array $client): string
{ {
$name = trim($client['Nominativo'] ?? ''); $name = trim($client['Nominativo'] ?? '');
@@ -49,7 +57,7 @@ try {
$api = VisualLimsApiClient::getInstance(); $api = VisualLimsApiClient::getInstance();
$params = [ $params = [
'$select' => 'IdCliente,Nominativo,CodiceCliente', '$select' => 'IdCliente,Nominativo,CodiceCliente,Inattivo',
'$orderby' => 'Nominativo asc' '$orderby' => 'Nominativo asc'
]; ];
@@ -64,6 +72,14 @@ try {
$clients = $data['value'] ?? []; $clients = $data['value'] ?? [];
// Filtro tipo, applicato SOLO alla ricerca, non al lookup per id
$searchClients = $clients;
if ($tipo === 'attivo') {
$searchClients = array_values(array_filter($clients, fn($c) => !isInattivo($c)));
} elseif ($tipo === 'inattivo') {
$searchClients = array_values(array_filter($clients, fn($c) => isInattivo($c)));
}
// If requesting by specific ID, used for loading selected value // If requesting by specific ID, used for loading selected value
if ($id !== null) { if ($id !== null) {
foreach ($clients as $c) { foreach ($clients as $c) {
@@ -88,7 +104,7 @@ try {
// Search by query // Search by query
$results = []; $results = [];
foreach ($clients as $c) { foreach ($searchClients as $c) {
$name = trim($c['Nominativo'] ?? ''); $name = trim($c['Nominativo'] ?? '');
$code = trim($c['CodiceCliente'] ?? ''); $code = trim($c['CodiceCliente'] ?? '');