'.$button_back.'':'';
/*Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
*/
//Defaults
$contract = [
'type' => (isset($_GET['type'])? $_GET['type'] : ''),
'billing_plan' => (isset($_GET['billing_plan'])? $_GET['billing_plan'] : ''),
'year' => (isset($_GET['year'])? $_GET['year'] : ''),
'quarter' => (isset($_GET['quarter'])? $_GET['quarter'] : ''),
'month' => (isset($_GET['month'])? $_GET['month'] : '')
];
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$p = '&p='.$pagination_page;
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
//SET DEFAULT VALUES
$ye = (isset($_GET['year'])? $_GET['year'] : $curYear);
$mo = (isset($_GET['month'])? $_GET['month'] : '');
$qu = ((isset($_GET['month']) ? (int)ceil(date("n",strtotime($mo)) / 3): $curQuarter));
// Determine the URL
$url = 'index.php?page=report_contracts_billing'.$status.$search;
//ADD status
$cs = $_GET['status'] = 1;
//REMOVE $_GETs
unset($_GET['year']);
unset($_GET['month']);
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/contracts/'.$GET_VALUES;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
//Return QueryTotal from API
$api_url = '/v2/contracts/'.$GET_VALUES.'&totals=';
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = 0;}
template_header('contracts', 'contracts','view');
$view = '
'.$contract_h2.' ('.$query_total.')
'.$contract_p .'
'.$back_btn_orgin.'
';
$view .= '
';
$view .= '
| '.$contract_id.' |
'.$contract_status.' |
'.$contract_account.' |
'.$contract_type.' |
'.$contract_billinglabel.' |
'.$contract_start_date.' |
'.$contract_end_date.' |
'.$contract_reference.' |
BillingCount |
'.$contract_service.' |
'.$general_actions.' |
';
if (empty($responses)){
$view .= '
| '.$message_no_contract.' |
';
}
else {
foreach ($responses as $response){
$servicetools = json_decode($response['servicetool'] ?? '',true) ?? '';
$ignore_lists = json_decode($response['ignore_list'] ?? '',true) ?? '';
$date = date('Y-m-d', strtotime('+'.$response['duration'].' months', strtotime($response['start_date'])));
//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 = '/v2/application/type=ServiceReport&serialnumber='.substr($url_input,0,-1).$ignored_serialnumbers.'&between='.$response['start_date'].'||'.$date.'/contract_usage_servicereports';
$contract_usage_servicereports = ioServer($api_url,'');
//Decode Payload
if (!empty($contract_usage_servicereports)){$contract_usage_servicereports = json_decode($contract_usage_servicereports,true);}else{$contract_usage_servicereports = null;}
$usage_billing = usageBilling($contract_usage_servicereports);
//Initial billing_run value
$billing_run = 0;
switch ($response['billing_plan']) {
case 1:
# month
if (isset($usage_billing[$ye]['quarters'][$qu]['months'][$mo])){
if ($mo != ''){
$billing_run = $usage_billing[$ye]['quarters'][$qu]['months'][$mo];
}
}
break;
case 2:
# quarter
if (isset($usage_billing[$ye]['quarters'][$qu]['total'])){
$billing_run = $usage_billing[$ye]['quarters'][$qu]['total'];
}
break;
case 3:
# year
if (isset($usage_billing[$ye]['total'])){
$billing_run = $usage_billing[$ye]['total'];
}
break;
}
//Variable translation
$status = 'contract_status' . $response['status'];
$type = 'contract_type'.$response['type'];
$contract_billingplan_text = 'contract_billing'.$response['billing_plan'] ?? '';
//calculate enddate from duration
$date = date('Y-m-d', strtotime('+'.$response['duration'].' months', strtotime($response['start_date'])));
//GetPartnerDetails
$partner_data = json_decode($response['accounthierarchy'],true);
$view .= '
| '.$response['rowID'].' |
'.(($response['status'] == 1)? ''.$$status: (($response['status'] == 3) ? ''.$$status : ''.$$status)).' |
'.$partner_data['soldto'].' |
'.$$type.' |
'.$$contract_billingplan_text.' |
'.$response['start_date'].' |
'.$date.' |
'.$response['reference'].' |
'.$billing_run.' |
'.$response['service_count'].' |
'.$general_view .' |
';
}
}
$view .= '
';
$view.='';
//OUTPUT
echo $view;
template_footer();
?>