diff --git a/public/userarea/include/navigationbar.php b/public/userarea/include/navigationbar.php index 2535f62..8eede55 100644 --- a/public/userarea/include/navigationbar.php +++ b/public/userarea/include/navigationbar.php @@ -1,8 +1,8 @@
-
- - + + - - - - + + + + \ No newline at end of file diff --git a/public/userarea/ratego/calculate_supplier_ratings.php b/public/userarea/ratego/calculate_supplier_ratings.php index 03cf86d..0bc4065 100644 --- a/public/userarea/ratego/calculate_supplier_ratings.php +++ b/public/userarea/ratego/calculate_supplier_ratings.php @@ -35,17 +35,26 @@ SELECT 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, + CASE + WHEN SUM(CASE WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN 1 ELSE 0 END) = 0 + AND SUM(CASE WHEN LOWER(ap.test_Rating) NOT IN ('pass', 'p', 'comply', 'complies', 'fail', 'f', 'doesn\'t comply') THEN 1 ELSE 0 END) = 0 + THEN 100 + ELSE GREATEST(0, 100 - ( + SUM( + CASE + WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN + POWER(COALESCE(asv.severity, 1), 2) * + CASE WHEN COALESCE(asv.is_legal, 'N') = 'Y' THEN 2.0 ELSE 1.0 END + ELSE 0 + END + ) / NULLIF(COUNT(ap.idAnalysis_Project), 0) * 100 * + (1 + 2 * (SUM(CASE WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN 1 ELSE 0 END) / NULLIF(COUNT(ap.idAnalysis_Project), 0))) + + SUM(CASE + WHEN LOWER(ap.test_Rating) NOT IN ('pass', 'p', 'comply', 'complies', 'fail', 'f', 'doesn\'t comply') THEN 0.3 + ELSE 0 + END) + )) + END AS rating, NOW() AS calculation_date FROM products p JOIN reports r ON p.idproducts = r.idproducts @@ -61,7 +70,6 @@ ON DUPLICATE KEY UPDATE data_analyses = VALUES(data_analyses), rating = VALUES(rating), calculation_date = VALUES(calculation_date); - "; if ($conn->query($query) === TRUE) { diff --git a/public/userarea/ratego/ratego.php b/public/userarea/ratego/ratego.php index bd3a3bb..f95d2ab 100644 --- a/public/userarea/ratego/ratego.php +++ b/public/userarea/ratego/ratego.php @@ -32,6 +32,7 @@ + @@ -46,14 +47,22 @@
-
-
-
-

Supplier Ratings

+
+
+
+
+
+

+ RATE&GO +

