CM69 - Bugfix graph cartest, CMXX - Healthindex update

This commit is contained in:
“VeLiTi”
2024-10-02 16:57:01 +02:00
parent 17df4c7bc1
commit bf567ec426
14 changed files with 776 additions and 125 deletions

View File

@@ -23,6 +23,7 @@ if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
$healthindex_allowed = isAllowed('report_healthindex' ,$_SESSION['profile'],$_SESSION['permission'],'R');
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
@@ -248,6 +249,11 @@ if ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4){
$view_users = ' <a href="index.php?page=users&partnerid='.$soldto_id[0].'" class="btn">'.$button_partner_assigned_users.'</a>';
}
$healthindex ='';
if ($healthindex_allowed === 1){
$healthindex = '<a href="index.php?page=report_healthindex&partnerid='.$soldto_id[0].'" class="btn">'.$view_asset_data_ranking.'</a>';
}
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$view_asset_actions.'
@@ -256,6 +262,7 @@ $view .= '<div class="content-block">
<a href="index.php?page=contracts&accountID='.$account_hierarchy->soldto.'" class="btn">'.$button_partner_assigned_contracts.'</a>
'.$view_communication.'
'.$view_users.'
'.$healthindex.'
</div>';
//OUTPUT

View File

@@ -79,6 +79,10 @@ if(isset($get_content) && $get_content!=''){
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
}
}
elseif ($v[0] == 'rowid') {
//build up search
$clause .= ' AND ed.rowID = :'.$v[0];
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];
}
@@ -97,7 +101,7 @@ if (isset($criterias['totals']) && $criterias['totals'] ==''){
}
else {
//SQL for Paging
$sql = 'SELECT e.productrowid, e.hw_version, e.serialnumber, ed.rowID, ed.equipmentid, ed.measurement, ed.historyid from equipment e JOIN equipment_data ed ON e.rowID = ed.equipmentid '.$whereclause.' ORDER BY ed.equipmentid, ed.historyid ASC';
$sql = 'SELECT e.productrowid, e.hw_version, e.serialnumber, ed.* from equipment e JOIN equipment_data ed ON e.rowID = ed.equipmentid '.$whereclause.' ORDER BY ed.equipmentid, ed.historyid ASC';
}
$stmt = $pdo->prepare($sql);

View File

