diff --git a/assets/functions.php b/assets/functions.php index d1e9c25..7b91872 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -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; } \ No newline at end of file diff --git a/equipment.php b/equipment.php index eeb40e1..37bcfd4 100644 --- a/equipment.php +++ b/equipment.php @@ -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 .= '

'.$equipment_label3.'

'.$$status_text.'

+
+
+

'.$view_asset_data_ranking.'

+

'.$total_score.'

'.$equipment_label2.'

@@ -265,6 +281,58 @@ $view .= '
'; } + +//Show equipment_data when available and allowed +if (isAllowed('equipment_data',$_SESSION['profile'],$_SESSION['permission'],'R') === 1 && !empty($equipment_data)){ +$view .= '
+
+ '.($view_asset_data_text ?? '').' +
+
+ + + + + + + + + + '; + 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 .= ' + + + + + '; + } + $view .= ' + +
'.$view_asset_data_rowID.''.$view_asset_data_historyid.''.$view_asset_data_ranking.''.$general_actions.'
'.$data->rowID.''.(($view_history == 1)? ''.$data->historyid.'':$data->historyid).''.$asset_score.''.$general_view.'
+
+ '; +$view .= ' +
+'; +} + if ($update_allowed === 1){ $view .= '
diff --git a/settings/translations/translations_DE.php b/settings/translations/translations_DE.php index d7b6297..5a4885a 100644 --- a/settings/translations/translations_DE.php +++ b/settings/translations/translations_DE.php @@ -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'; diff --git a/settings/translations/translations_NL.php b/settings/translations/translations_NL.php index 7478880..6a8d6f5 100644 --- a/settings/translations/translations_NL.php +++ b/settings/translations/translations_NL.php @@ -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'; diff --git a/settings/translations/translations_US.php b/settings/translations/translations_US.php index 9bbf915..0103815 100644 --- a/settings/translations/translations_US.php +++ b/settings/translations/translations_US.php @@ -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';