200 lines
7.7 KiB
PHP
200 lines
7.7 KiB
PHP
<?php include('../include/headscript.php'); ?>
|
|
<?php include("../class/company.php"); ?>
|
|
<!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">
|
|
<?php include('../include/seo.php'); ?>
|
|
|
|
<link rel="shortcut icon" href="../assets/images/favicon.ico">
|
|
<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">
|
|
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
|
<script src="../assets/js/jquery.min.js"></script>
|
|
|
|
<!-- DataTables CSS -->
|
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/jquery.dataTables.min.css">
|
|
|
|
<!-- DataTables JS -->
|
|
<script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
|
|
|
|
|
|
</head>
|
|
|
|
<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">Supplier Ratings</h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Button for Rating Calculation -->
|
|
<div class="row">
|
|
<div class="col-md-12 text-right">
|
|
<button id="calculate-rating" class="btn btn-primary mb-3">
|
|
Calculate Ratings
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Chart Section -->
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div id="supplier-rating-chart"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Table Section -->
|
|
<div class="row mt-4">
|
|
<div class="col-md-12">
|
|
<div class="table-responsive">
|
|
<table id="supplierTable" class="table table-bordered table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Supplier Name</th>
|
|
<th>Number of Products</th>
|
|
<th>Total Analyses</th>
|
|
<th>PASS Analyses</th>
|
|
<th>FAIL Analyses</th>
|
|
<th>DATA Analyses</th>
|
|
<th>Rating</th>
|
|
<th>Date Calculated</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<!-- DataTables popolerà dinamicamente il contenuto -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include('../include/footer.php'); ?>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Funzione per aggiornare il grafico
|
|
function updateChart(response) {
|
|
const suppliers = response.map(s => s.name);
|
|
const ratings = response.map(s => s.rating);
|
|
const colors = response.map(s => s.color);
|
|
|
|
const options = {
|
|
series: [{
|
|
data: ratings
|
|
}],
|
|
chart: {
|
|
type: 'bar',
|
|
height: 400
|
|
},
|
|
colors: colors,
|
|
xaxis: {
|
|
categories: suppliers
|
|
},
|
|
title: {
|
|
text: 'Supplier Ratings',
|
|
align: 'center'
|
|
}
|
|
};
|
|
|
|
// Renderizza il grafico
|
|
const chart = new ApexCharts(
|
|
document.querySelector("#supplier-rating-chart"),
|
|
options
|
|
);
|
|
chart.render();
|
|
}
|
|
|
|
// Inizializza DataTables
|
|
const supplierTable = $('#supplierTable').DataTable({
|
|
ajax: {
|
|
url: 'get_supplier_ratings.php',
|
|
dataSrc: '' // I dati JSON sono un array diretto
|
|
},
|
|
columns: [{
|
|
data: 'name',
|
|
render: function(data, type, row) {
|
|
return `<a href="supplier-detail.php?id=${row.id}" class="text-primary">${data}</a>`;
|
|
}
|
|
},
|
|
{
|
|
data: 'total_products'
|
|
},
|
|
{
|
|
data: 'total_analyses'
|
|
},
|
|
{
|
|
data: 'pass_analyses'
|
|
},
|
|
{
|
|
data: 'fail_analyses'
|
|
},
|
|
{
|
|
data: 'data_analyses'
|
|
},
|
|
{
|
|
data: 'rating',
|
|
render: function(data, type, row) {
|
|
const color = data >= 8 ? '#28a745' : data >= 5 ? '#ffc107' : '#dc3545';
|
|
return `<span style="color: ${color}; font-weight: bold;">${data}</span>`;
|
|
}
|
|
},
|
|
{
|
|
data: 'date'
|
|
}
|
|
],
|
|
order: [
|
|
[6, 'desc']
|
|
], // Ordina per rating di default
|
|
pageLength: 50, // Mostra 10 righe per pagina
|
|
responsive: true, // Adatta il layout alla finestra
|
|
initComplete: function(settings, json) {
|
|
updateChart(json); // Aggiorna il grafico dopo aver caricato la tabella
|
|
}
|
|
});
|
|
|
|
// Funzione per calcolare i rating e aggiornare grafico e tabella
|
|
$('#calculate-rating').on('click', function() {
|
|
$.ajax({
|
|
url: 'calculate_supplier_ratings.php',
|
|
method: 'POST',
|
|
success: function() {
|
|
alert('Ratings calculated successfully!');
|
|
supplierTable.ajax.reload(); // Ricarica la tabella
|
|
$.get('get_supplier_ratings.php', function(response) {
|
|
updateChart(response); // Aggiorna il grafico
|
|
});
|
|
},
|
|
error: function() {
|
|
alert('Error calculating ratings.');
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|