added fatturazione avanzata to template and imported
This commit is contained in:
@@ -110,6 +110,9 @@
|
||||
ids.add(String(val));
|
||||
}
|
||||
}
|
||||
if (row.fixedFields && row.fixedFields.ClienteFatturazione) {
|
||||
ids.add(String(row.fixedFields.ClienteFatturazione));
|
||||
}
|
||||
});
|
||||
|
||||
// Batch resolve via single request per ID
|
||||
@@ -156,33 +159,50 @@
|
||||
return textA.localeCompare(textB, "it", { sensitivity: "base" });
|
||||
});
|
||||
}
|
||||
// Select2 AJAX config for client selects
|
||||
const clientSelect2Config = {
|
||||
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) {
|
||||
return { q: params.term || "", limit: 20 };
|
||||
},
|
||||
processResults: function (data) {
|
||||
const results = (data.results || []).map((item) => ({
|
||||
...item,
|
||||
text: formatClientLabel(item),
|
||||
}));
|
||||
|
||||
return { results: results };
|
||||
},
|
||||
cache: true,
|
||||
},
|
||||
// Mappa: quale filtro Inattivo applicare per ogni campo cliente
|
||||
const clientFieldTipoMap = {
|
||||
ClienteFornitore: "attivo",
|
||||
ClienteAnalisi: "attivo",
|
||||
ClienteFatturazione: "inattivo",
|
||||
};
|
||||
|
||||
// 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() {
|
||||
// No longer loads all clients — AJAX Select2 handles search
|
||||
// Just resolve names for pre-selected values
|
||||
@@ -215,6 +235,7 @@
|
||||
getParams: (cid) => ({ id_cliente: cid }),
|
||||
},
|
||||
ClienteFornitore: { source: "clients" },
|
||||
ClienteFatturazione: { source: "clients" },
|
||||
ClienteAnalisi: { source: "clients" },
|
||||
};
|
||||
|
||||
@@ -536,6 +557,7 @@
|
||||
sel.className =
|
||||
"cell-input dropdown-select client-select searchable-client fornitore-select";
|
||||
sel.dataset.currentValue = row.cliente_fornitore_id || "";
|
||||
sel.dataset.clientTipo = "attivo";
|
||||
sel.innerHTML = buildClientOptionsHTML(
|
||||
row.cliente_fornitore_id,
|
||||
);
|
||||
@@ -631,12 +653,13 @@
|
||||
if (config && config.source === "clients") {
|
||||
const reqCls = col.isRequired ? " required-input" : "";
|
||||
const req = col.isRequired ? " required" : "";
|
||||
const tipo = clientFieldTipoMap[col.key] || "";
|
||||
let opts = '<option value="">Select...</option>';
|
||||
if (value) {
|
||||
const label = clientNameCache[value] || value;
|
||||
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
|
||||
@@ -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>`;
|
||||
} else if (col.type === "cliente_fornitore_id") {
|
||||
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>`;
|
||||
} else if (col.type === "fixed" && col.dataType === "DATE") {
|
||||
cell.innerHTML =
|
||||
@@ -1079,8 +1102,9 @@
|
||||
} else if (col.type === "fixed") {
|
||||
const isApiField = !!fixedFieldApiConfig[col.key];
|
||||
if (isApiField) {
|
||||
const tipo = clientFieldTipoMap[col.key] || "";
|
||||
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>`;
|
||||
} else {
|
||||
cell.innerHTML =
|
||||
@@ -1115,12 +1139,12 @@
|
||||
const clientSel = document.getElementById("clientSelect");
|
||||
if (clientSel) {
|
||||
clientSel.innerHTML = buildClientOptionsHTML(meta.defaultIdclient);
|
||||
$(clientSel).select2(clientSelect2Config);
|
||||
initClientSelect2(clientSel);
|
||||
}
|
||||
const fornitSel = document.getElementById("clienteFornitoreSelect");
|
||||
if (fornitSel) {
|
||||
fornitSel.innerHTML = buildClientOptionsHTML("");
|
||||
$(fornitSel).select2(clientSelect2Config);
|
||||
initClientSelect2(fornitSel);
|
||||
}
|
||||
|
||||
// Fixed field selects in top row
|
||||
@@ -1130,7 +1154,7 @@
|
||||
|
||||
// Client-sourced → init as AJAX Select2
|
||||
if (config && config.source === "clients") {
|
||||
$(sel).select2(clientSelect2Config);
|
||||
initClientSelect2(sel);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1583,7 +1607,7 @@
|
||||
$(this)
|
||||
.find(".searchable-client:not(.select2-hidden-accessible)")
|
||||
.each(function () {
|
||||
$(this).select2(clientSelect2Config);
|
||||
initClientSelect2(this);
|
||||
});
|
||||
$(this)
|
||||
.find(".searchable-dropdown:not(.select2-hidden-accessible)")
|
||||
|
||||
Reference in New Issue
Block a user