product_media; $media_responses = ioServer($api_url,''); //Decode Payload if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;} $media_responses = $media_responses[0] ?? ''; //CALL TO API FOR History $api_url = '/v2/equipments/equipmentID='.$responses->equipmentID.'&type=ServiceReport&history=1'; $history = ioServer($api_url,''); //Decode Payload if (!empty($history)){$history = json_decode($history);}else{$history = null;} //CALL TO API FOR EQUIPMENT DATA $api_url = '/v2/equipment_data/equipmentid='.$responses->equipmentID; $equipment_data = ioServer($api_url,''); //Decode Payload if (!empty($equipment_data )){$equipment_data = json_decode($equipment_data );}else{$equipment_data = null;} //CALL TO API FOR CUSTOMER AND WARRANTY DATA (type = customer,Warranty in history) $api_url = '/v2/history/equipmentID='.$responses->equipmentID.'&type=customer,Warranty'; $registration_data = ioServer($api_url,''); //Decode Payload if (!empty($registration_data)){$registration_data = json_decode($registration_data);}else{$registration_data = null;} // Separate customer and warranty data $latest_customer = null; $latest_warranty = null; if (is_array($registration_data) && count($registration_data) > 0) { foreach ($registration_data as $record) { if ($record->type === 'Customer' && $latest_customer === null) { $latest_customer = $record; } if ($record->type === 'Warranty' && $latest_warranty === null) { $latest_warranty = $record; } } } //GET PRODUCTS_SOFTWARE $api_url = '/v2/products_software_versions/hw_version='.$responses->hw_version.'&status=1'; $products_software = ioServer($api_url,''); //Decode Payload if (!empty($products_software)){$products_software = json_decode($products_software);}else{$products_software = null;} //------------------------------ //Variables //------------------------------ $status_text = 'status'.$responses->status.'_text'; $warrantydate = warrantyStatus($responses->warranty_date); $service_date_due = serviceStatus($responses->service_date); $firmware_status = availableFirmware($responses->sw_version, $responses->sw_version_latest); // Get upgrade version text if exists $sw_version_upgrade_text = ''; if (!empty($responses->sw_version_upgrade) && isset($products_software) && $products_software != '') { foreach ($products_software as $products_soft) { if ($products_soft->rowID == $responses->sw_version_upgrade) { $sw_version_upgrade_text = $products_soft->version; break; } } } //Calculate Healthindex based on last test $total_score = assetHealthIndex($_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],$equipment_data,0); //GetPartnerDetails $partner_data = json_decode($responses->accounthierarchy); $salesid = getPartnerName($partner_data->salesid) ?? $not_specified; $soldto = getPartnerName($partner_data->soldto) ?? '-'; $shipto = getPartnerName($partner_data->shipto) ?? '-'; $location = getPartnerName($partner_data->location) ?? '-'; if (isset($partner_data->section)){$section = getPartnerName($partner_data->section) ?? '-';} else {$section = '-';} //Check if productcode is 0 and status if ($responses->productcode == 0 && $responses->status == 0) {$location = $product_location_raw;} if ($responses->productcode == 0 && $responses->status == 1) {$location = $product_location_SFG;} if ($responses->productcode == 0 && $responses->status == 2) {$location = $product_location_FG;} if ($update_allowed === 1){ if (isset($_POST['description'])) { //GET ALL POST DATA $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/history', $data); if ($responses === 'NOK'){ } else { header('Location: index.php?page=equipment&equipmentID='.$_POST['equipmentid'].'&success_msg=2'); exit; } } } // Handle success messages if (isset($_GET['success_msg'])) { if ($_GET['success_msg'] == 1) { $success_msg = $message_eq_1; } if ($_GET['success_msg'] == 2) { $success_msg = $message_eq_2; } if ($_GET['success_msg'] == 3) { $success_msg = $message_eq_3; } } template_header('Asset', 'asset', 'view'); $view = '

'.$view_asset_h2.' - '.$responses->equipmentID.'

'; //------------------------------------ //CHECK IF USER IS ALSO CREATOR OF RECORD THEN OVERRIDE UPDATE_ALLOWED_EDIT //------------------------------------ $equipment_owner = (($responses->createdby == $_SESSION['authorization']['clientID'])? 1 : 0); //------------------------------------ // //------------------------------------ if ($update_allowed_edit === 1 || $equipment_owner === 1){ $view .= '✏️'; } $view .= '
'; if (isset($success_msg)){ $view .= '

'.$success_msg.'

'; } $view .= '
'; $view .= '
'.$view_asset_information.'

'.$equipment_label3.'

'.$$status_text.'

'.$view_asset_data_ranking.'

'.$total_score.'

'.$equipment_label2.'

'.$responses->serialnumber.'

'.$equipment_label10.'

'.$responses->equipmentID.'

'.$product_code.'

'.(($view_product == 1)? ''.$responses->productcode.' ':$responses->productcode).'

'.$product_name.'

'.(($view_product == 1)? ''.(${$responses->productname} ?? $responses->productname).' ':(${$responses->productname} ?? $responses->productname)).'

'; if (!empty($media_responses['full_path'])){ $view .='
'; } $view .='
'; $view .='
'.$view_asset_partners.'

'.$general_salesid.'

'.$salesid.'

'.$general_soldto.'

'.$soldto.'

'.$general_shipto.'

'.$shipto.'

'.$general_location.'

'.$location.'

'.$general_section.'

'.$section.'

'.(($latest_customer || $latest_warranty) ? ''.($register_title ?? 'Registration').' ' : '').'

