580 lines
21 KiB
PHP
580 lines
21 KiB
PHP
<?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, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''');
|
|
}
|
|
|
|
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)}
|
|
|
|
|
Category: ${escapeHtml(categoria)}
|
|
|
|
|
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>
|