←':''; //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; //PAGE Security $page_manage = 'contract_manage'; $update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U'); $update_allowed_edit = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'U'); $delete_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'D'); $create_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'C'); $view_equipment = isAllowed('equipment' ,$_SESSION['profile'],$_SESSION['permission'],'R'); //GET Details from URL $GET_VALUES = urlGETdetails($_GET) ?? ''; $contract_ID = $_GET['rowID'] ?? ''; //CALL TO API FOR General information $api_url = '/v1/contracts/rowID='.$contract_ID;; $responses = ioServer($api_url,''); //Decode Payload if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} $responses = $responses[0]; //------------------------------ //Variables //------------------------------ $contract_status_text = 'contract_status'.$responses->status ?? ''; $contract_type_text = 'contract_type'.$responses->type ?? ''; $contract_billingplan_text = 'contract_billing'.$responses->billing_plan ?? ''; $servicetools = json_decode($responses->servicetool,true) ?? ''; $assigned_users = json_decode($responses->assigned_users,true) ?? ''; $ignore_lists = json_decode($responses->ignore_list,true) ?? ''; //Partnerdata $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) ?? '-'; // Handle success messages if (isset($_GET['success_msg'])) { if ($_GET['success_msg'] == 1) { $success_msg = $message_contract_1; } if ($_GET['success_msg'] == 2) { $success_msg = $message_contract_2; } if ($_GET['success_msg'] == 3) { $success_msg = $message_contract_3; } } template_header('Contract', 'contract', 'view'); $view = '

'.$responses->rowID.'

'; //------------------------------------ // //------------------------------------ if ($update_allowed_edit === 1){ $view .= '✏️'; } $view .= '
'; if (isset($success_msg)){ $view .= '

'.$success_msg.'

'; } $view .= '
'; $view .= '
'.($product_data ?? '').'

'.$contract_id.'

'.$responses->rowID.'

'.$contract_status.'

'.(($responses->status == 1)? '': (($responses->status == 3) ? '': '')).''.$$contract_status_text.'

'.$contract_type.'

'.$$contract_type_text.'

'.$contract_billinglabel.'

'.($$contract_billingplan_text ?? '').'

'.$contract_start_date.'

'.$responses->start_date.'

'.$contract_duration.'

'.$responses->duration.'

'; if ($responses->duration !='' && $responses->start_date !=''){ $date = date('Y-m-d', strtotime('+'.$responses->duration.' months', strtotime($responses->start_date))); $view .= '

'.$contract_end_date.'

'.$date.'

'.$contract_service.'

'.$responses->service_count.'

'; } $view .='
'; $view .='
'.$view_asset_partners.'

'.$general_salesid.'

'.$salesid.'

'.$general_soldto.'

'.$soldto.'

'.$general_shipto.'

'.$shipto.'

'.$general_location.'

'.$location.'

'.$contract_reference.'

'.$responses->reference.'

'; $view .= '
'; //get all assigned serialnumbers $url_input = ''; foreach($servicetools as $service_tool){ $url_input .= $service_tool.','; } //get ignore list $ignored_serialnumbers = ''; if (!empty($ignore_lists)){ foreach($ignore_lists as $list){ $ignored_serialnumbers .= $list.','; } $ignored_serialnumbers = '&ignore='.substr($ignored_serialnumbers,0,-1); } //Return report_usage_servicereports $api_url = '/v1/application/type=ServiceReport&serialnumber='.substr($url_input,0,-1).$ignored_serialnumbers.'&between='.$responses->start_date.'||'.$date.'/contract_usage_servicereports'; $contract_usage_servicereports = ioServer($api_url,''); //Decode Payload if (!empty($contract_usage_servicereports)){$contract_usage_servicereports = decode_payload($contract_usage_servicereports);}else{$contract_usage_servicereports = null;} $contract_usage_servicereports = json_decode(json_encode($contract_usage_servicereports),true); $service_events = usageView($contract_usage_servicereports); $view .= '
'.$menu_service_reports.'
'.$service_events.'
'; $usage_billing = usageBilling($contract_usage_servicereports); $view .= '
'.$contract_billinglabel.'
'; foreach($usage_billing as $key => $value){ $view .= ' '; foreach ($value['quarters'] as $key => $value){ $view .= ' billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'> '; foreach($value['months'] as $key => $value){ //CONVERT KEY TO MONTH NAME $monthObj = DateTime::createFromFormat('!m', $key); $key = $monthObj->format('F'); $view .= ' billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'> '; } } } $view .= '
'.$general_year.' '.$general_total.' billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'>'.$general_quarter.' billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'>'.$general_total.' billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$general_month.' billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$general_total.'
'.$key.' '.$value['total'].'
'.$key.' '.$value['total'].' billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'> billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>
billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'> billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'> billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$key.' billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$value.'
'; $view .= '
'.$contract_assigned_users.'
'; //Check for assigned users foreach ($assigned_users as $user){ $view .= ''; } $view .= '
'.$user.'
'; $view .= '
'. $contract_servicetool.'
'; //Check for assigned tools foreach ($servicetools as $tools){ $view .= ''; } $view .= '
'.(($view_equipment == 1)? ''.$tools.' ':$tools).'
'; $view .= '
'. $contract_ignore_serial.'
'; //Check for ignore list foreach ($ignore_lists as $list){ $view .= ''; } $view .= '
'.(($view_equipment == 1)? ''.$list.'':$list).'
'; $view .= '
'.$tab3.'
'.$general_created.' '.getRelativeTime($responses->created).'
'.$general_createdby.' '.$responses->createdby.'
'.$general_updated.' '.getRelativeTime($responses->updated).'
'.$general_updatedby.' '.$responses->updatedby.'
'; $view .=''; //OUTPUT echo $view; template_footer() ?>