report search

This commit is contained in:
2026-06-10 11:02:43 +02:00
parent 6e43a178af
commit d088364a0d
7 changed files with 1558 additions and 23 deletions
@@ -257,35 +257,56 @@ class VisualLimsApiClient
}
/**
* Recupera contenuto binario - Adattato per https://bvcpsitaly-elims.com/limsapi
* Get raw/binary content from VisualLims API.
* Used for PDF downloads from MediaFile/DownloadStream.
*/
public function getRaw($endpoint)
{
$token = $this->getToken();
// IMPORTANTE: usa /odata/ e NON /api/odata/
$url = "{$this->baseUrl}/odata/{$endpoint}";
/*
* Normal JSON OData calls use:
* {$this->baseUrl}/api/odata/...
*
* Media file downloads use:
* {$this->baseUrl}/api/MediaFile/DownloadStream...
*/
$url = rtrim($this->baseUrl, '/') . '/api/' . ltrim($endpoint, '/');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer {$token}",
"Accept: */*"
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer {$token}",
"Accept: application/pdf,*/*"
],
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 60
]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$curlError = curl_error($ch);
curl_close($ch);
if ($response === false) {
throw new Exception("Errore cURL: " . $curl_error);
throw new Exception("Errore cURL download raw: " . $curlError);
}
if ($http_code !== 200) {
throw new Exception("HTTP {$http_code} su endpoint: " . $url);
if ($httpCode < 200 || $httpCode >= 300) {
throw new Exception(
"Errore HTTP {$httpCode} durante download raw. Content-Type: {$contentType}. Response: " .
substr($response, 0, 500)
);
}
if (empty($response)) {
throw new Exception("Risposta vuota dal download raw.");
}
return $response;
+46
View File
@@ -0,0 +1,46 @@
<?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php';
ini_set('display_errors', '0');
error_reporting(E_ALL);
try {
$idRapportoFile = isset($_GET['id_rapporto_file']) ? (int)$_GET['id_rapporto_file'] : 0;
if ($idRapportoFile <= 0) {
throw new Exception("Parametro id_rapporto_file mancante o non valido.");
}
/*
* This endpoint returns the PDF binary stream.
* Do not call this with the normal get() method because get() expects JSON.
*/
$endpoint = "MediaFile/DownloadStream?objectType=RapportoFile&propertyName=FileContent&objectKey={$idRapportoFile}";
$api = VisualLimsApiClient::getInstance();
$pdfContent = $api->getRaw($endpoint);
if (empty($pdfContent)) {
throw new Exception("PDF vuoto o non ricevuto dal server.");
}
$fileName = "rapporto_{$idRapportoFile}.pdf";
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $fileName . '"');
header('Content-Length: ' . strlen($pdfContent));
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
echo $pdfContent;
exit;
} catch (Exception $e) {
http_response_code(500);
header('Content-Type: application/json; charset=utf-8');
echo json_encode([
'success' => false,
'error' => $e->getMessage()
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}
+143
View File
@@ -0,0 +1,143 @@
<?php
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();
$idCliente = isset($_GET['id_cliente']) ? (int)$_GET['id_cliente'] : 0;
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 3;
$signedStatus = trim($_GET['signed_status'] ?? 'all');
if ($idCliente <= 0) {
throw new Exception("Parametro id_cliente mancante o non valido.");
}
/*
* Allowed limits only.
* This prevents risky wide queries on the live LIMS.
*/
$allowedLimits = [1, 3, 5, 10];
if (!in_array($limit, $allowedLimits, true)) {
$limit = 3;
}
/*
* Allowed signature filters.
*/
$allowedSignedStatuses = ['all', 'signed', 'not_signed'];
if (!in_array($signedStatus, $allowedSignedStatuses, true)) {
$signedStatus = 'all';
}
/*
* Base filter by customer.
* We already verified that Rapporto can expand Cliente and returns Cliente.IdCliente.
*/
$filters = [
"Cliente/IdCliente eq {$idCliente}"
];
if ($signedStatus === 'signed') {
$filters[] = "Firmato eq true";
}
if ($signedStatus === 'not_signed') {
$filters[] = "Firmato eq false";
}
$filter = implode(' and ', $filters);
/*
* Important:
* - $top limits the number of reports.
* - $orderby=Data desc gets the latest reports first.
* - $expand=RapportiFiles retrieves only the PDF file metadata, not the binary PDF.
*/
$params = [
'$filter' => $filter,
'$select' => 'IdRapporto,CodiceRapporto,Data,Versione,Firmato,DataStampa',
'$expand' => 'RapportiFiles',
'$orderby' => 'Data desc',
'$top' => $limit
];
$endpoint = "Rapporto?" . http_build_query($params);
file_put_contents(
__DIR__ . '/last_rapporti_cliente_endpoint.txt',
'[' . date('Y-m-d H:i:s') . '] ' . $endpoint . PHP_EOL,
FILE_APPEND
);
$data = $api->get($endpoint);
$items = $data['value'] ?? [];
if (!is_array($items)) {
$items = [];
}
$reports = [];
foreach ($items as $item) {
$rapportiFiles = $item['RapportiFiles'] ?? [];
$pdfFiles = [];
if (is_array($rapportiFiles)) {
foreach ($rapportiFiles as $file) {
$idRapportoFile = intval($file['IdRapportoFile'] ?? 0);
if ($idRapportoFile > 0) {
$pdfFiles[] = [
'id_rapporto_file' => $idRapportoFile,
'file_name' => $file['FileName'] ?? null,
'categoria' => $file['Categoria'] ?? null,
'tipo_rapporto' => $file['TipoRapporto'] ?? null,
'download_url' => "download_rapporto_pdf.php?id_rapporto_file={$idRapportoFile}"
];
}
}
}
$reports[] = [
'id_rapporto' => $item['IdRapporto'] ?? null,
'codice_rapporto' => $item['CodiceRapporto'] ?? null,
'data' => $item['Data'] ?? null,
'data_stampa' => $item['DataStampa'] ?? null,
'versione' => $item['Versione'] ?? null,
'firmato' => $item['Firmato'] ?? null,
'pdf_files' => $pdfFiles
];
}
echo json_encode([
'success' => true,
'id_cliente' => $idCliente,
'limit' => $limit,
'signed_status' => $signedStatus,
'endpoint' => $endpoint,
'count' => count($reports),
'reports' => $reports
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} catch (Exception $e) {
file_put_contents(
__DIR__ . '/error_log.txt',
date('Y-m-d H:i:s') . ' - get_rapporti_cliente.php - ' . $e->getMessage() . PHP_EOL,
FILE_APPEND
);
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}
+46 -7
View File
@@ -17,6 +17,7 @@ try {
// rapporto_by_codice_expand_step.php?codice=2541111&step=files_campioni
$codiceRapporto = trim($_GET['codice'] ?? '');
// Safe step mode: default is base, but allows controlled read-only steps
$step = trim($_GET['step'] ?? 'base');
if ($codiceRapporto === '') {
@@ -25,10 +26,9 @@ try {
$allowedSteps = [
'base' => '',
'files' => 'RapportiFiles',
'allegati' => 'RapportiAllegati',
'campioni' => 'CampioniDatiRapporto',
'files_campioni' => 'RapportiFiles,CampioniDatiRapporto'
'files' => 'RapportiFiles,Cliente',
'cliente' => 'Cliente'
];
if (!array_key_exists($step, $allowedSteps)) {
@@ -37,7 +37,8 @@ try {
// Escape OData per eventuali apostrofi
$codiceRapportoSafe = str_replace("'", "''", $codiceRapporto);
// Safe version of codice rapporto for filenames
$codiceRapportoFileSafe = preg_replace('/[^a-zA-Z0-9_-]/', '_', $codiceRapporto);
/*
* STEP 1 - Trova IdRapporto partendo da CodiceRapporto.
* Query leggera, con $select e $top=1.
@@ -107,15 +108,43 @@ try {
$detailData = $api->get($detailEndpoint);
$pdfFiles = [];
if ($step === 'files') {
$rapportiFiles = $detailData['RapportiFiles'] ?? [];
if (is_array($rapportiFiles)) {
foreach ($rapportiFiles as $file) {
$idRapportoFile = intval($file['IdRapportoFile'] ?? 0);
if ($idRapportoFile > 0) {
$pdfFiles[] = [
'id_rapporto_file' => $idRapportoFile,
'file_name' => $file['FileName'] ?? null,
'categoria' => $file['Categoria'] ?? null,
'tipo_rapporto' => $file['TipoRapporto'] ?? null,
'download_endpoint' => "MediaFile/DownloadStream?objectType=RapportoFile&propertyName=FileContent&objectKey={$idRapportoFile}"
];
}
}
}
}
$clienteData = null;
if ($step === 'cliente' || $step === 'files') {
$clienteData = $detailData['Cliente'] ?? null;
}
file_put_contents(
__DIR__ . "/rapporto_codice_{$codiceRapportoSafe}_{$step}.json",
__DIR__ . "/rapporto_codice_{$codiceRapportoFileSafe}_{$step}.json",
json_encode([
'search' => $searchData,
'detail' => $detailData
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
);
echo json_encode([
$response = [
'success' => true,
'codice_rapporto' => $codiceRapporto,
'id_rapporto' => $rapportoId,
@@ -124,7 +153,17 @@ try {
'detail_endpoint' => $detailEndpoint,
'rapporto_base' => $rapportoBase,
'data' => $detailData
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
];
if ($step === 'files') {
$response['pdf_files'] = $pdfFiles;
}
if ($step === 'cliente' || $step === 'files') {
$response['cliente'] = $clienteData;
}
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} catch (Exception $e) {
file_put_contents(
__DIR__ . '/error_log.txt',
+8 -2
View File
@@ -57,8 +57,14 @@
</li>
<li class="menu-label">Reports</li>
<li>
<a href="rapporti_cliente_lookup.php" target="">
<div class="parent-icon"><i class="bx bx-file-find"></i>
</div>
<div class="menu-title">Ricerca Reports</div>
</a>
</li>
<li class="menu-label">Others</li>
+700
View File
@@ -0,0 +1,700 @@
<?php include('include/headscript.php'); ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<link href="assets/plugins/datatable/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
<title>TRF-Project - Customer Reports</title>
<style>
.lookup-wrapper {
width: 100%;
max-width: none;
margin: 0;
}
.lookup-title {
font-size: 18px;
font-weight: 700;
}
.lookup-subtitle {
font-size: 13px;
color: #6c757d;
}
.compact-card .card-body {
padding: 1rem;
}
.table-report th {
font-size: 12px;
text-transform: uppercase;
color: #6c757d;
white-space: nowrap;
}
.table-report td {
font-size: 13px;
vertical-align: middle;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 10px;
border-radius: 999px;
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.status-pill-success {
background: #e8fff1;
color: #198754;
}
.status-pill-warning {
background: #fff3cd;
color: #b58100;
}
.pdf-icon-link {
width: 36px;
height: 36px;
border-radius: 10px;
background: #dc3545;
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 20px;
text-decoration: none;
transition: all 0.15s ease-in-out;
}
.pdf-icon-link:hover {
color: #fff;
opacity: 0.85;
transform: translateY(-1px);
}
.no-pdf {
font-size: 12px;
color: #adb5bd;
font-weight: 600;
}
.empty-state {
border: 1px dashed #ced4da;
border-radius: 10px;
padding: 24px;
text-align: center;
color: #6c757d;
background: #fafafa;
}
.spinner-inline {
display: none;
margin-left: 8px;
}
.customer-box {
display: none;
border: 1px solid #e9ecef;
background: #fff;
border-radius: 10px;
padding: 12px 14px;
margin-bottom: 15px;
}
.customer-label {
font-size: 11px;
text-transform: uppercase;
color: #6c757d;
font-weight: 700;
}
.customer-value {
font-size: 14px;
color: #212529;
font-weight: 700;
}
.json-preview {
display: none;
background: #111827;
color: #e5e7eb;
border-radius: 10px;
padding: 14px;
font-size: 12px;
max-height: 420px;
overflow: auto;
white-space: pre-wrap;
}
@media (max-width: 768px) {
.table-responsive {
border-radius: 10px;
}
}
.select2-container {
width: 100% !important;
}
.select2-container--default .select2-selection--single {
height: 38px;
border: 1px solid #ced4da;
border-radius: 6px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height: 36px;
font-size: 14px;
color: #212529;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 36px;
}
.select2-dropdown {
z-index: 9999;
}
</style>
</head>
<body>
<div class="wrapper">
<?php include('include/navbar.php'); ?>
<?php include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<?php include('top_stat_widget.php'); ?>
<div class="lookup-wrapper">
<div class="card radius-10 compact-card">
<div class="card-header">
<div class="d-flex align-items-center justify-content-between flex-wrap gap-2">
<div>
<div class="lookup-title">Customer Test Reports</div>
<div class="lookup-subtitle">
Select a VisualLims customer and retrieve the latest reports with PDF links.
</div>
</div>
</div>
</div>
<div class="card-body">
<form id="customerReportsForm" class="row g-3 align-items-end">
<div class="col-md-5">
<label for="idCliente" class="form-label fw-semibold">Customer</label>
<select id="idCliente" name="idCliente" class="form-select">
<option value="">Loading customers...</option>
</select>
</div>
<div class="col-md-2">
<label for="limitReports" class="form-label fw-semibold">Limit</label>
<select id="limitReports" name="limitReports" class="form-select">
<option value="1">Last 1</option>
<option value="3" selected>Last 3</option>
<option value="5">Last 5</option>
<option value="10">Last 10</option>
</select>
</div>
<div class="col-md-2">
<label for="signedStatus" class="form-label fw-semibold">Status</label>
<select id="signedStatus" name="signedStatus" class="form-select">
<option value="all" selected>All</option>
<option value="signed">Signed</option>
<option value="not_signed">Not signed</option>
</select>
</div>
<div class="col-md-3">
<button type="submit" id="btnSearchReports" class="btn btn-primary w-100">
<i class="bx bx-search"></i> Search Reports
<span class="spinner-border spinner-border-sm spinner-inline" id="searchSpinner" role="status" aria-hidden="true"></span>
</button>
</div>
</form>
</div>
</div>
<div id="customerBox" class="customer-box">
<div class="row g-3">
<div class="col-md-4">
<div class="customer-label">Customer Code</div>
<div class="customer-value" id="selectedCustomerCode">-</div>
</div>
<div class="col-md-8">
<div class="customer-label">Customer Name</div>
<div class="customer-value" id="selectedCustomerName">-</div>
</div>
</div>
</div>
<div id="resultContainer" style="display:none;">
<div class="card radius-10 compact-card">
<div class="card-header">
<div class="d-flex align-items-center justify-content-between flex-wrap gap-2">
<h6 class="mb-0">
Reports
<span class="badge bg-light text-dark ms-1" id="reportCountBadge">0</span>
</h6>
<button type="button" id="toggleJsonBtn" class="btn btn-sm btn-outline-secondary">
<i class="bx bx-code-alt"></i> Show JSON
</button>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover table-report align-middle mb-0" id="reportsTable">
<thead>
<tr>
<th>Report Number</th>
<th>Report ID</th>
<th>Report Date</th>
<th>Print Date</th>
<th>Version</th>
<th>Status</th>
<th class="text-center">PDF</th>
</tr>
</thead>
<tbody id="reportsTableBody"></tbody>
</table>
</div>
<pre id="jsonPreview" class="json-preview mt-3"></pre>
</div>
</div>
</div>
<div id="emptyState" class="empty-state">
<i class="bx bx-file-find" style="font-size:34px;"></i>
<div class="mt-2 fw-semibold">No reports loaded</div>
<div class="small">Select a customer, choose the limit and click Search Reports.</div>
</div>
</div>
</div>
</div>
<div class="overlay toggle-icon"></div>
<a href="javaScript:;" class="back-to-top">
<i class='bx bxs-up-arrow-alt'></i>
</a>
<?php include('include/footer.php'); ?>
</div>
<?php include('jsinclude.php'); ?>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script src="assets/plugins/datatable/js/jquery.dataTables.min.js"></script>
<script src="assets/plugins/datatable/js/dataTables.bootstrap5.min.js"></script>
<script>
$(document).ready(function() {
let lastJsonResponse = null;
let loadedCustomers = [];
let reportsDataTable = null;
function escapeHtml(value) {
if (value === null || value === undefined) {
return '';
}
return String(value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function formatDate(value) {
if (!value) {
return '-';
}
const date = new Date(value);
if (isNaN(date.getTime())) {
return value;
}
return date.toLocaleString('it-IT', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
});
}
function setLoading(isLoading) {
$('#btnSearchReports').prop('disabled', isLoading);
$('#searchSpinner').toggle(isLoading);
}
function resetResults() {
lastJsonResponse = null;
if (reportsDataTable !== null) {
reportsDataTable.destroy();
reportsDataTable = null;
}
$('#resultContainer').hide();
$('#emptyState').show();
$('#reportsTableBody').html('');
$('#reportCountBadge').text('0');
$('#jsonPreview').hide().text('');
$('#toggleJsonBtn').html('<i class="bx bx-code-alt"></i> Show JSON');
}
function loadCustomers() {
$.ajax({
url: 'get_clienti.php',
method: 'GET',
dataType: 'json',
success: function(response) {
const select = $('#idCliente');
select.empty();
const customers = response.value || response || [];
loadedCustomers = Array.isArray(customers) ? customers : [];
select.append('<option value="">Select customer...</option>');
loadedCustomers.forEach(function(customer) {
const idCliente = customer.IdCliente || '';
const codiceCliente = customer.CodiceCliente || '';
const nominativo = customer.Nominativo || '';
const label = codiceCliente ?
codiceCliente + ' - ' + nominativo :
nominativo;
select.append(
'<option value="' + escapeHtml(idCliente) + '" ' +
'data-code="' + escapeHtml(codiceCliente) + '" ' +
'data-name="' + escapeHtml(nominativo) + '">' +
escapeHtml(label) +
'</option>'
);
});
if ($.fn.select2) {
select.select2({
width: '100%',
placeholder: 'Search customer...',
allowClear: true,
minimumInputLength: 0,
matcher: function(params, data) {
if ($.trim(params.term) === '') {
return data;
}
if (typeof data.text === 'undefined') {
return null;
}
const term = params.term.toLowerCase();
const text = data.text.toLowerCase();
if (text.indexOf(term) > -1) {
return data;
}
return null;
},
sorter: function(data) {
const term = $('.select2-search__field').val();
if (!term) {
return data;
}
const search = term.toLowerCase();
return data.sort(function(a, b) {
const aText = (a.text || '').toLowerCase();
const bText = (b.text || '').toLowerCase();
const aStarts = aText.startsWith(search);
const bStarts = bText.startsWith(search);
if (aStarts && !bStarts) return -1;
if (!aStarts && bStarts) return 1;
return aText.localeCompare(bText);
});
}
});
}
},
error: function(xhr) {
$('#idCliente').html('<option value="">Error loading customers</option>');
let message = 'Unable to load customers.';
if (xhr.responseJSON && xhr.responseJSON.error) {
message = xhr.responseJSON.error;
}
Swal.fire({
title: 'Customer loading error',
text: message,
icon: 'error',
confirmButtonText: 'OK'
});
}
});
}
function updateSelectedCustomerBox() {
const selectedOption = $('#idCliente option:selected');
const customerCode = selectedOption.data('code') || '-';
const customerName = selectedOption.data('name') || '-';
if (!$('#idCliente').val()) {
$('#customerBox').hide();
$('#selectedCustomerCode').text('-');
$('#selectedCustomerName').text('-');
return;
}
$('#selectedCustomerCode').text(customerCode);
$('#selectedCustomerName').text(customerName);
$('#customerBox').show();
}
function renderStatus(isSigned) {
if (isSigned === true) {
return '<span class="status-pill status-pill-success"><i class="bx bx-check-circle"></i> Signed</span>';
}
if (isSigned === false) {
return '<span class="status-pill status-pill-warning"><i class="bx bx-time"></i> Not signed</span>';
}
return '-';
}
function renderPdfCell(pdfFiles) {
if (!Array.isArray(pdfFiles) || pdfFiles.length === 0) {
return '<span class="no-pdf">No PDF</span>';
}
const firstPdf = pdfFiles[0];
if (!firstPdf.download_url) {
return '<span class="no-pdf">No PDF</span>';
}
return `
<a href="${escapeHtml(firstPdf.download_url)}"
target="_blank"
class="pdf-icon-link"
title="${escapeHtml(firstPdf.file_name || 'Download PDF')}">
<i class="bx bxs-file-pdf"></i>
</a>
`;
}
function initReportsDataTable() {
if (reportsDataTable !== null) {
reportsDataTable.destroy();
reportsDataTable = null;
}
reportsDataTable = $('#reportsTable').DataTable({
paging: false,
searching: false,
info: false,
ordering: true,
order: [
[2, 'desc']
],
autoWidth: false,
responsive: true,
columnDefs: [{
targets: 6,
orderable: false
}],
language: {
emptyTable: 'No reports found',
zeroRecords: 'No matching reports found'
}
});
}
function renderReports(response) {
lastJsonResponse = response;
const reports = response.reports || [];
const tbody = $('#reportsTableBody');
tbody.empty();
$('#reportCountBadge').text(reports.length);
if (reports.length > 0) {
reports.forEach(function(report) {
const reportDateOrder = report.data || '';
const printDateOrder = report.data_stampa || '';
const statusOrder = report.firmato === true ? 1 : 0;
const row = `
<tr>
<td>
<strong>${escapeHtml(report.codice_rapporto || '-')}</strong>
</td>
<td>${escapeHtml(report.id_rapporto || '-')}</td>
<td data-order="${escapeHtml(reportDateOrder)}">${escapeHtml(formatDate(report.data))}</td>
<td data-order="${escapeHtml(printDateOrder)}">${escapeHtml(formatDate(report.data_stampa))}</td>
<td>${escapeHtml(report.versione !== null && report.versione !== undefined ? report.versione : '-')}</td>
<td data-order="${statusOrder}">${renderStatus(report.firmato)}</td>
<td class="text-center">${renderPdfCell(report.pdf_files)}</td>
</tr>
`;
tbody.append(row);
});
}
$('#jsonPreview').text(JSON.stringify(response, null, 4));
$('#emptyState').hide();
$('#resultContainer').show();
setTimeout(function() {
initReportsDataTable();
}, 50);
}
$('#idCliente').on('change', function() {
updateSelectedCustomerBox();
resetResults();
});
$('#customerReportsForm').on('submit', function(event) {
event.preventDefault();
const idCliente = $('#idCliente').val();
const limit = $('#limitReports').val();
const signedStatus = $('#signedStatus').val();
if (!idCliente) {
Swal.fire({
title: 'Missing customer',
text: 'Please select a customer.',
icon: 'warning',
confirmButtonText: 'OK'
});
return;
}
resetResults();
updateSelectedCustomerBox();
setLoading(true);
$.ajax({
url: 'get_rapporti_cliente.php',
method: 'GET',
dataType: 'json',
data: {
id_cliente: idCliente,
limit: limit,
signed_status: signedStatus
},
success: function(response) {
if (!response || response.success !== true) {
Swal.fire({
title: 'No data',
text: response && response.error ? response.error : 'No reports were returned.',
icon: 'warning',
confirmButtonText: 'OK'
});
return;
}
renderReports(response);
},
error: function(xhr) {
let message = 'Unexpected error while loading reports.';
if (xhr.responseJSON && xhr.responseJSON.error) {
message = xhr.responseJSON.error;
} else if (xhr.responseText) {
message = xhr.responseText.substring(0, 500);
}
Swal.fire({
title: 'Error',
text: message,
icon: 'error',
confirmButtonText: 'OK'
});
},
complete: function() {
setLoading(false);
}
});
});
$('#toggleJsonBtn').on('click', function() {
const jsonPreview = $('#jsonPreview');
const isVisible = jsonPreview.is(':visible');
jsonPreview.toggle(!isVisible);
if (isVisible) {
$(this).html('<i class="bx bx-code-alt"></i> Show JSON');
} else {
$(this).html('<i class="bx bx-hide"></i> Hide JSON');
}
});
loadCustomers();
});
</script>
</body>
</html>
+580
View File
@@ -0,0 +1,580 @@
<?php include('include/headscript.php'); ?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--favicon-->
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?>
<title>TRF-Project - Test Report Lookup</title>
<style>
.compact-card .card-body {
padding: 1rem;
}
.lookup-wrapper {
max-width: 1100px;
margin: 0 auto;
}
.lookup-title {
font-size: 18px;
font-weight: 700;
}
.lookup-subtitle {
font-size: 13px;
color: #6c757d;
}
.result-section-title {
font-size: 14px;
font-weight: 700;
margin-bottom: 10px;
color: #344767;
}
.info-box {
border: 1px solid #e9ecef;
border-radius: 10px;
padding: 14px;
background: #fff;
height: 100%;
}
.info-label {
font-size: 11px;
text-transform: uppercase;
color: #6c757d;
font-weight: 700;
margin-bottom: 3px;
}
.info-value {
font-size: 14px;
color: #212529;
font-weight: 600;
word-break: break-word;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 10px;
border-radius: 999px;
font-size: 12px;
font-weight: 700;
}
.status-pill-success {
background: #e8fff1;
color: #198754;
}
.status-pill-warning {
background: #fff3cd;
color: #b58100;
}
.pdf-card {
border: 1px solid #f1d1d1;
background: #fffafa;
border-radius: 10px;
padding: 14px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.pdf-icon {
width: 46px;
height: 46px;
border-radius: 12px;
background: #dc3545;
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 24px;
flex-shrink: 0;
}
.pdf-file-name {
font-weight: 700;
font-size: 14px;
margin-bottom: 2px;
}
.pdf-meta {
font-size: 12px;
color: #6c757d;
}
.json-preview {
display: none;
background: #111827;
color: #e5e7eb;
border-radius: 10px;
padding: 14px;
font-size: 12px;
max-height: 420px;
overflow: auto;
white-space: pre-wrap;
}
.empty-state {
border: 1px dashed #ced4da;
border-radius: 10px;
padding: 24px;
text-align: center;
color: #6c757d;
background: #fafafa;
}
.spinner-inline {
display: none;
margin-left: 8px;
}
.btn-download-pdf {
white-space: nowrap;
}
@media (max-width: 768px) {
.pdf-card {
flex-direction: column;
align-items: flex-start;
}
.btn-download-pdf {
width: 100%;
}
}
</style>
</head>
<body>
<!--wrapper-->
<div class="wrapper">
<!--sidebar wrapper -->
<?php include('include/navbar.php'); ?>
<!--end sidebar wrapper -->
<!--start header -->
<?php include('include/topbar.php'); ?>
<!--end header -->
<!--start page wrapper -->
<div class="page-wrapper">
<div class="page-content">
<?php include('top_stat_widget.php'); ?>
<div class="lookup-wrapper">
<div class="card radius-10 compact-card">
<div class="card-header">
<div class="d-flex align-items-center justify-content-between flex-wrap gap-2">
<div>
<div class="lookup-title">Test Report Lookup</div>
<div class="lookup-subtitle">
Search a test report from VisualLims by report number and download the PDF if available.
</div>
</div>
</div>
</div>
<div class="card-body">
<form id="reportSearchForm" class="row g-3 align-items-end">
<div class="col-md-8">
<label for="codiceRapporto" class="form-label fw-semibold">
Report Number
</label>
<input type="text"
class="form-control"
id="codiceRapporto"
name="codiceRapporto"
placeholder="Example: 2621521"
autocomplete="off">
</div>
<div class="col-md-4">
<button type="submit" id="btnSearchReport" class="btn btn-primary w-100">
<i class="bx bx-search"></i> Proceed
<span class="spinner-border spinner-border-sm spinner-inline" id="searchSpinner" role="status" aria-hidden="true"></span>
</button>
</div>
</form>
</div>
</div>
<div id="resultContainer" style="display:none;">
<div class="card radius-10 compact-card">
<div class="card-header">
<div class="d-flex align-items-center justify-content-between flex-wrap gap-2">
<h6 class="mb-0">Report Data</h6>
<button type="button" id="toggleJsonBtn" class="btn btn-sm btn-outline-secondary">
<i class="bx bx-code-alt"></i> Show JSON
</button>
</div>
</div>
<div class="card-body">
<div class="result-section-title">General Information</div>
<div class="row g-3 mb-4">
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Report Number</div>
<div class="info-value" id="resCodiceRapporto">-</div>
</div>
</div>
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Report ID</div>
<div class="info-value" id="resIdRapporto">-</div>
</div>
</div>
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Customer Code</div>
<div class="info-value" id="resCodiceCliente">-</div>
</div>
</div>
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Customer Name</div>
<div class="info-value" id="resNominativoCliente">-</div>
</div>
</div>
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Report Date</div>
<div class="info-value" id="resDataRapporto">-</div>
</div>
</div>
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Print Date</div>
<div class="info-value" id="resDataStampa">-</div>
</div>
</div>
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Version</div>
<div class="info-value" id="resVersione">-</div>
</div>
</div>
<div class="col-md-3">
<div class="info-box">
<div class="info-label">Signed</div>
<div class="info-value" id="resFirmato">-</div>
</div>
</div>
<div class="col-md-6">
<div class="info-box">
<div class="info-label">Detail Endpoint</div>
<div class="info-value small" id="resDetailEndpoint">-</div>
</div>
</div>
</div>
<div class="result-section-title">Available PDF Files</div>
<div id="pdfFilesContainer" class="mb-4"></div>
<pre id="jsonPreview" class="json-preview"></pre>
</div>
</div>
</div>
<div id="emptyState" class="empty-state">
<i class="bx bx-file-find" style="font-size:34px;"></i>
<div class="mt-2 fw-semibold">No report loaded</div>
<div class="small">Enter a report number and click Proceed.</div>
</div>
</div>
</div>
</div>
<!--end page wrapper -->
<!--start overlay-->
<div class="overlay toggle-icon"></div>
<!--end overlay-->
<!--Start Back To Top Button-->
<a href="javaScript:;" class="back-to-top">
<i class='bx bxs-up-arrow-alt'></i>
</a>
<!--End Back To Top Button-->
<?php include('include/footer.php'); ?>
</div>
<!--end wrapper-->
<?php include('jsinclude.php'); ?>
<script>
$(document).ready(function() {
let lastJsonResponse = null;
function escapeHtml(value) {
if (value === null || value === undefined) {
return '';
}
return String(value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function formatDate(value) {
if (!value) {
return '-';
}
const date = new Date(value);
if (isNaN(date.getTime())) {
return value;
}
return date.toLocaleString('it-IT', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
});
}
function setLoading(isLoading) {
$('#btnSearchReport').prop('disabled', isLoading);
$('#searchSpinner').toggle(isLoading);
}
function resetResult() {
lastJsonResponse = null;
$('#resultContainer').hide();
$('#emptyState').show();
$('#jsonPreview').hide().text('');
$('#toggleJsonBtn').html('<i class="bx bx-code-alt"></i> Show JSON');
$('#resCodiceRapporto').text('-');
$('#resIdRapporto').text('-');
$('#resCodiceCliente').text('-');
$('#resNominativoCliente').text('-');
$('#resDataRapporto').text('-');
$('#resDataStampa').text('-');
$('#resVersione').text('-');
$('#resFirmato').text('-');
$('#resDetailEndpoint').text('-');
$('#pdfFilesContainer').html('');
}
function renderPdfFiles(pdfFiles) {
const container = $('#pdfFilesContainer');
container.empty();
if (!Array.isArray(pdfFiles) || pdfFiles.length === 0) {
container.html(`
<div class="empty-state">
<i class="bx bx-file-blank" style="font-size:28px;"></i>
<div class="mt-2 fw-semibold">No PDF available</div>
<div class="small">No report PDF file was returned by VisualLims.</div>
</div>
`);
return;
}
pdfFiles.forEach(function(file) {
const idRapportoFile = file.id_rapporto_file || '';
const fileName = file.file_name || 'report.pdf';
const categoria = file.categoria || '-';
const tipoRapporto = file.tipo_rapporto || '-';
const downloadUrl = 'download_rapporto_pdf.php?id_rapporto_file=' + encodeURIComponent(idRapportoFile);
const html = `
<div class="pdf-card mb-2">
<div class="d-flex align-items-center gap-3">
<div class="pdf-icon">
<i class="bx bxs-file-pdf"></i>
</div>
<div>
<div class="pdf-file-name">${escapeHtml(fileName)}</div>
<div class="pdf-meta">
ID File: ${escapeHtml(idRapportoFile)}
&nbsp;|&nbsp;
Category: ${escapeHtml(categoria)}
&nbsp;|&nbsp;
Type: ${escapeHtml(tipoRapporto)}
</div>
</div>
</div>
<a href="${downloadUrl}" target="_blank" class="btn btn-danger btn-sm btn-download-pdf">
<i class="bx bx-download"></i> Download PDF
</a>
</div>
`;
container.append(html);
});
}
function renderResult(response) {
lastJsonResponse = response;
const base = response.rapporto_base || {};
const data = response.data || {};
const cliente = response.cliente || data.Cliente || {};
$('#resCodiceRapporto').text(response.codice_rapporto || base.CodiceRapporto || '-');
$('#resIdRapporto').text(response.id_rapporto || base.IdRapporto || '-');
$('#resCodiceCliente').text(cliente.CodiceCliente || '-');
$('#resNominativoCliente').text(cliente.Nominativo || '-');
$('#resDataRapporto').text(formatDate(base.Data || data.Data));
$('#resDataStampa').text(formatDate(base.DataStampa || data.DataStampa));
$('#resVersione').text(base.Versione !== undefined ? base.Versione : (data.Versione !== undefined ? data.Versione : '-'));
$('#resDetailEndpoint').text(response.detail_endpoint || '-');
const isSigned = base.Firmato === true || data.Firmato === true;
if (isSigned) {
$('#resFirmato').html('<span class="status-pill status-pill-success"><i class="bx bx-check-circle"></i> Signed</span>');
} else {
$('#resFirmato').html('<span class="status-pill status-pill-warning"><i class="bx bx-time"></i> Not signed</span>');
}
renderPdfFiles(response.pdf_files || []);
$('#jsonPreview').text(JSON.stringify(response, null, 4));
$('#emptyState').hide();
$('#resultContainer').show();
}
$('#reportSearchForm').on('submit', function(event) {
event.preventDefault();
const codiceRapporto = $('#codiceRapporto').val().trim();
if (!codiceRapporto) {
Swal.fire({
title: 'Missing report number',
text: 'Please enter a report number.',
icon: 'warning',
confirmButtonText: 'OK'
});
return;
}
resetResult();
setLoading(true);
$.ajax({
url: 'get_rapporto_prova.php',
method: 'GET',
dataType: 'json',
data: {
codice: codiceRapporto,
step: 'files'
},
success: function(response) {
if (!response || response.success !== true) {
Swal.fire({
title: 'Report not found',
text: response && response.message ? response.message : 'No report was found for this number.',
icon: 'warning',
confirmButtonText: 'OK'
});
return;
}
renderResult(response);
},
error: function(xhr) {
let message = 'Unexpected error while loading the report.';
if (xhr.responseJSON && xhr.responseJSON.error) {
message = xhr.responseJSON.error;
} else if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message;
} else if (xhr.responseText) {
message = xhr.responseText.substring(0, 500);
}
Swal.fire({
title: 'Error',
text: message,
icon: 'error',
confirmButtonText: 'OK'
});
},
complete: function() {
setLoading(false);
}
});
});
$('#toggleJsonBtn').on('click', function() {
const jsonPreview = $('#jsonPreview');
const isVisible = jsonPreview.is(':visible');
jsonPreview.toggle(!isVisible);
if (isVisible) {
$(this).html('<i class="bx bx-code-alt"></i> Show JSON');
} else {
$(this).html('<i class="bx bx-hide"></i> Hide JSON');
}
});
const urlParams = new URLSearchParams(window.location.search);
const prefillCodice = urlParams.get('codice');
if (prefillCodice) {
$('#codiceRapporto').val(prefillCodice);
$('#reportSearchForm').trigger('submit');
}
});
</script>
</body>
</html>