'; $view .= '
'; $view .= '
'.$view_asset_details.'
'; //Check if license is attached if (!empty($responses->sw_version_license)) { $view .= ''; } //SHOW ONLY SW_UPGRADE WHEN SET if (isset($products_software) && $products_software !=''){ foreach ($products_software as $products_soft){ if ($products_soft->rowID == $responses->sw_version_upgrade){ $view .= ' '; } } } $view .= '
'.$warranty_status.' '.$warrantydate.'
'.$service_status.' '.$service_date_due.'
'.$software_status.' '.$firmware_status.((!empty($responses->sw_version_upgrade)) ? ' ' : '').'
'.$equipment_label5.' '.$responses->hw_version.'
'.$equipment_label6.' '.$responses->sw_version.'
'.($equipment_license ?? 'License').' '.$responses->sw_version_license; // Check if license is active $current_date = date('Y-m-d H:i:s'); $is_active = false; if (!empty($responses->license_status) && $responses->license_status == 1) { $starts_at = $responses->starts_at ?? null; $expires_at = $responses->expires_at ?? null; if ($starts_at && $expires_at) { if ($current_date >= $starts_at && $current_date <= $expires_at) { $is_active = true; } } elseif ($starts_at && !$expires_at) { if ($current_date >= $starts_at) { $is_active = true; } } elseif (!$starts_at && $expires_at) { if ($current_date <= $expires_at) { $is_active = true; } } elseif (!$starts_at && !$expires_at) { $is_active = true; } } if ($is_active) { $view .= ' / '.$enabled ?? 'Active'; } else { $view .= ' / '.$disabled ?? 'Inactive'; } $view .= '
'.($equipment_sw_version_upgrade ?? 'sw_version_upgrade').' '.$products_soft->version.'
'; //SHOW LOCATION BASED ON GEOLOCATION if (!empty($responses->geolocation) || $responses->geolocation != ''){ $geolocation = json_decode($responses->geolocation,true); if ($geolocation[1] != ''){ $view .= '
'; } } //Get all related service events if (isAllowed('servicereports',$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'R') === 1){ $service_events = serviceEvents($history,$page); $view .= '
'.$view_asset_servicereport.'
'.$service_events.'
'; } //Show equipment_data when available and allowed if (isAllowed('equipment_data',$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'R') === 1 && !empty($equipment_data)){ $view .= '
'.($view_asset_data_text ?? '').'
'; foreach ($equipment_data as $data){ $view .= ''; } $view .= '
'.$view_asset_data_rowID.' '.$view_asset_data_historyid.' '.$view_asset_data_ranking.'
'.$data->rowID.' '.(($view_history == 1)? ''.$data->historyid.' ':$data->historyid).' '.$data->healthindex.'
'; $view .= '
'; } if ($update_allowed === 1){ $view .= '
'.$view_asset_notes.'
'; } $view .= '
'.$tab3.'
'.$general_created.' '.getRelativeTime($responses->created).'
'.$general_updated.' '.getRelativeTime($responses->updated).'
'; //DISPLAY RELATED COMMUNICATION RECORDS $soldto_id = explode("-",$partner_data->soldto) ?? ''; $shipto_id = explode("-",$partner_data->shipto) ?? ''; $partner_users_id = ($shipto_id[0] != '')? $shipto_id[0] : (($soldto_id[0] != '')? $soldto_id[0] : 1); $view_communication = ''; if ($partner_users_id != 1 && ($_SESSION['authorization']['permission'] == 3 || $_SESSION['authorization']['permission'] == 4)){ $view_communication = ' '.$button_partner_assigned_communication.''; } //DISPLAY RELATED USERS $view_users =''; if ($partner_users_id != 1 && ($_SESSION['authorization']['permission'] == 3 || $_SESSION['authorization']['permission'] == 4)){ $view_users = ' '.$button_partner_assigned_users.''; } $view .= '
'.$view_asset_actions.'
'.$view_communication.' '.$view_users.' '; if ($update_allowed === 1){ $view .=''.$button_firmware.''; } $view .='
'; //OUTPUT echo $view; // Add customer data modal if data exists if ($latest_customer || $latest_warranty) { $customer_payload = $latest_customer ? json_decode($latest_customer->description, true) : null; $warranty_payload = $latest_warranty ? json_decode($latest_warranty->description, true) : null; echo '

'.($register_title ?? 'Registration').'

'; if ($warranty_payload) { // Check if warranty is still active $warranty_end_date = $warranty_payload['end_date'] ?? null; $warranty_display = '-'; $warranty_payload['createdby'] = $latest_warranty->createdby ?? '-'; if ($warranty_end_date) { $end_date_obj = new DateTime(substr($warranty_end_date, 0, 10)); // Extract date part (YYYY-MM-DD) $current_date_obj = new DateTime(date('Y-m-d')); if ($end_date_obj >= $current_date_obj) { // Warranty is still active $warranty_display = ($warranty_recent ?? 'Active') . ' - ' . htmlspecialchars($warranty_end_date); } else { // Warranty has expired $warranty_display = ($warranty_outdated_text ?? 'Expired'); } } echo '

'.$warranty_display.'

'.htmlspecialchars($warranty_payload['organization'] ?? '-').'

'.htmlspecialchars($warranty_payload['createdby'] ?? '-').'

'.htmlspecialchars($warranty_payload['phone'] ?? '-').'

'.htmlspecialchars($warranty_payload['city'] ?? '-').'

'.htmlspecialchars($warranty_payload['country'] ?? '-').'

'.getRelativeTime($latest_warranty->created).'

'; } else { echo '

No warranty information available

'; } echo '
'; } // Modal for log echo ' '; template_footer() ?>