@@ -79,6 +79,10 @@ if(isset($get_content) && $get_content!=''){
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
}
}
elseif ($v[0] == 'rowid') {
//build up search
$clause .= ' AND ed.rowID = :'.$v[0];
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];
}
@@ -97,7 +101,7 @@ if (isset($criterias['totals']) && $criterias['totals'] ==''){
}
else {
//SQL for Paging
$sql = 'SELECT e.productrowid, e.hw_version, e.serialnumber, ed.rowID, ed.equipmentid, ed.measurement, ed.historyid from equipment e JOIN equipment_data ed ON e.rowID = ed.equipmentid '.$whereclause.' ORDER BY ed.equipmentid, ed.historyid ASC';
$sql = 'SELECT e.productrowid, e.hw_version, e.serialnumber, ed.* from equipment e JOIN equipment_data ed ON e.rowID = ed.equipmentid '.$whereclause.' ORDER BY ed.equipmentid, ed.historyid ASC';
}
$stmt = $pdo->prepare($sql);
@@ -152,6 +156,7 @@ else {
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
//------------------------------------------
//JSON_EnCODE
//------------------------------------------

View File

@@ -0,0 +1,194 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Equipment_data
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//Get user_rights from users.php
$partner = json_decode($partnerhierarchy);
//SoldTo is empty
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
//default whereclause
$whereclause = '';
switch ($permission) {
case '4':
$whereclause = '';
break;
case '3':
$whereclause = '';
break;
case '2':
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
$whereclause = 'WHERE e.accounthierarchy like :condition ';
break;
default:
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
$whereclause = 'WHERE e.accounthierarchy like :condition ';
break;
}
//------------------------------------------
//NEW ARRAY
//------------------------------------------
$criterias = [];
$clause = '';
//------------------------------------------
//Check for $_GET variables and build up clause
//------------------------------------------
if(isset($get_content) && $get_content!=''){
//GET VARIABLES FROM URL
$requests = explode("&", $get_content);
//Check for keys and values
foreach ($requests as $y){
$v = explode("=", $y);
//INCLUDE VARIABLES IN ARRAY
$criterias[$v[0]] = $v[1];
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='products' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='success_msg' || $v[0] =='download' || $v[0] =='sort'){
//do nothing
}
elseif ($v[0] == 'serialnumber') {
//build up serialnumber
//check if multiple serialnumbers are provided
if (str_contains($v[1], ',')){
$inputs = explode(",",$v[1]);
$new_querystring = ''; //empty querystring
$x=0;
foreach($inputs as $input){
//create key
$new_key = $v[0].'_'.$x;
//inject new key/value to array
$criterias[$new_key] = $input;
$new_querystring .= ':'.$new_key.',';
$x++;
}
//remove obsolete last character from new_querystring
$new_querystring = substr($new_querystring,0, -1);
//add new_querystring to clause
$clause .= ' AND e.serialnumber IN ('.$new_querystring.')';
//remove original key/value from array
unset($criterias[$v[0]]);
}
else {
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
}
}
elseif ($v[0] == 'status') {
//Update status based on status
$clause .= ' AND e.'.$v[0].' = :'.$v[0];
$status = $v[1];
}
elseif ($v[0] == 'search') {
//build up search
$clause .= ' AND (e.serialnumber like :'.$v[0].' OR ed1.equipmentid like :'.$v[0].')';
}
elseif ($v[0] == 'partnerid') {
//build up accounthierarchy
$clause .= ' AND e.accounthierarchy like :'.$v[0];
}
elseif ($v[0] == 'rowid') {
//build up search
$clause .= ' AND ed.rowID = :'.$v[0];
}
elseif ($v[0] == 'servicedate') {
//build up service coverage
$clause .= ' AND e.service_date <= :'.$v[0];
}
elseif ($v[0] == 'warrantydate') {
//build up warranty coverage
$clause .= ' AND e.warranty_date >= :'.$v[0];
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];
}
}
if ($whereclause == '' && $clause !=''){
$whereclause = 'WHERE '.substr($clause, 4);
} else {
$whereclause .= $clause;
}
}
if (isset($criterias['totals']) && $criterias['totals'] ==''){
//Request for total rows
$sql = 'SELECT count(*) as count FROM products p JOIN equipment e ON p.rowID = e.productrowid JOIN equipment_data ed1 ON e.rowID = ed1.equipmentid LEFT JOIN equipment_data ed2 ON (ed1.equipmentid = ed2.equipmentid AND ed1.rowID < ed2.rowID) '.$whereclause.' AND ed2.rowID IS NULL';
}
else {
//SQL for Paging
$sql ='SELECT p.productcode,p.productname,e.productrowid,e.created,e.status,e.accounthierarchy,e.serialnumber,e.hw_version,e.sw_version,e.service_date,e.warranty_date, e.order_ref,e.geolocation, ed1.* FROM products p JOIN equipment e ON p.rowID = e.productrowid JOIN equipment_data ed1 ON e.rowID = ed1.equipmentid LEFT JOIN equipment_data ed2 ON (ed1.equipmentid = ed2.equipmentid AND ed1.rowID < ed2.rowID) '.$whereclause.' AND ed2.rowID IS NULL ORDER BY e.accounthierarchy LIMIT :page,:num_products';
}
$stmt = $pdo->prepare($sql);
//------------------------------------------
//Bind to query
//------------------------------------------
if (str_contains($whereclause, ':condition')){
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
}
if (!empty($criterias)){
foreach ($criterias as $key => $value){
$key_condition = ':'.$key;
if (str_contains($whereclause, $key_condition)){
if ($key == 'search'){
$search_value = '%'.$value.'%';
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
}
elseif ($key == 'partnerid'){
$search_value = '%"_"'.$value.'-%';
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
}
elseif ($key == 'p'){
//Do nothing (bug)
}
else {
$stmt->bindValue($key, $value, PDO::PARAM_STR);
}
}
}
}
//------------------------------------------
// Debuglog
//------------------------------------------
if (debug){
$message = $date.';'.$sql.';'.$username;
debuglog($message);
}
//------------------------------------------
//Add paging details
//------------------------------------------
if(isset($criterias['totals']) && $criterias['totals']==''){
$stmt->execute();
$messages = $stmt->fetch();
$messages = $messages[0];
}
else {
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
$stmt->bindValue('page', ($current_page - 1) * $page_rows_equipment, PDO::PARAM_INT);
$stmt->bindValue('num_products', $page_rows_equipment, PDO::PARAM_INT);
//Excute Query
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
//------------------------------------------
//JSON_EnCODE
//------------------------------------------
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
//------------------------------------------
//Send results
//------------------------------------------
echo $messages;
?>

View File

@@ -2592,46 +2592,15 @@ function storeMeasurementEquipment($serialnumber){
}
//STORE RESULTS IN EQUIPMENT DATA
foreach ($equipment_watchlist as $equipment => $data){
//GET the equipmentid and historyid from watchlist
if (str_contains($equipment,'||')){
$identification = explode('||',$equipment);
//json_encode array
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
//Check if record exists
$sql = 'SELECT * FROM equipment_data WHERE equipmentid = ? and historyid =?';
$stmt = $pdo->prepare($sql);
$stmt->execute([$identification[2],$identification[3]]);
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!empty($equipment_data)){
//EXIST UPDATE
$sql = 'UPDATE equipment_data SET measurement = ? WHERE equipmentid = ? and historyid =?';
}
else {
//EXIST INSERT
$sql = 'INSERT INTO equipment_data (measurement, equipmentid, historyid) VALUES (?,?,?)';
}
//EXECUTE QUERY
$stmt = $pdo->prepare($sql);
$stmt->execute([$data, $identification[2],$identification[3]]);
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// calculatehealthindex of asset ++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
function assetHealthIndex($prof,$pem,$healthdata){
$healthindex = 100;
//Allowed check
if (isAllowed('equipment_data',$prof,$pem,'R') === 1 && !empty($healthdata)){
//GET last data
$last_data_measurement = end($healthdata);
foreach (json_decode($last_data_measurement->measurement,true) as $data_measure){
//Calculate healthindex
$healthindex = 100;
foreach ($data as $data_measure){
switch ($data_measure['deviation']) {
case 1:
$healthindex = $healthindex - $data_measure['deviation'];
@@ -2643,7 +2612,72 @@ function assetHealthIndex($prof,$pem,$healthdata){
$healthindex = $healthindex - ($data_measure['deviation']*3);
break;
}
}
}
//json_encode array
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
//Check if record exists
$sql = 'SELECT * FROM equipment_data WHERE equipmentid = ? and historyid =?';
$stmt = $pdo->prepare($sql);
$stmt->execute([$identification[2],$identification[3]]);
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!empty($equipment_data)){
//EXIST UPDATE
$sql = 'UPDATE equipment_data SET measurement = ?, healthindex = ? WHERE equipmentid = ? and historyid = ?';
}
else {
//EXIST INSERT
$sql = 'INSERT INTO equipment_data (measurement, , healthindex, equipmentid, historyid) VALUES (?,?,?,?)';
}
//EXECUTE QUERY
$stmt = $pdo->prepare($sql);
$stmt->execute([$data, $healthindex, $identification[2],$identification[3]]);
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// calculatehealthindex of asset ++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
function assetHealthIndex($prof,$pem,$healthdata,$type){
$healthindex = 100;
//Allowed check
if (isAllowed('equipment_data',$prof,$pem,'R') === 1 && !empty($healthdata)){
//GET last data based on type returned
//Type
// 0 = $healthdata per equipmentid
// 1 = $healthdata per rowID of equipment_data
switch ($type) {
case 0:
$last_data_measurement = end($healthdata);
break;
default:
$last_data_measurement = $healthdata;
break;
}
//Ensure $last_data_measurement is an array
$last_data_measurement = (is_object($last_data_measurement))? (array) $last_data_measurement : $last_data_measurement;
foreach (json_decode($last_data_measurement['measurement'],true) as $data_measure){
switch ($data_measure['deviation']) {
case 1:
$healthindex = $healthindex - $data_measure['deviation'];
break;
case 2:
$healthindex = $healthindex - ($data_measure['deviation']*2);
break;
case 3:
$healthindex = $healthindex - ($data_measure['deviation']*3);
break;
}
}
}
//Not allowed or no data return 100% health

View File

@@ -2,15 +2,6 @@ var port, textEncoder, writableStreamClosed, writer, historyIndex = -1;
const lineHistory = [];
maintenanceRun = 0;
// To read and clean device data
const VCP = []; //for VCP values
const VPP1 = []; //for VPP1 values
const VPP2 = []; //for VPP2 values
const VBAT = []; //for VBAT values
const PWM = []; //for PWM values
const STATE = []; //for STATE values
const xChart = []; //x-axis chart values
function progressBar(percentage, message, color){
var readbar = document.getElementById("readBar");
readBar.style.background = color;
@@ -239,26 +230,92 @@ const plug_data = document.getElementById("plug_data");
async function appendToTerminal(newStuff) {
serialResultsDiv.innerHTML += newStuff;
const keyword = '$STATUS;STATE';
const keyword2 = 'PWM';
// To read and clean device data
VCP = []; //for VCP values
VPP1 = []; //for VPP1 values
VPP2 = []; //for VPP2 values
VBAT = []; //for VBAT values
PWM = []; //for PWM values
STATE = []; //for STATE values
xChart = []; //x-axis chart values
// Input string with multiple status reports
const statusString = serialResultsDiv.innerHTML;
let lineCounter = 0;
// Split the input by newline to get each status report
let statusLines = statusString.split(/\r?\n/);
// Process each status line and populate the parameter arrays and counters
statusLines.forEach((line) => {
if (line.includes(keyword) && line.includes(keyword2) && /\d$/.test(line.trim())) {
const pairs = line.split(';'); // Split by ';'
// Loop through each pair and split by '='
pairs.forEach(pair => {
const [key, value] = pair.split('=');
if (key && value !== undefined && key !== "$STATUS") { // Skip '$STATUS'
// Push the value and counter to the corresponding parameter object
if (key === "STATE") {
let state
switch (value) {
case 'FULL_CONNECT':
state = 5;
break;
case 'REACTIVATE':
state = 3;
break;
case 'WAIT_CONNECT':
state = -5;
break;
case 'DISCONNECTED':
state = 0;
break;
default:
state = 0;
break;
}
STATE.push(state);
} else if (key === "VCP") {
VCP.push(value / 1000000);
} else if (key === "VPP1") {
VPP1.push(value / 1000000);
} else if (key === "VPP2") {
VPP2.push(value / 1000000);
} else if (key === "VBAT") {
VBAT.push(value / 1000000);
} else if (key === "PWM") {
PWM.push(value /10);
}
}
});
xChart.push(lineCounter);
lineCounter = lineCounter + 1;
}
});
//vcp_data.value +=newStuff
if (typeof plug_data !== "undefined"){
var plugdata = {"VCP":{VCP}, "VPP1":{VPP1},"VPP2":{VPP2},"VBAT":{VBAT}, "PWM":{PWM},"STATE":{STATE}, "xChart":{xChart}}
plug_data.value = JSON.stringify(plugdata);
}
serialOutput +=newStuff;
//serialOutput +=newStuff;
}
function renderChart(){
var test = serialResultsDiv.innerHTML.split(";");
test.forEach(getData);
const xValues = xChart;
new Chart("chart_VCP", {
type: "line",
data: {
labels: xValues,
labels: xChart,
datasets: [{
label: "VCP",
data: VCP,
@@ -300,54 +357,76 @@ function renderChart(){
}
//Get the RAW data and turn into object
function getData(item) {
function getData() {
const keyword = '$STATUS;STATE';
const keyword2 = 'PWM';
let item_array = item.split("=");
let xaxis = xChart.length + 1;
// To read and clean device data
const VCP = []; //for VCP values
const VPP1 = []; //for VPP1 values
const VPP2 = []; //for VPP2 values
const VBAT = []; //for VBAT values
const PWM = []; //for PWM values
const STATE = []; //for STATE values
const xChart = []; //x-axis chart values
if (item_array[0] == "VCP"){
let vcp = item_array[1] / 1000000;
VCP.push(vcp)
xChart.push(xaxis);
}
if (item_array[0] == "VPP1"){
let vpp1 = item_array[1] / 1000000;
VPP1.push(vpp1)
}
if (item_array[0] == "VPP2"){
let vpp2 = item_array[1] / 1000000;
VPP2.push(vpp2)
}
if (item_array[0] == "VBAT"){
let vbat = item_array[1] / 1000000;
VBAT.push(vbat)
}
if (item_array[0] == "STATE"){
let state
switch (item_array[1]) {
case 'FULL_CONNECT':
state = 5;
break;
case 'REACTIVATE':
state = 3;
break;
case 'WAIT_CONNECT':
state = -5;
break;
case 'DISCONNECTED':
state = 0;
break;
}
STATE.push(state)
}
if (item_array[0] == "PWM")
{
var check_return = item_array[1].match(/[^\r\n]+/g);
if (check_return.length == 2){
let pwm = check_return[0] / 10;
PWM.push(pwm)
}
// Input string with multiple status reports
const statusString = serialResultsDiv.innerHTML;
let lineCounter = 0;
// Split the input by newline to get each status report
let statusLines = statusString.split(/\r?\n/);
// Process each status line and populate the parameter arrays and counters
statusLines.forEach((line) => {
if (line.includes(keyword) && line.includes(keyword2) && /\d$/.test(line.trim())) {
const pairs = line.split(';'); // Split by ';'
// Loop through each pair and split by '='
pairs.forEach(pair => {
const [key, value] = pair.split('=');
if (key && value !== undefined && key !== "$STATUS") { // Skip '$STATUS'
// Push the value and counter to the corresponding parameter object
if (key === "STATE") {
let state
switch (value) {
case 'FULL_CONNECT':
state = 5;
break;
case 'REACTIVATE':
state = 3;
break;
case 'WAIT_CONNECT':
state = -5;
break;
case 'DISCONNECTED':
state = 0;
break;
default:
state = 0;
break;
}
STATE.push(state);
} else if (key === "VCP") {
VCP.push(value / 1000000);
} else if (key === "VPP1") {
VPP1.push(value / 1000000);
} else if (key === "VPP2") {
VPP2.push(value / 1000000);
} else if (key === "VBAT") {
VBAT.push(value / 1000000);
} else if (key === "PWM") {
PWM.push(value /10);
}
}
});
xChart.push(lineCounter);
lineCounter = lineCounter + 1;
}
});
}
async function closePort(){

View File

@@ -64,6 +64,7 @@ $view .= '<div class="content-block">
$view .='</select>
<input type="hidden" id="lineToSend" >
<input id="plug_data" type="hidden" value="">
</div>
<div id="connectdevice" style="display:flex;">
<div>

View File

@@ -59,8 +59,8 @@ $warrantydate = warrantyStatus($responses->warranty_date);
$service_date_due = serviceStatus($responses->service_date);
$firmware_status = availableFirmware($responses->sw_version, $responses->hw_version);
//Calculate Asset-Health
$total_score = assetHealthIndex($_SESSION['profile'],$_SESSION['permission'],$equipment_data);
//Calculate Healthindex based on last test
$total_score = assetHealthIndex($_SESSION['profile'],$_SESSION['permission'],$equipment_data,0);
//GetPartnerDetails
$partner_data = json_decode($responses->accounthierarchy);
@@ -300,27 +300,12 @@ $view .= '<div class="content-block">
</thead>
<tbody>';
foreach ($equipment_data as $data){
$asset_score = 100;
foreach (json_decode($data->measurement,true) as $data_measure){
switch ($data_measure['deviation']) {
case 1:
$asset_score = $asset_score - $data_measure['deviation'];
break;
case 2:
$asset_score = $asset_score - ($data_measure['deviation']*2);
break;
case 3:
$asset_score = $asset_score - ($data_measure['deviation']*3);
break;
}
}
$view .= '<tr>
<td>'.$data->rowID.'</td>
<td>'.(($view_history == 1)? '<a href="index.php?page=history&equipmentID='.$responses->equipmentID.'&historyid='.$data->historyid.'" class="btn2">'.$data->historyid.'</a>':$data->historyid).'</td>
<td><span class="status '.(($asset_score >= 85) ?'enabled' : (($asset_score <= 50)? 'disabled' : 'id2')).'">'.$asset_score.'</span></td>
<td><a href="index.php?page=" class="btn_link">'.$general_view.'</a></td>
<td><span class="status '.(($data->healthindex >= 85) ?'enabled' : (($data->healthindex <= 50)? 'disabled' : 'id2')).'">'.$data->healthindex.'</span></td>
<td><a href="index.php?page=equipment_data&equipmentID='.$responses->equipmentID.'&rowID='.$data->rowID.'" class="btn_link">'.$general_view.'</a></td>
</tr>';
}
$view .= '

114
equipment_data.php Normal file
View File

@@ -0,0 +1,114 @@
<?php
defined(page_security_key) or exit;
$page = 'equipment_data';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
// Default input product values
$equipment_data = [
'rowID' => '',
'equipmentid' => '',
'historyid' => '',
'created' => '',
'createdby' => $_SESSION['username'],
'measurement' => ''
];
$equipmentID = $_GET['equipmentID']??'';
if (isset($_GET['rowID'])) {
// ID param exists, edit an existing product
//CALL TO API
$api_url = '/v1/equipment_data/rowID='.$_GET['rowID'];
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
$equipment_data = json_decode(json_encode($responses[0]), true);
}
template_header('Equipment_data', 'equipment_data', 'manage');
$view ='
<form action="" method="post">
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.$view_asset_data_text.'</h2>
<a href="index.php?page=equipment&equipmentID='.$equipmentID.'" class="btn alt mar-right-2">'.$button_cancel.'</a>
';
$view .= '</div>';
$view .= '<div class="tabs">
<a href="#" class="active">'.$tab1.'</a>
<a href="#">'.$tab3.'</a>
</div>
';
$view .= '<div class="content-block tab-content active">
<div class="form responsive-width-100">
<label for="">'.$view_asset_data_rowID.'</label>
<p>'.$equipment_data['rowID'].'</p>
<label for="">'.$view_asset_data_historyid.'</label>
<p>'.$equipment_data['historyid'].'</p>
<label for="">'.$view_asset_data_ranking.'</label>
<p>'.$equipment_data['healthindex'].'</p>
';
if (isset($_GET['rowID']) && $_GET['rowID'] !='' && !empty($equipment_data['measurement'])){
$measurements = json_decode($equipment_data['measurement'],true);
$view .= '
<label for="">'.$view_asset_data.'</label>
<div class="table">
<table>
<thead>
<tr>
<td>Test</td>
<td>Measurement</td>
<td>Deviaton</td>
</tr>
</thead>
<tbody>
';
foreach ($measurements as $name => $measurement){
$view .='
<tr>
<td>'.$measurement['measurement'].'</td>
<td>'.$measurement['value'].'</td>
<td>'.$measurement['deviation'].'</td>
</tr>
';
}
$view .= '</tbody>
</table>
</div>';
}
$view .= '
</div>
</div>';
$view .= '<div class="content-block tab-content">
<div class="form responsive-width-100">
<label for="productcode">'.$general_created.'</label>
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$equipment_data['created'].'" readonly>
<label for="productcode">'.$general_createdby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$equipment_data['createdby'].'" readonly>
</div>
</div>';
$view .= '</form>';
//Output
echo $view;
template_footer()
?>

219
report_healthindex.php Normal file
View File

@@ -0,0 +1,219 @@
<?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';
//SET PAGE ORIGIN FOR NAVIGATION AND SECURITY
$prev_page = $_SESSION['prev_origin'] ?? '';
$page = $_SESSION['origin'] = 'report_healthindex';
//create backbutton to prev_origin
$back_btn_orgin = ($prev_page != '')? '<a href="'.$prev_page.'" class="btn alt mar-right-2">'.$button_back.'</a>':'';
/*Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}*/
//GET PARAMETERS && STORE in SESSION for FURTHER USE/NAVIGATION
$pagination_page = $_SESSION['p'] = isset($_GET['p']) ? $_GET['p'] : 1;
$status = $_SESSION['status'] = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
$sort = $_SESSION['sort'] = isset($_GET['sort']) ? '&sort='.$_GET['sort'] : '';
$search = $_SESSION['search'] = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
$software = $_SESSION['firmware'] = isset($_GET['firmware']) ? '&firmware='.$_GET['firmware'] : '';
$servicedate = $_SESSION['servicedate'] = isset($_GET['servicedate']) ? '&servicedate='.$_GET['servicedate'] : '';
$warrantydate = $_SESSION['warrantydate'] = isset($_GET['warrantydate']) ? '&warrantydate='.$_GET['warrantydate'] : '';
$partnerid = $_SESSION['partnerid'] = isset($_GET['partnerid']) ? '&partnerid='.$_GET['partnerid'] : '';
$productselected = $_SESSION['productcode'] = isset($_GET['productcode']) ? '&productcode='.$_GET['productcode'] : '';
$serialnumber_input = $_SESSION['serialnumber'] = isset($_GET['serialnumber']) ? '&serialnumber='.$_GET['serialnumber'] : '';
//GET PARAMETERS FOR FILTERS
$filter = urlGETdetailsFilter($_GET) ?? '';
// Determine the URL
$url = 'index.php?page=report_healthindex'.$status.$search.$software.$servicedate.$warrantydate.$partnerid.$sort.$productselected.$serialnumber_input;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/equipment_healthindex/'.$GET_VALUES;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses);}else{$responses = null;}
//Return QueryTotal from API
$api_url = '/v2/equipment_healthindex/'.$GET_VALUES.'&totals=';
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = $query_total;}else{$query_total = null;}
//Get Products related to assets
$api_url = '/v1/equipments/'.$GET_VALUES.'&products=';
$query_products = ioServer($api_url,'');
//Decode Payload
if (!empty($query_products)){$query_products = decode_payload($query_products);}else{$query_products = null;}
//BUILD LIST OF PRODUCTS
$product_list = '';
if ($query_products != null){
$product_list = '
<select name="productcode">
<option value="" disabled selected>'.$equipment_label4.'</option>';
foreach ($query_products as $product){
$product_list .= '<option value="'.$product->productcode.'">'.$product->productname.'</option>';
}
$product_list .= '</select>';
}
if (isset($_GET['download'])){
downloadToExcel('equipment_healthindex',$responses);
}
template_header('Healthindex', 'healthindex','view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-database"></i>
<div class="txt">
<h2>'.$view_asset_data_ranking.' ('.$query_total.')</h2>
<p></p>
</div>
</div>
'.$back_btn_orgin.'
</div>';
$view .= '
<div class="content-header responsive-flex-column pad-top-5">';
$view .= '
<form action="" method="get">
'.$filter.'
<div class="filters">
<a href="#"><i class="fa-solid fa-filter"></i>'.$general_filters.'</a>
<div class="list">
<select name="status">
<option value="" disabled selected>'.$equipment_label3.'</option>
<option value="0"'.($status==0?' selected':'').'>'.$status0_text.'</option>
<option value="1"'.($status==1?' selected':'').'>'.$status1_text.'</option>
<option value="2"'.($status==2?' selected':'').'>'.$status2_text.'</option>
<option value="3"'.($status==3?' selected':'').'>'.$status3_text.'</option>
<option value="4"'.($status==4?' selected':'').'>'.$status4_text.'</option>
<option value="5"'.($status==5?' selected':'').'>'.$status5_text.'</option>
</select>
'.$product_list.'
<button type="submit">'.$button_apply.'</button>
<a class="cancel_link" style="color: #FFFFFF;text-decoration: none;" href="index.php?page=report_healthindex">'.$general_filters_clear.'</a>
</div>
</div>
';
//SHOW DOWNLOAD TO EXCELL OPTION ONLY TO ADMIN USERS
if ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4){
$view .='<div class="filters">
<a href="index.php?page=report_healthindex&download="><i class="fa-solid fa-download"></i></a>
</div>';
}
$view .= '<div class="search">
<label for="search">
<input id="search" type="text" name="search" placeholder="'.$equiment_search.'" value="" class="responsive-width-100">
<i class="fas fa-search"></i>
</label>
</div>
</form>
</div>
';
$view .= '
<div class="content-block">
<div class="table">
<table class="sortable">
<thead>
<tr>
<th class="responsive-hidden">'.$view_asset_data_ranking.'</th>
<th class="responsive-hidden">'.$equipment_label1.'</th>
<th>'.$equipment_label2.'</th>
<th>'.$equipment_label3.'</th>
<th>'.$equipment_label4.'</th>
<th class="responsive-hidden"></th>
<th class="responsive-hidden">'.$general_soldto.'</th>
<th class="responsive-hidden">'.$general_shipto.'</th>
<th>'.$view_asset_actions.'</th>
</tr>
</thead>
<tbody>
';
if (empty($responses)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.$message_no_assets.'</td>
</tr>';
}
foreach ($responses as $response){
//Translate status INT to STR
$status_text = 'status'.$response->status.'_text';
//GetPartnerDetails
$partner_data = json_decode($response->accounthierarchy);
$soldto = getPartnerName($partner_data->soldto) ?? $not_specified;
$shipto = getPartnerName($partner_data->shipto) ?? $not_specified;
//Additional items
$picture = glob("./assets/images/products/".$response->productcode.".{jpg,jpeg,png,gif}", GLOB_BRACE);
$indicators = overviewIndicators($response->warranty_date,$response->service_date,$response->sw_version,$response->hw_version);
$view .= '<tr>
<td class="responsive-hidden"><span class="status '.(($response->healthindex >= 85) ?'enabled' : (($response->healthindex <= 50)? 'disabled' : 'id2')).'">'.$response->healthindex.'</span></td>
<td class="responsive-hidden">'.$indicators.'</td>
<td>'.$response->serialnumber.'</td>
<td><span class="status id'.$response->status.'">'.$$status_text.'</span></td>
<td>'.$response->productcode.'-'.$response->productname.'</td>';
$view .= ' <td class="responsive-hidden">';
if (!empty($picture)){
$view .='
<img style="border-radius: 4px;height: 40px;" src="'.$picture[0].'" alt="">
';
}
$view .= ' </td>
<td class="responsive-hidden">'.$soldto.'</td>
<td class="responsive-hidden">'.$shipto.'</td>
<td><a href="index.php?page=equipment&equipmentID='.$response->equipmentid.'" class="btn_link">'.$general_view .'</a></td>
</tr>
';
}
$view .= '
</tbody>
</table>
</div>
</div>
';
$view.='<div class="pagination">';
if ($pagination_page > 1) {
$page = $pagination_page-1;
$view .= '<a href="'.$url.'&p=1">'.$general_first.'</a>';
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_prev.'</a>';
}
$totals = ceil($query_total / $page_rows_equipment) == 0 ? 1 : ceil($query_total / $page_rows_equipment);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_equipment < $query_total){
$page = $pagination_page+1;
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_next.'</a>';
$view .= '<a href="'.$url.'&p='.$totals.'">'.$general_last.'</a>';
}
$view .= '</div>';
//OUTPUT
echo $view;
template_footer();
?>

View File

@@ -15,7 +15,7 @@ $main_menu = array ('dashboard','sales','build','cartests','marketing','equipmen
$equipments_sub = array('equipments','servicereports','histories','firmwaretool','equipments_mass_update');
$sales_sub = array('accounts','contracts');
$admin_sub = array('users','communications','partners');
$reporting_sub = array('report_build','report_usage');
$reporting_sub = array('report_build','report_healthindex','report_usage');
$settings_sub = array('config','language','log','maintenance');
//URLS
@@ -164,6 +164,12 @@ $urls = array(
"icon" => "fa-solid fa-magnifying-glass-chart",
"name" => "menu_report_build"
),
"report_healthindex" => array(
"url" => "report_healthindex",
"selected" => "report_healthindex",
"icon" => "fa-solid fa-magnifying-glass-chart",
"name" => "menu_report_healthindex"
),
"report_usage" => array(
"url" => "report_usage",
"selected" => "report_usage",

View File

@@ -23,6 +23,7 @@ $menu_build = 'Bau';
$menu_cartest = 'Fahrzeugdatenbank';
$menu_report_main = 'Berichte';
$menu_report_build = 'Bestand und Produktion';
$menu_report_healthindex= 'Healthindex';
$menu_report_usage = 'Systemnutzung';
$menu_maintenance = 'Maintenance';
@@ -153,7 +154,7 @@ $view_asset_actions = 'Aktionen';
$view_asset_data_text = 'Vermögenswerte - analyses';
$view_asset_data_rowID = 'Analyse nummer';
$view_asset_data_historyid = 'Reference test';
$view_asset_data_ranking = 'Vermögenswerte - health';
$view_asset_data_ranking = 'Healthindex';
$view_asset_data = 'Observations';
$not_specified = 'Nicht angegeben';

View File

@@ -23,6 +23,7 @@ $menu_build = 'Build';
$menu_cartest = 'Auto database';
$menu_report_main = 'Rapporten';
$menu_report_build = 'Voorraad en Productie';
$menu_report_healthindex= 'Healthindex';
$menu_report_usage = 'Systeemgebruik';
$menu_maintenance = 'Maintenance';
@@ -153,7 +154,7 @@ $view_asset_actions = 'Acties';
$view_asset_data_text = 'Activa - analyses';
$view_asset_data_rowID = 'Analyse nummer';
$view_asset_data_historyid = 'Gerelateerde test';
$view_asset_data_ranking = 'Activa - health';
$view_asset_data_ranking = 'Healthindex';
$view_asset_data = 'Observaties';
$not_specified = 'Niet gespecificeerd';

View File

@@ -23,6 +23,7 @@ $menu_build = 'Build';
$menu_cartest = 'Car database';
$menu_report_main = 'Reports';
$menu_report_build = 'Stock and Production';
$menu_report_healthindex= 'Healthindex';
$menu_report_usage = 'System usage';
$menu_maintenance = 'Maintenance';
@@ -151,7 +152,7 @@ $view_asset_actions = 'Actions';
$view_asset_data_text = 'Asset - Test analyses';
$view_asset_data_rowID = 'Analyses ID';
$view_asset_data_historyid = 'Related Test';
$view_asset_data_ranking = 'Asset - health';
$view_asset_data_ranking = 'Healthindex';
$view_asset_data = 'Observations';
$not_specified = 'Not specified';