added clienti in template, export
This commit is contained in:
@@ -414,6 +414,8 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
|
||||
<?php elseif (in_array($fm['fixed_field_key'], [
|
||||
'ClienteResponsabile',
|
||||
'ClienteFornitore',
|
||||
'ClienteAnalisi',
|
||||
'MoltiplicatorePrezzo',
|
||||
'AnagraficaCertestObject',
|
||||
'AnagraficaCertestService'
|
||||
@@ -1230,6 +1232,8 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
|
||||
const keysWithDropdown = [
|
||||
'ClienteResponsabile',
|
||||
'ClienteFornitore',
|
||||
'ClienteAnalisi',
|
||||
'MoltiplicatorePrezzo',
|
||||
'AnagraficaCertestObject',
|
||||
'AnagraficaCertestService'
|
||||
@@ -1443,15 +1447,25 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
|
||||
const clientId = <?php echo (int)($template['idclient'] ?? 0); ?>;
|
||||
|
||||
const requestCache = {};
|
||||
|
||||
async function fetchJson(url) {
|
||||
const r = await fetch(url);
|
||||
const text = await r.text();
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status} on ${url}: ${text.slice(0, 200)}`);
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (e) {
|
||||
throw new Error(`Invalid JSON from ${url}: ${text.slice(0, 200)}`);
|
||||
if (requestCache[url]) {
|
||||
return requestCache[url];
|
||||
}
|
||||
|
||||
requestCache[url] = (async () => {
|
||||
const r = await fetch(url);
|
||||
const text = await r.text();
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status} on ${url}: ${text.slice(0, 200)}`);
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (e) {
|
||||
throw new Error(`Invalid JSON from ${url}: ${text.slice(0, 200)}`);
|
||||
}
|
||||
})();
|
||||
|
||||
return requestCache[url];
|
||||
}
|
||||
|
||||
function normalizeList(j, key) {
|
||||
@@ -1465,6 +1479,16 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
return [];
|
||||
}
|
||||
|
||||
function formatClientLabel(x) {
|
||||
const nome = x.Nominativo ?? x.Nome ?? x.name ?? 'Nome non disponibile';
|
||||
const id = x.IdCliente ?? x.Id ?? x.id ?? '';
|
||||
const codiceCliente = (x.CodiceCliente ?? x.codiceCliente ?? '').toString().trim();
|
||||
const suffix = (codiceCliente.split('_')[1] || '').trim();
|
||||
const shortCode = suffix || (codiceCliente ? codiceCliente.charAt(0) : '--');
|
||||
|
||||
return `${nome.trim()} - ${shortCode} (ID: ${id})`;
|
||||
}
|
||||
|
||||
async function loadData(key) {
|
||||
if (key === 'MoltiplicatorePrezzo') {
|
||||
const j = await fetchJson('get_moltiplicatoreprezzo.php');
|
||||
@@ -1507,6 +1531,16 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
|
||||
})).filter(x => x.id != null && x.label);
|
||||
}
|
||||
|
||||
if (key === 'ClienteFornitore' || key === 'ClienteAnalisi') {
|
||||
const j = await fetchJson('get_clienti.php');
|
||||
const list = normalizeList(j, key);
|
||||
|
||||
return list.map(x => ({
|
||||
id: x.IdCliente ?? x.Id ?? x.id,
|
||||
label: formatClientLabel(x)
|
||||
})).filter(x => x.id != null && x.label);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user