Merge branch 'lasha_kapanadze_filters_charts_and_fixProblems'
This commit is contained in:
commit
6e97456cf4
32
dbbackup/auth_chart_order.sql
Normal file
32
dbbackup/auth_chart_order.sql
Normal file
@ -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;
|
||||
@ -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');
|
||||
|
||||
38
public/userarea/statkpi/chartorder.php
Normal file
38
public/userarea/statkpi/chartorder.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
include('../../Connections/repnew.php');
|
||||
include('../include/headscript.php');
|
||||
include("../class/company.php");
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
if ($conn->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);
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,97 @@
|
||||
<?php include('../../Connections/repnew.php'); ?>
|
||||
<?php
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// error_reporting(1);
|
||||
// ini_set('display_errors', 1);
|
||||
// Ottieni i filtri dal POST
|
||||
$startDate = isset($_POST['startDate']) ? $_POST['startDate'] : '';
|
||||
$endDate = isset($_POST['endDate']) ? $_POST['endDate'] : '';
|
||||
$supplierFilter = isset($_POST['supplier']) ? $_POST['supplier'] : '';
|
||||
$endDate = isset($_POST['endDate']) ? $_POST['endDate'] : '';
|
||||
// suppliers can be multiple
|
||||
if(isset($_POST['supplier']) && !empty($_POST['supplier'])){
|
||||
$suppliers = implode(',', $_POST['supplier']);
|
||||
$supplierArr = explode(',', $suppliers);
|
||||
$supplierFilter = '';
|
||||
foreach($supplierArr as $supplier){
|
||||
$supplierFilter .= "'".$supplier."',";
|
||||
}
|
||||
$supplierFilter = substr($supplierFilter,0,-1);
|
||||
} else{
|
||||
$supplierFilter = "";
|
||||
}
|
||||
|
||||
if(isset($_POST["productsRefnumber"]) && !empty($_POST["productsRefnumber"])){
|
||||
$refNumbers = implode(',', $_POST['productsRefnumber']);
|
||||
$refNumbersArr = explode(',', $refNumbers);
|
||||
$refNumberFilter = '';
|
||||
foreach($refNumbersArr as $refNumber){
|
||||
$refNumberFilter .= "'".$refNumber."',";
|
||||
}
|
||||
$refNumberFilter = substr($refNumberFilter,0,-1);
|
||||
}else{
|
||||
$refNumberFilter = "";
|
||||
}
|
||||
|
||||
if(isset($_POST["productsSeason"]) && !empty($_POST["productsSeason"])){
|
||||
$productsSeasons = implode(',', $_POST['productsSeason']);
|
||||
$productsSeasonsArr = explode(',', $productsSeasons);
|
||||
$productsSeasonFilter = '';
|
||||
foreach($productsSeasonsArr as $productsSeason){
|
||||
$productsSeasonFilter .= "'".$productsSeason."',";
|
||||
}
|
||||
$productsSeasonFilter = substr($productsSeasonFilter,0,-1);
|
||||
}else{
|
||||
$productsSeasonFilter = "";
|
||||
}
|
||||
|
||||
if(isset($_POST["ageRange"]) && !empty($_POST["ageRange"])){
|
||||
$ageRanges = implode(',', $_POST['ageRange']);
|
||||
$ageRangesArr = explode(',', $ageRanges);
|
||||
$ageRangeFilter = '';
|
||||
foreach($ageRangesArr as $ageRange){
|
||||
$ageRangeFilter .= "'".$ageRange."',";
|
||||
}
|
||||
$ageRangeFilter = substr($ageRangeFilter,0,-1);
|
||||
}else{
|
||||
$ageRangeFilter = "";
|
||||
}
|
||||
|
||||
if(isset($_POST["reportsLabName"]) && !empty($_POST["reportsLabName"])){
|
||||
$labNames = implode(',', $_POST['reportsLabName']);
|
||||
$labNamesArr = explode(',', $labNames);
|
||||
$labNameFilter = '';
|
||||
foreach($labNamesArr as $labName){
|
||||
$labNameFilter .= "'".$labName."',";
|
||||
}
|
||||
$labNameFilter = substr($labNameFilter,0,-1);
|
||||
}else{
|
||||
$labNameFilter = "";
|
||||
}
|
||||
|
||||
if(isset($_POST["reportsTestType"]) && !empty($_POST["reportsTestType"])){
|
||||
$tesTypes = implode(',', $_POST['reportsTestType']);
|
||||
$tesTypesArr = explode(',', $tesTypes);
|
||||
$tesTypeFilter = '';
|
||||
foreach($tesTypesArr as $tesType){
|
||||
$tesTypeFilter .= "'".$tesType."',";
|
||||
}
|
||||
$tesTypeFilter = substr($tesTypeFilter,0,-1);
|
||||
}else{
|
||||
$tesTypeFilter = "";
|
||||
}
|
||||
|
||||
if(isset($_POST["reportsNumberLab"]) && !empty($_POST["reportsNumberLab"])){
|
||||
$numberLabs = implode(',', $_POST['reportsNumberLab']);
|
||||
$numberLabsArr = explode(',', $numberLabs);
|
||||
$numberLabFilter = '';
|
||||
foreach($numberLabsArr as $numberLab){
|
||||
$numberLabFilter .= "'".$numberLab."',";
|
||||
}
|
||||
$numberLabFilter = substr($numberLabFilter,0,-1);
|
||||
}else{
|
||||
$numberLabFilter = "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Creazione della condizione dei filtri di data e supplier
|
||||
$filters = "WHERE 1=1";
|
||||
@ -13,13 +99,45 @@ if (!empty($startDate) && !empty($endDate)) {
|
||||
$filters .= " AND r.reportsDateOut BETWEEN '$startDate' AND '$endDate'";
|
||||
}
|
||||
if (!empty($supplierFilter)) {
|
||||
$filters .= " AND p.namesupplier = '$supplierFilter'";
|
||||
$filters .= " AND p.namesupplier IN ($supplierFilter)";
|
||||
}
|
||||
if (!empty($refNumberFilter)) {
|
||||
$filters .= " AND p.products_refnumber IN ($refNumberFilter)";
|
||||
}
|
||||
|
||||
if (!empty($productsSeasonFilter)) {
|
||||
$filters .= " AND p.products_season IN ($productsSeasonFilter)";
|
||||
}
|
||||
|
||||
if (!empty($ageRangeFilter)) {
|
||||
$filters .= " AND p.agerange IN ($ageRangeFilter)";
|
||||
}
|
||||
|
||||
if (!empty($labNameFilter)) {
|
||||
$filters .= " AND r.reports_LabName IN ($labNameFilter)";
|
||||
}
|
||||
|
||||
if (!empty($tesTypeFilter)) {
|
||||
$filters .= " AND r.reports_testype IN ($tesTypeFilter)";
|
||||
}
|
||||
|
||||
if (!empty($numberLabFilter)) {
|
||||
$filters .= " AND r.reportsNumberLab IN ($numberLabFilter)";
|
||||
}
|
||||
|
||||
// Statistic 1: Total number of products (filtered by supplier if necessary)
|
||||
$totalProductsQuery = "SELECT COUNT(DISTINCT p.idproducts) AS totalProducts FROM products p";
|
||||
$totalProductsQuery = "SELECT COUNT(DISTINCT p.idproducts) AS totalProducts FROM products p WHERE 1=1";
|
||||
if (!empty($supplierFilter)) {
|
||||
$totalProductsQuery .= " WHERE p.namesupplier = '$supplierFilter'";
|
||||
$totalProductsQuery .= " AND p.namesupplier IN ($supplierFilter)";
|
||||
}
|
||||
if (!empty($refNumberFilter)) {
|
||||
$totalProductsQuery .= " AND p.products_refnumber IN ($refNumberFilter)";
|
||||
}
|
||||
if (!empty($productsSeasonFilter)) {
|
||||
$totalProductsQuery .= " AND p.products_season IN ($productsSeasonFilter)";
|
||||
}
|
||||
if (!empty($ageRangeFilter)) {
|
||||
$totalProductsQuery .= " AND p.agerange IN ($ageRangeFilter)";
|
||||
}
|
||||
$totalProductsResult = $conn->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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user