CMXX - Asset Health

This commit is contained in:
“VeLiTi”
2024-10-01 12:27:40 +02:00
parent 00f7d4f6ba
commit 17df4c7bc1
5 changed files with 115 additions and 0 deletions

View File

@@ -2619,4 +2619,33 @@ function storeMeasurementEquipment($serialnumber){
$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){
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
return $healthindex;
}

View File

@@ -25,6 +25,7 @@ $update_allowed_edit = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['p
$delete_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'C');
$view_product = isAllowed('product' ,$_SESSION['profile'],$_SESSION['permission'],'R');
$view_history = isAllowed('history' ,$_SESSION['profile'],$_SESSION['permission'],'C');
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
@@ -42,6 +43,14 @@ $history = ioServer($api_url,'');
//Decode Payload
if (!empty($history)){$history = decode_payload($history);}else{$history = null;}
//CALL TO API FOR EQUIPMENT DATA
$api_url = '/v1/equipment_data/equipmentid='.$_GET['equipmentID'];
$equipment_data = ioServer($api_url,'');
//Decode Payload
if (!empty($equipment_data )){$equipment_data = decode_payload($equipment_data );}else{$equipment_data = null;}
//------------------------------
//Variables
//------------------------------
@@ -50,6 +59,9 @@ $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);
//GetPartnerDetails
$partner_data = json_decode($responses->accounthierarchy);
$salesid = getPartnerName($partner_data->salesid) ?? $not_specified;
@@ -132,6 +144,10 @@ $view .= ' <div class="content-block order-details">
<div class="order-detail">
<h3>'.$equipment_label3.'</h3>
<p><span class="status id'.$responses->status.'">'.$$status_text.'</span></p>
</div>
<div class="order-detail">
<h3>'.$view_asset_data_ranking.'</h3>
<p><span class="status '.(($total_score >= 85) ?'enabled' : (($total_score <= 50)? 'disabled' : 'id2')).'">'.$total_score.'</span></p>
</div>
<div class="order-detail">
<h3>'.$equipment_label2.'</h3>
@@ -265,6 +281,58 @@ $view .= '<div class="content-block">
</div>
';
}
//Show equipment_data when available and allowed
if (isAllowed('equipment_data',$_SESSION['profile'],$_SESSION['permission'],'R') === 1 && !empty($equipment_data)){
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.($view_asset_data_text ?? '').'
</div>
<div class="table">
<table class="sortable">
<thead>
<tr>
<th>'.$view_asset_data_rowID.'</th>
<th>'.$view_asset_data_historyid.'</th>
<th>'.$view_asset_data_ranking.'</th>
<th>'.$general_actions.'</th>
</tr>
</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>
</tr>';
}
$view .= '
</tbody>
</table>
</div>
';
$view .= '
</div>
';
}
if ($update_allowed === 1){
$view .= '<div class="content-block">
<div class="block-header">

View File

@@ -150,6 +150,12 @@ $view_asset_servicereport = 'Serviceberichte';
$view_asset_notes = 'Zusätzliche Notizen';
$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 = 'Observations';
$not_specified = 'Nicht angegeben';
$warranty_status = 'Garantiestatus';

View File

@@ -150,6 +150,12 @@ $view_asset_servicereport = 'Service rapporten';
$view_asset_notes = 'Extra notities';
$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 = 'Observaties';
$not_specified = 'Niet gespecificeerd';
$warranty_status = 'Garantie status';

View File

@@ -148,6 +148,12 @@ $view_asset_servicereport = 'Service reports';
$view_asset_notes = 'Additional notes';
$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 = 'Observations';
$not_specified = 'Not specified';
$warranty_status = 'Warranty status';