Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae78bf0393 | ||
|
|
65f02b9212 | ||
|
|
e6c8549cea | ||
|
|
9a0770391e | ||
|
|
ea33db6c48 | ||
|
|
764cdade18 | ||
|
|
1293bcf4fd | ||
|
|
76f4a8e291 | ||
|
|
233a1b3678 | ||
|
|
65608712ad | ||
|
|
6a7a56cd0f |
@@ -43,6 +43,7 @@ class VisualLimsApiClient
|
|||||||
{
|
{
|
||||||
$ch = curl_init("{$this->baseUrl}/api/authentication/authenticate");
|
$ch = curl_init("{$this->baseUrl}/api/authentication/authenticate");
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'VisualLims-Client/1.0');
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
||||||
'Username' => $this->username,
|
'Username' => $this->username,
|
||||||
@@ -105,6 +106,7 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'VisualLims-Client/1.0');
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
"Authorization: Bearer {$token}",
|
"Authorization: Bearer {$token}",
|
||||||
"Accept: application/json"
|
"Accept: application/json"
|
||||||
@@ -144,6 +146,7 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'VisualLims-Client/1.0');
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
@@ -177,6 +180,7 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'VisualLims-Client/1.0');
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
@@ -225,6 +229,7 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'VisualLims-Client/1.0');
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
@@ -268,6 +273,7 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'VisualLims-Client/1.0');
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
"Authorization: Bearer {$token}",
|
"Authorization: Bearer {$token}",
|
||||||
"Accept: */*"
|
"Accept: */*"
|
||||||
|
|||||||
@@ -120,4 +120,4 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controllo blocco cliente.
|
||||||
|
*
|
||||||
|
* Il cliente usa il campo CodiceASL dell'anagrafica LIMS come nota di blocco
|
||||||
|
* (es. "BLOCCO PER PAGAMENTO"), perché i campi nativi del Blocco Accettazione
|
||||||
|
* non sono esposti dall'API.
|
||||||
|
*
|
||||||
|
* Regola: se è indicato il cliente di Fatturazione avanzata si controlla quello,
|
||||||
|
* altrimenti il Client.
|
||||||
|
*
|
||||||
|
* NESSUNA chiamata API: legge solo il file di cache scritto da get_clienti.php
|
||||||
|
* (cache/clienti.json), con la sua durata già esistente. Se il file non c'è,
|
||||||
|
* il controllo viene saltato.
|
||||||
|
*
|
||||||
|
* Restituisce null se non c'è blocco o se il controllo non è possibile:
|
||||||
|
* è solo un avviso e non deve mai far fallire l'export o la mail.
|
||||||
|
*/
|
||||||
|
if (!function_exists('getClientBlockAlert')) {
|
||||||
|
function getClientBlockAlert($clienteId, $clienteFatturazione = null): ?array
|
||||||
|
{
|
||||||
|
// Mappa IdCliente => [Nominativo, CodiceASL], letta una sola volta per richiesta
|
||||||
|
static $clienti = null;
|
||||||
|
|
||||||
|
$useFatturazione = !empty($clienteFatturazione);
|
||||||
|
$targetId = $useFatturazione ? (int) $clienteFatturazione : (int) $clienteId;
|
||||||
|
|
||||||
|
if ($targetId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($clienti === null) {
|
||||||
|
$clienti = [];
|
||||||
|
$cacheFile = dirname(__DIR__) . '/cache/clienti.json';
|
||||||
|
|
||||||
|
if (!is_file($cacheFile)) {
|
||||||
|
error_log("getClientBlockAlert: cache clienti non trovata ({$cacheFile}), controllo saltato");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = json_decode((string) file_get_contents($cacheFile), true);
|
||||||
|
foreach (($json['value'] ?? []) as $c) {
|
||||||
|
$clienti[(int) ($c['IdCliente'] ?? 0)] = [
|
||||||
|
'nominativo' => trim((string) ($c['Nominativo'] ?? '')),
|
||||||
|
'codiceASL' => trim((string) ($c['CodiceASL'] ?? '')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cliente = $clienti[$targetId] ?? null;
|
||||||
|
if (!$cliente) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$motivo = $cliente['codiceASL'];
|
||||||
|
if ($motivo === '' || stripos($motivo, 'blocco') === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'idCliente' => $targetId,
|
||||||
|
'nominativo' => $cliente['nominativo'],
|
||||||
|
'motivo' => $motivo,
|
||||||
|
'campo' => $useFatturazione ? 'Fatturazione avanzata' : 'Client',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,7 +69,7 @@ try {
|
|||||||
|
|
||||||
$stmtLoadAnalyses = $pdo->prepare("
|
$stmtLoadAnalyses = $pdo->prepare("
|
||||||
SELECT idmatrice, analysis_recordkey, analysis_name, analysis_method,
|
SELECT idmatrice, analysis_recordkey, analysis_name, analysis_method,
|
||||||
analysis_level, is_web_selectable, is_accredited
|
analysis_level, analysis_price, is_web_selectable, is_accredited
|
||||||
FROM identification_parts_analyses
|
FROM identification_parts_analyses
|
||||||
WHERE part_id = ?
|
WHERE part_id = ?
|
||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
@@ -78,10 +78,10 @@ try {
|
|||||||
$stmtInsertAnalysis = $pdo->prepare("
|
$stmtInsertAnalysis = $pdo->prepare("
|
||||||
INSERT INTO identification_parts_analyses
|
INSERT INTO identification_parts_analyses
|
||||||
(part_id, iddatadb, idmatrice, analysis_recordkey, analysis_name, analysis_method,
|
(part_id, iddatadb, idmatrice, analysis_recordkey, analysis_name, analysis_method,
|
||||||
analysis_level, is_web_selectable, is_accredited, created_at, updated_at)
|
analysis_level, analysis_price, is_web_selectable, is_accredited, created_at, updated_at)
|
||||||
VALUES
|
VALUES
|
||||||
(:part_id, :iddatadb, :idmatrice, :analysis_recordkey, :analysis_name, :analysis_method,
|
(:part_id, :iddatadb, :idmatrice, :analysis_recordkey, :analysis_name, :analysis_method,
|
||||||
:analysis_level, :is_web_selectable, :is_accredited, NOW(), NOW())
|
:analysis_level, :analysis_price, :is_web_selectable, :is_accredited, NOW(), NOW())
|
||||||
");
|
");
|
||||||
|
|
||||||
$stmtInsertCF = $pdo->prepare("
|
$stmtInsertCF = $pdo->prepare("
|
||||||
@@ -161,6 +161,7 @@ try {
|
|||||||
':analysis_name' => $an['analysis_name'] ?? null,
|
':analysis_name' => $an['analysis_name'] ?? null,
|
||||||
':analysis_method' => $an['analysis_method'] ?? null,
|
':analysis_method' => $an['analysis_method'] ?? null,
|
||||||
':analysis_level' => ($an['analysis_level'] !== null && $an['analysis_level'] !== '') ? (int)$an['analysis_level'] : null,
|
':analysis_level' => ($an['analysis_level'] !== null && $an['analysis_level'] !== '') ? (int)$an['analysis_level'] : null,
|
||||||
|
':analysis_price' => ($an['analysis_price'] !== null && $an['analysis_price'] !== '') ? $an['analysis_price'] : null,
|
||||||
':is_web_selectable' => (int)($an['is_web_selectable'] ?? 0),
|
':is_web_selectable' => (int)($an['is_web_selectable'] ?? 0),
|
||||||
':is_accredited' => (int)($an['is_accredited'] ?? 0),
|
':is_accredited' => (int)($an['is_accredited'] ?? 0),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -146,6 +146,10 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
background: #fd7e14;
|
background: #fd7e14;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-delete {
|
||||||
|
background: #dc3545;
|
||||||
|
}
|
||||||
|
|
||||||
.pager-bar {
|
.pager-bar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -232,7 +236,7 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<table class="err-table">
|
<table class="err-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width:170px;">Azioni</th>
|
<th style="width:210px;">Azioni</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Client</th>
|
<th>Client</th>
|
||||||
<th>Errore</th>
|
<th>Errore</th>
|
||||||
@@ -250,6 +254,7 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<a href="download_logs.php?iddatadb=<?= (int)$row['iddatadb'] ?>" class="action-btn btn-log" title="Scarica log"><i class="fas fa-file-download"></i></a>
|
<a href="download_logs.php?iddatadb=<?= (int)$row['iddatadb'] ?>" class="action-btn btn-log" title="Scarica log"><i class="fas fa-file-download"></i></a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<button type="button" class="action-btn btn-revert revert-btn" data-iddatadb="<?= (int)$row['iddatadb'] ?>" title="Riporta a Imported"><i class="fas fa-rotate-left"></i></button>
|
<button type="button" class="action-btn btn-revert revert-btn" data-iddatadb="<?= (int)$row['iddatadb'] ?>" title="Riporta a Imported"><i class="fas fa-rotate-left"></i></button>
|
||||||
|
<button type="button" class="action-btn btn-delete delete-btn" data-iddatadb="<?= (int)$row['iddatadb'] ?>" title="Elimina record"><i class="fas fa-trash"></i></button>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="status-badge status-x">Error</span>
|
<span class="status-badge status-x">Error</span>
|
||||||
@@ -297,11 +302,12 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Reinvia: richiama export_to_lims.php da capo (create incluso)
|
// Reinvia: richiama export_to_lims.php. Se la commessa era già stata creata,
|
||||||
|
// il CHECK PRELIMINARE la verifica nel LIMS e non ne crea una seconda.
|
||||||
$(document).on('click', '.resend-btn', function() {
|
$(document).on('click', '.resend-btn', function() {
|
||||||
const $btn = $(this);
|
const $btn = $(this);
|
||||||
const iddatadb = $btn.data('iddatadb');
|
const iddatadb = $btn.data('iddatadb');
|
||||||
if (!confirm('Reinviare questa commessa al LIMS? Verrà creata una nuova commessa nel LIMS.')) return;
|
if (!confirm('Reinviare questa commessa al LIMS? Se risulta già nel LIMS verrà solo riallineata, altrimenti ne verrà creata una nuova.')) return;
|
||||||
|
|
||||||
const original = $btn.html();
|
const original = $btn.html();
|
||||||
$btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i>');
|
$btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i>');
|
||||||
@@ -330,6 +336,39 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Elimina record
|
||||||
|
$(document).on('click', '.delete-btn', function() {
|
||||||
|
const $btn = $(this);
|
||||||
|
const iddatadb = $btn.data('iddatadb');
|
||||||
|
if (!confirm('Eliminare definitivamente questo record? L\'operazione non è reversibile.')) return;
|
||||||
|
|
||||||
|
const original = $btn.html();
|
||||||
|
$btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i>');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'revert_status.php',
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
iddatadb: iddatadb,
|
||||||
|
action: 'delete'
|
||||||
|
},
|
||||||
|
success: function(res) {
|
||||||
|
if (res && res.success) {
|
||||||
|
const $tr = $('tr[data-id="' + iddatadb + '"]');
|
||||||
|
$tr.fadeOut(300, () => $tr.remove());
|
||||||
|
} else {
|
||||||
|
alert('Errore: ' + ((res && res.message) ? res.message : 'cancellazione non riuscita'));
|
||||||
|
$btn.prop('disabled', false).html(original);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('Errore di rete.');
|
||||||
|
$btn.prop('disabled', false).html(original);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Revert a Imported (i)
|
// Revert a Imported (i)
|
||||||
$(document).on('click', '.revert-btn', function() {
|
$(document).on('click', '.revert-btn', function() {
|
||||||
const $btn = $(this);
|
const $btn = $(this);
|
||||||
|
|||||||
@@ -42,6 +42,23 @@
|
|||||||
}
|
}
|
||||||
window.noPriceBadgeHTML = noPriceBadgeHTML;
|
window.noPriceBadgeHTML = noPriceBadgeHTML;
|
||||||
|
|
||||||
|
// Riquadro "cliente bloccato" per la finestra di export singolo
|
||||||
|
function blockAlertHTML(b) {
|
||||||
|
if (!b || !b.motivo) return "";
|
||||||
|
return (
|
||||||
|
`<div class="alert alert-danger py-2 px-3 mt-3 mb-0 small">` +
|
||||||
|
`<i class="fas fa-ban me-1"></i><strong>Cliente bloccato</strong> (${escHtml(b.campo)}): ` +
|
||||||
|
`${escHtml(b.nominativo)} - ${escHtml(b.idCliente)}<br>` +
|
||||||
|
`<strong>${escHtml(b.motivo)}</strong></div>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Badge "Bloccato" per l'elenco commesse dell'Export All
|
||||||
|
function blockBadgeHTML(b) {
|
||||||
|
if (!b || !b.motivo) return "";
|
||||||
|
return `<span class="badge" title="${escHtml(b.nominativo + ": " + b.motivo)}" style="margin-left:6px; font-size:0.85em; cursor:help; vertical-align:middle; background:#f8d7da; color:#842029;"><i class="fas fa-ban"></i> Bloccato</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
function getGridRow(iddatadb) {
|
function getGridRow(iddatadb) {
|
||||||
return document.querySelector(`.grid-row[data-id="${iddatadb}"]`);
|
return document.querySelector(`.grid-row[data-id="${iddatadb}"]`);
|
||||||
}
|
}
|
||||||
@@ -169,15 +186,28 @@
|
|||||||
formData.append("iddatadb", iddatadb);
|
formData.append("iddatadb", iddatadb);
|
||||||
if (batchUuid) formData.append("batch_uuid", batchUuid);
|
if (batchUuid) formData.append("batch_uuid", batchUuid);
|
||||||
|
|
||||||
const response = await fetch("export_to_lims.php", {
|
// Marca la riga come "in export" nei dati: se il grid virtuale la ri-renderizza
|
||||||
method: "POST",
|
// durante l'attesa, il pulsante Export resta disabilitato.
|
||||||
body: formData,
|
const startIdx = getRowIndexByIddatadb(iddatadb);
|
||||||
});
|
if (startIdx >= 0) window.gridData[startIdx]._exporting = true;
|
||||||
if (!response.ok)
|
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
if (data.success) {
|
let data;
|
||||||
|
try {
|
||||||
|
const response = await fetch("export_to_lims.php", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
if (!response.ok)
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
data = await response.json();
|
||||||
|
} finally {
|
||||||
|
const endIdx = getRowIndexByIddatadb(iddatadb);
|
||||||
|
if (endIdx >= 0) delete window.gridData[endIdx]._exporting;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rifiutato perché la riga risulta già esportata (pagina non aggiornata):
|
||||||
|
// allinea la griglia allo stato reale invece di lasciarla esportabile.
|
||||||
|
if (data.success || (data.rejected && data.status === "l")) {
|
||||||
// Update gridData
|
// Update gridData
|
||||||
const idx = getRowIndexByIddatadb(iddatadb);
|
const idx = getRowIndexByIddatadb(iddatadb);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
@@ -254,7 +284,8 @@
|
|||||||
.map((n) => `<li>${escHtml(n)}</li>`)
|
.map((n) => `<li>${escHtml(n)}</li>`)
|
||||||
.join("") +
|
.join("") +
|
||||||
`</ul>`
|
`</ul>`
|
||||||
: "");
|
: "") +
|
||||||
|
blockAlertHTML(data.blockAlert);
|
||||||
label.textContent = "Esportazione Completata";
|
label.textContent = "Esportazione Completata";
|
||||||
} else {
|
} else {
|
||||||
msg.textContent = `Errore: ${data.message}`;
|
msg.textContent = `Errore: ${data.message}`;
|
||||||
@@ -444,8 +475,9 @@
|
|||||||
data.message || "Unknown error",
|
data.message || "Unknown error",
|
||||||
);
|
);
|
||||||
showExportResult(data);
|
showExportResult(data);
|
||||||
// Mail di riepilogo per la singola commessa
|
// Mail di riepilogo per la singola commessa (non per un export rifiutato:
|
||||||
sendExportSummaryMail([iddatadb]);
|
// non è stato inviato nulla e la riga può risultare già 'l')
|
||||||
|
if (!data.rejected) sendExportSummaryMail([iddatadb]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (gridRow) {
|
if (gridRow) {
|
||||||
setRowExporting(gridRow, false);
|
setRowExporting(gridRow, false);
|
||||||
@@ -453,6 +485,9 @@
|
|||||||
}
|
}
|
||||||
showRowError(gridRow, iddatadb, error.message);
|
showRowError(gridRow, iddatadb, error.message);
|
||||||
showExportResult({ success: false, message: error.message });
|
showExportResult({ success: false, message: error.message });
|
||||||
|
// Timeout/errore di rete: il server può aver completato lo stesso.
|
||||||
|
// La mail riporta lo stato reale della riga in DB.
|
||||||
|
sendExportSummaryMail([iddatadb]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -692,7 +727,8 @@
|
|||||||
const total = eligibleRows.length;
|
const total = eligibleRows.length;
|
||||||
let processed = 0,
|
let processed = 0,
|
||||||
succeeded = 0,
|
succeeded = 0,
|
||||||
failed = 0;
|
failed = 0,
|
||||||
|
skipped = 0;
|
||||||
const exportedList = []; // { commessaweb, noPriceCount, noPriceAnalyses }
|
const exportedList = []; // { commessaweb, noPriceCount, noPriceAnalyses }
|
||||||
const processedIds = []; // iddatadb processati (ok o errore) per la mail
|
const processedIds = []; // iddatadb processati (ok o errore) per la mail
|
||||||
|
|
||||||
@@ -728,19 +764,26 @@
|
|||||||
const gridRow = row || getGridRow(iddatadb);
|
const gridRow = row || getGridRow(iddatadb);
|
||||||
if (gridRow) setRowExporting(gridRow, true);
|
if (gridRow) setRowExporting(gridRow, true);
|
||||||
|
|
||||||
processedIds.push(iddatadb);
|
|
||||||
try {
|
try {
|
||||||
const data = await sendExport(iddatadb, batchUuid);
|
const data = await sendExport(iddatadb, batchUuid);
|
||||||
processed++;
|
processed++;
|
||||||
if (data.success) {
|
if (data.rejected) {
|
||||||
|
// Già esportata / export in corso altrove: niente inviato, fuori dalla mail
|
||||||
|
skipped++;
|
||||||
|
if (data.status !== "l" && gridRow)
|
||||||
|
showRowError(gridRow, iddatadb, data.message);
|
||||||
|
} else if (data.success) {
|
||||||
|
processedIds.push(iddatadb);
|
||||||
succeeded++;
|
succeeded++;
|
||||||
exportedList.push({
|
exportedList.push({
|
||||||
commessaweb: data.commessaweb,
|
commessaweb: data.commessaweb,
|
||||||
noPriceCount: data.noPriceCount || 0,
|
noPriceCount: data.noPriceCount || 0,
|
||||||
noPriceAnalyses: data.noPriceAnalyses || [],
|
noPriceAnalyses: data.noPriceAnalyses || [],
|
||||||
|
blockAlert: data.blockAlert || null,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
failed++;
|
failed++;
|
||||||
|
processedIds.push(iddatadb);
|
||||||
const errIdx = getRowIndexByIddatadb(iddatadb);
|
const errIdx = getRowIndexByIddatadb(iddatadb);
|
||||||
if (errIdx >= 0)
|
if (errIdx >= 0)
|
||||||
window.gridData[errIdx]._exportError =
|
window.gridData[errIdx]._exportError =
|
||||||
@@ -755,6 +798,7 @@
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
processed++;
|
processed++;
|
||||||
failed++;
|
failed++;
|
||||||
|
processedIds.push(iddatadb);
|
||||||
const errIdx = getRowIndexByIddatadb(iddatadb);
|
const errIdx = getRowIndexByIddatadb(iddatadb);
|
||||||
if (errIdx >= 0)
|
if (errIdx >= 0)
|
||||||
window.gridData[errIdx]._exportError = error.message;
|
window.gridData[errIdx]._exportError = error.message;
|
||||||
@@ -793,23 +837,34 @@
|
|||||||
if (batchCancelled) {
|
if (batchCancelled) {
|
||||||
labelEl.textContent = "Export All — Cancelled";
|
labelEl.textContent = "Export All — Cancelled";
|
||||||
msgEl.innerHTML = `Exported: <strong>${succeeded}</strong><br>Errors: <strong>${failed}</strong><br>Not processed: <strong>${total - processed}</strong>`;
|
msgEl.innerHTML = `Exported: <strong>${succeeded}</strong><br>Errors: <strong>${failed}</strong><br>Not processed: <strong>${total - processed}</strong>`;
|
||||||
} else if (failed === 0) {
|
} else if (failed === 0 && skipped === 0) {
|
||||||
labelEl.textContent = "Export All — Complete";
|
labelEl.textContent = "Export All — Complete";
|
||||||
msgEl.innerHTML = `All <strong>${succeeded}</strong> rows exported successfully.`;
|
msgEl.innerHTML = `All <strong>${succeeded}</strong> rows exported successfully.`;
|
||||||
} else {
|
} else {
|
||||||
labelEl.textContent = "Export All — Completed with errors";
|
labelEl.textContent =
|
||||||
|
failed > 0
|
||||||
|
? "Export All — Completed with errors"
|
||||||
|
: "Export All — Complete";
|
||||||
msgEl.innerHTML = `Exported: <strong>${succeeded}</strong><br>Errors: <strong>${failed}</strong>`;
|
msgEl.innerHTML = `Exported: <strong>${succeeded}</strong><br>Errors: <strong>${failed}</strong>`;
|
||||||
}
|
}
|
||||||
|
if (skipped > 0)
|
||||||
|
msgEl.innerHTML += `<br>Skipped (already exported / in progress — reload the page): <strong>${skipped}</strong>`;
|
||||||
|
|
||||||
if (exportedList.length) {
|
if (exportedList.length) {
|
||||||
const npCommesse = exportedList.filter(
|
const npCommesse = exportedList.filter(
|
||||||
(x) => x.noPriceCount > 0,
|
(x) => x.noPriceCount > 0,
|
||||||
).length;
|
).length;
|
||||||
|
const blockedCommesse = exportedList.filter(
|
||||||
|
(x) => x.blockAlert,
|
||||||
|
).length;
|
||||||
msgEl.innerHTML +=
|
msgEl.innerHTML +=
|
||||||
`<hr class="my-2">` +
|
`<hr class="my-2">` +
|
||||||
(npCommesse > 0
|
(npCommesse > 0
|
||||||
? `<div class="small text-danger fw-semibold mb-1"><i class="fas fa-exclamation-triangle"></i> ${npCommesse} commesse con analisi senza prezzo</div>`
|
? `<div class="small text-danger fw-semibold mb-1"><i class="fas fa-exclamation-triangle"></i> ${npCommesse} commesse con analisi senza prezzo</div>`
|
||||||
: "") +
|
: "") +
|
||||||
|
(blockedCommesse > 0
|
||||||
|
? `<div class="small fw-semibold mb-1" style="color:#842029;"><i class="fas fa-ban"></i> ${blockedCommesse} commesse con cliente bloccato</div>`
|
||||||
|
: "") +
|
||||||
`<div class="small fw-semibold mb-1">Commesse esportate:</div>` +
|
`<div class="small fw-semibold mb-1">Commesse esportate:</div>` +
|
||||||
`<ul class="mb-0 ps-3">` +
|
`<ul class="mb-0 ps-3">` +
|
||||||
exportedList
|
exportedList
|
||||||
@@ -820,6 +875,7 @@
|
|||||||
x.noPriceCount,
|
x.noPriceCount,
|
||||||
x.noPriceAnalyses,
|
x.noPriceAnalyses,
|
||||||
) +
|
) +
|
||||||
|
blockBadgeHTML(x.blockAlert) +
|
||||||
`</li>`,
|
`</li>`,
|
||||||
)
|
)
|
||||||
.join("") +
|
.join("") +
|
||||||
|
|||||||
@@ -43,17 +43,23 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
* Clear all validation-error highlights from the grid.
|
* Clear all validation-error highlights from the grid.
|
||||||
*/
|
*/
|
||||||
function clearValidationErrors() {
|
function clearValidationErrors() {
|
||||||
document.querySelectorAll(".grid-cell.validation-error").forEach((cell) => {
|
document
|
||||||
cell.classList.remove("validation-error");
|
.querySelectorAll(".grid-cell.validation-error")
|
||||||
cell.querySelectorAll(".input-validation-error").forEach((el) => {
|
.forEach((cell) => {
|
||||||
el.classList.remove("input-validation-error");
|
cell.classList.remove("validation-error");
|
||||||
|
cell.querySelectorAll(".input-validation-error").forEach(
|
||||||
|
(el) => {
|
||||||
|
el.classList.remove("input-validation-error");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const tooltip = cell.querySelector(".validation-tooltip");
|
||||||
|
if (tooltip) tooltip.remove();
|
||||||
|
});
|
||||||
|
document
|
||||||
|
.querySelectorAll(".grid-row.validation-row-error")
|
||||||
|
.forEach((row) => {
|
||||||
|
row.classList.remove("validation-row-error");
|
||||||
});
|
});
|
||||||
const tooltip = cell.querySelector(".validation-tooltip");
|
|
||||||
if (tooltip) tooltip.remove();
|
|
||||||
});
|
|
||||||
document.querySelectorAll(".grid-row.validation-row-error").forEach((row) => {
|
|
||||||
row.classList.remove("validation-row-error");
|
|
||||||
});
|
|
||||||
// Also clear batch-row-error that came from validation
|
// Also clear batch-row-error that came from validation
|
||||||
clearAllRowErrors();
|
clearAllRowErrors();
|
||||||
}
|
}
|
||||||
@@ -90,16 +96,24 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (targetIndex) {
|
if (targetIndex) {
|
||||||
const rowIndex = row.querySelector(".grid-cell[data-row]")?.getAttribute("data-row");
|
const rowIndex = row
|
||||||
|
.querySelector(".grid-cell[data-row]")
|
||||||
|
?.getAttribute("data-row");
|
||||||
if (rowIndex !== null) {
|
if (rowIndex !== null) {
|
||||||
cell = row.querySelector(`.grid-cell[data-row="${rowIndex}"][data-index="${targetIndex}"]`);
|
cell = row.querySelector(
|
||||||
|
`.grid-cell[data-row="${rowIndex}"][data-index="${targetIndex}"]`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Direct data-col match
|
// Direct data-col match
|
||||||
const rowIndex = row.querySelector(".grid-cell[data-row]")?.getAttribute("data-row");
|
const rowIndex = row
|
||||||
|
.querySelector(".grid-cell[data-row]")
|
||||||
|
?.getAttribute("data-row");
|
||||||
if (rowIndex !== null) {
|
if (rowIndex !== null) {
|
||||||
cell = row.querySelector(`.grid-cell[data-col="${err.field}"][data-row="${rowIndex}"]`);
|
cell = row.querySelector(
|
||||||
|
`.grid-cell[data-col="${err.field}"][data-row="${rowIndex}"]`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,8 +208,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
* Show the result of a single export in the response modal.
|
* Show the result of a single export in the response modal.
|
||||||
*/
|
*/
|
||||||
function showExportResult(data) {
|
function showExportResult(data) {
|
||||||
const responseModalElement =
|
const responseModalElement = document.getElementById(
|
||||||
document.getElementById("exportResponseModal");
|
"exportResponseModal",
|
||||||
|
);
|
||||||
if (!responseModalElement) {
|
if (!responseModalElement) {
|
||||||
alert("Errore: Modale di risposta non trovato");
|
alert("Errore: Modale di risposta non trovato");
|
||||||
return;
|
return;
|
||||||
@@ -276,20 +291,28 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
errorEl.className = "batch-error-msg";
|
errorEl.className = "batch-error-msg";
|
||||||
errorEl.textContent = "⚠ Errore — clicca per dettagli";
|
errorEl.textContent = "⚠ Errore — clicca per dettagli";
|
||||||
errorEl.addEventListener("click", () => {
|
errorEl.addEventListener("click", () => {
|
||||||
document.getElementById("exportResponseMessage").innerHTML = message.replace(/\n/g, "<br>");
|
document.getElementById("exportResponseMessage").innerHTML =
|
||||||
document.getElementById("exportResponseModalLabel").textContent = "Errore Validazione (id: " + iddatadb + ")";
|
message.replace(/\n/g, "<br>");
|
||||||
new bootstrap.Modal(document.getElementById("exportResponseModal"), { keyboard: false }).show();
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Errore Validazione (id: " + iddatadb + ")";
|
||||||
|
new bootstrap.Modal(
|
||||||
|
document.getElementById("exportResponseModal"),
|
||||||
|
{ keyboard: false },
|
||||||
|
).show();
|
||||||
});
|
});
|
||||||
btnCell.appendChild(errorEl);
|
btnCell.appendChild(errorEl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearAllRowErrors() {
|
function clearAllRowErrors() {
|
||||||
document.querySelectorAll(".grid-row.batch-row-error").forEach((row) => {
|
document
|
||||||
row.classList.remove("batch-row-error");
|
.querySelectorAll(".grid-row.batch-row-error")
|
||||||
const msg = row.querySelector(".batch-error-msg");
|
.forEach((row) => {
|
||||||
if (msg) msg.remove();
|
row.classList.remove("batch-row-error");
|
||||||
});
|
const msg = row.querySelector(".batch-error-msg");
|
||||||
|
if (msg) msg.remove();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableAllRowButtons() {
|
function disableAllRowButtons() {
|
||||||
@@ -333,15 +356,23 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
// Show validating state on the row
|
// Show validating state on the row
|
||||||
setRowExporting(gridRow, true);
|
setRowExporting(gridRow, true);
|
||||||
const spinner = gridRow.querySelector(".batch-row-spinner");
|
const spinner = gridRow.querySelector(".batch-row-spinner");
|
||||||
if (spinner) spinner.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Validating...';
|
if (spinner)
|
||||||
|
spinner.innerHTML =
|
||||||
|
'<i class="fas fa-spinner fa-spin"></i> Validating...';
|
||||||
|
|
||||||
validateRows([{ iddatadb: parseInt(iddatadb), index: parseInt(rowIndex) }])
|
validateRows([
|
||||||
|
{ iddatadb: parseInt(iddatadb), index: parseInt(rowIndex) },
|
||||||
|
])
|
||||||
.then((validationData) => {
|
.then((validationData) => {
|
||||||
setRowExporting(gridRow, false);
|
setRowExporting(gridRow, false);
|
||||||
gridRow.classList.remove("batch-disabled");
|
gridRow.classList.remove("batch-disabled");
|
||||||
|
|
||||||
if (!validationData.success) {
|
if (!validationData.success) {
|
||||||
showExportResult({ success: false, message: validationData.message || "Errore di validazione" });
|
showExportResult({
|
||||||
|
success: false,
|
||||||
|
message:
|
||||||
|
validationData.message || "Errore di validazione",
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +391,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
gridRow.classList.remove("batch-disabled");
|
gridRow.classList.remove("batch-disabled");
|
||||||
|
|
||||||
console.error("Validation error:", error);
|
console.error("Validation error:", error);
|
||||||
showExportResult({ success: false, message: "Errore di validazione: " + error.message });
|
showExportResult({
|
||||||
|
success: false,
|
||||||
|
message: "Errore di validazione: " + error.message,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +436,11 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
gridRow.classList.remove("batch-disabled");
|
gridRow.classList.remove("batch-disabled");
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
showRowError(gridRow, iddatadb, data.message || "Errore sconosciuto");
|
showRowError(
|
||||||
|
gridRow,
|
||||||
|
iddatadb,
|
||||||
|
data.message || "Errore sconosciuto",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
showExportResult(data);
|
showExportResult(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -577,8 +615,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
document.getElementById("exportResponseMessage").innerHTML =
|
document.getElementById("exportResponseMessage").innerHTML =
|
||||||
`Nessuna riga valida per l'esportazione.<br>` +
|
`Nessuna riga valida per l'esportazione.<br>` +
|
||||||
`<strong>${invalidCount}</strong> righe con errori di validazione.`;
|
`<strong>${invalidCount}</strong> righe con errori di validazione.`;
|
||||||
document.getElementById("exportResponseModalLabel").textContent =
|
document.getElementById(
|
||||||
"Validazione Fallita";
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Validazione Fallita";
|
||||||
new bootstrap.Modal(
|
new bootstrap.Modal(
|
||||||
document.getElementById("exportResponseModal"),
|
document.getElementById("exportResponseModal"),
|
||||||
{ keyboard: false },
|
{ keyboard: false },
|
||||||
@@ -595,27 +634,38 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
if (invalidCount > 0) {
|
if (invalidCount > 0) {
|
||||||
countText += ` (${invalidCount} escluse per errori di validazione)`;
|
countText += ` (${invalidCount} escluse per errori di validazione)`;
|
||||||
}
|
}
|
||||||
document.getElementById("exportBatchCount").textContent = countText;
|
document.getElementById("exportBatchCount").textContent =
|
||||||
|
countText;
|
||||||
confirmModal.show();
|
confirmModal.show();
|
||||||
|
|
||||||
const confirmBtn = document.getElementById("exportBatchConfirmBtn");
|
const confirmBtn = document.getElementById(
|
||||||
|
"exportBatchConfirmBtn",
|
||||||
|
);
|
||||||
if (pendingBatchConfirmHandler) {
|
if (pendingBatchConfirmHandler) {
|
||||||
confirmBtn.removeEventListener("click", pendingBatchConfirmHandler);
|
confirmBtn.removeEventListener(
|
||||||
|
"click",
|
||||||
|
pendingBatchConfirmHandler,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
pendingBatchConfirmHandler = () => {
|
pendingBatchConfirmHandler = () => {
|
||||||
pendingBatchConfirmHandler = null;
|
pendingBatchConfirmHandler = null;
|
||||||
confirmModal.hide();
|
confirmModal.hide();
|
||||||
startBatchExport(validRows);
|
startBatchExport(validRows);
|
||||||
};
|
};
|
||||||
confirmBtn.addEventListener("click", pendingBatchConfirmHandler, { once: true });
|
confirmBtn.addEventListener(
|
||||||
|
"click",
|
||||||
|
pendingBatchConfirmHandler,
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
showValidationSpinner(false);
|
showValidationSpinner(false);
|
||||||
console.error("Batch validation error:", error);
|
console.error("Batch validation error:", error);
|
||||||
document.getElementById("exportResponseMessage").textContent =
|
document.getElementById("exportResponseMessage").textContent =
|
||||||
"Errore di validazione: " + error.message;
|
"Errore di validazione: " + error.message;
|
||||||
document.getElementById("exportResponseModalLabel").textContent =
|
document.getElementById(
|
||||||
"Errore Validazione";
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Errore Validazione";
|
||||||
new bootstrap.Modal(
|
new bootstrap.Modal(
|
||||||
document.getElementById("exportResponseModal"),
|
document.getElementById("exportResponseModal"),
|
||||||
{ keyboard: false },
|
{ keyboard: false },
|
||||||
@@ -635,54 +685,51 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
);
|
);
|
||||||
unsavedModal.show();
|
unsavedModal.show();
|
||||||
|
|
||||||
document
|
document.getElementById("batchSaveAndExportBtn").addEventListener(
|
||||||
.getElementById("batchSaveAndExportBtn")
|
"click",
|
||||||
.addEventListener(
|
() => {
|
||||||
"click",
|
unsavedModal.hide();
|
||||||
() => {
|
// Trigger Save All, then proceed
|
||||||
unsavedModal.hide();
|
const saveAllEl = document.querySelector(".save-all-btn");
|
||||||
// Trigger Save All, then proceed
|
if (!saveAllEl) return;
|
||||||
const saveAllEl =
|
|
||||||
document.querySelector(".save-all-btn");
|
|
||||||
if (!saveAllEl) return;
|
|
||||||
|
|
||||||
// Watch for all .cell-changed to disappear
|
// Watch for all .cell-changed to disappear
|
||||||
const observer = new MutationObserver(() => {
|
const observer = new MutationObserver(() => {
|
||||||
if (!hasUnsavedChanges()) {
|
if (!hasUnsavedChanges()) {
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
const eligibleRows = collectEligibleRows();
|
const eligibleRows = collectEligibleRows();
|
||||||
if (eligibleRows.length === 0) {
|
if (eligibleRows.length === 0) {
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseMessage",
|
||||||
|
).textContent =
|
||||||
|
"Tutte le righe sono già state esportate al LIMS.";
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Export All";
|
||||||
|
new bootstrap.Modal(
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
"exportResponseMessage",
|
"exportResponseModal",
|
||||||
).textContent =
|
),
|
||||||
"Tutte le righe sono già state esportate al LIMS.";
|
{ keyboard: false },
|
||||||
document.getElementById(
|
).show();
|
||||||
"exportResponseModalLabel",
|
return;
|
||||||
).textContent = "Export All";
|
|
||||||
new bootstrap.Modal(
|
|
||||||
document.getElementById(
|
|
||||||
"exportResponseModal",
|
|
||||||
),
|
|
||||||
{ keyboard: false },
|
|
||||||
).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showBatchConfirm(eligibleRows);
|
|
||||||
}
|
}
|
||||||
});
|
showBatchConfirm(eligibleRows);
|
||||||
observer.observe(
|
}
|
||||||
document.querySelector(".grid-container"),
|
});
|
||||||
{
|
observer.observe(
|
||||||
subtree: true,
|
document.querySelector(".grid-container"),
|
||||||
attributes: true,
|
{
|
||||||
attributeFilter: ["class"],
|
subtree: true,
|
||||||
},
|
attributes: true,
|
||||||
);
|
attributeFilter: ["class"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
saveAllEl.click();
|
saveAllEl.click();
|
||||||
},
|
},
|
||||||
{ once: true },
|
{ once: true },
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,7 +801,11 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
succeeded++;
|
succeeded++;
|
||||||
} else {
|
} else {
|
||||||
failed++;
|
failed++;
|
||||||
showRowError(row, iddatadb, data.message || "Errore sconosciuto");
|
showRowError(
|
||||||
|
row,
|
||||||
|
iddatadb,
|
||||||
|
data.message || "Errore sconosciuto",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
processed++;
|
processed++;
|
||||||
@@ -794,7 +845,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
const modalEl = document.getElementById("exportResponseModal");
|
const modalEl = document.getElementById("exportResponseModal");
|
||||||
const modal = new bootstrap.Modal(modalEl, { keyboard: false });
|
const modal = new bootstrap.Modal(modalEl, { keyboard: false });
|
||||||
modal.show();
|
modal.show();
|
||||||
modalEl.addEventListener("hidden.bs.modal", cleanupBackdrop, { once: true });
|
modalEl.addEventListener("hidden.bs.modal", cleanupBackdrop, {
|
||||||
|
once: true,
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "class/VisualLimsApiClient.class.php";
|
require_once "class/VisualLimsApiClient.class.php";
|
||||||
|
require_once "class/block_alert.php";
|
||||||
include('include/headscript.php');
|
include('include/headscript.php');
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
@@ -143,6 +144,100 @@ function importaCommessaWithRetry($api, $commessaId, array $payload, $maxRetries
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔹 CHECK PRELIMINARE + LOCK: una sola esportazione per riga, mai una seconda commessa.
|
||||||
|
// Protegge da pagine non aggiornate (due schede, pagina Errors vecchia, doppio click,
|
||||||
|
// LIMS lento con richiesta ancora in corso).
|
||||||
|
$chkId = (int)($_POST['iddatadb'] ?? 0);
|
||||||
|
if ($chkId > 0) {
|
||||||
|
$rejectExport = function ($reason, $cur = null) use ($chkId, $commessaLogFile, $writeBatchIndex, $batchUuid) {
|
||||||
|
file_put_contents(
|
||||||
|
$commessaLogFile,
|
||||||
|
"\n[EXPORT RIFIUTATO] " . date('Y-m-d H:i:s') . " | {$reason}" .
|
||||||
|
" | user_id=" . ($GLOBALS['iduserlogin'] ?? 'n/d') .
|
||||||
|
" | IP=" . ($_SERVER['REMOTE_ADDR'] ?? '-') .
|
||||||
|
" | batch=" . ($batchUuid ?? '-') . "\n",
|
||||||
|
FILE_APPEND
|
||||||
|
);
|
||||||
|
$writeBatchIndex("SKIP iddatadb={$chkId} :: {$reason}");
|
||||||
|
echo json_encode([
|
||||||
|
"success" => false,
|
||||||
|
"rejected" => true,
|
||||||
|
"status" => $cur['status'] ?? null,
|
||||||
|
"commessaweb" => $cur['commessaweb'] ?? null,
|
||||||
|
"message" => "Commessa non inviata (riga {$chkId}): {$reason}. Ricarica la pagina.",
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Lock per riga: tenuto fino a fine script (rilasciato da MySQL alla chiusura connessione)
|
||||||
|
$gotLock = (int)$pdo->query("SELECT GET_LOCK(" . $pdo->quote("lims_export_{$chkId}") . ", 0)")->fetchColumn();
|
||||||
|
if ($gotLock !== 1) {
|
||||||
|
$rejectExport("esportazione già in corso");
|
||||||
|
}
|
||||||
|
|
||||||
|
$chk = $pdo->prepare("SELECT status, idcommessaweb, commessaweb FROM datadb WHERE iddatadb = ?");
|
||||||
|
$chk->execute([$chkId]);
|
||||||
|
$cur = $chk->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$cur) {
|
||||||
|
$rejectExport("riga non trovata");
|
||||||
|
}
|
||||||
|
if (!in_array($cur['status'], ['i', 'x'], true)) {
|
||||||
|
$rejectExport("già esportata (status={$cur['status']}, commessa=" . ($cur['commessaweb'] ?: '-') . ")", $cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
$existingId = (int)($cur['idcommessaweb'] ?? 0);
|
||||||
|
if ($existingId > 0) {
|
||||||
|
// Commessa già creata da un export precedente (fallito, o interrotto da un crash/timeout PHP):
|
||||||
|
// controlla lo stato nel LIMS invece di crearne una nuova (sarebbe un duplicato).
|
||||||
|
// NB: il revert a 'i' azzera idcommessaweb, quindi qui non arrivano le righe riportate a mano.
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
try {
|
||||||
|
$existing = $api->get("CommessaWeb({$existingId})");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$existing = null;
|
||||||
|
if (strpos($e->getMessage(), 'HTTP 404') === false) {
|
||||||
|
$rejectExport("impossibile verificare la commessa {$existingId} nel LIMS: " . $e->getMessage(), $cur);
|
||||||
|
}
|
||||||
|
// 404: la commessa non esiste più nel LIMS → si può esportare da capo
|
||||||
|
}
|
||||||
|
|
||||||
|
$stato = $existing['StatoCommessaWeb'] ?? null;
|
||||||
|
$notSentYet = $existing !== null && $stato === 'Nuova' && empty($existing['DataInviatoWeb']);
|
||||||
|
|
||||||
|
$writeLog(null, "IdCommessa esistente: {$existingId}\nStatoCommessaWeb: " . ($stato ?? '404') .
|
||||||
|
"\nDataInviatoWeb: " . ($existing['DataInviatoWeb'] ?? '-'), "PRECHECK - commessa esistente (iddatadb={$chkId})");
|
||||||
|
|
||||||
|
if ($stato === 'Elaborata') {
|
||||||
|
// Già importata nel LIMS: riallinea la riga, nessuna nuova commessa
|
||||||
|
$codice = substr(trim((string)($existing['CodiceCommessa'] ?? '')), 0, 30);
|
||||||
|
$pdo->prepare("UPDATE datadb SET status = 'l', commessaweb = :c, log_file = :lf WHERE iddatadb = :id")
|
||||||
|
->execute(['c' => $codice, 'lf' => basename($commessaLogFile), 'id' => $chkId]);
|
||||||
|
|
||||||
|
$writeLog(null, "Riga riallineata: status='l', commessaweb={$codice}", "PRECHECK - RECOVERED (iddatadb={$chkId})");
|
||||||
|
$writeBatchIndex("RECOVERED iddatadb={$chkId} commessa={$existingId} codice={$codice}");
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
"success" => true,
|
||||||
|
"recovered" => true,
|
||||||
|
"idcommessaweb" => $existingId,
|
||||||
|
"commessaweb" => $codice,
|
||||||
|
"message" => "Commessa già presente nel LIMS: riga riallineata senza crearne una nuova",
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($existing !== null && !$notSentYet) {
|
||||||
|
// Inviata ma non (ancora) importata: rifare l'export creerebbe un duplicato → verifica manuale
|
||||||
|
$rejectExport("commessa {$existingId} già inviata al LIMS ma non ancora importata (stato: {$stato}). " .
|
||||||
|
"Riprova tra qualche minuto o verifica nel LIMS", $cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 404 o mai inviata al laboratorio: si ricrea da capo (la vecchia CommessaWeb resta orfana in "Nuova")
|
||||||
|
$writeBatchIndex("RECREATE iddatadb={$chkId} old_commessa={$existingId} stato=" . ($stato ?? '404'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$iddatadb = $_POST['iddatadb'] ?? null;
|
$iddatadb = $_POST['iddatadb'] ?? null;
|
||||||
if (!$iddatadb) {
|
if (!$iddatadb) {
|
||||||
@@ -348,6 +443,11 @@ try {
|
|||||||
$commessaId = $commessaWeb["IdCommessa"];
|
$commessaId = $commessaWeb["IdCommessa"];
|
||||||
$commessaWebCode = substr($commessaWeb["CodiceCommessa"] ?? "TEST CommessaWeb", 0, 30); // Limite a 30 caratteri
|
$commessaWebCode = substr($commessaWeb["CodiceCommessa"] ?? "TEST CommessaWeb", 0, 30); // Limite a 30 caratteri
|
||||||
|
|
||||||
|
// 🔹 STEP 5.1: salva SUBITO l'id della commessa creata: se l'export fallisce più avanti,
|
||||||
|
// il CHECK PRELIMINARE sa che nel LIMS esiste già e non ne crea una seconda.
|
||||||
|
$pdo->prepare("UPDATE datadb SET idcommessaweb = :idc, commessaweb = :cw WHERE iddatadb = :id")
|
||||||
|
->execute(['idc' => $commessaId, 'cw' => $commessaWebCode, 'id' => $iddatadb]);
|
||||||
|
|
||||||
// 🔹 STEP 6: Create Campioni (Samples) for each part
|
// 🔹 STEP 6: Create Campioni (Samples) for each part
|
||||||
$campioni = [];
|
$campioni = [];
|
||||||
$logContentStep6 = "";
|
$logContentStep6 = "";
|
||||||
@@ -768,6 +868,13 @@ try {
|
|||||||
$logFileStep91 = $logDir . "commessa_{$commessaId}_importa_step91_" . time() . ".txt";
|
$logFileStep91 = $logDir . "commessa_{$commessaId}_importa_step91_" . time() . ".txt";
|
||||||
$writeLog($logFileStep91, $logContentStep91, "STEP 9.5 - ImportaCommessa (commessa={$commessaId}, succeeded=" . ($importSucceeded ? '1' : '0') . ")");
|
$writeLog($logFileStep91, $logContentStep91, "STEP 9.5 - ImportaCommessa (commessa={$commessaId}, succeeded=" . ($importSucceeded ? '1' : '0') . ")");
|
||||||
|
|
||||||
|
// Import non confermato → errore ('x'), non 'l'. Prima veniva comunque segnata 'l'
|
||||||
|
// perché CodiceCommessa (codice web) non è mai vuoto. Al reinvio il CHECK PRELIMINARE
|
||||||
|
// ricontrolla lo stato nel LIMS: se nel frattempo è "Elaborata" la riga viene solo riallineata.
|
||||||
|
if (!$importSucceeded) {
|
||||||
|
throw new Exception("ImportaCommessa non confermata dal LIMS (stato: " . ($importStato ?? 'null') . ")");
|
||||||
|
}
|
||||||
|
|
||||||
// 🔹 STEP 10: GET di controllo post-PATCH
|
// 🔹 STEP 10: GET di controllo post-PATCH
|
||||||
$expand = "CommesseCustomFields(\$expand=CustomField)";
|
$expand = "CommesseCustomFields(\$expand=CustomField)";
|
||||||
$commessaAfterPatch = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
|
$commessaAfterPatch = $api->get("CommessaWeb(" . $commessaId . ")?\$expand=" . $expand);
|
||||||
@@ -798,6 +905,19 @@ try {
|
|||||||
|
|
||||||
// Indice di lotto: esito OK di questa commessa
|
// Indice di lotto: esito OK di questa commessa
|
||||||
$writeBatchIndex("OK iddatadb={$iddatadb} commessa={$commessaId} codice={$finalCodiceCommessa} log=" . basename($commessaLogFile));
|
$writeBatchIndex("OK iddatadb={$iddatadb} commessa={$commessaId} codice={$finalCodiceCommessa} log=" . basename($commessaLogFile));
|
||||||
|
// 🔹 STEP 10.2: Controllo blocco cliente (solo avviso, non blocca mai l'export)
|
||||||
|
$blockAlert = null;
|
||||||
|
try {
|
||||||
|
$blockAlert = getClientBlockAlert($clienteId, $clienteFatturazione);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
error_log("Controllo blocco cliente fallito (iddatadb={$iddatadb}): " . $e->getMessage());
|
||||||
|
}
|
||||||
|
$writeLog(
|
||||||
|
null,
|
||||||
|
$blockAlert ? json_encode($blockAlert, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : "Nessun blocco",
|
||||||
|
"STEP 10.2 - Controllo blocco cliente (iddatadb={$iddatadb})"
|
||||||
|
);
|
||||||
|
|
||||||
// 🔹 STEP 11: Prepare final response
|
// 🔹 STEP 11: Prepare final response
|
||||||
$finalCommessa = [
|
$finalCommessa = [
|
||||||
"Cliente" => $clienteId,
|
"Cliente" => $clienteId,
|
||||||
@@ -823,6 +943,7 @@ try {
|
|||||||
"failedAnalyses" => $failedAnalyses,
|
"failedAnalyses" => $failedAnalyses,
|
||||||
"noPriceCount" => count($noPriceAnalyses),
|
"noPriceCount" => count($noPriceAnalyses),
|
||||||
"noPriceAnalyses" => $noPriceAnalyses,
|
"noPriceAnalyses" => $noPriceAnalyses,
|
||||||
|
"blockAlert" => $blockAlert,
|
||||||
"message" => "Export successful",
|
"message" => "Export successful",
|
||||||
"logFiles" => [
|
"logFiles" => [
|
||||||
"step5_create" => $logFileStep5,
|
"step5_create" => $logFileStep5,
|
||||||
@@ -834,7 +955,7 @@ try {
|
|||||||
"step10_get" => $logFileStep10
|
"step10_get" => $logFileStep10
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
} catch (Exception $e) {
|
} catch (Throwable $e) {
|
||||||
// --- LOG ERRORE DEDICATO (accanto agli altri log in logs/api/) ---
|
// --- LOG ERRORE DEDICATO (accanto agli altri log in logs/api/) ---
|
||||||
$errIddatadb = $iddatadb ?? 'unknown';
|
$errIddatadb = $iddatadb ?? 'unknown';
|
||||||
$errCommessaId = $commessaId ?? null;
|
$errCommessaId = $commessaId ?? null;
|
||||||
|
|||||||
@@ -39,8 +39,14 @@ if (!empty($explicitIds)) {
|
|||||||
// Scoping di sicurezza: solo record del template/utente/import corretti.
|
// Scoping di sicurezza: solo record del template/utente/import corretti.
|
||||||
$conds = ['d.templateid = ?', 'd.status = ?'];
|
$conds = ['d.templateid = ?', 'd.status = ?'];
|
||||||
$params = [$templateId, $status];
|
$params = [$templateId, $status];
|
||||||
if (!$showAll) { $conds[] = 'd.user_id = ?'; $params[] = $userId; }
|
if (!$showAll) {
|
||||||
if ($importref !== '') { $conds[] = 'd.importreferencecode = ?'; $params[] = $importref; }
|
$conds[] = 'd.user_id = ?';
|
||||||
|
$params[] = $userId;
|
||||||
|
}
|
||||||
|
if ($importref !== '') {
|
||||||
|
$conds[] = 'd.importreferencecode = ?';
|
||||||
|
$params[] = $importref;
|
||||||
|
}
|
||||||
$ph = implode(',', array_fill(0, count($explicitIds), '?'));
|
$ph = implode(',', array_fill(0, count($explicitIds), '?'));
|
||||||
$conds[] = "d.iddatadb IN ($ph)";
|
$conds[] = "d.iddatadb IN ($ph)";
|
||||||
foreach ($explicitIds as $id) $params[] = $id;
|
foreach ($explicitIds as $id) $params[] = $id;
|
||||||
@@ -57,7 +63,7 @@ if (!empty($explicitIds)) {
|
|||||||
$idStmt = $pdo->prepare("
|
$idStmt = $pdo->prepare("
|
||||||
SELECT d.iddatadb FROM datadb d
|
SELECT d.iddatadb FROM datadb d
|
||||||
WHERE {$whereSql}
|
WHERE {$whereSql}
|
||||||
ORDER BY d.excelrow ASC, d.iddatadb ASC
|
ORDER BY CAST(d.excelrow AS UNSIGNED) ASC, d.excelrow ASC, d.iddatadb ASC
|
||||||
LIMIT {$perPage} OFFSET {$offset}
|
LIMIT {$perPage} OFFSET {$offset}
|
||||||
");
|
");
|
||||||
$idStmt->execute($params);
|
$idStmt->execute($params);
|
||||||
@@ -356,7 +362,7 @@ try {
|
|||||||
SELECT d.iddatadb
|
SELECT d.iddatadb
|
||||||
FROM datadb d {$joinSql}
|
FROM datadb d {$joinSql}
|
||||||
WHERE {$whereSql}
|
WHERE {$whereSql}
|
||||||
ORDER BY d.excelrow ASC, d.iddatadb ASC
|
ORDER BY CAST(d.excelrow AS UNSIGNED) ASC, d.excelrow ASC, d.iddatadb ASC
|
||||||
LIMIT {$perPage} OFFSET {$offset}
|
LIMIT {$perPage} OFFSET {$offset}
|
||||||
");
|
");
|
||||||
$pageStmt->execute($params);
|
$pageStmt->execute($params);
|
||||||
@@ -379,7 +385,7 @@ try {
|
|||||||
$allStmt = $pdo->prepare("
|
$allStmt = $pdo->prepare("
|
||||||
SELECT d.iddatadb FROM datadb d {$joinSql}
|
SELECT d.iddatadb FROM datadb d {$joinSql}
|
||||||
WHERE {$whereSql}
|
WHERE {$whereSql}
|
||||||
ORDER BY d.excelrow ASC, d.iddatadb ASC
|
ORDER BY CAST(d.excelrow AS UNSIGNED) ASC, d.excelrow ASC, d.iddatadb ASC
|
||||||
LIMIT " . FILTER_ALLIDS_CAP . "
|
LIMIT " . FILTER_ALLIDS_CAP . "
|
||||||
");
|
");
|
||||||
$allStmt->execute($params);
|
$allStmt->execute($params);
|
||||||
|
|||||||
@@ -20,17 +20,20 @@ try {
|
|||||||
$stmt = $pdo->query("SELECT DISTINCT idclient FROM datadb WHERE idclient IS NOT NULL AND idclient > 0 ORDER BY idclient ASC");
|
$stmt = $pdo->query("SELECT DISTINCT idclient FROM datadb WHERE idclient IS NOT NULL AND idclient > 0 ORDER BY idclient ASC");
|
||||||
$ids = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$ids = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
$fakeClients = array_map(fn($id) => [
|
$fakeClients = array_map(fn($id) => [
|
||||||
'IdCliente' => (int) $id,
|
'IdCliente' => (int) $id,
|
||||||
'Nominativo' => "Cliente Simulato {$id}",
|
'Nominativo' => "Cliente Simulato {$id}",
|
||||||
'CodiceCliente' => "SIM_{$id}",
|
'CodiceCliente' => "SIM_{$id}",
|
||||||
|
'CodiceASL' => null, // campo usato come nota di blocco (es. "BLOCCO PER PAGAMENTO")
|
||||||
], $ids);
|
], $ids);
|
||||||
echo json_encode(['value' => $fakeClients]);
|
echo json_encode(['value' => $fakeClients]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parametri OData
|
// Parametri OData
|
||||||
|
// CodiceASL viene usato dal cliente come nota di blocco (es. "BLOCCO PER PAGAMENTO"),
|
||||||
|
// perché i campi nativi del Blocco Accettazione non sono esposti dall'API.
|
||||||
$params = [
|
$params = [
|
||||||
'$select' => 'IdCliente,Nominativo,CodiceCliente,Inattivo',
|
'$select' => 'IdCliente,Nominativo,CodiceCliente,Inattivo,CodiceASL',
|
||||||
'$orderby' => 'Nominativo asc'
|
'$orderby' => 'Nominativo asc'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -54,10 +57,12 @@ try {
|
|||||||
$errorMessage = $e->getMessage();
|
$errorMessage = $e->getMessage();
|
||||||
// Controlla se l'errore è legato all'autenticazione (HTTP 400 con messaggio specifico)
|
// Controlla se l'errore è legato all'autenticazione (HTTP 400 con messaggio specifico)
|
||||||
if (strpos($errorMessage, 'HTTP 400') !== false && strpos($errorMessage, 'Cannot persist the object') !== false) {
|
if (strpos($errorMessage, 'HTTP 400') !== false && strpos($errorMessage, 'Cannot persist the object') !== false) {
|
||||||
// Forza il refresh del token
|
// Forza il refresh del token, solo se la classe lo supporta
|
||||||
|
if (!method_exists($api, 'refreshToken')) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Assumi che VisualLimsApiClient abbia un metodo per il refresh del token
|
$api->refreshToken();
|
||||||
$api->refreshToken(); // Da implementare in VisualLimsApiClient se non esiste
|
|
||||||
error_log("Tentativo $retry: Refresh token eseguito per endpoint $endpoint");
|
error_log("Tentativo $retry: Refresh token eseguito per endpoint $endpoint");
|
||||||
} catch (Exception $refreshEx) {
|
} catch (Exception $refreshEx) {
|
||||||
error_log("Errore durante il refresh del token: " . $refreshEx->getMessage());
|
error_log("Errore durante il refresh del token: " . $refreshEx->getMessage());
|
||||||
@@ -74,7 +79,7 @@ try {
|
|||||||
throw new Exception("Massimo numero di tentativi raggiunto per $endpoint");
|
throw new Exception("Massimo numero di tentativi raggiunto per $endpoint");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache file (1 hour TTL)
|
// Cache file (15 minuti TTL: così un blocco impostato nel LIMS compare entro 15 minuti)
|
||||||
$cacheFile = __DIR__ . '/cache/clienti.json';
|
$cacheFile = __DIR__ . '/cache/clienti.json';
|
||||||
if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < 7200)) {
|
if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < 7200)) {
|
||||||
readfile($cacheFile);
|
readfile($cacheFile);
|
||||||
@@ -89,12 +94,12 @@ try {
|
|||||||
file_put_contents($cacheFile, $json);
|
file_put_contents($cacheFile, $json);
|
||||||
|
|
||||||
echo $json;
|
echo $json;
|
||||||
} catch (Exception $e) {
|
} catch (Throwable $e) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
$errorResponse = [
|
$errorResponse = [
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
'file' => $e->getFile(),
|
'file' => $e->getFile(),
|
||||||
'line' => $e->getLine(),
|
'line' => $e->getLine(),
|
||||||
'trace' => $e->getTraceAsString()
|
'trace' => $e->getTraceAsString()
|
||||||
];
|
];
|
||||||
error_log("Errore in get_clienti.php: " . json_encode($errorResponse));
|
error_log("Errore in get_clienti.php: " . json_encode($errorResponse));
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
// Script di TEST: recupera TUTTI i campi di pochi clienti (nessun $select, nessuna cache).
|
||||||
|
// Da mettere nella stessa cartella di get_clienti.php.
|
||||||
|
//
|
||||||
|
// Uso:
|
||||||
|
// test_clienti_full.php -> primi 3 clienti
|
||||||
|
// test_clienti_full.php?top=5 -> primi 5 clienti
|
||||||
|
// test_clienti_full.php?id=123 -> solo il cliente con IdCliente = 123
|
||||||
|
// test_clienti_full.php?expand=XYZ -> include anche la relazione XYZ
|
||||||
|
|
||||||
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||||
|
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
ini_set('display_errors', '0');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
$top = isset($_GET['top']) ? max(1, min(20, (int) $_GET['top'])) : 3;
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'$top' => $top,
|
||||||
|
'$orderby' => 'Nominativo asc',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($_GET['id']) && ctype_digit($_GET['id'])) {
|
||||||
|
$params['$filter'] = 'IdCliente eq ' . (int) $_GET['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_GET['expand']) && preg_match('/^[A-Za-z0-9_,\/()$=;]+$/', $_GET['expand'])) {
|
||||||
|
$params['$expand'] = $_GET['expand'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// PHP_QUERY_RFC3986 codifica gli spazi come %20 (più compatibile con OData)
|
||||||
|
$endpoint = 'Cliente?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986);
|
||||||
|
|
||||||
|
$data = $api->get($endpoint);
|
||||||
|
|
||||||
|
// Copia su file per consultarla con calma
|
||||||
|
file_put_contents(
|
||||||
|
__DIR__ . '/clienti_full_response.json',
|
||||||
|
json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Elenco dei nomi dei campi trovati, utile per capire cosa è disponibile
|
||||||
|
$campi = [];
|
||||||
|
foreach ($data['value'] ?? [] as $row) {
|
||||||
|
$campi = array_unique(array_merge($campi, array_keys($row)));
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'endpoint' => $endpoint,
|
||||||
|
'campi' => array_values($campi),
|
||||||
|
'dati' => $data,
|
||||||
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode([
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
@@ -263,6 +263,116 @@
|
|||||||
await resolveClientNames();
|
await resolveClientNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Blocco clienti (CodiceASL contenente "blocco") ─────────────────────
|
||||||
|
|
||||||
|
const clientBlockMap = {}; // IdCliente -> testo completo di CodiceASL
|
||||||
|
|
||||||
|
async function loadClientBlocks() {
|
||||||
|
try {
|
||||||
|
const resp = await fetch("get_clienti.php", { cache: "no-store" });
|
||||||
|
const json = await resp.json();
|
||||||
|
(json.value || []).forEach((c) => {
|
||||||
|
const txt = (c.CodiceASL || "").trim();
|
||||||
|
if (txt && /blocco/i.test(txt)) {
|
||||||
|
clientBlockMap[String(c.IdCliente)] = txt;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
"[gridRenderer] clienti bloccati:",
|
||||||
|
Object.keys(clientBlockMap).length,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
"[gridRenderer] errore caricamento blocchi clienti",
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regola: se "Fatturazione avanzata" è compilata si controlla quella, altrimenti il Client
|
||||||
|
function getRowBlockInfo(rowIndex) {
|
||||||
|
const row = data[rowIndex];
|
||||||
|
if (!row) return null;
|
||||||
|
const fatt =
|
||||||
|
(row.fixedFields && row.fixedFields.ClienteFatturazione) || "";
|
||||||
|
if (fatt) {
|
||||||
|
return {
|
||||||
|
colKey: "ClienteFatturazione",
|
||||||
|
reason: clientBlockMap[String(fatt)] || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
colKey: "idclient",
|
||||||
|
reason: clientBlockMap[String(row.idclient || "")] || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideBlockTooltip(el) {
|
||||||
|
if (window.bootstrap && bootstrap.Tooltip) {
|
||||||
|
const t = bootstrap.Tooltip.getInstance(el);
|
||||||
|
if (t) t.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyBlockMarker(rowIndex, rowEl) {
|
||||||
|
const row = data[rowIndex];
|
||||||
|
if (!row) return;
|
||||||
|
rowEl =
|
||||||
|
rowEl ||
|
||||||
|
(rowContainer &&
|
||||||
|
rowContainer.querySelector(
|
||||||
|
`.grid-row[data-id="${row.iddatadb}"]`,
|
||||||
|
));
|
||||||
|
if (!rowEl) return;
|
||||||
|
|
||||||
|
// Rimuove marcatori precedenti (sia su Client sia su Fatturazione avanzata)
|
||||||
|
rowEl
|
||||||
|
.querySelectorAll(".grid-cell.client-blocked")
|
||||||
|
.forEach((c) => c.classList.remove("client-blocked"));
|
||||||
|
rowEl.querySelectorAll(".client-block-icon").forEach((i) => {
|
||||||
|
hideBlockTooltip(i);
|
||||||
|
i.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
const info = getRowBlockInfo(rowIndex);
|
||||||
|
if (!info || !info.reason) return;
|
||||||
|
|
||||||
|
const cell = rowEl.querySelector(
|
||||||
|
`.grid-cell[data-col="${info.colKey}"]`,
|
||||||
|
);
|
||||||
|
if (!cell) return;
|
||||||
|
|
||||||
|
cell.classList.add("client-blocked");
|
||||||
|
const icon = document.createElement("span");
|
||||||
|
icon.className = "client-block-icon";
|
||||||
|
icon.innerHTML = '<i class="fas fa-exclamation-circle"></i>';
|
||||||
|
icon.dataset.reason = info.reason;
|
||||||
|
icon.setAttribute("aria-label", info.reason);
|
||||||
|
cell.appendChild(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshAllBlockMarkers() {
|
||||||
|
data.forEach((_, i) => applyBlockMarker(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
function initBlockTooltips() {
|
||||||
|
$(document).on("mouseenter", ".client-block-icon", function () {
|
||||||
|
if (!(window.bootstrap && bootstrap.Tooltip)) {
|
||||||
|
this.title = this.dataset.reason;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bootstrap.Tooltip.getOrCreateInstance(this, {
|
||||||
|
title: this.dataset.reason,
|
||||||
|
placement: "top",
|
||||||
|
container: "body",
|
||||||
|
trigger: "manual",
|
||||||
|
}).show();
|
||||||
|
});
|
||||||
|
$(document).on("mouseleave", ".client-block-icon", function () {
|
||||||
|
hideBlockTooltip(this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ── Fixed field data loading ───────────────────────────────────────────
|
// ── Fixed field data loading ───────────────────────────────────────────
|
||||||
|
|
||||||
const fixedFieldApiConfig = {
|
const fixedFieldApiConfig = {
|
||||||
@@ -463,6 +573,7 @@
|
|||||||
async function preloadAllData() {
|
async function preloadAllData() {
|
||||||
// 1. Clients
|
// 1. Clients
|
||||||
await loadClientData();
|
await loadClientData();
|
||||||
|
await loadClientBlocks();
|
||||||
|
|
||||||
// 2. Non-dependent fixed fields
|
// 2. Non-dependent fixed fields
|
||||||
const nonDependent = Object.keys(fixedFieldApiConfig).filter(
|
const nonDependent = Object.keys(fixedFieldApiConfig).filter(
|
||||||
@@ -755,7 +866,8 @@
|
|||||||
|
|
||||||
function renderActionButtons(rowIndex) {
|
function renderActionButtons(rowIndex) {
|
||||||
const row = data[rowIndex];
|
const row = data[rowIndex];
|
||||||
const isExported = row.status === "l";
|
// _exporting: export in corso per questa riga (la riga può essere ri-renderizzata durante l'attesa)
|
||||||
|
const isExported = row.status === "l" || row._exporting === true;
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.className = "grid-cell button-cell";
|
div.className = "grid-cell button-cell";
|
||||||
div.style.flex = "0 0 auto";
|
div.style.flex = "0 0 auto";
|
||||||
@@ -874,6 +986,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyBlockMarker(rowIndex, rowDiv);
|
||||||
|
|
||||||
return rowDiv;
|
return rowDiv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -970,6 +1084,8 @@
|
|||||||
|
|
||||||
cell.classList.add("cell-changed");
|
cell.classList.add("cell-changed");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
refreshAllBlockMarkers();
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSingleRow(rowIndex) {
|
function renderSingleRow(rowIndex) {
|
||||||
@@ -1078,6 +1194,9 @@
|
|||||||
if (columns[colPos]) {
|
if (columns[colPos]) {
|
||||||
columns[colPos].width = newWidth;
|
columns[colPos].width = newWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Riallinea larghezza/posizione delle tendine Select2 aperte
|
||||||
|
$(window).trigger("resize.select2");
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncVisibleRowsToGridData() {
|
function syncVisibleRowsToGridData() {
|
||||||
@@ -1714,6 +1833,8 @@
|
|||||||
}
|
}
|
||||||
cell.classList.add("cell-changed");
|
cell.classList.add("cell-changed");
|
||||||
updateDirtyIndicator();
|
updateDirtyIndicator();
|
||||||
|
|
||||||
|
if (colType === "idclient") applyBlockMarker(rowIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle SceltaMultipla changes and persist them into gridData.
|
// Handle SceltaMultipla changes and persist them into gridData.
|
||||||
@@ -1765,6 +1886,8 @@
|
|||||||
data[rowIndex]._dirty = true;
|
data[rowIndex]._dirty = true;
|
||||||
cell.classList.add("cell-changed");
|
cell.classList.add("cell-changed");
|
||||||
updateDirtyIndicator();
|
updateDirtyIndicator();
|
||||||
|
|
||||||
|
if (key === "ClienteFatturazione") applyBlockMarker(rowIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1908,6 +2031,9 @@
|
|||||||
if (columns[colPos]) {
|
if (columns[colPos]) {
|
||||||
columns[colPos].width = newWidth;
|
columns[colPos].width = newWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Riallinea larghezza/posizione delle tendine Select2 aperte
|
||||||
|
$(window).trigger("resize.select2");
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopResize() {
|
function stopResize() {
|
||||||
@@ -1971,6 +2097,7 @@
|
|||||||
// Events
|
// Events
|
||||||
attachEvents();
|
attachEvents();
|
||||||
initLazySelect2();
|
initLazySelect2();
|
||||||
|
initBlockTooltips();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start when DOM ready
|
// Start when DOM ready
|
||||||
|
|||||||
@@ -1518,6 +1518,38 @@ $gridMeta = [
|
|||||||
}
|
}
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
/* ── Cliente bloccato (CodiceASL contiene "blocco") ── */
|
||||||
|
.grid-container .grid-cell.client-blocked {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-container .grid-cell.client-blocked>select,
|
||||||
|
.grid-container .grid-cell.client-blocked .select2-container {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-width: 0;
|
||||||
|
width: auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-container .grid-cell.client-blocked select,
|
||||||
|
.grid-container .grid-cell.client-blocked .select2-container--default .select2-selection--single {
|
||||||
|
background-color: #f8d7da !important;
|
||||||
|
border-color: #f1aeb5 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-container .grid-cell.client-blocked .select2-selection__rendered {
|
||||||
|
color: #842029 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-block-icon {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
color: #dc3545;
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="row parts-row">
|
<div class="row parts-row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-12">
|
||||||
<!-- Prima riga: Elenco Parti, Rinumera, Voce -->
|
<!-- Prima riga: Elenco Parti, Rinumera, Voce -->
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; min-width: 0;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; min-width: 0;">
|
||||||
<h6 style="margin: 0; white-space: nowrap;">Elenco Parti</h6>
|
<h6 style="margin: 0; white-space: nowrap;">Elenco Parti</h6>
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
<i class="fas fa-microphone"></i> Voce
|
<i class="fas fa-microphone"></i> Voce
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn btn-outline-primary btn-sm ms-2" id="showHideImageBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">
|
<button type="button" class="btn btn-outline-primary btn-sm ms-2" id="showHideImageBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">
|
||||||
<i class="fas fa-eye-slash" style="font-size: 0.8rem;"></i>
|
<i class="fas fa-eye" style="font-size: 0.8rem;"></i>
|
||||||
<i class="fas fa-image ms-1" style="font-size: 0.8rem;"></i>
|
<i class="fas fa-image ms-1" style="font-size: 0.8rem;"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -119,7 +119,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3 d-none">
|
||||||
<h6>Foto del Campione</h6>
|
<h6>Foto del Campione</h6>
|
||||||
<div style="display: flex; align-items: center; margin-bottom: 10px;">
|
<div style="display: flex; align-items: center; margin-bottom: 10px;">
|
||||||
<button type="button" class="btn btn-primary btn-sm" id="downloadPhotoBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem; margin-right: 10px;"><i class="fas fa-download"></i></button>
|
<button type="button" class="btn btn-primary btn-sm" id="downloadPhotoBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem; margin-right: 10px;"><i class="fas fa-download"></i></button>
|
||||||
@@ -432,7 +432,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Evita stretching del flex nella riga dei filtri */
|
/* Evita stretching del flex nella riga dei filtri */
|
||||||
#partsModal .modal-body>.row .col-md-9>div[style*="display: flex"]>* {
|
#partsModal .parts-row>div:first-child>div[style*="display: flex"]>* {
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,7 +611,7 @@
|
|||||||
|
|
||||||
#partsTable {
|
#partsTable {
|
||||||
table-layout: fixed !important;
|
table-layout: fixed !important;
|
||||||
width: max-content !important;
|
width: 100% !important;
|
||||||
min-width: unset !important;
|
min-width: unset !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,9 +733,6 @@
|
|||||||
|
|
||||||
/* Extra field propagation header - full column width */
|
/* Extra field propagation header - full column width */
|
||||||
#partsTable th.extra-field-th {
|
#partsTable th.extra-field-th {
|
||||||
width: auto !important;
|
|
||||||
min-width: 220px !important;
|
|
||||||
max-width: none !important;
|
|
||||||
padding: 0.25rem !important;
|
padding: 0.25rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -757,9 +754,9 @@
|
|||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
line-height: 1.15;
|
line-height: 1.15;
|
||||||
color: #222;
|
color: #222;
|
||||||
white-space: nowrap !important;
|
white-space: normal !important;
|
||||||
overflow: visible !important;
|
word-break: break-word;
|
||||||
text-overflow: unset !important;
|
overflow: hidden !important;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -806,5 +803,69 @@
|
|||||||
z-index: 1065 !important
|
z-index: 1065 !important
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Campi nelle celle: occupano tutta la cella */
|
||||||
|
#partsTable td input.form-control,
|
||||||
|
#partsTable td textarea.form-control {
|
||||||
|
width: 100% !important;
|
||||||
|
max-width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTable td>div[style*="display: flex"] {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Select2 nelle celle (Matrice ed Extra): occupano la cella e vanno a capo */
|
||||||
|
#partsTable td .select2-container {
|
||||||
|
width: 100% !important;
|
||||||
|
min-width: 0 !important;
|
||||||
|
max-width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTable td .part-matrice+.select2 {
|
||||||
|
flex: 1 1 auto !important;
|
||||||
|
width: auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTable td .select2-selection--single {
|
||||||
|
height: auto !important;
|
||||||
|
min-height: 24px !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTable td .select2-selection__rendered {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
white-space: normal !important;
|
||||||
|
word-break: break-word;
|
||||||
|
overflow: visible !important;
|
||||||
|
text-overflow: clip !important;
|
||||||
|
line-height: 1.2 !important;
|
||||||
|
padding: 2px 22px 2px 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTable td .select2-selection__arrow {
|
||||||
|
height: 100% !important;
|
||||||
|
top: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Campo extra di tipo testo: textarea che cresce col contenuto */
|
||||||
|
#partsTable textarea.part-extra-field {
|
||||||
|
field-sizing: content;
|
||||||
|
min-height: 24px;
|
||||||
|
height: auto;
|
||||||
|
padding: 0.1rem 0.3rem;
|
||||||
|
line-height: 1.2;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
resize: none;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Voci del dropdown che vanno a capo */
|
||||||
|
.select2-results__option {
|
||||||
|
white-space: normal;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
/* rosso */
|
/* rosso */
|
||||||
</style>
|
</style>
|
||||||
+150
-77
@@ -147,10 +147,9 @@ $(document).ready(function () {
|
|||||||
return `
|
return `
|
||||||
<td class="extra-field-td" style="width:200px;">
|
<td class="extra-field-td" style="width:200px;">
|
||||||
<input type="hidden" class="part-extra-field-id" value="${partsExtraField.field_id}">
|
<input type="hidden" class="part-extra-field-id" value="${partsExtraField.field_id}">
|
||||||
<input type="text" class="form-control form-control-sm part-extra-field" data-type="${partsExtraField.data_type || ""}" value="${selectedValueText || ""}">
|
<textarea rows="1" class="form-control form-control-sm part-extra-field" data-type="${partsExtraField.data_type || ""}">${selectedValueText || ""}</textarea>
|
||||||
</td>`;
|
</td>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildExtraFieldHeaderHtml() {
|
function buildExtraFieldHeaderHtml() {
|
||||||
if (!partsExtraField) return "";
|
if (!partsExtraField) return "";
|
||||||
|
|
||||||
@@ -888,6 +887,17 @@ $(document).ready(function () {
|
|||||||
$("#partsTableBody").empty();
|
$("#partsTableBody").empty();
|
||||||
$("#global-matrice").empty();
|
$("#global-matrice").empty();
|
||||||
$("#macro-matrice-filter").empty();
|
$("#macro-matrice-filter").empty();
|
||||||
|
|
||||||
|
// Ripristina lo stato di default: foto nascosta
|
||||||
|
const $partsRow = $("#partsModal .parts-row");
|
||||||
|
$partsRow.find("> .col-md-3").addClass("d-none");
|
||||||
|
$partsRow
|
||||||
|
.find("> div:first-child")
|
||||||
|
.removeClass("col-md-9")
|
||||||
|
.addClass("col-md-12");
|
||||||
|
$("#showHideImageBtn").html(
|
||||||
|
"<i class='fas fa-eye' style='font-size: 0.8rem;'></i><i class='fas fa-image ms-1' style='font-size: 0.8rem;'></i>",
|
||||||
|
);
|
||||||
$(".temp-alert").remove();
|
$(".temp-alert").remove();
|
||||||
$(".modal-backdrop").remove();
|
$(".modal-backdrop").remove();
|
||||||
$("body").removeClass("modal-open").css("padding-right", "");
|
$("body").removeClass("modal-open").css("padding-right", "");
|
||||||
@@ -2154,6 +2164,9 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
window.saveAllParts = saveAllParts;
|
window.saveAllParts = saveAllParts;
|
||||||
|
window.markUnsaved = function () {
|
||||||
|
markUnsaved();
|
||||||
|
};
|
||||||
function renumberParts() {
|
function renumberParts() {
|
||||||
console.log(
|
console.log(
|
||||||
"Inizio rinumera parts, numero righe:",
|
"Inizio rinumera parts, numero righe:",
|
||||||
@@ -2672,135 +2685,195 @@ $(document).on("click", "#showHideImageBtn", function () {
|
|||||||
// RESIZABLE PARTS TABLE COLUMNS - FIXED COLGROUP VERSION
|
// RESIZABLE PARTS TABLE COLUMNS - FIXED COLGROUP VERSION
|
||||||
// ===================
|
// ===================
|
||||||
(function () {
|
(function () {
|
||||||
// Larghezze default per indice colonna (0-based)
|
const NUM_W = 55; // colonna Num fissa
|
||||||
const defaultWidths = [55, 320, 360, 150, 220, 230];
|
const MIN_W = 70; // larghezza minima di ogni colonna
|
||||||
const savedWidths = [...defaultWidths];
|
|
||||||
|
// Pesi di default delle colonne dopo Num
|
||||||
|
// senza extra: Descrizione, Matrice, Data, Azioni
|
||||||
|
// con extra: Descrizione, Matrice, Data, Extra, Azioni
|
||||||
|
const DEFAULT_NO_EXTRA = [320, 360, 150, 200];
|
||||||
|
const DEFAULT_EXTRA = [280, 320, 140, 240, 180];
|
||||||
|
|
||||||
|
let weights = null;
|
||||||
|
let weightsCount = 0;
|
||||||
|
|
||||||
function getColgroup() {
|
function getColgroup() {
|
||||||
return $("#partsTableColgroup");
|
return $("#partsTableColgroup");
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncColgroupToHeaders() {
|
function getThs() {
|
||||||
const $table = $("#partsTable");
|
return $("#partsTable thead tr:first th");
|
||||||
const $ths = $table.find("thead tr:first th");
|
|
||||||
const $colgroup = getColgroup();
|
|
||||||
const thCount = $ths.length;
|
|
||||||
|
|
||||||
// Assicura che ci siano esattamente tante <col> quante <th>
|
|
||||||
while ($colgroup.find("col").length < thCount) {
|
|
||||||
$colgroup.append("<col>");
|
|
||||||
}
|
|
||||||
while ($colgroup.find("col").length > thCount) {
|
|
||||||
$colgroup.find("col:last").remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Applica le larghezze salvate
|
|
||||||
$colgroup.find("col").each(function (i) {
|
|
||||||
const w = savedWidths[i] !== undefined ? savedWidths[i] : 150;
|
|
||||||
$(this).css("width", w + "px");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Imposta larghezza totale della tabella = somma colonne (evita reflow)
|
|
||||||
const total = savedWidths.slice(0, thCount).reduce((a, b) => a + b, 0);
|
|
||||||
$table.css("width", total + "px");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyColumnWidth(colIndex, newWidth) {
|
function getAvail() {
|
||||||
const w = Math.max(40, Math.round(newWidth));
|
const w = $("#partsModal .parts-table-scroll").innerWidth();
|
||||||
savedWidths[colIndex] = w;
|
return w > 0 ? Math.floor(w) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
const $col = getColgroup().find("col").eq(colIndex);
|
function ensureCols(n) {
|
||||||
if ($col.length) {
|
const $cg = getColgroup();
|
||||||
$col.css("width", w + "px");
|
while ($cg.find("col").length < n) $cg.append("<col>");
|
||||||
|
while ($cg.find("col").length > n) $cg.find("col:last").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureWeights(n) {
|
||||||
|
const k = n - 1;
|
||||||
|
if (weights && weightsCount === k) return;
|
||||||
|
if (k === 4) weights = DEFAULT_NO_EXTRA.slice();
|
||||||
|
else if (k === 5) weights = DEFAULT_EXTRA.slice();
|
||||||
|
else weights = Array(k).fill(150);
|
||||||
|
weightsCount = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converte i pesi in pixel: la somma è sempre = larghezza disponibile
|
||||||
|
function computePx(n) {
|
||||||
|
const avail = getAvail();
|
||||||
|
const rest = Math.max(avail - NUM_W, MIN_W * (n - 1));
|
||||||
|
const sum = weights.reduce((a, b) => a + b, 0) || 1;
|
||||||
|
const px = [NUM_W];
|
||||||
|
let used = 0;
|
||||||
|
for (let i = 0; i < weights.length; i++) {
|
||||||
|
const v =
|
||||||
|
i === weights.length - 1
|
||||||
|
? rest - used
|
||||||
|
: Math.floor((rest * weights[i]) / sum);
|
||||||
|
px.push(v);
|
||||||
|
used += v;
|
||||||
}
|
}
|
||||||
|
return px;
|
||||||
|
}
|
||||||
|
|
||||||
// Aggiorna larghezza totale tabella senza toccare le altre colonne
|
// Riallinea larghezza e posizione delle tendine Select2 aperte nella tabella
|
||||||
const thCount = $("#partsTable thead tr:first th").length;
|
function syncOpenSelect2() {
|
||||||
const total = savedWidths.slice(0, thCount).reduce((a, b) => a + b, 0);
|
$("#partsTable select.select2-hidden-accessible").each(function () {
|
||||||
$("#partsTable").css("width", total + "px");
|
const inst = $(this).data("select2");
|
||||||
|
if (!inst || typeof inst.isOpen !== "function" || !inst.isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const dd = inst.dropdown;
|
||||||
|
try {
|
||||||
|
if (dd && typeof dd._resizeDropdown === "function") {
|
||||||
|
dd._resizeDropdown();
|
||||||
|
}
|
||||||
|
if (dd && typeof dd._positionDropdown === "function") {
|
||||||
|
dd._positionDropdown();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Se la versione di Select2 non lo supporta, chiude la tendina
|
||||||
|
inst.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
const n = getThs().length;
|
||||||
|
if (!n || !getAvail()) return;
|
||||||
|
ensureCols(n);
|
||||||
|
ensureWeights(n);
|
||||||
|
const px = computePx(n);
|
||||||
|
getColgroup()
|
||||||
|
.find("col")
|
||||||
|
.each(function (i) {
|
||||||
|
$(this).css("width", px[i] + "px");
|
||||||
|
});
|
||||||
|
|
||||||
|
syncOpenSelect2();
|
||||||
}
|
}
|
||||||
|
|
||||||
function addResizers() {
|
function addResizers() {
|
||||||
const $table = $("#partsTable");
|
const $ths = getThs();
|
||||||
if (!$table.length) return;
|
const n = $ths.length;
|
||||||
|
if (!n) return;
|
||||||
|
|
||||||
|
$ths.find(".parts-resizer").remove();
|
||||||
|
|
||||||
|
// Resizer sul bordo destro delle colonne da 1 a n-2:
|
||||||
|
// sposta spazio tra la colonna e quella alla sua destra
|
||||||
|
$ths.each(function (i) {
|
||||||
|
if (i === 0 || i >= n - 1) return;
|
||||||
|
|
||||||
$table.find("thead tr:first th").each(function (colIndex) {
|
|
||||||
const $th = $(this);
|
const $th = $(this);
|
||||||
|
$th.css("position", "relative");
|
||||||
// Salta colonna Num (indice 0) — non ridimensionabile
|
|
||||||
if (colIndex === 0) return;
|
|
||||||
|
|
||||||
// Non aggiungere due volte
|
|
||||||
if ($th.find(".parts-resizer").length) return;
|
|
||||||
|
|
||||||
const $resizer = $("<span class='parts-resizer'></span>");
|
const $resizer = $("<span class='parts-resizer'></span>");
|
||||||
$th.css("position", "relative"); // necessario per il posizionamento assoluto
|
|
||||||
$th.append($resizer);
|
$th.append($resizer);
|
||||||
|
|
||||||
$resizer.on("mousedown", function (e) {
|
$resizer.on("mousedown", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
|
ensureWeights(n);
|
||||||
|
const startPx = computePx(n);
|
||||||
|
const a = startPx[i];
|
||||||
|
const b = startPx[i + 1];
|
||||||
const startX = e.pageX;
|
const startX = e.pageX;
|
||||||
// Leggi la larghezza ESATTA dalla <col>, non dal <th>
|
|
||||||
const startWidth =
|
|
||||||
savedWidths[colIndex] !== undefined
|
|
||||||
? savedWidths[colIndex]
|
|
||||||
: parseInt(
|
|
||||||
getColgroup()
|
|
||||||
.find("col")
|
|
||||||
.eq(colIndex)
|
|
||||||
.css("width"),
|
|
||||||
10,
|
|
||||||
) || 150;
|
|
||||||
|
|
||||||
$("body")
|
$("body").css({ "user-select": "none", cursor: "col-resize" });
|
||||||
.css("user-select", "none")
|
|
||||||
.css("cursor", "col-resize");
|
|
||||||
|
|
||||||
$(document).on("mousemove.partsResize", function (ev) {
|
$(document).on("mousemove.partsResize", function (ev) {
|
||||||
const delta = ev.pageX - startX;
|
const delta = ev.pageX - startX;
|
||||||
applyColumnWidth(colIndex, startWidth + delta);
|
const newA = Math.min(
|
||||||
|
Math.max(a + delta, MIN_W),
|
||||||
|
a + b - MIN_W,
|
||||||
|
);
|
||||||
|
const newB = a + b - newA;
|
||||||
|
|
||||||
|
const px = startPx.slice();
|
||||||
|
px[i] = newA;
|
||||||
|
px[i + 1] = newB;
|
||||||
|
weights = px.slice(1); // i pixel diventano i nuovi pesi
|
||||||
|
render();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("mouseup.partsResize", function () {
|
$(document).on("mouseup.partsResize", function () {
|
||||||
$("body").css("user-select", "").css("cursor", "");
|
$("body").css({ "user-select": "", cursor: "" });
|
||||||
$(document).off(".partsResize");
|
$(document).off(".partsResize");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function refresh() {
|
||||||
syncColgroupToHeaders();
|
render();
|
||||||
addResizers();
|
addResizers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init al primo show del modale
|
|
||||||
$(document).on("shown.bs.modal", "#partsModal", function () {
|
$(document).on("shown.bs.modal", "#partsModal", function () {
|
||||||
setTimeout(init, 120);
|
setTimeout(refresh, 120);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Re-init dopo ogni AJAX (nuove righe, caricamenti)
|
|
||||||
$(document).ajaxComplete(function () {
|
$(document).ajaxComplete(function () {
|
||||||
if ($("#partsModal").hasClass("show")) {
|
if ($("#partsModal").hasClass("show")) {
|
||||||
setTimeout(syncColgroupToHeaders, 200);
|
setTimeout(refresh, 200);
|
||||||
setTimeout(addResizers, 220);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Re-init dopo aggiunta/rimozione righe
|
|
||||||
$(document).on(
|
$(document).on(
|
||||||
"click",
|
"click",
|
||||||
".add-row-global, .add-mix-global, .add-mix-row, .remove-row, #renumberPartsBtn, #clonePartsBtn",
|
".add-row-global, .add-mix-global, .add-mix-row, .remove-row, #renumberPartsBtn, #clonePartsBtn",
|
||||||
function () {
|
function () {
|
||||||
setTimeout(syncColgroupToHeaders, 120);
|
setTimeout(refresh, 120);
|
||||||
setTimeout(addResizers, 140);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
window.initPartsResizableColumns = init;
|
let resizeTimer = null;
|
||||||
window.applyPartsColumnWidths = syncColgroupToHeaders;
|
$(window).on("resize.partsCols", function () {
|
||||||
|
if (!$("#partsModal").hasClass("show")) return;
|
||||||
|
clearTimeout(resizeTimer);
|
||||||
|
resizeTimer = setTimeout(render, 150);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Textarea campo extra: auto-altezza (per browser senza field-sizing)
|
||||||
|
$(document).on(
|
||||||
|
"input focus",
|
||||||
|
"#partsTable textarea.part-extra-field",
|
||||||
|
function () {
|
||||||
|
this.style.height = "auto";
|
||||||
|
this.style.height = this.scrollHeight + "px";
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
window.initPartsResizableColumns = refresh;
|
||||||
|
window.applyPartsColumnWidths = refresh;
|
||||||
})();
|
})();
|
||||||
// ===================
|
// ===================
|
||||||
// NAVIGAZIONE TABELLA PARTI CON FRECCE TASTIERA
|
// NAVIGAZIONE TABELLA PARTI CON FRECCE TASTIERA
|
||||||
|
|||||||
@@ -8,12 +8,41 @@ header('Content-Type: application/json');
|
|||||||
|
|
||||||
$iddatadb = (int)($_POST['iddatadb'] ?? 0);
|
$iddatadb = (int)($_POST['iddatadb'] ?? 0);
|
||||||
$newStatus = $_POST['status'] ?? 'i';
|
$newStatus = $_POST['status'] ?? 'i';
|
||||||
|
$action = $_POST['action'] ?? 'revert';
|
||||||
|
|
||||||
if ($iddatadb <= 0) {
|
if ($iddatadb <= 0) {
|
||||||
echo json_encode(['success' => false, 'message' => 'ID record mancante']);
|
echo json_encode(['success' => false, 'message' => 'ID record mancante']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cancellazione record (consentita solo da stato 'i' o 'x')
|
||||||
|
if ($action === 'delete') {
|
||||||
|
try {
|
||||||
|
$db = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM datadb WHERE iddatadb = ? AND status IN ('i', 'x')");
|
||||||
|
$stmt->execute([$iddatadb]);
|
||||||
|
|
||||||
|
if ($stmt->rowCount() > 0) {
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} else {
|
||||||
|
$chk = $pdo->prepare("SELECT status FROM datadb WHERE iddatadb = ?");
|
||||||
|
$chk->execute([$iddatadb]);
|
||||||
|
$current = $chk->fetchColumn();
|
||||||
|
|
||||||
|
if ($current === false) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Record non trovato']);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['success' => false, 'message' => "Cancellazione non consentita: stato attuale '$current'"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Da questa azione consentiamo solo il ritorno a 'i'
|
// Da questa azione consentiamo solo il ritorno a 'i'
|
||||||
if ($newStatus !== 'i') {
|
if ($newStatus !== 'i') {
|
||||||
echo json_encode(['success' => false, 'message' => 'Stato non consentito']);
|
echo json_encode(['success' => false, 'message' => 'Stato non consentito']);
|
||||||
@@ -24,8 +53,11 @@ try {
|
|||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
// Aggiorna solo se attualmente è in stato 'l' (To LIMS)
|
// Aggiorna solo se attualmente è in stato 'l' (To LIMS).
|
||||||
$stmt = $pdo->prepare("UPDATE datadb SET status = ? WHERE iddatadb = ? AND status = 'l'");
|
// Azzera idcommessaweb: il revert è una scelta esplicita di riesportare, altrimenti il
|
||||||
|
// CHECK PRELIMINARE di export_to_lims.php riallineerebbe la riga alla vecchia commessa.
|
||||||
|
// commessaweb resta come traccia del codice precedente.
|
||||||
|
$stmt = $pdo->prepare("UPDATE datadb SET status = ?, idcommessaweb = NULL WHERE iddatadb = ? AND status IN ('l', 'x')");
|
||||||
$stmt->execute([$newStatus, $iddatadb]);
|
$stmt->execute([$newStatus, $iddatadb]);
|
||||||
|
|
||||||
if ($stmt->rowCount() > 0) {
|
if ($stmt->rowCount() > 0) {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ try {
|
|||||||
$api = VisualLimsApiClient::getInstance();
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'$select' => 'IdCliente,Nominativo,CodiceCliente,Inattivo',
|
'$select' => 'IdCliente,Nominativo,CodiceCliente,Inattivo,CodiceASL',
|
||||||
'$orderby' => 'Nominativo asc'
|
'$orderby' => 'Nominativo asc'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
include('include/headscript.php');
|
include('include/headscript.php');
|
||||||
require_once __DIR__ . '/class/Mailer.class.php';
|
require_once __DIR__ . '/class/Mailer.class.php';
|
||||||
|
require_once __DIR__ . '/class/block_alert.php';
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,9 +92,10 @@ $sql = "
|
|||||||
FROM datadb d
|
FROM datadb d
|
||||||
LEFT JOIN auth_users u ON d.user_id = u.id
|
LEFT JOIN auth_users u ON d.user_id = u.id
|
||||||
WHERE d.iddatadb IN ($ph)
|
WHERE d.iddatadb IN ($ph)
|
||||||
|
ORDER BY FIELD(d.iddatadb, $ph)
|
||||||
";
|
";
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute($ids);
|
$stmt->execute(array_merge($ids, $ids));
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
if (empty($rows)) {
|
if (empty($rows)) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Righe non trovate']);
|
echo json_encode(['success' => false, 'message' => 'Righe non trovate']);
|
||||||
@@ -157,6 +159,16 @@ foreach ($s->fetchAll(PDO::FETCH_ASSOC) as $r) {
|
|||||||
}
|
}
|
||||||
$noPriceTotal = array_sum(array_map('count', $noPriceByRow));
|
$noPriceTotal = array_sum(array_map('count', $noPriceByRow));
|
||||||
|
|
||||||
|
// cliente bloccato per ogni iddatadb (CodiceASL con "blocco", letto dalla cache clienti, nessuna chiamata API)
|
||||||
|
$blockByRow = []; // iddatadb => ['idCliente','nominativo','motivo','campo']
|
||||||
|
foreach ($rows as $r) {
|
||||||
|
$bl = getClientBlockAlert($r['idclient'] ?? 0, $r['ClienteFatturazione'] ?? null);
|
||||||
|
if ($bl) {
|
||||||
|
$blockByRow[(int)$r['iddatadb']] = $bl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$blockTotal = count($blockByRow);
|
||||||
|
|
||||||
// destinatari: utente/i dell'export che hanno la notifica attiva + admin fisso
|
// destinatari: utente/i dell'export che hanno la notifica attiva + admin fisso
|
||||||
$recipients = [];
|
$recipients = [];
|
||||||
foreach ($rows as $r) {
|
foreach ($rows as $r) {
|
||||||
@@ -174,14 +186,18 @@ if (empty($recipients)) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// conteggi
|
// conteggi. La mail riflette lo stato in DB al momento dell'invio: una riga ancora 'i'
|
||||||
|
// (export interrotto da timeout/errore di rete, o ancora in corso) NON è un successo.
|
||||||
$okCount = 0;
|
$okCount = 0;
|
||||||
$errCount = 0;
|
$errCount = 0;
|
||||||
|
$pendingCount = 0;
|
||||||
foreach ($rows as $r) {
|
foreach ($rows as $r) {
|
||||||
if ($r['status'] === 'l') $okCount++;
|
if ($r['status'] === 'l') $okCount++;
|
||||||
elseif ($r['status'] === 'x') $errCount++;
|
elseif ($r['status'] === 'x') $errCount++;
|
||||||
|
else $pendingCount++;
|
||||||
}
|
}
|
||||||
$hasError = $errCount > 0;
|
$hasError = $errCount > 0;
|
||||||
|
$hasPending = $pendingCount > 0;
|
||||||
|
|
||||||
// --- tabella righe ---
|
// --- tabella righe ---
|
||||||
$rowsHtml = '';
|
$rowsHtml = '';
|
||||||
@@ -196,7 +212,7 @@ foreach ($rows as $r) {
|
|||||||
$bg = '#fdecea';
|
$bg = '#fdecea';
|
||||||
$col = '#c0392b';
|
$col = '#c0392b';
|
||||||
} else {
|
} else {
|
||||||
$label = htmlspecialchars((string)$st);
|
$label = 'NON CONFERMATA';
|
||||||
$bg = '#fff8e1';
|
$bg = '#fff8e1';
|
||||||
$col = '#8a6d3b';
|
$col = '#8a6d3b';
|
||||||
}
|
}
|
||||||
@@ -237,12 +253,44 @@ foreach ($rows as $r) {
|
|||||||
</td>
|
</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sotto-riga: cliente bloccato
|
||||||
|
$bl = $blockByRow[(int)$r['iddatadb']] ?? null;
|
||||||
|
if ($bl) {
|
||||||
|
$blCampo = htmlspecialchars($bl['campo']);
|
||||||
|
$blNome = htmlspecialchars($bl['nominativo'] !== '' ? $bl['nominativo'] : (string)$bl['idCliente']);
|
||||||
|
$blMotivo = htmlspecialchars($bl['motivo']);
|
||||||
|
|
||||||
|
$rowsHtml .= "<tr>
|
||||||
|
<td colspan='5' style='padding:8px 12px 12px 24px;border-bottom:1px solid #eee;background:#fdecea;'>
|
||||||
|
<div style='font-size:12px;color:#842029;font-weight:600;'>
|
||||||
|
<span style='display:inline-block;padding:2px 8px;border-radius:10px;background:#842029;color:#fff;font-size:11px;'>Cliente bloccato</span>
|
||||||
|
{$blCampo}: {$blNome}
|
||||||
|
</div>
|
||||||
|
<div style='margin-top:4px;font-size:13px;color:#842029;font-weight:700;'>{$blMotivo}</div>
|
||||||
|
</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$headerColor = $hasError ? '#c0392b' : '#1e7e34';
|
if ($hasError) {
|
||||||
$headerText = $hasError ? 'Export completato con errori' : 'Export completato con successo';
|
$headerColor = '#c0392b';
|
||||||
|
$headerText = 'Export completato con errori';
|
||||||
|
} elseif ($hasPending) {
|
||||||
|
$headerColor = '#b7791f';
|
||||||
|
$headerText = 'Export da verificare';
|
||||||
|
} else {
|
||||||
|
$headerColor = '#1e7e34';
|
||||||
|
$headerText = 'Export completato con successo';
|
||||||
|
}
|
||||||
$total = count($rows);
|
$total = count($rows);
|
||||||
|
|
||||||
|
// Committente / Fatturazione in testata solo se uguali per tutte le righe (batch misti → "vari")
|
||||||
|
$headerClient = function ($col) use ($rows, $clientLabel) {
|
||||||
|
$vals = array_unique(array_map(fn($r) => (int)($r[$col] ?? 0), $rows));
|
||||||
|
return count($vals) === 1 ? $clientLabel(reset($vals)) : 'vari';
|
||||||
|
};
|
||||||
|
|
||||||
$html = "
|
$html = "
|
||||||
<div style='font-family:Arial,Helvetica,sans-serif;max-width:820px;margin:0 auto;border:1px solid #e0e0e0;border-radius:8px;overflow:hidden;'>
|
<div style='font-family:Arial,Helvetica,sans-serif;max-width:820px;margin:0 auto;border:1px solid #e0e0e0;border-radius:8px;overflow:hidden;'>
|
||||||
<div style='background:{$headerColor};color:#fff;padding:18px 24px;'>
|
<div style='background:{$headerColor};color:#fff;padding:18px 24px;'>
|
||||||
@@ -250,9 +298,9 @@ $html = "
|
|||||||
<p style='margin:6px 0 0;font-size:13px;opacity:.9;'>Riepilogo esportazione verso LIMS" .
|
<p style='margin:6px 0 0;font-size:13px;opacity:.9;'>Riepilogo esportazione verso LIMS" .
|
||||||
($templateName !== '' ? " · Template: <strong>" . htmlspecialchars($templateName) . "</strong>" : "") . "</p>
|
($templateName !== '' ? " · Template: <strong>" . htmlspecialchars($templateName) . "</strong>" : "") . "</p>
|
||||||
<p style='margin:6px 0 0;font-size:13px;opacity:.95;'>
|
<p style='margin:6px 0 0;font-size:13px;opacity:.95;'>
|
||||||
Committente: <strong>" . $clientLabel($rows[0]['idclient'] ?? 0) . "</strong>
|
Committente: <strong>" . $headerClient('idclient') . "</strong>
|
||||||
·
|
·
|
||||||
FatturazioneAvanzata: <strong>" . $clientLabel($rows[0]['ClienteFatturazione'] ?? 0) . "</strong>
|
FatturazioneAvanzata: <strong>" . $headerClient('ClienteFatturazione') . "</strong>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div style='padding:20px 24px;'>
|
<div style='padding:20px 24px;'>
|
||||||
@@ -260,7 +308,9 @@ $html = "
|
|||||||
Totale commesse: <strong>{$total}</strong> •
|
Totale commesse: <strong>{$total}</strong> •
|
||||||
<span style='color:#1e7e34;'>Inviate: {$okCount}</span> •
|
<span style='color:#1e7e34;'>Inviate: {$okCount}</span> •
|
||||||
<span style='color:#c0392b;'>Errori: {$errCount}</span>" .
|
<span style='color:#c0392b;'>Errori: {$errCount}</span>" .
|
||||||
($noPriceTotal > 0 ? " • <span style='color:#c0392b;'>Analisi No price: {$noPriceTotal}</span>" : "") . "
|
($pendingCount > 0 ? " • <span style='color:#8a6d3b;'>Non confermate: {$pendingCount}</span>" : "") .
|
||||||
|
($noPriceTotal > 0 ? " • <span style='color:#c0392b;'>Analisi No price: {$noPriceTotal}</span>" : "") .
|
||||||
|
($blockTotal > 0 ? " • <span style='color:#842029;'>Clienti bloccati: {$blockTotal}</span>" : "") . "
|
||||||
</p>
|
</p>
|
||||||
<table style='width:100%;border-collapse:collapse;font-size:14px;table-layout:fixed;'>
|
<table style='width:100%;border-collapse:collapse;font-size:14px;table-layout:fixed;'>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -274,15 +324,16 @@ $html = "
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>{$rowsHtml}</tbody>
|
<tbody>{$rowsHtml}</tbody>
|
||||||
</table>
|
</table>
|
||||||
" . ($hasError ? "<p style='margin:18px 0 0;padding:12px;background:#fdecea;border-left:4px solid #c0392b;color:#c0392b;font-size:13px;border-radius:4px;'>⚠️ Alcune commesse non sono state inviate al LIMS. Controlla la sezione <strong>Errors</strong> nell'applicazione per i dettagli e per rilanciarle.</p>" : "") . "
|
" . ($hasError ? "<p style='margin:18px 0 0;padding:12px;background:#fdecea;border-left:4px solid #c0392b;color:#c0392b;font-size:13px;border-radius:4px;'>⚠️ Alcune commesse non sono state inviate al LIMS. Controlla la sezione <strong>Errors</strong> nell'applicazione per i dettagli e per rilanciarle.</p>" : "") .
|
||||||
|
($hasPending ? "<p style='margin:18px 0 0;padding:12px;background:#fff8e1;border-left:4px solid #b7791f;color:#8a6d3b;font-size:13px;border-radius:4px;'>⚠️ Per alcune commesse l'esito non è ancora confermato (timeout o errore di rete durante l'invio). <strong>Non rilanciarle</strong>: ricarica la pagina tra qualche minuto e verifica lo stato.</p>" : "") . "
|
||||||
</div>
|
</div>
|
||||||
<div style='background:#fafafa;padding:14px 24px;font-size:12px;color:#999;border-top:1px solid #eee;'>
|
<div style='background:#fafafa;padding:14px 24px;font-size:12px;color:#999;border-top:1px solid #eee;'>
|
||||||
Messaggio automatico da SmartTRF — non rispondere a questa email.
|
Messaggio automatico da SmartTRF — non rispondere a questa email.
|
||||||
</div>
|
</div>
|
||||||
</div>";
|
</div>";
|
||||||
|
|
||||||
$subjectPrefix = $hasError ? '⚠️ Errori Export LIMS' : '✅ Export LIMS OK';
|
$subjectPrefix = $hasError ? '⚠️ Errori Export LIMS' : ($hasPending ? '⏳ Export LIMS da verificare' : '✅ Export LIMS OK');
|
||||||
$subject = "{$subjectPrefix} — {$total} commesse ({$okCount} ok, {$errCount} err)";
|
$subject = "{$subjectPrefix} — {$total} commesse ({$okCount} ok, {$errCount} err" . ($pendingCount > 0 ? ", {$pendingCount} non confermate" : "") . ")";
|
||||||
|
|
||||||
$res = Mailer::send($recipients, $subject, $html);
|
$res = Mailer::send($recipients, $subject, $html);
|
||||||
|
|
||||||
@@ -290,5 +341,5 @@ echo json_encode([
|
|||||||
'success' => $res['ok'],
|
'success' => $res['ok'],
|
||||||
'message' => $res['ok'] ? 'Mail inviata' : ('Mail non inviata: ' . $res['error']),
|
'message' => $res['ok'] ? 'Mail inviata' : ('Mail non inviata: ' . $res['error']),
|
||||||
'recipients' => $recipients,
|
'recipients' => $recipients,
|
||||||
'counts' => ['ok' => $okCount, 'err' => $errCount, 'total' => $total],
|
'counts' => ['ok' => $okCount, 'err' => $errCount, 'pending' => $pendingCount, 'total' => $total],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ try {
|
|||||||
|
|
||||||
// 1. Clients
|
// 1. Clients
|
||||||
warmLog('[clients] Fetching...', $isCli);
|
warmLog('[clients] Fetching...', $isCli);
|
||||||
$params = ['$select' => 'IdCliente,Nominativo,CodiceCliente,Inattivo', '$orderby' => 'Nominativo asc'];
|
$params = ['$select' => 'IdCliente,Nominativo,CodiceCliente,Inattivo,CodiceASL', '$orderby' => 'Nominativo asc'];
|
||||||
$clientData = $api->get("Cliente?" . http_build_query($params));
|
$clientData = $api->get("Cliente?" . http_build_query($params));
|
||||||
file_put_contents($cacheDir . '/clienti.json', json_encode($clientData));
|
file_put_contents($cacheDir . '/clienti.json', json_encode($clientData));
|
||||||
$clientCount = count($clientData['value'] ?? []);
|
$clientCount = count($clientData['value'] ?? []);
|
||||||
|
|||||||
Reference in New Issue
Block a user