update
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user