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
|
||||
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'] : '';
|
||||
// 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";
|
||||
|
||||
$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
|
||||
|
||||
@ -32,6 +32,21 @@ include('parsedatachart.php');
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
#activeFilters{
|
||||
display: flex;
|
||||
font-size: 16px;
|
||||
flex-direction: row;
|
||||
background: 0;
|
||||
}
|
||||
|
||||
|
||||
.badge{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.width-100 {
|
||||
width: 100%;
|
||||
}
|
||||
@ -187,13 +202,23 @@ include('parsedatachart.php');
|
||||
|
||||
.filters-applied {
|
||||
display: inline-block;
|
||||
background-color: #3368ff;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
padding: 5px 10px;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
width: 100%;
|
||||
margin: 20px;
|
||||
}
|
||||
.chart-box {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
@ -208,6 +233,40 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- sidebar filter style -->
|
||||
<style>
|
||||
|
||||
.filter-sidebar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 300px;
|
||||
height: 100%;
|
||||
background: #f8f9fa;
|
||||
box-shadow: -2px 0 5px rgba(0,0,0,0.1);
|
||||
padding: 20px;
|
||||
display: none;
|
||||
z-index: 999;
|
||||
}
|
||||
.active-filters {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
body {
|
||||
transition: margin-right 0.3s; /* Smooth transition */
|
||||
}
|
||||
|
||||
#main-content{
|
||||
transition: margin-right 0.3s; /* Smooth transition */
|
||||
}
|
||||
|
||||
.collapsed {
|
||||
margin-right: 300px; /* Hide the sidebar */
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Begin page -->
|
||||
@ -223,7 +282,7 @@ include('parsedatachart.php');
|
||||
|
||||
<?php include('../include/topbar.php'); ?>
|
||||
|
||||
<div class="page-content-wrapper ">
|
||||
<div class="page-content-wrapper " id="main-content">
|
||||
|
||||
<div class="container-fluid" >
|
||||
|
||||
@ -242,6 +301,140 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
<!-- end page title end breadcrumb -->
|
||||
|
||||
<button id="toggleFilters" class="btn btn-primary">Toggle Filters</button>
|
||||
|
||||
<!-- Right Sidebar -->
|
||||
<div class="filter-sidebar" id="filterSidebar">
|
||||
<?php
|
||||
|
||||
// 'refNumbers' => $refNumbers,
|
||||
// 'productsSeasons' => $productsSeasons,
|
||||
// 'ageRange' => $ageRange,
|
||||
// 'labName' => $labName,
|
||||
// 'tesType' => $tesType,
|
||||
// 'numberLabs' => $numberLabs,
|
||||
|
||||
?>
|
||||
<div class="form-group">
|
||||
<label for="productsRefnumber">Product Ref Number</label>
|
||||
<select id="productsRefnumber" class="form-control select2" multiple>
|
||||
|
||||
<?php foreach ($refNumbers as $refNumber): ?>
|
||||
<option value="<?php echo $refNumber['refNumber']; ?>"><?php echo $refNumber['refNumber']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="productsSeason">Product Season</label>
|
||||
<select id="productsSeason" class="form-control select2" multiple>
|
||||
<?php foreach ($productsSeasons as $productSeason): ?>
|
||||
<option value="<?php echo $productSeason['season']; ?>"><?php echo $productSeason['season']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ageRange">Age Range</label>
|
||||
<select id="ageRange" class="form-control select2" multiple>
|
||||
<?php foreach ($ageRange as $age): ?>
|
||||
<option value="<?php echo $age['ageRange']; ?>"><?php echo $age['ageRange']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="reportsLabName">Lab Name</label>
|
||||
<select id="reportsLabName" class="form-control select2" multiple>
|
||||
<?php foreach ($labName as $lab): ?>
|
||||
<option value="<?php echo $lab['labName']; ?>"><?php echo $lab['labName']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="reportsTestType">Tes Type</label>
|
||||
<select id="reportsTestType" class="form-control select2" multiple>
|
||||
<?php foreach ($tesType as $test): ?>
|
||||
<option value="<?php echo $test['tesType']; ?>"><?php echo $test['tesType']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="reportsNumberLab">Report Number</label>
|
||||
<select id="reportsNumberLab" class="form-control select2" multiple>
|
||||
<?php foreach ($numberLabs as $number): ?>
|
||||
<option value="<?php echo $number['reportNumber']; ?>"><?php echo $number['reportNumber']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Scripts -->
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('.select2').select2({
|
||||
placeholder: "Select options",
|
||||
allowClear: true
|
||||
});
|
||||
|
||||
$('#toggleFilters').on('click', function() {
|
||||
$('#filterSidebar').toggle();
|
||||
$('#main-content').toggleClass('collapsed');
|
||||
});
|
||||
|
||||
$('.select2').on('change', function() {
|
||||
updateActiveFilters();
|
||||
});
|
||||
|
||||
$('#startDate, #endDate').on('change', function() {
|
||||
updateActiveFilters();
|
||||
});
|
||||
|
||||
function updateActiveFilters() {
|
||||
let activeFilters = [];
|
||||
$('.select2').each(function() {
|
||||
const selectedValues = $(this).val();
|
||||
if (selectedValues) {
|
||||
// activeFilters with values
|
||||
// activeFilters.push(`${$(this).prev('label').text()}: ${selectedValues.join(', ')}`);
|
||||
// activefilters without values
|
||||
activeFilters.push($(this).prev('label').text());
|
||||
}
|
||||
});
|
||||
$('#startDate, #endDate').each(function(){
|
||||
const selectedValue = $(this).val();
|
||||
if(selectedValue){
|
||||
activeFilters.push($(this).prev('label').text());
|
||||
}
|
||||
})
|
||||
|
||||
$('#activeFilters').html(activeFilters.map(f => `<span class="badge badge-info mr-1">${f} <button class="close" onclick="removeFilter('${f}')">×</button></span>`).join(''));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function removeFilter(filter) {
|
||||
const label = filter.split(':')[0];
|
||||
const select = $('label').filter(function() {
|
||||
return $(this).text().trim() === label;
|
||||
}).next('select');
|
||||
|
||||
const dateInput = $('label').filter(function(){
|
||||
return $(this).text().trim() === label;
|
||||
}).next('input')
|
||||
|
||||
// Clear the select2 field
|
||||
if (select.length) {
|
||||
select.val(null).trigger('change');
|
||||
}
|
||||
// Clear the date field
|
||||
if(dateInput.length){
|
||||
dateInput.val(null).trigger('change');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<div class="row">
|
||||
@ -262,8 +455,7 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label for="supplierFilter">Supplier</label>
|
||||
<select id="supplierFilter" class="form-control select2">
|
||||
<option value="">All Suppliers</option>
|
||||
<select id="supplierFilter" class="form-control select2" multiple>
|
||||
<?php foreach ($productBySupplier as $supplier): ?>
|
||||
<option value="<?php echo $supplier['supplier']; ?>"><?php echo $supplier['supplier']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
@ -272,9 +464,9 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
<hr>
|
||||
<!-- Active Filters Display -->
|
||||
<div id="activeFilters" class="mt-3" style="display: none;">
|
||||
<div id="activeFiltersDiv" class="mt-3" style="background-color:white;">
|
||||
<h6>Active Filters:</h6>
|
||||
<div id="filterDisplay" class="filters-applied badge badge-info p-2" style="font-size: 16px;"></div>
|
||||
<div id="activeFilters" class="filters-applied badge badge-info p-2" style="font-size: 16px;"></div>
|
||||
<button id="clearFilters" class="btn btn-sm btn-warning ml-3">Clear Filters</button>
|
||||
</div>
|
||||
|
||||
@ -286,7 +478,9 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
<!-- end row -->
|
||||
|
||||
<div class="row">
|
||||
<div class="chart-container" id="charts">
|
||||
|
||||
<div class="row chart-box" id="chart1" data-id="1">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@ -347,11 +541,11 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
<!-- end row -->
|
||||
|
||||
<div class="row">
|
||||
<div class="row chart-box" id="chart2" data-id="2">
|
||||
<div class="col-md-4"> <!-- Colonna per il primo grafico (Pie Chart) -->
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Reports Overview</h5>
|
||||
<h5 class="card-title" id="reports_overview">Reports Overview</h5>
|
||||
<div id="reportPieChart"></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -366,7 +560,7 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row chart-box" id="chart3" data-id="3">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@ -377,7 +571,7 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row chart-box" id="chart4" data-id="4">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@ -388,7 +582,7 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row chart-box" id="chart5" data-id="5">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@ -401,7 +595,7 @@ include('parsedatachart.php');
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div><!-- container -->
|
||||
|
||||
</div> <!-- Page content Wrapper -->
|
||||
@ -415,75 +609,73 @@ include('parsedatachart.php');
|
||||
|
||||
</div>
|
||||
<!-- END wrapper -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.14.0/Sortable.min.js"></script>
|
||||
<script>
|
||||
// Define the horizontal bar chart for analysis distribution
|
||||
var analysisBarChartOptions = {
|
||||
series: [{
|
||||
name: 'Total Tests',
|
||||
data: [] // Initially empty, will be filled via AJAX
|
||||
}],
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 500
|
||||
},
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
columnWidth: '100%',
|
||||
endingShape: 'rounded'
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const chartContainer = document.getElementById('charts');
|
||||
const sortable = new Sortable(chartContainer, {
|
||||
animation: 150,
|
||||
onEnd: function () {
|
||||
saveChartOrder(); // Save chart order after dragging
|
||||
}
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: true
|
||||
},
|
||||
stroke: {
|
||||
show: true,
|
||||
width: 2,
|
||||
colors: ['transparent']
|
||||
},
|
||||
xaxis: {
|
||||
title: {
|
||||
text: 'Number of Tests'
|
||||
}
|
||||
},
|
||||
yaxis: {
|
||||
labels: {
|
||||
show: true,
|
||||
maxWidth: 700, // Increased max width for labels
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
colors: ['#000']
|
||||
}
|
||||
},
|
||||
title: {
|
||||
text: 'Analysis Name'
|
||||
}
|
||||
},
|
||||
fill: {
|
||||
opacity: 1,
|
||||
colors: ['#004d00']
|
||||
},
|
||||
tooltip: {
|
||||
y: {
|
||||
formatter: function(val) {
|
||||
return val + " tests";
|
||||
}
|
||||
}
|
||||
},
|
||||
title: {
|
||||
text: 'Analysis Distribution',
|
||||
align: 'center'
|
||||
},
|
||||
grid: {
|
||||
padding: {
|
||||
left: 10 // Increased left padding for more label space
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// Create the initial chart
|
||||
var analysisBarChart = new ApexCharts(document.querySelector("#analysisDistributionChart"), analysisBarChartOptions);
|
||||
analysisBarChart.render();
|
||||
// Function to save chart order to localStorage
|
||||
function saveChartOrder() {
|
||||
const order = Array.from(chartContainer.children).map(chart => chart.dataset.id);
|
||||
localStorage.setItem('chartOrder', JSON.stringify(order));
|
||||
|
||||
// lets save it for the user
|
||||
$.ajax({
|
||||
url: 'chartorder.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
method:'save',
|
||||
order: order
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
},
|
||||
error: function() {
|
||||
alert('Error saving chart order.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Function to restore chart order from localStorage
|
||||
function loadChartOrder() {
|
||||
|
||||
// Load the saved order from localStorage
|
||||
|
||||
const savedOrder = JSON.parse(localStorage.getItem('chartOrder'));
|
||||
if (savedOrder) {
|
||||
savedOrder.forEach(id => {
|
||||
const chart = document.querySelector(`[data-id='${id}']`);
|
||||
chartContainer.appendChild(chart); // Append charts in saved order
|
||||
});
|
||||
}
|
||||
|
||||
// Load the saved order from the database
|
||||
$.ajax({
|
||||
url: 'chartorder.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
method:'load'
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
const order = JSON.parse(response);
|
||||
order.forEach(id => {
|
||||
const chart = document.querySelector(`[data-id='${id}']`);
|
||||
chartContainer.appendChild(chart); // Append charts in saved order
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Load the saved chart order when the page loads
|
||||
loadChartOrder();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@ -495,6 +687,12 @@ include('parsedatachart.php');
|
||||
var startDate = $('#startDate').val();
|
||||
var endDate = $('#endDate').val();
|
||||
var supplier = $('#supplierFilter').val();
|
||||
var productsRefnumber = $('#productsRefnumber').val();
|
||||
var productsSeason = $('#productsSeason').val();
|
||||
var ageRange = $('#ageRange').val();
|
||||
var reportsLabName = $('#reportsLabName').val();
|
||||
var reportsTestType = $('#reportsTestType').val();
|
||||
var reportsNumberLab = $('#reportsNumberLab').val();
|
||||
|
||||
$.ajax({
|
||||
url: 'parsedatachart.php',
|
||||
@ -502,10 +700,22 @@ include('parsedatachart.php');
|
||||
data: {
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
supplier: supplier
|
||||
supplier: supplier,
|
||||
productsRefnumber: productsRefnumber,
|
||||
productsSeason: productsSeason,
|
||||
ageRange: ageRange,
|
||||
reportsLabName: reportsLabName,
|
||||
reportsTestType: reportsTestType,
|
||||
reportsNumberLab: reportsNumberLab
|
||||
},
|
||||
success: function(response) {
|
||||
if (!response) {
|
||||
alert('No data found.');
|
||||
data = {};
|
||||
return;
|
||||
}else{
|
||||
var data = JSON.parse(response);
|
||||
}
|
||||
|
||||
// Aggiorna le cards con i nuovi dati
|
||||
$('#totalProducts').text(data.totalProducts);
|
||||
@ -530,56 +740,18 @@ include('parsedatachart.php');
|
||||
return parseInt(item.totalTests, 10); // Converte il conteggio dei test in numeri interi
|
||||
});
|
||||
|
||||
// Aggiorna il grafico a barre verticali
|
||||
analysisBarChart.updateOptions({
|
||||
xaxis: {
|
||||
categories: analysisLabels // Aggiorna le etichette
|
||||
}
|
||||
});
|
||||
analysisBarChart.updateSeries([{
|
||||
data: analysisCounts // Aggiorna i dati del grafico
|
||||
}]);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert('Error retrieving data.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Eventi per applicare i filtri
|
||||
$('#startDate, #endDate, #supplierFilter').on('change', function() {
|
||||
updateData();
|
||||
});
|
||||
// remove pie chart and create a new one
|
||||
$('#reportPieChart').html('');
|
||||
|
||||
// Clear filters
|
||||
$('#clearFilters').on('click', function() {
|
||||
$('#startDate').val('');
|
||||
$('#endDate').val('');
|
||||
$('#supplierFilter').val('').trigger('change');
|
||||
updateData();
|
||||
$('#activeFilters').hide();
|
||||
});
|
||||
var intFailReports = parseInt(data.failReportsPie);
|
||||
var intPassReports = parseInt(data.passReportsPie);
|
||||
var intOtherReports = parseInt(data.otherReportsPie);
|
||||
|
||||
// Chiamata iniziale per caricare i dati alla prima visualizzazione della pagina
|
||||
updateData();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
document.getElementById('totalProducts').innerText = <?php echo $totalProducts; ?>;
|
||||
document.getElementById('totalReports').innerText = <?php echo $totalReports; ?>;
|
||||
document.getElementById('failedReports').innerText = <?php echo $failedReports; ?>;
|
||||
document.getElementById('failedReportsPercent').innerText = "(<?php echo number_format($failedReportsPercent, 2); ?>%)";
|
||||
document.getElementById('totalTests').innerText = <?php echo $totalTests; ?>;
|
||||
document.getElementById('failedTests').innerText = <?php echo $failedTests; ?>;
|
||||
document.getElementById('failedTestsPercent').innerText = "(<?php echo number_format($failedTestsPercent, 2); ?>%)";
|
||||
</script>
|
||||
<script>
|
||||
// Data for pie chart (Reports: Fail, Pass, Others)
|
||||
var options = {
|
||||
series: [<?php echo $failReportsPie; ?>, <?php echo $passReportsPie; ?>, <?php echo $otherReportsPie; ?>],
|
||||
series: [intFailReports, intPassReports, intOtherReports],
|
||||
chart: {
|
||||
width: '100%', // Mantieni la larghezza al 100% all'interno della colonna Bootstrap
|
||||
type: 'pie',
|
||||
@ -606,11 +778,17 @@ include('parsedatachart.php');
|
||||
|
||||
var chart = new ApexCharts(document.querySelector("#reportPieChart"), options);
|
||||
chart.render();
|
||||
</script>
|
||||
<script>
|
||||
|
||||
// remove bar chart and create a new one
|
||||
$('#worsttenanalysis').html('');
|
||||
|
||||
// Data for the bar chart
|
||||
var analysisNames = <?php echo json_encode(array_column($topFailingAnalysis, 'name')); ?>;
|
||||
var failCounts = <?php echo json_encode(array_column($topFailingAnalysis, 'failCount')); ?>;
|
||||
var analysisNames = data.topFailingAnalysis.map(function(item) {
|
||||
return item.name;
|
||||
});
|
||||
var failCounts = data.topFailingAnalysis.map(function(item) {
|
||||
return parseInt(item.failCount, 10);
|
||||
});
|
||||
|
||||
var options = {
|
||||
series: [{
|
||||
@ -674,14 +852,23 @@ include('parsedatachart.php');
|
||||
|
||||
var chart = new ApexCharts(document.querySelector("#worsttenanalysis"), options);
|
||||
chart.render();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// remove bar chart and create a new one
|
||||
$('#worstSuppliersChart').html('');
|
||||
|
||||
// Data for the bar chart of worst suppliers
|
||||
var supplierNames = <?php echo json_encode(array_column($worstSuppliers, 'supplier')); ?>;
|
||||
var failPercentages = <?php echo json_encode(array_column($worstSuppliers, 'failPercentage')); ?>;
|
||||
var totalReportsForSupplier = <?php echo json_encode(array_column($worstSuppliers, 'totalReports')); ?>;
|
||||
var failedReportsForSupplier = <?php echo json_encode(array_column($worstSuppliers, 'failedReports')); ?>;
|
||||
var supplierNames = data.worstSuppliers.map(function(item) {
|
||||
return item.supplier;
|
||||
});
|
||||
var failPercentages = data.worstSuppliers.map(function(item) {
|
||||
return parseFloat(item.failPercentage);
|
||||
});
|
||||
var totalReportsForSupplier = data.worstSuppliers.map(function(item) {
|
||||
return parseInt(item.totalReports, 10);
|
||||
});
|
||||
var failedReportsForSupplier = data.worstSuppliers.map(function(item) {
|
||||
return parseInt(item.failedReports, 10);
|
||||
});
|
||||
|
||||
var options = {
|
||||
series: [{
|
||||
@ -735,12 +922,17 @@ include('parsedatachart.php');
|
||||
|
||||
var chart = new ApexCharts(document.querySelector("#worstSuppliersChart"), options);
|
||||
chart.render();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// remove bar chart and create a new one
|
||||
$('#productBySupplierChart').html('');
|
||||
|
||||
// Prepara i dati per il grafico
|
||||
var supplierNames = <?php echo json_encode(array_column($productBySupplier, 'supplier')); ?>;
|
||||
var totalProducts = <?php echo json_encode(array_column($productBySupplier, 'totalProducts')); ?>;
|
||||
var supplierNames = data.productBySupplier.map(function(item) {
|
||||
return item.supplier;
|
||||
});
|
||||
var totalProducts = data.productBySupplier.map(function(item) {
|
||||
return parseInt(item.totalProducts, 10);
|
||||
});
|
||||
|
||||
var options = {
|
||||
series: [{
|
||||
@ -788,9 +980,139 @@ include('parsedatachart.php');
|
||||
|
||||
var chart = new ApexCharts(document.querySelector("#productBySupplierChart"), options);
|
||||
chart.render();
|
||||
|
||||
// remove bar chart and create a new one
|
||||
$('#analysisDistributionChart').html('');
|
||||
|
||||
var analysisNames = data.analysisDistribution.map(function(item) {
|
||||
return item.analysisName;
|
||||
});
|
||||
var totalTests = data.analysisDistribution.map(function(item) {
|
||||
return parseInt(item.totalTests, 10);
|
||||
});
|
||||
// Define the horizontal bar chart for analysis distribution
|
||||
var analysisBarChartOptions = {
|
||||
series: [{
|
||||
name: 'Total Tests',
|
||||
data: totalTests // Initially empty, will be filled via AJAX
|
||||
}],
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 500
|
||||
},
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
columnWidth: '100%',
|
||||
endingShape: 'rounded'
|
||||
}
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: true
|
||||
},
|
||||
stroke: {
|
||||
show: true,
|
||||
width: 2,
|
||||
colors: ['transparent']
|
||||
},
|
||||
xaxis: {
|
||||
categories: analysisNames,
|
||||
title: {
|
||||
text: 'Number of Tests'
|
||||
}
|
||||
},
|
||||
yaxis: {
|
||||
labels: {
|
||||
show: true,
|
||||
maxWidth: 700, // Increased max width for labels
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
colors: ['#000']
|
||||
}
|
||||
},
|
||||
title: {
|
||||
text: 'Analysis Name'
|
||||
}
|
||||
},
|
||||
fill: {
|
||||
opacity: 1,
|
||||
colors: ['#004d00']
|
||||
},
|
||||
tooltip: {
|
||||
y: {
|
||||
formatter: function(val) {
|
||||
return val + " tests";
|
||||
}
|
||||
}
|
||||
},
|
||||
title: {
|
||||
text: 'Analysis Distribution',
|
||||
align: 'center'
|
||||
},
|
||||
grid: {
|
||||
padding: {
|
||||
left: 10 // Increased left padding for more label space
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create the initial chart
|
||||
var analysisBarChart = new ApexCharts(document.querySelector("#analysisDistributionChart"), analysisBarChartOptions);
|
||||
analysisBarChart.render();
|
||||
|
||||
},
|
||||
error: function() {
|
||||
alert('Error retrieving data.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Eventi per applicare i filtri
|
||||
$('#startDate, #endDate, #supplierFilter, #productsRefnumber, #productsSeason, #ageRange, #reportsLabName, #reportsTestType, #reportsNumberLab').on('change', function() {
|
||||
updateData();
|
||||
});
|
||||
|
||||
// Clear filters
|
||||
$('#clearFilters').on('click', function() {
|
||||
$('#startDate').val('');
|
||||
$('#endDate').val('');
|
||||
$('#supplierFilter').val('').trigger('change');
|
||||
$('#productsRefnumber').val('').trigger('change');
|
||||
$('#productsSeason').val('').trigger('change');
|
||||
$('#ageRange').val('').trigger('change');
|
||||
$('#reportsLabName').val('').trigger('change');
|
||||
$('#reportsTestType').val('').trigger('change');
|
||||
$('#reportsNumberLab').val('').trigger('change');
|
||||
updateData();
|
||||
// $('#activeFilters').hide();
|
||||
});
|
||||
|
||||
// Chiamata iniziale per caricare i dati alla prima visualizzazione della pagina
|
||||
updateData();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
document.getElementById('totalProducts').innerText = <?php echo $totalProducts; ?>;
|
||||
document.getElementById('totalReports').innerText = <?php echo $totalReports; ?>;
|
||||
document.getElementById('failedReports').innerText = <?php echo $failedReports; ?>;
|
||||
document.getElementById('failedReportsPercent').innerText = "(<?php echo number_format($failedReportsPercent, 2); ?>%)";
|
||||
document.getElementById('totalTests').innerText = <?php echo $totalTests; ?>;
|
||||
document.getElementById('failedTests').innerText = <?php echo $failedTests; ?>;
|
||||
document.getElementById('failedTestsPercent').innerText = "(<?php echo number_format($failedTestsPercent, 2); ?>%)";
|
||||
</script>
|
||||
<script>
|
||||
|
||||
// for multiple select
|
||||
$(document).ready(function() {
|
||||
$('.select2').select2({
|
||||
placeholder: "Select options",
|
||||
allowClear: true,
|
||||
width: '100%'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- plugin JS -->
|
||||
<script src="../assets/js/popper.min.js"></script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user