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 .= '
'.$$status_text.'
+'.$total_score.'
| '.$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.' | +