- -
- -
diff --git a/dbbackup/auth_chart_order.sql b/dbbackup/auth_chart_order.sql new file mode 100644 index 0000000..077565d --- /dev/null +++ b/dbbackup/auth_chart_order.sql @@ -0,0 +1,32 @@ +/* + Navicat Premium Dump SQL + + Source Server : local + Source Server Type : MySQL + Source Server Version : 100432 (10.4.32-MariaDB) + Source Host : localhost:3306 + Source Schema : reportifynew + + Target Server Type : MySQL + Target Server Version : 100432 (10.4.32-MariaDB) + File Encoding : 65001 + + Date: 25/09/2024 01:08:34 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for auth_chart_order +-- ---------------------------- +DROP TABLE IF EXISTS `chart_order`; +CREATE TABLE `chart_order` ( + `id` int NOT NULL, + `user_id` int NULL DEFAULT NULL, + `order` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, + `insert_date` datetime NULL DEFAULT current_timestamp ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + +SET FOREIGN_KEY_CHECKS = 1; 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/chartorder.php b/public/userarea/statkpi/chartorder.php new file mode 100644 index 0000000..6d96484 --- /dev/null +++ b/public/userarea/statkpi/chartorder.php @@ -0,0 +1,38 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// two methods save and load data +if ($_POST['method'] == 'save') { + $order = $_POST['order']; + $user_id = $iduserlogin; + // check if user already have order + $sql = "SELECT * FROM chart_order WHERE user_id = $user_id"; + $result = $conn->query($sql); + $order = implode(',', $order); + if ($result->num_rows > 0) { + $sql = "UPDATE chart_order SET `order` = '$order' WHERE user_id = $user_id"; + } else { + $sql = "INSERT INTO chart_order (user_id, `order`) VALUES ($user_id, '$order')"; + } + $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); + if($result->num_rows == 0) { + echo json_encode([]); + return; + }else{ + $row = $result->fetch_assoc(); + $order_list = explode(',', $row['order']); + echo json_encode($order_list); + } +} \ No newline at end of file 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..84620f4 100644 --- a/public/userarea/statkpi/statkpi.php +++ b/public/userarea/statkpi/statkpi.php @@ -32,6 +32,21 @@ include('parsedatachart.php'); @@ -208,6 +233,40 @@ include('parsedatachart.php'); + + + + + @@ -223,9 +282,9 @@ include('parsedatachart.php'); -