stakpidetails
This commit is contained in:
parent
95f929069e
commit
88dc8d41a4
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
// Connessione al database
|
||||
include('../include/headscript.php');
|
||||
$tableName = 'products'; // Per la pagina products.php
|
||||
$tableName = 'products'; // Nome tabella per products.php
|
||||
|
||||
// Verifica che i parametri necessari siano stati inviati
|
||||
if (isset($_POST['user']) && isset($_POST['table'])) {
|
||||
$userId = $_POST['user'];
|
||||
$tablen = $tableName;
|
||||
$page = $tableName;
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
@ -18,31 +18,34 @@ if (isset($_POST['user']) && isset($_POST['table'])) {
|
||||
// Query per verificare se il record esiste
|
||||
$query = "SELECT * FROM user_table_settings WHERE iduser = ? AND page = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("is", $userId, $tablen);
|
||||
$stmt->bind_param("is", $userId, $page);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
// Restituisci i dati esistenti
|
||||
$row = $result->fetch_assoc();
|
||||
echo json_encode([
|
||||
'column_visibility' => $row['column_visibility'],
|
||||
'column_order' => $row['column_order']
|
||||
]);
|
||||
|
||||
// Costruisci l'output JSON nel formato che DataTables si aspetta
|
||||
$settings = [
|
||||
'columns' => array_map(function ($visible) {
|
||||
return ['visible' => $visible];
|
||||
}, json_decode($row['column_visibility'], true)), // Converti la visibilità in array associativo
|
||||
'ColReorder' => json_decode($row['column_order'], true), // Decodifica l'ordine delle colonne
|
||||
'time' => time() // Aggiungi un timestamp per evitare che i dati vengano memorizzati in cache
|
||||
];
|
||||
|
||||
echo json_encode($settings);
|
||||
} else {
|
||||
// Crea un record di default se non esiste
|
||||
$defaultVisibility = json_encode([/* Impostazioni di visibilità predefinite */]);
|
||||
$defaultOrder = json_encode([/* Ordine delle colonne predefinito */]);
|
||||
|
||||
$insertQuery = "INSERT INTO user_table_settings (iduser, page, column_visibility, column_order, created_at) VALUES (?, ?, ?, ?, NOW())";
|
||||
$insertStmt = $conn->prepare($insertQuery);
|
||||
$insertStmt->bind_param("isss", $userId, $tablen, $defaultVisibility, $defaultOrder);
|
||||
$insertStmt->execute();
|
||||
|
||||
// Restituisci le impostazioni predefinite
|
||||
echo json_encode([
|
||||
'column_visibility' => $defaultVisibility,
|
||||
'column_order' => $defaultOrder
|
||||
]);
|
||||
// Se non ci sono dati, invia un errore (o imposta valori predefiniti)
|
||||
http_response_code(404);
|
||||
echo json_encode(['error' => 'No settings found']);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
} else {
|
||||
// Se i parametri non sono validi, restituisci errore
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Invalid request']);
|
||||
}
|
||||
|
||||
@ -216,6 +216,30 @@ $result = $conn->query($query);
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var hasUserInteracted = false; // Flag per tracciare l'interazione dell'utente
|
||||
|
||||
// Carica le impostazioni salvate dal server prima di inizializzare DataTables
|
||||
var stateLoaded = false;
|
||||
var columnSettings = {}; // Variabile per memorizzare le impostazioni della tabella
|
||||
|
||||
// Recupera le impostazioni salvate dal server
|
||||
$.ajax({
|
||||
url: 'get_user_table_settings.php', // PHP che recupera i settaggi
|
||||
method: 'POST',
|
||||
data: {
|
||||
user: "<?php echo $iduserlogin; ?>", // ID utente
|
||||
table: 'products' // Nome della tabella
|
||||
},
|
||||
async: false, // Carica in modo sincrono per garantire che le impostazioni siano pronte prima di DataTables
|
||||
success: function(response) {
|
||||
columnSettings = JSON.parse(response);
|
||||
console.log("Impostazioni recuperate:", columnSettings);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Errore nel caricamento delle impostazioni:', xhr.responseText);
|
||||
}
|
||||
});
|
||||
|
||||
// Inizializza DataTables con ColReorder, filtri e ColVis
|
||||
var table = $('#productsTable').DataTable({
|
||||
responsive: true,
|
||||
@ -223,7 +247,9 @@ $result = $conn->query($query);
|
||||
order: [
|
||||
[1, 'asc']
|
||||
], // Ordina per descrizione
|
||||
colReorder: true, // Abilita il riordinamento delle colonne
|
||||
colReorder: {
|
||||
order: columnSettings && columnSettings.ColReorder ? columnSettings.ColReorder : null // Usa le impostazioni di ColReorder se presenti
|
||||
},
|
||||
dom: 'Bfrtip', // Integra i bottoni
|
||||
buttons: [{
|
||||
extend: 'colvis', // ColVis per mostrare/nascondere colonne
|
||||
@ -233,6 +259,19 @@ $result = $conn->query($query);
|
||||
columns: ':not(:last-child)' // Non nascondere l'ultima colonna (Actions)
|
||||
}],
|
||||
initComplete: function() {
|
||||
console.log("DataTables initComplete");
|
||||
|
||||
// Se sono state caricate impostazioni di visibilità delle colonne, applicale
|
||||
if (columnSettings && columnSettings.columns) {
|
||||
console.log("Applico visibilità colonne:", columnSettings.columns);
|
||||
this.api().columns().every(function(index) {
|
||||
var column = this;
|
||||
column.visible(columnSettings.columns[index].visible, false); // Non ridisegnare ogni volta
|
||||
});
|
||||
}
|
||||
|
||||
this.api().columns.adjust().draw(false); // Ridisegna la tabella alla fine
|
||||
|
||||
// Aggiungi i filtri per ogni colonna (eccetto la colonna delle azioni)
|
||||
this.api().columns().every(function() {
|
||||
var column = this;
|
||||
@ -247,48 +286,42 @@ $result = $conn->query($query);
|
||||
}
|
||||
});
|
||||
},
|
||||
// Recupera le impostazioni salvate dal server
|
||||
stateSave: true,
|
||||
stateSaveCallback: function(settings, data) {
|
||||
// Salva le impostazioni sul server tramite AJAX
|
||||
$.ajax({
|
||||
url: 'save_user_table_settings.php', // PHP che salva i settaggi
|
||||
method: 'POST',
|
||||
data: {
|
||||
user: "<?php echo $iduserlogin; ?>", // ID utente
|
||||
table: 'products', // Nome della tabella
|
||||
settings: JSON.stringify(data) // Impostazioni della tabella
|
||||
},
|
||||
success: function(response) {
|
||||
console.log('Settings saved:', response);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error saving settings:', xhr.responseText);
|
||||
}
|
||||
});
|
||||
},
|
||||
stateLoadCallback: function(settings) {
|
||||
var o;
|
||||
// Carica le impostazioni salvate dal server tramite AJAX
|
||||
$.ajax({
|
||||
url: 'get_user_table_settings.php', // PHP che recupera i settaggi
|
||||
method: 'POST',
|
||||
data: {
|
||||
user: "<?php echo $iduserlogin; ?>", // ID utente
|
||||
table: 'products' // Nome della tabella
|
||||
},
|
||||
async: false,
|
||||
success: function(response) {
|
||||
o = JSON.parse(response);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error loading settings:', xhr.responseText);
|
||||
}
|
||||
});
|
||||
return o;
|
||||
console.log("Salvataggio stato tabella");
|
||||
|
||||
// Salva le impostazioni sul server solo se l'utente ha interagito
|
||||
if (hasUserInteracted) {
|
||||
$.ajax({
|
||||
url: 'save_user_table_settings.php', // PHP che salva i settaggi
|
||||
method: 'POST',
|
||||
data: {
|
||||
user: "<?php echo $iduserlogin; ?>", // ID utente
|
||||
table: 'products', // Nome della tabella
|
||||
settings: JSON.stringify(data) // Impostazioni della tabella
|
||||
},
|
||||
success: function(response) {
|
||||
console.log('Impostazioni salvate:', response);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Errore nel salvataggio delle impostazioni:', xhr.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Imposta il flag `hasUserInteracted` quando l'utente modifica qualcosa (colonne o riordina)
|
||||
table.on('column-reorder', function() {
|
||||
hasUserInteracted = true;
|
||||
console.log("Colonne riordinate");
|
||||
});
|
||||
|
||||
table.on('column-visibility', function() {
|
||||
hasUserInteracted = true;
|
||||
console.log("Visibilità colonna cambiata");
|
||||
});
|
||||
|
||||
// Gestione del click su "Reports" per visualizzare la tabella child con i report e le analisi
|
||||
$('#productsTable').on('click', '.show-reports', function() {
|
||||
var tr = $(this).closest('tr');
|
||||
@ -387,12 +420,6 @@ $result = $conn->query($query);
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
62
public/userarea/products/save_user_table_settings.php
Normal file
62
public/userarea/products/save_user_table_settings.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// Connessione al database
|
||||
include('../include/headscript.php');
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Recupera i dati dalla richiesta POST
|
||||
$iduser = isset($_POST['user']) ? $_POST['user'] : 0;
|
||||
$table = isset($_POST['table']) ? $_POST['table'] : '';
|
||||
$settings = isset($_POST['settings']) ? $_POST['settings'] : '';
|
||||
|
||||
if ($iduser && $table && $settings) {
|
||||
// Decodifica il JSON delle impostazioni
|
||||
$settingsArray = json_decode($settings, true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
// Estrai visibilità e ordine delle colonne
|
||||
$column_visibility = json_encode(array_column($settingsArray['columns'], 'visible'));
|
||||
$column_order = json_encode($settingsArray['ColReorder']);
|
||||
|
||||
// Verifica se esistono già impostazioni per l'utente e la pagina
|
||||
$stmt = $conn->prepare("SELECT column_visibility, column_order FROM user_table_settings WHERE iduser = ? AND page = ?");
|
||||
$stmt->bind_param("is", $iduser, $table);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$row = $result->fetch_assoc();
|
||||
$existing_visibility = $row['column_visibility'];
|
||||
$existing_order = $row['column_order'];
|
||||
|
||||
// Aggiorna solo se c'è una differenza rispetto alle impostazioni già salvate
|
||||
if ($existing_visibility != $column_visibility || $existing_order != $column_order) {
|
||||
$stmt = $conn->prepare("UPDATE user_table_settings SET column_visibility = ?, column_order = ?, updated_at = NOW() WHERE iduser = ? AND page = ?");
|
||||
$stmt->bind_param("ssis", $column_visibility, $column_order, $iduser, $table);
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(['success' => true, 'message' => 'Settings updated']);
|
||||
} else {
|
||||
echo json_encode(['error' => 'Failed to update settings']);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['success' => true, 'message' => 'No changes to save']);
|
||||
}
|
||||
} else {
|
||||
// Inserisci nuove impostazioni solo se non esistono già
|
||||
$stmt = $conn->prepare("INSERT INTO user_table_settings (iduser, page, column_visibility, column_order, created_at) VALUES (?, ?, ?, ?, NOW())");
|
||||
$stmt->bind_param("isss", $iduser, $table, $column_visibility, $column_order);
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(['success' => true, 'message' => 'Settings saved']);
|
||||
} else {
|
||||
echo json_encode(['error' => 'Failed to save settings']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['error' => 'Invalid JSON format']);
|
||||
}
|
||||
} else {
|
||||
// Se non ci sono dati sufficienti, invia un errore
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Invalid request']);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
427
public/userarea/statkpi/parsedatachart-details.php
Normal file
427
public/userarea/statkpi/parsedatachart-details.php
Normal file
@ -0,0 +1,427 @@
|
||||
<?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'] : '';
|
||||
// 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";
|
||||
if (!empty($startDate) && !empty($endDate)) {
|
||||
$filters .= " AND r.reportsDateOut BETWEEN '$startDate' AND '$endDate'";
|
||||
}
|
||||
if (!empty($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 WHERE 1=1";
|
||||
if (!empty($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'];
|
||||
|
||||
// Statistic 2: Total number of reports
|
||||
$totalReportsQuery = "
|
||||
SELECT COUNT(DISTINCT r.idreports) AS totalReports
|
||||
FROM reports r
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters
|
||||
";
|
||||
$totalReportsResult = $conn->query($totalReportsQuery);
|
||||
$totalReports = $totalReportsResult->fetch_assoc()['totalReports'];
|
||||
|
||||
// Statistic 3: Number of 'fail' reports and percentage compared to total
|
||||
$failedReportsQuery = "
|
||||
SELECT COUNT(DISTINCT r.idreports) AS failedReports
|
||||
FROM reports r
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters AND UPPER(r.reportsRating) IN ('FAIL', 'F', 'DOESN\'T COMPLY')
|
||||
";
|
||||
$failedReportsResult = $conn->query($failedReportsQuery);
|
||||
$failedReports = $failedReportsResult->fetch_assoc()['failedReports'];
|
||||
$failedReportsPercent = ($totalReports > 0) ? ($failedReports / $totalReports) * 100 : 0;
|
||||
|
||||
// Statistic 4: Total number of tests performed (distinct tests)
|
||||
$totalTestsQuery = "
|
||||
SELECT COUNT(DISTINCT rp.idreports, rp.idPart, rp.result_TestName) AS totalTests
|
||||
FROM result_project rp
|
||||
LEFT JOIN reports r ON rp.idreports = r.idreports
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters
|
||||
";
|
||||
$totalTestsResult = $conn->query($totalTestsQuery);
|
||||
$totalTests = $totalTestsResult->fetch_assoc()['totalTests'];
|
||||
|
||||
// Statistic 5: Number of 'fail' tests and percentage (case-insensitive for rating fail)
|
||||
$failedTestsQuery = "
|
||||
SELECT COUNT(DISTINCT rp.idreports, rp.idPart, rp.result_TestName) AS failedTests
|
||||
FROM result_project rp
|
||||
LEFT JOIN reports r ON rp.idreports = r.idreports
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters AND UPPER(rp.result_Rating) IN ('FAIL', 'F', 'DOESN\'T COMPLY')
|
||||
";
|
||||
$failedTestsResult = $conn->query($failedTestsQuery);
|
||||
$failedTests = $failedTestsResult->fetch_assoc()['failedTests'];
|
||||
$failedTestsPercent = ($totalTests > 0) ? ($failedTests / $totalTests) * 100 : 0;
|
||||
|
||||
// Pie Chart Data for Reports (Fail, Pass, Others)
|
||||
$failReportsPieQuery = "
|
||||
SELECT COUNT(*) AS failReports
|
||||
FROM reports r
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters AND UPPER(r.reportsRating) IN ('FAIL', 'F', 'DOESN\'T COMPLY')
|
||||
";
|
||||
$failReportsPieResult = $conn->query($failReportsPieQuery);
|
||||
$failReportsPie = $failReportsPieResult->fetch_assoc()['failReports'];
|
||||
|
||||
$passReportsPieQuery = "
|
||||
SELECT COUNT(*) AS passReports
|
||||
FROM reports r
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters AND UPPER(r.reportsRating) IN ('PASS', 'P', 'COMPLIES')
|
||||
";
|
||||
$passReportsPieResult = $conn->query($passReportsPieQuery);
|
||||
$passReportsPie = $passReportsPieResult->fetch_assoc()['passReports'];
|
||||
|
||||
$otherReportsPieQuery = "
|
||||
SELECT COUNT(*) AS otherReports
|
||||
FROM reports r
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters AND UPPER(r.reportsRating) NOT IN ('FAIL', 'F', 'DOESN\'T COMPLY', 'PASS', 'P', 'COMPLIES')
|
||||
";
|
||||
$otherReportsPieResult = $conn->query($otherReportsPieQuery);
|
||||
$otherReportsPie = $otherReportsPieResult->fetch_assoc()['otherReports'];
|
||||
|
||||
// Query to get the top 10 analyses with the most 'Fail' results
|
||||
$topFailingAnalysisQuery = "
|
||||
SELECT a.nameanalysisvoc AS analysisName, COUNT(DISTINCT rp.idreports, rp.idPart, rp.result_TestName) AS failCount
|
||||
FROM result_project rp
|
||||
LEFT JOIN reports r ON rp.idreports = r.idreports
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
LEFT JOIN analysisvocabulary a ON rp.result_TestName = a.idanalysisvocabulary
|
||||
$filters AND UPPER(rp.result_Rating) IN ('FAIL', 'F', 'DOESN\'T COMPLY')
|
||||
GROUP BY rp.result_TestName
|
||||
ORDER BY failCount DESC
|
||||
LIMIT 10
|
||||
";
|
||||
$topFailingAnalysisResult = $conn->query($topFailingAnalysisQuery);
|
||||
$topFailingAnalysis = [];
|
||||
while ($row = $topFailingAnalysisResult->fetch_assoc()) {
|
||||
$analysisName = (strlen($row['analysisName']) > 80) ? substr($row['analysisName'], 0, 80) . '...' : $row['analysisName'];
|
||||
$topFailingAnalysis[] = ['name' => $analysisName, 'failCount' => $row['failCount']];
|
||||
}
|
||||
|
||||
// Statistic for worst suppliers based on % of failed reports
|
||||
$worstSuppliersQuery = "
|
||||
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
|
||||
";
|
||||
$worstSuppliersResult = $conn->query($worstSuppliersQuery);
|
||||
$worstSuppliers = [];
|
||||
while ($row = $worstSuppliersResult->fetch_assoc()) {
|
||||
$worstSuppliers[] = [
|
||||
'supplier' => $row['supplier'],
|
||||
'failPercentage' => round($row['failPercentage'], 2),
|
||||
'totalReports' => $row['totalReports'],
|
||||
'failedReports' => $row['failedReports']
|
||||
];
|
||||
}
|
||||
|
||||
$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 $suPfilters
|
||||
GROUP BY p.namesupplier
|
||||
ORDER BY totalProducts DESC";
|
||||
|
||||
$productBySupplierResult = $conn->query($productBySupplierQuery);
|
||||
$productBySupplier = [];
|
||||
while ($row = $productBySupplierResult->fetch_assoc()) {
|
||||
$productBySupplier[] = [
|
||||
'supplier' => $row['supplier'],
|
||||
'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 = "
|
||||
SELECT a.nameanalysisvoc AS analysisName, COUNT(DISTINCT rp.idreports, rp.idPart, rp.result_TestName) AS totalTests
|
||||
FROM result_project rp
|
||||
LEFT JOIN analysisvocabulary a ON rp.result_TestName = a.idanalysisvocabulary
|
||||
LEFT JOIN reports r ON rp.idreports = r.idreports
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters
|
||||
GROUP BY rp.result_TestName
|
||||
ORDER BY totalTests DESC
|
||||
";
|
||||
|
||||
$analysisDistributionResult = $conn->query($analysisDistributionQuery);
|
||||
$analysisDistribution = [];
|
||||
while ($row = $analysisDistributionResult->fetch_assoc()) {
|
||||
$analysisDistribution[] = [
|
||||
'analysisName' => $row['analysisName'],
|
||||
'totalTests' => $row['totalTests']
|
||||
];
|
||||
}
|
||||
|
||||
// Ora controlliamo se è una richiesta AJAX
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Rispondi ai dati aggiornati tramite AJAX
|
||||
echo json_encode([
|
||||
'totalProducts' => $totalProducts,
|
||||
'totalReports' => $totalReports,
|
||||
'failedReports' => $failedReports,
|
||||
'failedReportsPercent' => $failedReportsPercent,
|
||||
'totalTests' => $totalTests,
|
||||
'failedTests' => $failedTests,
|
||||
'failedTestsPercent' => $failedTestsPercent,
|
||||
'failReportsPie' => $failReportsPie,
|
||||
'passReportsPie' => $passReportsPie,
|
||||
'otherReportsPie' => $otherReportsPie,
|
||||
'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
|
||||
}
|
||||
1127
public/userarea/statkpi/statkpi-details.php
Normal file
1127
public/userarea/statkpi/statkpi-details.php
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user