+ +
+ +
@@ -64,6 +73,24 @@
+
+
+ + +
+
+
+
+
+
+
+ +
@@ -105,11 +132,17 @@ + \ No newline at end of file diff --git a/public/userarea/ratego/supplier-detail.php b/public/userarea/ratego/supplier-detail.php index 99e2bc6..bb79d4a 100644 --- a/public/userarea/ratego/supplier-detail.php +++ b/public/userarea/ratego/supplier-detail.php @@ -171,7 +171,7 @@ if (!$supplier) {
+ = 80 ? 'rating-high' : ($supplier['rating'] >= 50 ? 'rating-medium' : 'rating-low'); ?>">
@@ -224,6 +224,18 @@ if (!$supplier) {
Analysis Distribution
+ +
@@ -233,6 +245,18 @@ if (!$supplier) {
Analysis Summary
+ +
@@ -245,18 +269,16 @@ if (!$supplier) {
Total Analysis Distribution
- -
- + +
- - - +
Analysis Name Total
@@ -272,40 +294,36 @@ if (!$supplier) {
Top FAIL Analyses
- + - - + +
@@ -315,12 +333,133 @@ if (!$supplier) { diff --git a/public/userarea/statkpi/chartorder.php b/public/userarea/statkpi/chartorder.php index 7f9cf75..4584792 100644 --- a/public/userarea/statkpi/chartorder.php +++ b/public/userarea/statkpi/chartorder.php @@ -24,6 +24,7 @@ if ($_POST['method'] == 'save') { } $conn->query($sql); echo 'Data saved'; + } else if($_POST['method'] == 'load') { $sql = "SELECT `order` FROM chart_order WHERE user_id = $iduserlogin ORDER BY insert_date DESC LIMIT 1"; $result = $conn->query($sql); diff --git a/public/userarea/statkpi/parsedatachart.php b/public/userarea/statkpi/parsedatachart.php index 51d6acb..6d73b56 100644 --- a/public/userarea/statkpi/parsedatachart.php +++ b/public/userarea/statkpi/parsedatachart.php @@ -248,16 +248,22 @@ $otherConditions = implode("', '", array_map('addslashes', RATING_OTHER)); // Query per il grafico a barre orizzontali con sezioni multicolore $horizontalBarQuery = " - SELECT - COALESCE(p.$groupingField, 'empty') AS groupingValue, - SUM(CASE WHEN UPPER(r.reportsRating) IN ('$passConditions') THEN 1 ELSE 0 END) AS passCount, - SUM(CASE WHEN UPPER(r.reportsRating) IN ('$failConditions') THEN 1 ELSE 0 END) AS failCount, - SUM(CASE WHEN UPPER(r.reportsRating) NOT IN ('$passConditions', '$failConditions') THEN 1 ELSE 0 END) AS otherCount - FROM reports r - LEFT JOIN products p ON r.idproducts = p.idproducts - $filters - GROUP BY COALESCE(p.$groupingField, 'empty') - LIMIT 20 +SELECT + COALESCE(p.$groupingField, 'empty') AS groupingValue, + SUM(CASE WHEN UPPER(r.reportsRating) IN ('$passConditions') THEN 1 ELSE 0 END) AS passCount, + SUM(CASE WHEN UPPER(r.reportsRating) IN ('$failConditions') THEN 1 ELSE 0 END) AS failCount, + SUM(CASE WHEN UPPER(r.reportsRating) NOT IN ('$passConditions', '$failConditions') THEN 1 ELSE 0 END) AS otherCount +FROM + reports r +LEFT JOIN + products p ON r.idproducts = p.idproducts +$filters +GROUP BY + COALESCE(p.$groupingField, 'empty') +ORDER BY + failCount DESC +LIMIT 20; + "; @@ -285,6 +291,8 @@ $horizontalBarAnalysisQuery = " LEFT JOIN products p ON r.idproducts = p.idproducts $filters GROUP BY COALESCE(p.$groupingField, 'empty') + ORDER BY + failCount DESC LIMIT 20 "; @@ -302,15 +310,22 @@ while ($row = $horizontalBarAnalysisResult->fetch_assoc()) { // Statistic for worst suppliers based on % of failed reports $worstSuppliersQuery = " - SELECT p.namesupplier AS supplier, COUNT(r.idreports) AS totalReports, +SELECT + p.namesupplier AS supplier, + COUNT(r.idreports) AS totalReports, SUM(CASE WHEN UPPER(r.reportsRating) IN ('FAIL', 'F', 'DOESN\'T COMPLY') THEN 1 ELSE 0 END) AS failedReports, (SUM(CASE WHEN UPPER(r.reportsRating) IN ('FAIL', 'F', 'DOESN\'T COMPLY') THEN 1 ELSE 0 END) / COUNT(r.idreports)) * 100 AS failPercentage - FROM reports r - LEFT JOIN products p ON r.idproducts = p.idproducts - $filters - GROUP BY p.namesupplier - ORDER BY failPercentage DESC - LIMIT 10 +FROM + reports r +LEFT JOIN + products p ON r.idproducts = p.idproducts +$filters +GROUP BY + p.namesupplier +ORDER BY + failPercentage DESC, + failedReports DESC +LIMIT 30; "; $worstSuppliersResult = $conn->query($worstSuppliersQuery); $worstSuppliers = []; diff --git a/public/userarea/statkpi/statkpi.php b/public/userarea/statkpi/statkpi.php index 33df936..40fb34d 100644 --- a/public/userarea/statkpi/statkpi.php +++ b/public/userarea/statkpi/statkpi.php @@ -280,7 +280,7 @@ include('parsedatachart.php');
- @@ -484,10 +484,14 @@ include('parsedatachart.php');
+
+

Product Statistic

+
+
-
+
@@ -548,7 +552,7 @@ include('parsedatachart.php');
-
+
@@ -565,19 +569,19 @@ include('parsedatachart.php');
-
Worst Analysis
-
- - - - +
Reports Breakdown
+
-
-
+
+

Supplier Statistic

+
+
+ +
@@ -593,7 +597,7 @@ include('parsedatachart.php');
-
+
@@ -608,8 +612,12 @@ include('parsedatachart.php');
+
+

Analysis Statistic

+
+
-
+
@@ -624,8 +632,29 @@ include('parsedatachart.php');
+
+
+
+
+
Worst Analysis
+
+ + + + +
+
+
+
-
+ + +
+

Components/Substances Statistic

+
+
+ +
@@ -640,8 +669,12 @@ include('parsedatachart.php');
+
+

Other Parameter Statistic

+
+
-
+
@@ -672,7 +705,7 @@ include('parsedatachart.php');
-
+
@@ -905,7 +938,19 @@ include('parsedatachart.php'); series: pieSeries, chart: { width: '100%', - type: 'pie' + type: 'pie', + toolbar: { + show: true, // Mostra l'hamburger menu + tools: { + download: true, // Opzioni di download + selection: false, + zoom: false, + zoomin: false, + zoomout: false, + pan: false, + reset: false + } + } }, labels: pieLabels, colors: ['#FF4D4D', '#28A745', '#FFA500'], @@ -933,35 +978,83 @@ include('parsedatachart.php'); // Genera la tabella $('#tableChart2').html(generatePieTable(pieLabels, pieSeries)); + var pieLabels = ['Pass', 'Fail', 'Others']; // Ordine richiesto + var pieSeries = [intPassReports, intFailReports, intOtherReports]; // Ordine dei dati: Pass, Fail, Others + + // Configurazione del grafico a barre + var barOptions = { + series: [{ + data: pieSeries // Utilizza i dati aggiornati + }], + chart: { + type: 'bar', + height: 400, // Altezza del grafico + toolbar: { + show: true, // Mostra l'hamburger menu + tools: { + download: true, // Opzioni di download + selection: false, + zoom: false, + zoomin: false, + zoomout: false, + pan: false, + reset: false + } + } + }, + plotOptions: { + bar: { + horizontal: false, + columnWidth: '50%', + distributed: true // Colori diversi per ogni colonna + } + }, + dataLabels: { + enabled: true + }, + xaxis: { + categories: pieLabels // Stesse etichette della pie chart + }, + colors: ['#28A745', '#FF4D4D', '#FFA500'], // Verde, Rosso, Arancione + legend: { + show: false + } + }; + + // Inizializza e renderizza il grafico a barre + var barChart = new ApexCharts(document.querySelector("#reportBarChart"), barOptions); + barChart.render(); + + // remove bar chart and create a new one // Funzione per generare la tabella function generateTable(names, counts) { let tableHTML = ` - - - - - - - - - `; +
AnalysisNumber of Failures
+ + + + + + + + `; for (let i = 0; i < names.length; i++) { tableHTML += ` - - - - - `; + + + + + `; } tableHTML += ` - -
AnalysisNumber of Failures
${names[i]}${counts[i]}
${names[i]}${counts[i]}
- `; + + + `; return tableHTML; } @@ -969,6 +1062,7 @@ include('parsedatachart.php'); // Inizializza il grafico come prima $('#worsttenanalysis').html(''); + var analysisNames = data.topFailingAnalysis.map(function(item) { return item.name; }); @@ -987,6 +1081,7 @@ include('parsedatachart.php'); plotOptions: { bar: { horizontal: true, + borderRadius: 10, dataLabels: { position: 'center' } @@ -995,7 +1090,7 @@ include('parsedatachart.php'); dataLabels: { enabled: true, style: { - colors: ['#fff'], + colors: ['black'], fontSize: '12px' }, formatter: function(val, opt) { @@ -1016,7 +1111,7 @@ include('parsedatachart.php'); text: 'Analysis' } }, - colors: ['#FF4D4D'], + colors: ['orange'], responsive: [{ breakpoint: 480, options: { @@ -1069,7 +1164,7 @@ include('parsedatachart.php'); ], chart: { type: 'bar', - height: 400, + height: 500, stacked: true, horizontal: true }, @@ -1080,6 +1175,7 @@ include('parsedatachart.php'); plotOptions: { bar: { horizontal: true, + borderRadius: 5, dataLabels: { enabled: false } @@ -1118,7 +1214,7 @@ include('parsedatachart.php'); ], chart: { type: 'bar', - height: 400, + height: 500, stacked: true, horizontal: true }, @@ -1129,6 +1225,7 @@ include('parsedatachart.php'); plotOptions: { bar: { horizontal: true, + borderRadius: 5, dataLabels: { enabled: false } @@ -1144,33 +1241,33 @@ include('parsedatachart.php'); // Funzione per generare la tabella function generateSupplierTable(names, failPercentages, totalReports, failedReports) { let tableHTML = ` - - - - - - - - - - - `; +
SupplierFailure Percentage (%)Failed ReportsTotal Reports
+ + + + + + + + + + `; for (let i = 0; i < names.length; i++) { tableHTML += ` - - - - - - - `; + + + + + + + `; } tableHTML += ` - -
SupplierFailure Percentage (%)Failed ReportsTotal Reports
${names[i]}${failPercentages[i].toFixed(2)}%${failedReports[i]}${totalReports[i]}
${names[i]}${failPercentages[i].toFixed(2)}%${failedReports[i]}${totalReports[i]}
- `; + + + `; return tableHTML; } @@ -1197,11 +1294,30 @@ include('parsedatachart.php'); }], chart: { type: 'bar', - height: 400 + height: 900 }, plotOptions: { bar: { horizontal: true, + borderRadius: 5, + colors: { + ranges: [{ + from: 0, + to: 30.00, + color: '#008000' + }, // Verde + { + from: 30, + to: 70, + color: '#FF8C00' + }, // Arancione + { + from: 70, + to: 100, + color: '#FF0000' + } // Rosso + ] + }, dataLabels: { position: 'center' } @@ -1233,13 +1349,24 @@ include('parsedatachart.php'); text: 'Suppliers' } }, - colors: ['#3368FF'], + tooltip: { + enabled: true, + y: { + formatter: function(val, opt) { + return supplierNames[opt.dataPointIndex] + + ' - ' + val.toFixed(2) + '%' + + ' (Fail: ' + failedReportsForSupplier[opt.dataPointIndex] + + ' - Total: ' + totalReportsForSupplier[opt.dataPointIndex] + ')'; + } + } + }, title: { - text: 'Top 10 Suppliers with the Highest Failed Reports Percentage', + text: 'Top Suppliers with the Highest Failed Reports Percentage', align: 'center' } }; + var chart = new ApexCharts(document.querySelector("#worstSuppliersChart"), options); chart.render(); @@ -1318,6 +1445,7 @@ include('parsedatachart.php'); plotOptions: { bar: { horizontal: false, + borderRadius: 5, columnWidth: '50%', dataLabels: { position: 'top' @@ -1415,11 +1543,12 @@ include('parsedatachart.php'); }], chart: { type: 'bar', - height: 500 + height: 550 }, plotOptions: { bar: { horizontal: true, + borderRadius: 5, columnWidth: '100%', endingShape: 'rounded' } @@ -1453,7 +1582,7 @@ include('parsedatachart.php'); }, fill: { opacity: 1, - colors: ['#004d00'] + colors: ['green'] }, tooltip: { y: { @@ -1488,29 +1617,29 @@ include('parsedatachart.php'); // Funzione per generare la tabella function generateAnalytesTable(analyteNames, failCounts) { let tableHTML = ` - - - - - - - - - `; +
Analyte NameNumber of Failures
+ + + + + + + + `; for (let i = 0; i < analyteNames.length; i++) { tableHTML += ` - - - - - `; + + + + + `; } tableHTML += ` - -
Analyte NameNumber of Failures
${analyteNames[i]}${failCounts[i]}
${analyteNames[i]}${failCounts[i]}
- `; + + + `; return tableHTML; } @@ -1536,6 +1665,7 @@ include('parsedatachart.php'); plotOptions: { bar: { horizontal: true, + borderRadius: 5, dataLabels: { position: 'center' // Etichette al centro delle barre } @@ -1544,12 +1674,14 @@ include('parsedatachart.php'); dataLabels: { enabled: true, style: { - colors: ['#fff'], // Colore del testo all'interno delle barre + colors: ['black'], // Colore del testo all'interno delle barre fontSize: '12px' }, + textAnchor: 'start', // Allinea il testo a sinistra + offsetX: -5, // Regola la distanza orizzontale formatter: function(val, opt) { return analyteNames[opt.dataPointIndex]; // Mostra il nome dell'analita dentro la barra - } + }, }, xaxis: { categories: failCounts, // Visualizza solo i numeri sull'asse X @@ -1656,7 +1788,19 @@ include('parsedatachart.php'); series: values, chart: { type: 'pie', - height: 350 + height: 350, + toolbar: { + show: true, // Mostra l'hamburger menu + tools: { + download: true, // Opzioni di download + selection: false, + zoom: false, + zoomin: false, + zoomout: false, + pan: false, + reset: false + } + } }, labels: labels, responsive: [{ @@ -1683,6 +1827,7 @@ include('parsedatachart.php'); $('#tablePhasePie').html(generatePhasePieTable(labels, values)); } + function renderPhaseBarChart(phaseRatingsData) { const labels = phaseRatingsData.map(item => item.phase); const passCounts = phaseRatingsData.map(item => parseInt(item.passCount, 10)); @@ -1718,7 +1863,8 @@ include('parsedatachart.php'); colors: ['#28A745', '#FF4D4D', '#FFA500'], plotOptions: { bar: { - horizontal: true, + horizontal: false, + borderRadius: 5, dataLabels: { enabled: false }