Merge branch 'development'

This commit is contained in:
“VeLiTi”
2024-06-27 09:10:22 +02:00
3 changed files with 195 additions and 14 deletions

View File

@@ -151,9 +151,34 @@ switch ($action) {
break;
default:
# code...
break;
case 'report_usage_servicereports':
$sql = 'SELECT YEAR(h.created) AS year, QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid = e.rowID where h.type = "ServiceReport" AND NOT e.productrowid = "31" GROUP BY YEAR(h.created), QUARTER(h.created), MONTH(h.created)';
break;
case 'report_usage_firmware':
$sql = 'SELECT YEAR(h.created) AS year,QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid=e.rowID where h.type="Firmware" AND NOT e.productrowid="31" GROUP BY YEAR(h.created),QUARTER(h.created), MONTH(h.created)';
break;
case 'report_usage_warranty':
$sql = 'SELECT YEAR(h.created) AS year, QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid = e.rowID where h.type = "Warranty" AND NOT e.productrowid = "31" GROUP BY YEAR(h.created), QUARTER(h.created), MONTH(h.created)';
break;
case 'report_usage_other':
$sql = 'SELECT YEAR(h.created) AS year, QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid = e.rowID where NOT h.type = "Warranty" OR NOT h.type = "Firmware" OR NOT h.type = "ServiceReport" GROUP BY YEAR(h.created), QUARTER(h.created), MONTH(h.created)';
break;
case 'report_usage_equipment':
$sql = 'SELECT YEAR(created) AS year, QUARTER(created) AS quarter, MONTH(created) as month, count(rowID) AS count FROM equipment GROUP BY YEAR(created), QUARTER(created), MONTH(created)';
break;
case 'report_usage_changes':
$sql = 'SELECT YEAR(created) AS year, QUARTER(created) AS quarter, MONTH(created) as month, count(rowID) AS count FROM changelog GROUP BY YEAR(created), QUARTER(created), MONTH(created)';
break;
case 'report_usage_users':
$sql = 'SELECT YEAR(created) AS year, QUARTER(created) AS quarter, MONTH(created) as month, count(id) AS count FROM users WHERE NOT view = "3" GROUP BY YEAR(created), QUARTER(created), MONTH(created)';
break;
}
$stmt = $pdo->prepare($sql);
@@ -192,20 +217,11 @@ switch ($action) {
}
break;
case 'serviceforecast':
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
break;
case 'warrantyforecast':
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
break;
case 'geolocation':
default:
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
break;
}
//------------------------------------------
//Encrypt results
//------------------------------------------

View File

@@ -234,7 +234,7 @@ echo <<<EOT
<title>$title</title>
<link rel="icon" type="image/png" href="$icon_image">
<link href="./style/admin.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<link rel="stylesheet" href="./style/leaflet.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.0.0/css/all.css">
<script src="./assets/leaflet.js"></script>
<script src="./assets/charts.js"></script>

165
usage_reporting.php Normal file
View File

@@ -0,0 +1,165 @@
<?php
defined(page_security_key) or exit;
if (debug && debug_id == $_SESSION['id']){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
include_once './assets/functions.php';
include_once './settings/settings.php';
/*Check if allowed
if (isAllowed('usage_reporting',$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
*/
//Return report_usage_servicereports
$api_url = '/v1/application/totals=/report_usage_servicereports';
$report_usage_servicereports = ioServer($api_url,'');
//Decode Payload
if (!empty($report_usage_servicereports)){$report_usage_servicereports = decode_payload($report_usage_servicereports);}else{$report_usage_servicereports = null;}
//Return report_usage_firmware
$api_url = '/v1/application/totals=/report_usage_firmware';
$report_usage_firmware = ioServer($api_url,'');
//Decode Payload
if (!empty($report_usage_firmware)){$report_usage_firmware = decode_payload($report_usage_firmware);}else{$report_usage_firmware = null;}
$api_url = '/v1/application/totals=/report_usage_warranty';
$report_usage_warranty = ioServer($api_url,'');
//Decode Payload
if (!empty($report_usage_warranty)){$report_usage_warranty = decode_payload($report_usage_warranty);}else{$report_usage_warranty = null;}
$api_url = '/v1/application/totals=/report_usage_other';
$report_usage_other = ioServer($api_url,'');
//Decode Payload
if (!empty($report_usage_other)){$report_usage_other = decode_payload($report_usage_other);}else{$report_usage_other = null;}
$api_url = '/v1/application/totals=/report_usage_equipment';
$report_usage_equipment = ioServer($api_url,'');
//Decode Payload
if (!empty($report_usage_equipment)){$report_usage_equipment = decode_payload($report_usage_equipment);}else{$report_usage_equipment = null;}
$api_url = '/v1/application/totals=/report_usage_changes';
$report_usage_changes = ioServer($api_url,'');
//Decode Payload
if (!empty($report_usage_changes)){$report_usage_changes = decode_payload($report_usage_changes);}else{$report_usage_changes = null;}
$api_url = '/v1/application/totals=/report_usage_users';
$report_usage_users = ioServer($api_url,'');
//Decode Payload
if (!empty($report_usage_users)){$report_usage_users = decode_payload($report_usage_users);}else{$report_usage_users = null;}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// visual forecast for service and warranty+++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
function usageReportingView($messages){
//GET TOTAL SERVICE COUNT
$totalcount = 0;
foreach ($messages as $message){
$totalcount += $message['count'];
}
$view = '<div style="margin-bottom: 30px;">
<ul style="width: 100%;max-width:100%" class="chart">
';
foreach ($messages as $message){
if ($message['year'] == date("Y")){
$height = ($message['count'] / $totalcount) * 100;
$fc_year = $message['year'];
$dateObj = DateTime::createFromFormat('!m', $message['month']);
$title = $dateObj->format('F').' '.$fc_year;
$view .='<li style="text-align:center;">' . $message['count'] . '<span style="height:' . $height . '%" title="' . $title . '"></span></li>';
} else {
}
}
$view .='</ul></div>';
return $view;
}
template_header('Usage', 'usage');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-house"></i>
<div class="txt">
<h2>Usage overview</h2>
<p></p>
</div>
</div>
</div>';
$usage_firmware = usageReportingView(json_decode(json_encode($report_usage_firmware), true)) ?? '';
$usage_servicereports = usageReportingView(json_decode(json_encode($report_usage_servicereports), true)) ?? '';
$usage_warranty = usageReportingView(json_decode(json_encode($report_usage_warranty), true)) ?? '';
$usage_other = usageReportingView(json_decode(json_encode($report_usage_other), true)) ?? '';
$usage_equipment = usageReportingView(json_decode(json_encode($report_usage_equipment), true)) ?? '';
$usage_changes = usageReportingView(json_decode(json_encode($report_usage_changes), true)) ?? '';
$usage_users = usageReportingView(json_decode(json_encode($report_usage_users), true)) ?? '';
$view .= '
<div class="content-block-wrapper">
<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>Firmware
</div>'.$usage_firmware.'
</div>
<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>ServiceReports
</div>'.$usage_servicereports.'
</div>
</div>
<div class="content-block-wrapper">
<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>Warranty
</div>'.$usage_warranty.'
</div>
<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>Other
</div>'.$usage_other.'
</div>
</div>
<div class="content-block-wrapper">
<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>Equipment
</div>'.$usage_equipment.'
</div>
<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>Changes
</div>'.$usage_changes.'
</div>
</div>
<div class="content-block-wrapper">
<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>Users
</div>'.$usage_users.'
</div>
</div>
';
//OUTPUT
echo $view;
template_footer();