added rate&go
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
include('../include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die(json_encode(['message' => "Connection failed: " . $conn->connect_error]));
|
||||
}
|
||||
|
||||
// Calcolo rating dei fornitori con dettagli
|
||||
$query = "
|
||||
INSERT INTO supplier_ratings (
|
||||
name,
|
||||
total_products,
|
||||
total_analyses,
|
||||
pass_analyses,
|
||||
fail_analyses,
|
||||
data_analyses,
|
||||
rating,
|
||||
calculation_date
|
||||
)
|
||||
SELECT
|
||||
p.namesupplier AS name,
|
||||
COUNT(DISTINCT p.idproducts) AS total_products,
|
||||
COUNT(ap.idAnalysis_Project) AS total_analyses,
|
||||
SUM(CASE
|
||||
WHEN LOWER(ap.test_Rating) IN ('pass', 'p', 'comply', 'complies') THEN 1
|
||||
ELSE 0
|
||||
END) AS pass_analyses,
|
||||
SUM(CASE
|
||||
WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN 1
|
||||
ELSE 0
|
||||
END) AS fail_analyses,
|
||||
SUM(CASE
|
||||
WHEN LOWER(ap.test_Rating) NOT IN ('pass', 'p', 'comply', 'complies', 'fail', 'f', 'doesn\'t comply') THEN 1
|
||||
ELSE 0
|
||||
END) AS data_analyses,
|
||||
GREATEST(0, 10 - (
|
||||
SUM(
|
||||
CASE
|
||||
WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN
|
||||
COALESCE(asv.severity, 1) *
|
||||
CASE WHEN COALESCE(asv.is_legal, 'N') = 'Y' THEN 1.5 ELSE 1.0 END
|
||||
ELSE 0
|
||||
END
|
||||
) * (1 + SUM(CASE WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN 1 ELSE 0 END) / NULLIF(COUNT(ap.idAnalysis_Project), 0))
|
||||
/ NULLIF(COUNT(ap.idAnalysis_Project), 0) * 100
|
||||
)) AS rating,
|
||||
NOW() AS calculation_date
|
||||
FROM products p
|
||||
JOIN reports r ON p.idproducts = r.idproducts
|
||||
JOIN parts pt ON r.idreports = pt.idreports
|
||||
JOIN analysis_project ap ON pt.idParts = ap.idPart
|
||||
LEFT JOIN analysis_severity asv ON ap.idAnalysis = asv.idanalysisvocabulary
|
||||
GROUP BY p.namesupplier
|
||||
ON DUPLICATE KEY UPDATE
|
||||
total_products = VALUES(total_products),
|
||||
total_analyses = VALUES(total_analyses),
|
||||
pass_analyses = VALUES(pass_analyses),
|
||||
fail_analyses = VALUES(fail_analyses),
|
||||
data_analyses = VALUES(data_analyses),
|
||||
rating = VALUES(rating),
|
||||
calculation_date = VALUES(calculation_date);
|
||||
|
||||
";
|
||||
|
||||
if ($conn->query($query) === TRUE) {
|
||||
echo json_encode(['message' => 'Ratings calculated successfully!']);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'message' => $conn->error,
|
||||
'exception' => 'mysqli_sql_exception',
|
||||
'file' => __FILE__,
|
||||
'line' => __LINE__
|
||||
]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
include('../include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Recupera il nome del fornitore
|
||||
$supplierName = isset($_GET['supplier']) ? $conn->real_escape_string($_GET['supplier']) : '';
|
||||
|
||||
// Verifica che il nome del fornitore sia presente
|
||||
if (empty($supplierName)) {
|
||||
die(json_encode(['error' => 'Supplier name is missing']));
|
||||
}
|
||||
|
||||
// Query per la distribuzione totale delle analisi
|
||||
$queryDistribution = "
|
||||
SELECT
|
||||
av.nameanalysisvoc AS analysis_name,
|
||||
COUNT(ap.idAnalysis_Project) AS total
|
||||
FROM products p
|
||||
JOIN reports r ON p.idproducts = r.idproducts
|
||||
JOIN parts pt ON r.idreports = pt.idreports
|
||||
JOIN analysis_project ap ON pt.idParts = ap.idPart
|
||||
LEFT JOIN analysisvocabulary av ON ap.result_TestName = av.idanalysisvocabulary
|
||||
WHERE p.namesupplier = '$supplierName' AND av.preferred = 'Y'
|
||||
GROUP BY av.nameanalysisvoc
|
||||
ORDER BY total DESC
|
||||
LIMIT 10;
|
||||
";
|
||||
|
||||
$resultDistribution = $conn->query($queryDistribution);
|
||||
$analysisDistribution = [];
|
||||
while ($row = $resultDistribution->fetch_assoc()) {
|
||||
$analysisDistribution[] = $row;
|
||||
}
|
||||
|
||||
// Query per la distribuzione delle analisi FAIL
|
||||
$queryFail = "
|
||||
SELECT
|
||||
av.nameanalysisvoc AS analysis_name,
|
||||
COUNT(*) AS fail
|
||||
FROM products p
|
||||
LEFT JOIN reports r ON p.idproducts = r.idproducts
|
||||
LEFT JOIN parts pt ON r.idreports = pt.idreports
|
||||
LEFT JOIN analysis_project ap ON pt.idParts = ap.idPart
|
||||
LEFT JOIN analysisvocabulary av ON ap.result_TestName = av.idanalysisvocabulary
|
||||
WHERE
|
||||
p.namesupplier = '$supplierName'
|
||||
AND LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply')
|
||||
AND av.preferred = 'Y'
|
||||
GROUP BY av.nameanalysisvoc
|
||||
ORDER BY fail DESC
|
||||
LIMIT 10;
|
||||
|
||||
";
|
||||
|
||||
$resultFail = $conn->query($queryFail);
|
||||
$failDistribution = [];
|
||||
while ($row = $resultFail->fetch_assoc()) {
|
||||
$failDistribution[] = $row;
|
||||
}
|
||||
|
||||
// Restituisci i dati come JSON
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'analysisDistribution' => $analysisDistribution,
|
||||
'failDistribution' => $failDistribution
|
||||
]);
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
include('../include/headscript.php');
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Recupera il nome del fornitore
|
||||
$supplierName = isset($_GET['supplier']) ? $conn->real_escape_string($_GET['supplier']) : '';
|
||||
|
||||
if (empty($supplierName)) {
|
||||
echo json_encode(['error' => 'Supplier name not provided.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Query SQL per ottenere i dettagli delle analisi FAIL
|
||||
$query = "
|
||||
SELECT
|
||||
av.nameanalysisvoc AS analysis_name,
|
||||
r.reportsNumberLab AS report_number, -- Numero del rapporto
|
||||
p.products_description AS product_description,
|
||||
p.products_refnumber AS product_refnumber, -- Numero di riferimento del prodotto
|
||||
r.idreports AS report_id -- ID del rapporto per eventuali azioni o collegamenti
|
||||
FROM products p
|
||||
JOIN reports r ON p.idproducts = r.idproducts
|
||||
JOIN parts pt ON r.idreports = pt.idreports
|
||||
JOIN analysis_project ap ON pt.idParts = ap.idPart
|
||||
JOIN analysisvocabulary av ON ap.result_TestName = av.idanalysisvocabulary
|
||||
WHERE p.namesupplier = 'PONTOGLIO S.P.A.'
|
||||
AND LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply');
|
||||
";
|
||||
|
||||
$result = $conn->query($query);
|
||||
|
||||
if (!$result) {
|
||||
echo json_encode(['error' => $conn->error]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$failDetails = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$failDetails[] = [
|
||||
'analysis_name' => $row['analysis_name'],
|
||||
'report_number' => $row['report_number'],
|
||||
'product_refnumber' => $row['product_refnumber'],
|
||||
'product_description' => $row['product_description'],
|
||||
'report_id' => $row['report_id'],
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode(['failDetails' => $failDetails]);
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
include('../include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Recupera i dati dei fornitori con dettagli aggiuntivi
|
||||
$query = "
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
total_products,
|
||||
total_analyses,
|
||||
pass_analyses,
|
||||
fail_analyses,
|
||||
data_analyses,
|
||||
rating,
|
||||
calculation_date
|
||||
FROM supplier_ratings
|
||||
ORDER BY rating DESC
|
||||
";
|
||||
$result = $conn->query($query);
|
||||
|
||||
$data = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$color = $row['rating'] >= 8 ? '#28a745' : ($row['rating'] >= 5 ? '#ffc107' : '#dc3545');
|
||||
$data[] = [
|
||||
'id' => $row['id'],
|
||||
'name' => $row['name'],
|
||||
'total_products' => $row['total_products'],
|
||||
'total_analyses' => $row['total_analyses'],
|
||||
'pass_analyses' => $row['pass_analyses'],
|
||||
'fail_analyses' => $row['fail_analyses'],
|
||||
'data_analyses' => $row['data_analyses'],
|
||||
'rating' => $row['rating'],
|
||||
'date' => $row['calculation_date'],
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
|
||||
$conn->close();
|
||||
@@ -0,0 +1,200 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,540 @@
|
||||
<?php include('../include/headscript.php'); ?>
|
||||
<?php include("../class/company.php"); ?>
|
||||
<?php
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Recupera l'ID del fornitore
|
||||
$supplierId = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
$query = "
|
||||
SELECT
|
||||
name,
|
||||
total_products,
|
||||
total_analyses,
|
||||
pass_analyses,
|
||||
fail_analyses,
|
||||
data_analyses,
|
||||
rating
|
||||
FROM supplier_ratings
|
||||
WHERE id = $supplierId
|
||||
LIMIT 1
|
||||
";
|
||||
$result = $conn->query($query);
|
||||
$supplier = $result->fetch_assoc();
|
||||
if (!$supplier) {
|
||||
die("Supplier not found.");
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!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="../assets/js/jquery.min.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
||||
<style>
|
||||
.collapsible {
|
||||
background-color: green;
|
||||
color: white;
|
||||
padding: 5px 10px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.collapsible.active {
|
||||
background-color: #d3d3d3;
|
||||
}
|
||||
|
||||
.collapsible-content {
|
||||
display: none;
|
||||
overflow: hidden;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.btn-details {
|
||||
background-color: #dc3545;
|
||||
color: white;
|
||||
padding: 5px 10px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.btn-details:hover {
|
||||
background-color: #c82333;
|
||||
}
|
||||
|
||||
.rating-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.rating-score {
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.rating-high {
|
||||
background-color: #28a745;
|
||||
}
|
||||
|
||||
.rating-medium {
|
||||
background-color: #ffc107;
|
||||
}
|
||||
|
||||
.rating-low {
|
||||
background-color: #dc3545;
|
||||
}
|
||||
|
||||
.data-card {
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin: 10px 0;
|
||||
transition: transform 0.3s, box-shadow 0.3s;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.data-card:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.data-title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.data-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.h1 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.data-label {
|
||||
font-size: 0.9rem;
|
||||
color: gray;
|
||||
}
|
||||
</style>
|
||||
</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 Details</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Supplier Info Section -->
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
<div class="card p-4">
|
||||
<div class="rating-box">
|
||||
<h3 class="m-0">
|
||||
<?php echo htmlspecialchars($supplier['name']); ?>
|
||||
</h3>
|
||||
<div class="rating-score
|
||||
<?php echo $supplier['rating'] >= 8 ? 'rating-high' : ($supplier['rating'] >= 5 ? 'rating-medium' : 'rating-low'); ?>">
|
||||
<?php echo number_format($supplier['rating'], 2); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Supplier Stats Section -->
|
||||
<div class="row text-center">
|
||||
<div class="col-md-3">
|
||||
<div class="data-card bg-primary text-white">
|
||||
<i class="bx bx-box h1"></i>
|
||||
<div class="data-title">Products</div>
|
||||
<div class="data-value"><?php echo $supplier['total_products']; ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="data-card bg-info text-white">
|
||||
<i class="bx bx-bar-chart-alt h1"></i>
|
||||
<div class="data-title">Total Analyses</div>
|
||||
<div class="data-value"><?php echo $supplier['total_analyses']; ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="data-card bg-success text-white">
|
||||
<i class="bx bx-check-circle h1"></i>
|
||||
<div class="data-title">PASS</div>
|
||||
<div class="data-value"><?php echo $supplier['pass_analyses']; ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="data-card bg-danger text-white">
|
||||
<i class="bx bx-x-circle h1"></i>
|
||||
<div class="data-title">FAIL</div>
|
||||
<div class="data-value"><?php echo $supplier['fail_analyses']; ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="data-card bg-warning text-white">
|
||||
<i class="bx bx-info-circle h1"></i>
|
||||
<div class="data-title">DATA</div>
|
||||
<div class="data-value"><?php echo $supplier['data_analyses']; ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-4">
|
||||
<!-- Pie Chart -->
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Analysis Distribution</h5>
|
||||
<div id="pie-chart"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Horizontal Stacked Bar Chart -->
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Analysis Summary</h5>
|
||||
<div id="stacked-bar-chart"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<!-- Distribuzione delle Analisi -->
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Total Analysis Distribution</h5>
|
||||
<div id="distribution-bar-chart"></div>
|
||||
<button class="collapsible">Toggle Table</button>
|
||||
<div class="collapsible-content">
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Analysis Name</th>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="distribution-table-body">
|
||||
<!-- Data loaded dynamically -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<!-- Analisi FAIL -->
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Top FAIL Analyses</h5>
|
||||
<div id="fail-bar-chart"></div>
|
||||
<!-- Pulsante Toggle Table -->
|
||||
<button id="toggle-fail-table" class="btn btn-secondary">Toggle Table</button>
|
||||
<div id="fail-table-container" style="display: none;">
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Analysis Name</th>
|
||||
<th>Fail Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="fail-table-body">
|
||||
<!-- Popolato dinamicamente -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Pulsante View Fail Details -->
|
||||
<button id="view-fail-details" class="btn btn-primary">View Fail Details</button>
|
||||
<div id="fail-details-container" style="display: none;">
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Analysis Name</th>
|
||||
<th>Report Number</th>
|
||||
<th>Ref Numb.</th>
|
||||
<th>Product Description</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="fail-details-table-body">
|
||||
<!-- Popolato dinamicamente -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Dati per i grafici principali
|
||||
const passCount = <?php echo isset($supplier['pass_analyses']) ? $supplier['pass_analyses'] : 0; ?>;
|
||||
const failCount = <?php echo isset($supplier['fail_analyses']) ? $supplier['fail_analyses'] : 0; ?>;
|
||||
const dataCount = <?php echo isset($supplier['data_analyses']) ? $supplier['data_analyses'] : 0; ?>;
|
||||
|
||||
// Pie Chart Configuration
|
||||
const pieChartOptions = {
|
||||
series: [passCount, failCount, dataCount],
|
||||
chart: {
|
||||
type: 'pie',
|
||||
height: 350
|
||||
},
|
||||
labels: ['PASS', 'FAIL', 'DATA'],
|
||||
colors: ['#28a745', '#dc3545', '#ffc107'],
|
||||
title: {
|
||||
text: 'Analysis Distribution',
|
||||
align: 'center'
|
||||
},
|
||||
legend: {
|
||||
position: 'bottom'
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: true,
|
||||
formatter: function(val, opts) {
|
||||
return opts.w.globals.series[opts.seriesIndex] + " (" + val.toFixed(2) + "%)";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const pieChart = new ApexCharts(document.querySelector("#pie-chart"), pieChartOptions);
|
||||
pieChart.render();
|
||||
|
||||
// Stacked Bar Chart Configuration
|
||||
const stackedBarChartOptions = {
|
||||
series: [{
|
||||
name: 'PASS',
|
||||
data: [passCount]
|
||||
},
|
||||
{
|
||||
name: 'FAIL',
|
||||
data: [failCount]
|
||||
},
|
||||
{
|
||||
name: 'DATA',
|
||||
data: [dataCount]
|
||||
}
|
||||
],
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 350,
|
||||
stacked: true,
|
||||
horizontal: true
|
||||
},
|
||||
colors: ['#28a745', '#dc3545', '#ffc107'],
|
||||
xaxis: {
|
||||
categories: ['Analysis'],
|
||||
title: {
|
||||
text: 'Count'
|
||||
}
|
||||
},
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
barHeight: '70%'
|
||||
}
|
||||
},
|
||||
title: {
|
||||
text: 'Analysis Summary',
|
||||
align: 'center'
|
||||
},
|
||||
legend: {
|
||||
position: 'bottom'
|
||||
}
|
||||
};
|
||||
|
||||
const stackedBarChart = new ApexCharts(document.querySelector("#stacked-bar-chart"), stackedBarChartOptions);
|
||||
stackedBarChart.render();
|
||||
|
||||
// Fetch and populate data for additional charts and tables
|
||||
const supplierName = "<?php echo htmlspecialchars($supplier['name']); ?>";
|
||||
|
||||
$.getJSON(`get_analysis_data.php?supplier=${supplierName}`, function(data) {
|
||||
if (data.error) {
|
||||
alert(data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Distribuzione delle analisi totali
|
||||
const distributionChartOptions = {
|
||||
series: [{
|
||||
data: data.analysisDistribution.map(item => item.total)
|
||||
}],
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 350,
|
||||
horizontal: true
|
||||
},
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
barHeight: '50%'
|
||||
}
|
||||
},
|
||||
xaxis: {
|
||||
categories: data.analysisDistribution.map(item => item.analysis_name),
|
||||
title: {
|
||||
text: 'Total Analyses'
|
||||
}
|
||||
},
|
||||
colors: ['#007bff'],
|
||||
title: {
|
||||
text: 'Total Analysis Distribution',
|
||||
align: 'center'
|
||||
}
|
||||
};
|
||||
|
||||
const distributionChart = new ApexCharts(document.querySelector("#distribution-bar-chart"), distributionChartOptions);
|
||||
distributionChart.render();
|
||||
|
||||
// Aggiorna tabella per Distribuzione Totale
|
||||
const distTableBody = document.querySelector("#distribution-table-body");
|
||||
data.analysisDistribution.forEach(row => {
|
||||
distTableBody.innerHTML += `<tr>
|
||||
<td>${row.analysis_name}</td>
|
||||
<td>${row.total}</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
// Distribuzione delle analisi FAIL
|
||||
const failChartOptions = {
|
||||
series: [{
|
||||
data: data.failDistribution.map(item => item.fail)
|
||||
}],
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 350,
|
||||
horizontal: true
|
||||
},
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
barHeight: '50%'
|
||||
}
|
||||
},
|
||||
xaxis: {
|
||||
categories: data.failDistribution.map(item => item.analysis_name),
|
||||
title: {
|
||||
text: 'Fail Count'
|
||||
}
|
||||
},
|
||||
colors: ['#dc3545'],
|
||||
title: {
|
||||
text: 'Top FAIL Analyses',
|
||||
align: 'center'
|
||||
}
|
||||
};
|
||||
|
||||
const failChart = new ApexCharts(document.querySelector("#fail-bar-chart"), failChartOptions);
|
||||
failChart.render();
|
||||
|
||||
// Aggiorna tabella per Distribuzione FAIL
|
||||
const failTableBody = document.querySelector("#fail-table-body");
|
||||
data.failDistribution.forEach(row => {
|
||||
failTableBody.innerHTML += `<tr>
|
||||
<td>${row.analysis_name}</td>
|
||||
<td>${row.fail}</td>
|
||||
</tr>`;
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione Toggle Table
|
||||
document.querySelector("#toggle-fail-table").addEventListener("click", function() {
|
||||
const table = document.querySelector("#fail-table-container");
|
||||
table.style.display = table.style.display === "block" ? "none" : "block";
|
||||
});
|
||||
|
||||
// Gestione View Fail Details
|
||||
document.querySelector("#view-fail-details").addEventListener("click", function() {
|
||||
const table = document.querySelector("#fail-details-container");
|
||||
|
||||
// Evita di richiamare più volte lo stesso contenuto
|
||||
if (!table.hasAttribute("data-loaded")) {
|
||||
$.getJSON(`get_fail_details.php?supplier=${supplierName}`, function(data) {
|
||||
const failDetailsTableBody = document.querySelector("#fail-details-table-body");
|
||||
|
||||
data.failDetails.forEach(row => {
|
||||
failDetailsTableBody.innerHTML += `
|
||||
<tr>
|
||||
<td>${row.analysis_name}</td>
|
||||
<td>${row.report_number}</td>
|
||||
<td>${row.product_refnumber}</td>
|
||||
<td>${row.product_description}</td>
|
||||
<td>
|
||||
<a href="../products/reportdetails.php?idreports=${row.report_id}" target="_blank" class="btn btn-sm btn-primary">
|
||||
View Details
|
||||
</a>
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
table.setAttribute("data-loaded", "true");
|
||||
});
|
||||
}
|
||||
|
||||
table.style.display = table.style.display === "block" ? "none" : "block";
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('../include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
include('../include/headscript.php');
|
||||
include('../class/company.php'); // Ricorda di includere anche $conn
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$id = intval($_POST['id']);
|
||||
$severity = intval($_POST['severity']);
|
||||
$is_legal = $_POST['is_legal'] === 'Y' ? 'Y' : 'N';
|
||||
|
||||
// Validazione del valore di severity
|
||||
if ($severity < 1 || $severity > 10) {
|
||||
echo 'Error: Severity must be between 1 and 10.';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verifica se esiste già un record per questa analisi
|
||||
$checkQuery = "SELECT COUNT(*) AS count FROM analysis_severity WHERE idanalysisvocabulary = ?";
|
||||
$stmt = $conn->prepare($checkQuery);
|
||||
$stmt->bind_param('i', $id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$row = $result->fetch_assoc();
|
||||
$exists = $row['count'] > 0;
|
||||
$stmt->close();
|
||||
|
||||
if ($exists) {
|
||||
// Aggiorna il record esistente
|
||||
$updateQuery = "
|
||||
UPDATE analysis_severity
|
||||
SET severity = ?, is_legal = ?
|
||||
WHERE idanalysisvocabulary = ?
|
||||
";
|
||||
$stmt = $conn->prepare($updateQuery);
|
||||
$stmt->bind_param('isi', $severity, $is_legal, $id);
|
||||
} else {
|
||||
// Inserisce un nuovo record
|
||||
$insertQuery = "
|
||||
INSERT INTO analysis_severity (idanalysisvocabulary, severity, is_legal)
|
||||
VALUES (?, ?, ?)
|
||||
";
|
||||
$stmt = $conn->prepare($insertQuery);
|
||||
$stmt->bind_param('iis', $id, $severity, $is_legal);
|
||||
}
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo 'success';
|
||||
} else {
|
||||
echo 'Error: Database error - ' . $stmt->error;
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<?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">
|
||||
<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">
|
||||
<script src="../assets/js/jquery.min.js"></script>
|
||||
<link rel="stylesheet" href="../assets/plugins/select2/select2.min.css">
|
||||
<script src="../assets/plugins/select2/select2.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
|
||||
<!-- Loader -->
|
||||
<div id="preloader">
|
||||
<div id="status">
|
||||
<div class="spinner"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Begin page -->
|
||||
<div id="wrapper">
|
||||
|
||||
<?php include('../include/navigationbar.php'); ?>
|
||||
|
||||
<!-- Start right Content here -->
|
||||
<div class="content-page">
|
||||
<!-- Start content -->
|
||||
<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">Preferred Analyses</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-custom">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Analysis Name</th>
|
||||
<th>Category</th>
|
||||
<th>Test Method</th>
|
||||
<th>Severity</th>
|
||||
<th>Legal</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
$query = "
|
||||
SELECT
|
||||
av.idanalysisvocabulary,
|
||||
av.nameanalysisvoc,
|
||||
av.category_analysis,
|
||||
av.testmethod_name,
|
||||
COALESCE(asv.severity, '') AS severity,
|
||||
COALESCE(asv.is_legal, 'N') AS is_legal
|
||||
FROM analysisvocabulary av
|
||||
LEFT JOIN analysis_severity asv
|
||||
ON av.idanalysisvocabulary = asv.idanalysisvocabulary
|
||||
WHERE av.preferred = 'Y'
|
||||
";
|
||||
$result = $conn->query($query);
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$severity = $row['severity'];
|
||||
$is_legal = $row['is_legal'];
|
||||
echo "<tr>";
|
||||
echo "<td>{$row['idanalysisvocabulary']}</td>";
|
||||
echo "<td>{$row['nameanalysisvoc']}</td>";
|
||||
echo "<td>{$row['category_analysis']}</td>";
|
||||
echo "<td>{$row['testmethod_name']}</td>";
|
||||
echo "<td>
|
||||
<input type='number' class='form-control form-control-sm severity-input'
|
||||
value='{$severity}'
|
||||
data-id='{$row['idanalysisvocabulary']}'
|
||||
min='1' max='10'>
|
||||
</td>";
|
||||
echo "<td>
|
||||
<select class='form-select form-select-sm legal-select'
|
||||
data-id='{$row['idanalysisvocabulary']}'>
|
||||
<option value='Y' " . ($is_legal === 'Y' ? 'selected' : '') . ">Yes</option>
|
||||
<option value='N' " . ($is_legal === 'N' ? 'selected' : '') . ">No</option>
|
||||
</select>
|
||||
</td>";
|
||||
echo "<td>
|
||||
<button class='btn btn-success btn-sm save-btn'
|
||||
data-id='{$row['idanalysisvocabulary']}'>Save</button>
|
||||
</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
} else {
|
||||
echo "<tr><td colspan='7' class='text-center'>No data available</td></tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php include('../include/footer.php'); ?>
|
||||
</div>
|
||||
<!-- End Right content here -->
|
||||
|
||||
</div>
|
||||
<!-- END wrapper -->
|
||||
<script>
|
||||
$(document).on('click', '.save-btn', function() {
|
||||
const id = $(this).data('id');
|
||||
const severity = $(this).closest('tr').find('.severity-input').val();
|
||||
const isLegal = $(this).closest('tr').find('.legal-select').val();
|
||||
|
||||
// Validazione del campo severity lato client
|
||||
if (severity < 1 || severity > 10 || isNaN(severity)) {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Invalid Input',
|
||||
text: 'Severity must be a number between 1 and 10.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Invio dati tramite AJAX
|
||||
$.ajax({
|
||||
url: 'update_analysis.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
id: id,
|
||||
severity: severity,
|
||||
is_legal: isLegal
|
||||
},
|
||||
success: function(response) {
|
||||
// Debug del valore ricevuto
|
||||
console.log('Response:', response.trim());
|
||||
if (response.trim() === 'success') {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Updated',
|
||||
text: 'The analysis has been updated successfully.',
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: response.trim(),
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: 'Failed to connect to the server.',
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/js/popper.min.js"></script>
|
||||
<script src="../assets/js/bootstrap.min.js"></script>
|
||||
<script src="../assets/js/jquery.blockUI.js"></script>
|
||||
<script src="../assets/js/waves.js"></script>
|
||||
<script src="../assets/js/app.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user