From 91b3490ff93d0dc5e5480f34ec1c2d069a21d889 Mon Sep 17 00:00:00 2001 From: kapsona777 Date: Tue, 24 Sep 2024 23:17:16 +0400 Subject: [PATCH] made filters and fixed chart problems --- public/userarea/assets/pages/dashboard.js | 4 +- public/userarea/statkpi/parsedatachart.php | 245 ++++++- public/userarea/statkpi/statkpi.php | 794 +++++++++++++-------- 3 files changed, 733 insertions(+), 310 deletions(-) diff --git a/public/userarea/assets/pages/dashboard.js b/public/userarea/assets/pages/dashboard.js index 540b2dc..14427d5 100644 --- a/public/userarea/assets/pages/dashboard.js +++ b/public/userarea/assets/pages/dashboard.js @@ -11,7 +11,9 @@ //line-chart -var ctx = document.getElementById('lineChart').getContext('2d'); +if( $('#lineChart').length > 0 ){ + var ctx = document.getElementById('lineChart').getContext('2d'); +} gradientStroke1 = ctx.createLinearGradient(0, 0, 0, 300); gradientStroke1.addColorStop(0, '#008cff'); diff --git a/public/userarea/statkpi/parsedatachart.php b/public/userarea/statkpi/parsedatachart.php index 9f9f30d..61a7c61 100644 --- a/public/userarea/statkpi/parsedatachart.php +++ b/public/userarea/statkpi/parsedatachart.php @@ -1,11 +1,97 @@ query($totalProductsQuery); $totalProducts = $totalProductsResult->fetch_assoc()['totalProducts']; @@ -138,13 +256,28 @@ while ($row = $worstSuppliersResult->fetch_assoc()) { ]; } +$suPfilters=''; // Statistic for products by suppliers + +if(!empty($supplierFilter)){ + $suPfilters .= " AND p.namesupplier IN ($supplierFilter)"; +} +if(!empty($refNumberFilter)){ + $suPfilters .= " AND p.products_refnumber IN ($refNumberFilter)"; +} +if(!empty($productsSeasonFilter)){ + $suPfilters .= " AND p.products_season IN ($productsSeasonFilter)"; +} +if(!empty($ageRangeFilter)){ + $suPfilters .= " AND p.agerange IN ($ageRangeFilter)"; +} $productBySupplierQuery = " SELECT p.namesupplier AS supplier, COUNT(p.idproducts) AS totalProducts FROM products p - WHERE p.namesupplier IS NOT NULL + WHERE p.namesupplier IS NOT NULL $suPfilters GROUP BY p.namesupplier - ORDER BY totalProducts DESC"; + ORDER BY totalProducts DESC"; + $productBySupplierResult = $conn->query($productBySupplierQuery); $productBySupplier = []; while ($row = $productBySupplierResult->fetch_assoc()) { @@ -153,6 +286,96 @@ while ($row = $productBySupplierResult->fetch_assoc()) { 'totalProducts' => $row['totalProducts'] ]; } +// refNumbers +$refNumbersQuery = " + SELECT p.products_refnumber AS refNumber + FROM products p + WHERE p.products_refnumber IS NOT NULL + GROUP BY p.products_refnumber +"; +$refNumbersResult = $conn->query($refNumbersQuery); +$refNumbers = []; +while ($row = $refNumbersResult->fetch_assoc()) { + $refNumbers[] = [ + 'refNumber' => $row['refNumber'] + ]; +} +// productsSeason +$productsSeasonQuery = " + SELECT p.products_season AS season + FROM products p + WHERE p.products_season IS NOT NULL + GROUP BY p.products_season +"; +$productsSeasonResult = $conn->query($productsSeasonQuery); +$productsSeasons = []; +while ($row = $productsSeasonResult->fetch_assoc()) { + $productsSeasons[] = [ + "season" => $row['season'] + ]; +} + +// ageRanges +$ageRangeQuery = " + SELECT p.agerange AS ageRange + FROM products p + WHERE p.agerange IS NOT NULL + GROUP BY p.agerange +"; + +$ageRangeResult = $conn->query($ageRangeQuery); +$ageRange = []; +while ($row = $ageRangeResult->fetch_assoc()) { + $ageRange[] = [ + "ageRange" => $row['ageRange'] + ]; +} + +// labNames +$labNameQuery = " + SELECT r.reports_LabName AS LabName + FROM reports r + WHERE r.reports_LabName IS NOT NULL + GROUP BY r.reports_LabName +"; +$labNameResult = $conn->query($labNameQuery); +$labName = []; +while ($row = $labNameResult->fetch_assoc()) { + $labName[] = [ + "LabName" => $row['LabName'] + ]; +} + +// tesTypes +$tesTypeQuery = " + SELECT r.reports_testype AS tesType + FROM reports r + WHERE r.reports_testype IS NOT NULL + GROUP BY r.reports_testype +"; +$tesTypeResult = $conn->query($tesTypeQuery); +$tesType = []; +while ($row = $tesTypeResult->fetch_assoc()) { + $tesType[] = [ + "tesType" => $row['tesType'] + ]; +} + +// numberLabs +$numberLabsQuery = " + SELECT r.reportsNumberLab as reportNumber + FROM reports r + WHERE r.reportsNumberLab IS NOT NULL + GROUP BY r.reportsNumberLab +"; +$numberLabsResult = $conn->query($numberLabsQuery); +$numberLabs = []; +while ($row = $numberLabsResult->fetch_assoc()) { + $numberLabs[] = [ + "reportNumber" => $row['reportNumber'] + ]; +} + // New Query: Distribution of analyses (for pie chart) $analysisDistributionQuery = " @@ -192,6 +415,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { 'topFailingAnalysis' => $topFailingAnalysis, 'worstSuppliers' => $worstSuppliers, 'productBySupplier' => $productBySupplier, + 'refNumbers' => $refNumbers, + 'productsSeasons' => $productsSeasons, + 'ageRange' => $ageRange, + 'labName' => $labName, + 'tesType' => $tesType, + 'numberLabs' => $numberLabs, 'analysisDistribution' => $analysisDistribution // Distribuzione delle analisi per il grafico a torta ]); exit; // Ferma l'esecuzione del resto dello script dopo aver risposto all'AJAX diff --git a/public/userarea/statkpi/statkpi.php b/public/userarea/statkpi/statkpi.php index 872e130..5debed4 100644 --- a/public/userarea/statkpi/statkpi.php +++ b/public/userarea/statkpi/statkpi.php @@ -186,8 +186,7 @@ include('parsedatachart.php'); } .filters-applied { - display: inline-block; - background-color: #3368ff; + display: inline-block; color: white; border-radius: 5px; padding: 5px 10px; @@ -208,6 +207,28 @@ include('parsedatachart.php'); + + + + + @@ -242,6 +263,116 @@ include('parsedatachart.php'); + + + +
+ $refNumbers, + // 'productsSeasons' => $productsSeasons, + // 'ageRange' => $ageRange, + // 'labName' => $labName, + // 'tesType' => $tesType, + // 'numberLabs' => $numberLabs, + + ?> +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ + +
@@ -262,8 +393,7 @@ include('parsedatachart.php');
- @@ -272,9 +402,9 @@ include('parsedatachart.php');

-