332 lines
14 KiB
PHP
332 lines
14 KiB
PHP
<?php include('../include/headscript.php'); ?>
|
|
<?php include("../class/company.php");
|
|
|
|
$conn = new mysqli($servername, $username, $password, $database);
|
|
|
|
$page = 'reports'; // Nome della pagina specifica per salvare/ripristinare le impostazioni
|
|
$conn = new mysqli($servername, $username, $password, $database);
|
|
|
|
// Recupera le impostazioni delle colonne e dell'ordinamento dal database
|
|
$query = "SELECT column_visibility, column_order FROM user_table_settings WHERE iduser = ? AND page = ?";
|
|
$stmt = $conn->prepare($query);
|
|
$stmt->bind_param("is", $iduserlogin, $page);
|
|
$stmt->execute();
|
|
$stmt->bind_result($column_visibility, $column_order);
|
|
$stmt->fetch();
|
|
$stmt->close();
|
|
|
|
// Query per ottenere tutti i report e i prodotti associati
|
|
$query = "
|
|
SELECT r.*, p.products_refnumber, p.products_description
|
|
FROM reports r
|
|
LEFT JOIN products p ON r.idproducts = p.idproducts";
|
|
$result = $conn->query($query);
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
|
<title>Reports</title>
|
|
|
|
<!-- Includi prima jQuery -->
|
|
<!-- Includi prima jQuery -->
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
|
|
<!-- DataTables CSS -->
|
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">
|
|
<!-- DataTables Buttons CSS -->
|
|
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.3.1/css/buttons.dataTables.min.css">
|
|
<!-- ColReorder CSS -->
|
|
<link rel="stylesheet" href="https://cdn.datatables.net/colreorder/1.5.6/css/colReorder.dataTables.min.css">
|
|
|
|
<!-- DataTables JS -->
|
|
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
|
|
<!-- DataTables Buttons JS -->
|
|
<script src="https://cdn.datatables.net/buttons/2.3.1/js/dataTables.buttons.min.js"></script>
|
|
<!-- Buttons ColVis JS -->
|
|
<script src="https://cdn.datatables.net/buttons/2.3.1/js/buttons.colVis.min.js"></script>
|
|
<!-- ColReorder JS -->
|
|
<script src="https://cdn.datatables.net/colreorder/1.5.6/js/dataTables.colReorder.min.js"></script>
|
|
|
|
|
|
<!-- Altri riferimenti al CSS e JS -->
|
|
<link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
|
<link href="../assets/css/icons.css" rel="stylesheet" type="text/css">
|
|
<link href="../assets/css/style.css" rel="stylesheet" type="text/css">
|
|
<link rel="shortcut icon" href="../assets/images/favicon.ico">
|
|
<link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet">
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.js"></script>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">
|
|
</head>
|
|
|
|
<style>
|
|
.bg-danger {
|
|
background-color: #ff4d4d !important;
|
|
/* Rosso per fallimenti */
|
|
}
|
|
|
|
.bg-success {
|
|
background-color: #28a745 !important;
|
|
/* Verde per successi */
|
|
}
|
|
|
|
.bg-warning {
|
|
background-color: #ffc107 !important;
|
|
/* Giallo per N/A o // */
|
|
}
|
|
|
|
.text-white {
|
|
color: white !important;
|
|
}
|
|
|
|
.text-dark {
|
|
color: black !important;
|
|
}
|
|
</style>
|
|
|
|
<body class="fixed-left">
|
|
|
|
<div id="wrapper">
|
|
<?php include('../include/navigationbar.php'); ?>
|
|
<div class="content-page">
|
|
<div class="content">
|
|
<?php include('../include/topbar.php'); ?>
|
|
<div class="page-content-wrapper">
|
|
<div class="container-fluid">
|
|
|
|
<div class="row">
|
|
<div class="col-sm-12">
|
|
<div class="page-title-box">
|
|
<h4 class="page-title">Reports</h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-xl-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table id="reportsTable" class="table table-striped table-hover" data-user="<?php echo $iduserlogin; ?>" data-table="reports">
|
|
<thead>
|
|
<tr>
|
|
<th>Report Number</th>
|
|
<th>Report Date</th>
|
|
<th>Product Ref</th>
|
|
<th>Product Description</th>
|
|
<th>Rating</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php while ($row = $result->fetch_assoc()) { ?>
|
|
<tr data-reportid="<?php echo $row['idreports']; ?>">
|
|
<td><?php echo $row['reportsNumberLab']; ?></td>
|
|
<td><?php echo $row['reportDateIn']; ?></td>
|
|
<td><?php echo $row['products_refnumber']; ?></td>
|
|
<td><?php echo $row['products_description']; ?></td>
|
|
<td><?php echo $row['reportsRating']; ?></td>
|
|
<td>
|
|
<button class="btn btn-info btn-sm show-analysis">Analysis</button>
|
|
<a class="btn btn-primary btn-sm report-details" href="../products/reportdetails.php?idreports=<?php echo $row['idreports']; ?>">Details</a>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div><!-- container -->
|
|
</div><!-- Page content Wrapper -->
|
|
</div><!-- content -->
|
|
<?php include('../include/footer.php'); ?>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
var hasUserInteracted = false;
|
|
|
|
// Recupera le impostazioni salvate dal server prima di inizializzare DataTables
|
|
var columnSettings = {};
|
|
var userId = $('#reportsTable').data('user');
|
|
var tableName = $('#reportsTable').data('table');
|
|
|
|
// Recupera le impostazioni salvate
|
|
$.ajax({
|
|
url: 'get_user_table_settings_reports.php',
|
|
method: 'POST',
|
|
data: {
|
|
user: userId,
|
|
table: tableName
|
|
},
|
|
async: false,
|
|
success: function(response) {
|
|
columnSettings = JSON.parse(response);
|
|
console.log("Impostazioni recuperate:", columnSettings);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Errore nel caricamento delle impostazioni:', xhr.responseText);
|
|
}
|
|
});
|
|
|
|
// Inizializza DataTables con ColReorder, filtri e ColVis
|
|
var table = $('#reportsTable').DataTable({
|
|
responsive: true,
|
|
pageLength: 50,
|
|
order: [
|
|
[0, 'asc']
|
|
],
|
|
colReorder: {
|
|
order: columnSettings && columnSettings.ColReorder ? columnSettings.ColReorder : null
|
|
},
|
|
dom: 'Bfrtip', // Integra i bottoni
|
|
buttons: [{
|
|
extend: 'colvis',
|
|
text: 'Select Columns',
|
|
collectionLayout: 'fixed four-column',
|
|
postfixButtons: ['colvisRestore'],
|
|
columns: ':not(:last-child)' // Escludi l'ultima colonna (Actions)
|
|
}],
|
|
initComplete: function() {
|
|
// Applica le impostazioni di visibilità delle colonne, se presenti
|
|
if (columnSettings && columnSettings.columns) {
|
|
console.log("Applico visibilità colonne:", columnSettings.columns);
|
|
this.api().columns().every(function(index) {
|
|
var column = this;
|
|
column.visible(columnSettings.columns[index].visible, false);
|
|
});
|
|
}
|
|
|
|
this.api().columns.adjust().draw(false);
|
|
|
|
// Aggiungi i filtri per ogni colonna (eccetto la colonna delle azioni)
|
|
this.api().columns().every(function() {
|
|
var column = this;
|
|
if (column.index() !== 5) { // Escludi la colonna "Action"
|
|
$('<input class="form-control form-control-sm" type="text" placeholder="Search"/>')
|
|
.appendTo($(column.header()))
|
|
.on('keyup change clear', function() {
|
|
if (column.search() !== this.value) {
|
|
column.search(this.value).draw();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
},
|
|
stateSave: true,
|
|
stateSaveCallback: function(settings, data) {
|
|
if (hasUserInteracted) {
|
|
$.ajax({
|
|
url: 'save_user_table_settings_reports.php',
|
|
method: 'POST',
|
|
data: {
|
|
user: userId,
|
|
table: tableName,
|
|
settings: JSON.stringify(data)
|
|
},
|
|
success: function(response) {
|
|
console.log('Impostazioni salvate:', response);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Errore nel salvataggio delle impostazioni:', xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
// Imposta il flag `hasUserInteracted` quando l'utente modifica qualcosa (colonne o riordina)
|
|
table.on('column-reorder', function() {
|
|
hasUserInteracted = true;
|
|
console.log("Colonne riordinate");
|
|
});
|
|
|
|
table.on('column-visibility', function() {
|
|
hasUserInteracted = true;
|
|
console.log("Visibilità colonna cambiata");
|
|
});
|
|
|
|
// Gestione del click su "Analysis" per visualizzare la tabella child con le analisi
|
|
$('#reportsTable').on('click', '.show-analysis', function() {
|
|
var tr = $(this).closest('tr');
|
|
var reportId = tr.data('reportid');
|
|
var row = $('#reportsTable').DataTable().row(tr);
|
|
var button = $(this);
|
|
|
|
button.prop('disabled', true);
|
|
button.html('<i class="fa fa-spinner fa-spin"></i> Loading...');
|
|
|
|
if (row.child.isShown()) {
|
|
row.child.hide();
|
|
tr.removeClass('shown');
|
|
button.html('Analysis');
|
|
button.prop('disabled', false);
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: 'get_analysis_by_report.php',
|
|
type: 'POST',
|
|
data: {
|
|
reportId: reportId
|
|
},
|
|
success: function(data) {
|
|
row.child(formatAnalysis(data)).show();
|
|
tr.addClass('shown');
|
|
},
|
|
complete: function() {
|
|
button.prop('disabled', false);
|
|
button.html('Analysis');
|
|
},
|
|
error: function() {
|
|
Swal.fire('Error!', 'There was an error loading the analysis.', 'error');
|
|
button.prop('disabled', false);
|
|
button.html('Analysis');
|
|
}
|
|
});
|
|
});
|
|
|
|
function formatAnalysis(data) {
|
|
var parsedData = JSON.parse(data);
|
|
var html = '<table class="table table-bordered child-table">';
|
|
html += '<thead><tr><th>Analysis Name</th><th>Final Rating</th></tr></thead>';
|
|
html += '<tbody>';
|
|
|
|
$.each(parsedData, function(index, analysis) {
|
|
var ratingClass = '';
|
|
if (analysis.finalRating === 'FAIL') {
|
|
ratingClass = 'bg-danger text-white';
|
|
} else if (analysis.finalRating === 'PASS') {
|
|
ratingClass = 'bg-success text-white';
|
|
} else if (analysis.finalRating === '//' || analysis.finalRating === 'N/A' || analysis.finalRating === 'DATA') {
|
|
ratingClass = 'bg-warning text-dark';
|
|
}
|
|
|
|
html += '<tr>';
|
|
html += '<td>' + (analysis.name ? analysis.name : 'N/A') + '</td>';
|
|
html += '<td class="' + ratingClass + '">' + (analysis.finalRating ? analysis.finalRating : 'N/A') + '</td>';
|
|
html += '</tr>';
|
|
});
|
|
|
|
html += '</tbody></table>';
|
|
return html;
|
|
}
|
|
});
|
|
</script>
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|