diff --git a/account.php b/account.php index 212a49c..5959e2e 100644 --- a/account.php +++ b/account.php @@ -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 = ' '.$button_partner_assigned_users.''; } +$healthindex =''; +if ($healthindex_allowed === 1){ + $healthindex = ''.$view_asset_data_ranking.''; +} + $view .= '
'.$view_asset_actions.' @@ -256,6 +262,7 @@ $view .= '
'.$button_partner_assigned_contracts.' '.$view_communication.' '.$view_users.' + '.$healthindex.'
'; //OUTPUT diff --git a/api/v1/get/equipment_data.php b/api/v1/get/equipment_data.php index c982a38..3777193 100644 --- a/api/v1/get/equipment_data.php +++ b/api/v1/get/equipment_data.php @@ -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); diff --git a/api/v2/get/equipment_data.php b/api/v2/get/equipment_data.php index 0ff3d88..67df24b 100644 --- a/api/v2/get/equipment_data.php +++ b/api/v2/get/equipment_data.php @@ -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 //------------------------------------------ diff --git a/api/v2/get/equipment_healthindex.php b/api/v2/get/equipment_healthindex.php new file mode 100644 index 0000000..e0601f7 --- /dev/null +++ b/api/v2/get/equipment_healthindex.php @@ -0,0 +1,194 @@ +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; + +?> \ No newline at end of file diff --git a/assets/functions.php b/assets/functions.php index 7b91872..de5d765 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -2591,47 +2591,16 @@ function storeMeasurementEquipment($serialnumber){ } } //STORE RESULTS IN EQUIPMENT DATA - foreach ($equipment_watchlist as $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); + + //Calculate healthindex + $healthindex = 100; - //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){ - + 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 diff --git a/assets/readdevice.js b/assets/readdevice.js index b648312..5fd11b8 100644 --- a/assets/readdevice.js +++ b/assets/readdevice.js @@ -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"){ + 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 + + // 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 ';' - 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) - } + // 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(){ diff --git a/buildtool.php b/buildtool.php index 8968e48..6308a77 100644 --- a/buildtool.php +++ b/buildtool.php @@ -64,6 +64,7 @@ $view .= '
$view .=' +
diff --git a/equipment.php b/equipment.php index 37bcfd4..44a8305 100644 --- a/equipment.php +++ b/equipment.php @@ -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 .= '
'; 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 .= ' '.$data->rowID.' '.(($view_history == 1)? ''.$data->historyid.'':$data->historyid).' - '.$asset_score.' - '.$general_view.' + '.$data->healthindex.' + '.$general_view.' '; } $view .= ' diff --git a/equipment_data.php b/equipment_data.php new file mode 100644 index 0000000..80e5577 --- /dev/null +++ b/equipment_data.php @@ -0,0 +1,114 @@ + '', + '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 =' +
+
+

'.$view_asset_data_text.'

+ '.$button_cancel.' +'; +$view .= '
'; + +$view .= ' + '; + +$view .= '
+
+ +

'.$equipment_data['rowID'].'

+ +

'.$equipment_data['historyid'].'

+ +

'.$equipment_data['healthindex'].'

+ '; + + if (isset($_GET['rowID']) && $_GET['rowID'] !='' && !empty($equipment_data['measurement'])){ + $measurements = json_decode($equipment_data['measurement'],true); + + $view .= ' + +
+ + + + + + + + + + '; + foreach ($measurements as $name => $measurement){ + + $view .=' + + + + + + '; + } + $view .= ' +
TestMeasurementDeviaton
'.$measurement['measurement'].''.$measurement['value'].''.$measurement['deviation'].'
+
'; + + } +$view .= ' +
+
'; + +$view .= '
+
+ + + + +
+
'; +$view .= '
'; + +//Output +echo $view; +template_footer() +?> \ No newline at end of file diff --git a/report_healthindex.php b/report_healthindex.php new file mode 100644 index 0000000..b4c9493 --- /dev/null +++ b/report_healthindex.php @@ -0,0 +1,219 @@ +'.$button_back.'':''; + +/*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 = ' + '; +} + +if (isset($_GET['download'])){ + downloadToExcel('equipment_healthindex',$responses); +} + +template_header('Healthindex', 'healthindex','view'); +$view = ' +
+
+ +
+

'.$view_asset_data_ranking.' ('.$query_total.')

+

+
+
+ '.$back_btn_orgin.' +
'; + + +$view .= ' +
'; + +$view .= ' +
+ '.$filter.' +
+ '.$general_filters.' +
+ + '.$product_list.' + + '.$general_filters_clear.' +
+
+ '; + +//SHOW DOWNLOAD TO EXCELL OPTION ONLY TO ADMIN USERS +if ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4){ + $view .='
+ +
'; +} +$view .= ' +
+
+'; + +$view .= ' +
+
+ + + + + + + + + + + + + + + + '; + + if (empty($responses)){ + + $view .= ' + + + '; + } + +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 .= ' + + + + + '; +$view .= ' + + + + + '; + } + $view .= ' + +
'.$view_asset_data_ranking.''.$equipment_label1.''.$equipment_label2.''.$equipment_label3.''.$equipment_label4.''.$general_soldto.''.$general_shipto.''.$view_asset_actions.'
'.$message_no_assets.'
'.$response->healthindex.''.$indicators.''.$response->serialnumber.''.$$status_text.''.$response->productcode.'-'.$response->productname.''; + if (!empty($picture)){ + $view .=' + + '; + } +$view .= ' '.$soldto.''.$shipto.''.$general_view .'
+
+
+'; + +$view.=''; +//OUTPUT +echo $view; + +template_footer(); +?> \ No newline at end of file diff --git a/settings/settingsmenu.php b/settings/settingsmenu.php index af56ca5..a62053f 100644 --- a/settings/settingsmenu.php +++ b/settings/settingsmenu.php @@ -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", diff --git a/settings/translations/translations_DE.php b/settings/translations/translations_DE.php index 5a4885a..3a24bf2 100644 --- a/settings/translations/translations_DE.php +++ b/settings/translations/translations_DE.php @@ -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'; diff --git a/settings/translations/translations_NL.php b/settings/translations/translations_NL.php index 6a8d6f5..a6a1669 100644 --- a/settings/translations/translations_NL.php +++ b/settings/translations/translations_NL.php @@ -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'; diff --git a/settings/translations/translations_US.php b/settings/translations/translations_US.php index 0103815..8f19e8a 100644 --- a/settings/translations/translations_US.php +++ b/settings/translations/translations_US.php @@ -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';