CMXX - Billing API
This commit is contained in:
@@ -1,121 +1,173 @@
|
|||||||
<?php
|
<?php
|
||||||
defined($security_key) or exit;
|
defined($security_key) or exit;
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
ini_set('display_startup_errors', '1');
|
||||||
|
error_reporting(E_ALL);
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
// contracts_billing
|
// contracts_billing
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
||||||
//GET PARAMETERS
|
//NEW ARRAY
|
||||||
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
|
$criterias = [];
|
||||||
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
|
//ADD DEFAULT VALUES TO STRING
|
||||||
|
$GET_VALUES = 'status=1&p=all'; //STATUS = ACTIVE
|
||||||
|
|
||||||
//SET DEFAULT VALUES
|
//Check for $_GET variables and build up GET VALUES
|
||||||
$ye = ((isset($_GET['year']) && $_GET['year'] !='' )? $_GET['year'] : $curYear);
|
if(isset($get_content) && $get_content!=''){
|
||||||
$mo = ((isset($_GET['month']) && $_GET['month'] !='')? $_GET['month'] : $curMonth_name);
|
//GET VARIABLES FROM URL
|
||||||
$qu = ((isset($_GET['month']) ? (int)ceil(date("n",strtotime($mo)) / 3): $curQuarter));
|
$requests = explode("&", $get_content);
|
||||||
|
//Check for keys and values
|
||||||
//ADD status
|
foreach ($requests as $y){
|
||||||
$cs = $_GET['status'] = 1;
|
$v = explode("=", $y);
|
||||||
//REMOVE $_GETs
|
//INCLUDE VARIABLES IN ARRAY
|
||||||
unset($_GET['year']);
|
$criterias[$v[0]] = $v[1];
|
||||||
unset($_GET['month']);
|
if ($v[0] == 'p' || $v[0] == 'page' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history' || $v[0] =='success_msg' || $v[0] =='year' || $v[0] =='month'){
|
||||||
//GET Details from URL
|
//do nothing
|
||||||
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
}
|
||||||
|
else{
|
||||||
//CALL TO API
|
//exclude empty values
|
||||||
$api_url = '/v2/contracts/'.$GET_VALUES;
|
if ($v[1] != '' || !empty($v[1]))
|
||||||
$responses = ioAPIv2($api_url,'',$token);
|
$GET_VALUES .= '&'.$v[0].'='.$v[1];
|
||||||
//Decode Payload
|
}
|
||||||
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
|
|
||||||
|
|
||||||
$output[] = '';
|
|
||||||
|
|
||||||
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 = ioAPIv2($api_url,'',$token);
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//SHOW USAGE PERCENTAGE
|
|
||||||
$usage_service_count = ($response['service_count'] != 0 || $response['service_count'] !='') ? $response['service_count']:1;
|
|
||||||
$usage_percentage = ($billing_run != 0) ? round((($billing_run/$usage_service_count)*100),2) : 0;
|
|
||||||
$usage_per_status = ($usage_percentage < 100) ? 'enabled' : 'disabled';
|
|
||||||
|
|
||||||
$output[] = array(
|
|
||||||
"#" => $response['rowID'] ,
|
|
||||||
$contract_status => $$status,
|
|
||||||
$contract_account => $partner_data['soldto'],
|
|
||||||
$contract_type => $$type,
|
|
||||||
$contract_billinglabel =>$$contract_billingplan_text,
|
|
||||||
$contract_start_date =>$response['start_date'],
|
|
||||||
$contract_end_date => $date,
|
|
||||||
$contract_reference =>$response['reference'],
|
|
||||||
$contract_billing_count =>$billing_run,
|
|
||||||
$contract_service_2 =>$response['service_count'],
|
|
||||||
$contract_overrun => $usage_percentage
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------
|
//SET DEFAULT VALUES
|
||||||
//JSON_ENCODE
|
$ye = ((isset($criterias['year']) && $criterias['year'] !='' )? $criterias['year'] : $curYear);
|
||||||
//------------------------------------------
|
$mo = ((isset($criterias['month']) && $criterias['month'] !='')? $criterias['month'] : $curMonth);
|
||||||
$messages = json_encode($output, JSON_UNESCAPED_UNICODE);
|
$qu = ((isset($criterias['month']) ? (int)ceil($mo / 3): $curQuarter));
|
||||||
|
$da = $ye.'-'.$mo.'-01';
|
||||||
|
|
||||||
|
//CALL TO API TO GET ALL ACTIVE CONTRACTS
|
||||||
|
$api_url = '/v2/contracts/'.$GET_VALUES;
|
||||||
|
$responses = ioAPIv2($api_url,'',$user_data['userkey']);
|
||||||
|
|
||||||
|
//Decode Payload
|
||||||
|
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
|
||||||
|
$output = [];
|
||||||
|
|
||||||
|
foreach ($responses as $response){
|
||||||
|
//CALCULATE CONTRACT END DATE
|
||||||
|
$date = date('Y-m-d', strtotime('+'.$response['duration'].' months', strtotime($response['start_date'])));
|
||||||
|
|
||||||
|
//CHECK IF SEARCH CRITERIA YEAR, QUARTER, MONTH FALL IN CONTRACT PERIOD
|
||||||
|
$inrange = dateInRange($response['start_date'], $date, $da) ?? 0;
|
||||||
|
|
||||||
|
if ($inrange == 1){
|
||||||
|
$servicetools = json_decode($response['servicetool'] ?? '',true) ?? '';
|
||||||
|
$ignore_lists = json_decode($response['ignore_list'] ?? '',true) ?? '';
|
||||||
|
|
||||||
|
//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 = ioAPIv2($api_url,'',$user_data['userkey']);
|
||||||
|
|
||||||
|
//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;
|
||||||
|
$period = 'n/a';
|
||||||
|
|
||||||
|
switch ($response['billing_plan']) {
|
||||||
|
case 1:
|
||||||
|
# month
|
||||||
|
//CONVERT KEY TO MONTH NAME
|
||||||
|
$monthObj = DateTime::createFromFormat('!m', $mo);
|
||||||
|
$period = $monthObj->format('F');
|
||||||
|
|
||||||
|
if (isset($usage_billing[$ye]['quarters'][$qu]['months'][$mo])){
|
||||||
|
$billing_run = $usage_billing[$ye]['quarters'][$qu]['months'][$mo];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
# quarter
|
||||||
|
$period = 'Q'.$qu;
|
||||||
|
|
||||||
|
if (isset($usage_billing[$ye]['quarters'][$qu]['total'])){
|
||||||
|
$billing_run = $usage_billing[$ye]['quarters'][$qu]['total'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
# year
|
||||||
|
$period = $ye;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
//SHOW USAGE PERCENTAGE
|
||||||
|
$usage_service_count = ($response['service_count'] > 0) ? $response['service_count']:1;
|
||||||
|
$usage_percentage = ($billing_run != 0) ? round((($billing_run/$usage_service_count)*100),2) : 0;
|
||||||
|
$usage_per_status = ($usage_percentage < 100) ? 'enabled' : 'disabled';
|
||||||
|
|
||||||
|
$output[] = array(
|
||||||
|
"#" => $response['rowID'] ,
|
||||||
|
$contract_status => $$status,
|
||||||
|
$contract_account => $partner_data['soldto'],
|
||||||
|
$contract_type => $$type,
|
||||||
|
$contract_billinglabel =>$$contract_billingplan_text,
|
||||||
|
$contract_start_date =>$response['start_date'],
|
||||||
|
$contract_end_date => $date,
|
||||||
|
$contract_reference =>$response['reference'],
|
||||||
|
$contract_billing_count =>$billing_run,
|
||||||
|
$contract_service_2 =>$response['service_count'],
|
||||||
|
$contract_overrun => $usage_percentage,
|
||||||
|
"Snapshot_date" => $da,
|
||||||
|
"Period" => $period
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = count( $output );
|
||||||
|
|
||||||
|
//SEND TOTALS WHEN REQUESTED
|
||||||
|
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||||
|
|
||||||
|
$messages = json_encode($total, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
//Paging
|
||||||
|
//------------------------------------------
|
||||||
|
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||||
|
$offset = ($current_page - 1) * $page_rows_contracts;
|
||||||
|
$output = array_slice( $output, $offset, $page_rows_contracts );
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
//JSON_ENCODE
|
||||||
|
//------------------------------------------
|
||||||
|
$messages = json_encode($output, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
|
||||||
//Send results
|
//Send results
|
||||||
echo $messages;
|
echo $messages;
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ elseif (isset($criterias['list']) && $criterias['list'] =='') {
|
|||||||
//SQL for Paging
|
//SQL for Paging
|
||||||
$sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.'';
|
$sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.'';
|
||||||
}
|
}
|
||||||
|
elseif (isset($criterias['p']) && $criterias['p'] =='all') {
|
||||||
|
//SQL for Paging
|
||||||
|
$sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.'';
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
//SQL for Paging
|
//SQL for Paging
|
||||||
$sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.' LIMIT :page,:num_products';
|
$sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.' LIMIT :page,:num_products';
|
||||||
@@ -115,7 +119,7 @@ if(isset($criterias['totals']) && $criterias['totals']==''){
|
|||||||
$messages = $stmt->fetch();
|
$messages = $stmt->fetch();
|
||||||
$messages = $messages[0];
|
$messages = $messages[0];
|
||||||
}
|
}
|
||||||
elseif(isset($criterias['list']) && $criterias['list']==''){
|
elseif((isset($criterias['list']) && $criterias['list']=='') || (isset($criterias['p']) && $criterias['p'] =='all')){
|
||||||
//Excute Query
|
//Excute Query
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
//Get results
|
//Get results
|
||||||
|
|||||||
@@ -2421,8 +2421,9 @@ function usageBilling($messages){
|
|||||||
foreach ($messages as $entry) {
|
foreach ($messages as $entry) {
|
||||||
$year = $entry['year'];
|
$year = $entry['year'];
|
||||||
$quarter = $entry['quarter'];
|
$quarter = $entry['quarter'];
|
||||||
$dateObj = DateTime::createFromFormat('!m', $entry['month']);
|
//$dateObj = DateTime::createFromFormat('!m', $entry['month']);
|
||||||
$month = $dateObj->format('F');
|
//$month = $dateObj->format('F');
|
||||||
|
$month = $entry['month'];
|
||||||
$count = $entry['count'];
|
$count = $entry['count'];
|
||||||
|
|
||||||
// Initialize arrays if not already set for year, quarter, and month
|
// Initialize arrays if not already set for year, quarter, and month
|
||||||
@@ -2779,7 +2780,7 @@ function blockContracts($token){
|
|||||||
|
|
||||||
//GET USAGE BILLING INFORMATION
|
//GET USAGE BILLING INFORMATION
|
||||||
$usage_billing = usageBilling($contract_usage_servicereports);
|
$usage_billing = usageBilling($contract_usage_servicereports);
|
||||||
$billing_cylce_usage = (($billing_plan == 1 && isset($usage_billing[$curYear]['quarters'][$curQuarter]['months'][$curMonth_name])) ? $usage_billing[$curYear]['quarters'][$curQuarter]['months'][$curMonth_name] : (($billing_plan == 2 && isset($usage_billing[$curYear]['quarters'][$curQuarter])) ? $usage_billing[$curYear]['quarters'][$curQuarter]: (($billing_plan == 3 && isset($usage_billing[$curYear])) ? $usage_billing[$curYear]: 0 )));
|
$billing_cylce_usage = (($billing_plan == 1 && isset($usage_billing[$curYear]['quarters'][$curQuarter]['months'][$curMonth])) ? $usage_billing[$curYear]['quarters'][$curQuarter]['months'][$curMonth] : (($billing_plan == 2 && isset($usage_billing[$curYear]['quarters'][$curQuarter])) ? $usage_billing[$curYear]['quarters'][$curQuarter]: (($billing_plan == 3 && isset($usage_billing[$curYear])) ? $usage_billing[$curYear]: 0 )));
|
||||||
|
|
||||||
//CHECK FOR OVERRUN
|
//CHECK FOR OVERRUN
|
||||||
if ($billing_cylce_usage >= $billing_max){
|
if ($billing_cylce_usage >= $billing_max){
|
||||||
@@ -2790,3 +2791,17 @@ function blockContracts($token){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
// check date is in range ++++++++++++++
|
||||||
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
function dateInRange($start_date, $end_date, $date_check)
|
||||||
|
{
|
||||||
|
// Convert to timestamp
|
||||||
|
$start_ts = strtotime($start_date);
|
||||||
|
$end_ts = strtotime($end_date);
|
||||||
|
$check_ts = strtotime($date_check);
|
||||||
|
|
||||||
|
// Check that user date is between start & end
|
||||||
|
return (($check_ts >= $start_ts) && ($check_ts <= $end_ts));
|
||||||
|
}
|
||||||
@@ -257,6 +257,10 @@ $view .= '<div class="content-block">
|
|||||||
';
|
';
|
||||||
|
|
||||||
foreach($value['months'] as $key => $value){
|
foreach($value['months'] as $key => $value){
|
||||||
|
//CONVERT KEY TO MONTH NAME
|
||||||
|
$monthObj = DateTime::createFromFormat('!m', $key);
|
||||||
|
$key = $monthObj->format('F');
|
||||||
|
|
||||||
$view .= '
|
$view .= '
|
||||||
<tr '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>
|
<tr '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|||||||
@@ -23,51 +23,38 @@ if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Defaults
|
//Defaults
|
||||||
$contract = [
|
$contract = [
|
||||||
'type' => (isset($_GET['type'])? $_GET['type'] : ''),
|
'type' => (isset($_GET['type'])? $_GET['type'] : ''),
|
||||||
'billing_plan' => (isset($_GET['billing_plan'])? $_GET['billing_plan'] : ''),
|
'billing_plan' => (isset($_GET['billing_plan'])? $_GET['billing_plan'] : ''),
|
||||||
'year' => (isset($_GET['year'])? $_GET['year'] : ''),
|
'year' => (isset($_GET['year'])? $_GET['year'] : ''),
|
||||||
'quarter' => (isset($_GET['quarter'])? $_GET['quarter'] : ''),
|
|
||||||
'month' => (isset($_GET['month'])? $_GET['month'] : '')
|
'month' => (isset($_GET['month'])? $_GET['month'] : '')
|
||||||
];
|
];
|
||||||
|
|
||||||
//GET PARAMETERS
|
//GET PARAMETERS
|
||||||
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
|
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
|
||||||
$p = '&p='.$pagination_page;
|
|
||||||
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
|
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
|
||||||
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
|
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
|
||||||
|
|
||||||
//SET DEFAULT VALUES
|
|
||||||
$ye = ((isset($_GET['year']) && $_GET['year'] !='' )? $_GET['year'] : $curYear);
|
|
||||||
$mo = ((isset($_GET['month']) && $_GET['month'] !='')? $_GET['month'] : $curMonth_name);
|
|
||||||
$qu = ((isset($_GET['month']) ? (int)ceil(date("n",strtotime($mo)) / 3): $curQuarter));
|
|
||||||
|
|
||||||
// Determine the URL
|
// Determine the URL
|
||||||
$url = 'index.php?page=report_contracts_billing'.$status.$search;
|
$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 Details from URL
|
||||||
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
||||||
|
|
||||||
//CALL TO API
|
//CALL TO API
|
||||||
$api_url = '/v2/contracts/'.$GET_VALUES;
|
$api_url = '/v2/billing/'.$GET_VALUES;
|
||||||
$responses = ioServer($api_url,'');
|
$responses = ioServer($api_url,'');
|
||||||
//Decode Payload
|
//Decode Payload
|
||||||
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
|
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
|
||||||
|
|
||||||
//Return QueryTotal from API
|
//Return QueryTotal from API
|
||||||
$api_url = '/v2/contracts/'.$GET_VALUES.'&totals=';
|
$api_url = '/v2/billing/'.$GET_VALUES.'&totals=';
|
||||||
$query_total = ioServer($api_url,'');
|
$query_total = ioServer($api_url,'');
|
||||||
//Decode Payload
|
//Decode Payload
|
||||||
if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = 0;}
|
if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = 0;}
|
||||||
|
|
||||||
|
template_header('reports', 'report_contracts_billing','view');
|
||||||
template_header('contracts', 'contracts','view');
|
|
||||||
$view = '
|
$view = '
|
||||||
<div class="content-title">
|
<div class="content-title">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
@@ -119,24 +106,24 @@ $view .= '
|
|||||||
<select name="month">
|
<select name="month">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<optgroup label="Q1">
|
<optgroup label="Q1">
|
||||||
<option value="January" '.($contract['month']=='January'?' selected':'').'>Jan</option>
|
<option value="1" '.($contract['month']==1?' selected':'').'>Jan</option>
|
||||||
<option value="February" '.($contract['month']=='February'?' selected':'').'>Feb</option>
|
<option value="2" '.($contract['month']==2?' selected':'').'>Feb</option>
|
||||||
<option value="March" '.($contract['month']=='March'?' selected':'').'>Mar</option>
|
<option value="3" '.($contract['month']==3?' selected':'').'>Mar</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="Q2">
|
<optgroup label="Q2">
|
||||||
<option value="April" '.($contract['month']== 'April'?' selected':'').'>Apr</option>
|
<option value="4" '.($contract['month']==4?' selected':'').'>Apr</option>
|
||||||
<option value="May" '.($contract['month']=='May'?' selected':'').'>May</option>
|
<option value="5" '.($contract['month']==5?' selected':'').'>5</option>
|
||||||
<option value="June" '.($contract['month']=='June'?' selected':'').'>Jun</option>
|
<option value="6" '.($contract['month']==6?' selected':'').'>Jun</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="Q3">
|
<optgroup label="Q3">
|
||||||
<option value="July" '.($contract['month']=='July'?' selected':'').'>Jul</option>
|
<option value="7" '.($contract['month']==7?' selected':'').'>Jul</option>
|
||||||
<option value="August" '.($contract['month']=='August'?' selected':'').'>Aug</option>
|
<option value="8" '.($contract['month']==8?' selected':'').'>Aug</option>
|
||||||
<option value="September" '.($contract['month']=='September'?' selected':'').'>Sept</option>
|
<option value="9" '.($contract['month']==9?' selected':'').'>Sept</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="Q4">
|
<optgroup label="Q4">
|
||||||
<option value="October" '.($contract['month']=='October'?' selected':'').'>Oct</option>
|
<option value="10" '.($contract['month']==10 ?' selected':'').'>Oct</option>
|
||||||
<option value="November" '.($contract['month']=='November'?' selected':'').'>Nov</option>
|
<option value="11" '.($contract['month']==11 ?' selected':'').'>Nov</option>
|
||||||
<option value="December" '.($contract['month']=='December'?' selected':'').'>Dec</option>
|
<option value="12" '.($contract['month']==12 ?' selected':'').'>Dec</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
</select>
|
</select>
|
||||||
<button type="submit">'.$button_apply.'</button>
|
<button type="submit">'.$button_apply.'</button>
|
||||||
@@ -152,12 +139,9 @@ $view .= '
|
|||||||
</div>
|
</div>
|
||||||
';
|
';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$view .= '
|
$view .= '
|
||||||
<div class="content-block">
|
<div class="content-block">
|
||||||
<div class="table">
|
<div class="table">
|
||||||
'.$ye.' - '.$qu.' - '.$mo.'
|
|
||||||
<table class="sortable">
|
<table class="sortable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -172,6 +156,7 @@ $view .= '
|
|||||||
<th>'.$contract_billing_count.'</th>
|
<th>'.$contract_billing_count.'</th>
|
||||||
<th>'.$contract_service_2.'</th>
|
<th>'.$contract_service_2.'</th>
|
||||||
<th>'.$contract_overrun.'</th>
|
<th>'.$contract_overrun.'</th>
|
||||||
|
<th>'.$contract_reference.'</th>
|
||||||
<th>'.$general_actions.'</th>
|
<th>'.$general_actions.'</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -188,85 +173,21 @@ $view .= '
|
|||||||
else {
|
else {
|
||||||
foreach ($responses as $response){
|
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);
|
|
||||||
|
|
||||||
//SHOW USAGE PERCENTAGE
|
|
||||||
$usage_service_count = ($response['service_count'] > 0) ? $response['service_count']:1;
|
|
||||||
$usage_percentage = ($billing_run != 0) ? round((($billing_run/$usage_service_count)*100),2) : 0;
|
|
||||||
$usage_per_status = ($usage_percentage < 100) ? 'enabled' : 'disabled';
|
|
||||||
$view .= '
|
$view .= '
|
||||||
<tr>
|
<tr>
|
||||||
<td>'.$response['rowID'].'</td>
|
<td>'.$response['#'].'</td>
|
||||||
<td>'.(($response['status'] == 1)? '<span class="status enabled">'.$$status: (($response['status'] == 3) ? '<span class="status disabled">'.$$status : '<span class="status">'.$$status)).'</td>
|
<td>'.(($response['Status'] == $contract_status1)? '<span class="status enabled">'.$response['Status']: (($response['Status'] == $contract_status3) ? '<span class="status disabled">'.$response['Status'] : '<span class="status">'.$response['Status'])).'</span></td>
|
||||||
<td>'.$partner_data['soldto'].'</td>
|
<td>'.$response['Account'].'</td>
|
||||||
<td>'.$$type.'</td>
|
<td>'.$response['Type'].'</td>
|
||||||
<td>'.$$contract_billingplan_text.'</td>
|
<td>'.$response['Billingplan'].'</td>
|
||||||
<td>'.$response['start_date'].'</td>
|
<td>'.$response['Start date'].'</td>
|
||||||
<td>'.$date.'</td>
|
<td>'.$response['End date'].'</td>
|
||||||
<td>'.$response['reference'].'</td>
|
<td>'.$response['Reference'].'</td>
|
||||||
<td>'.$billing_run.'</td>
|
<td>'.$response['Consumed'].'</td>
|
||||||
<td>'.$response['service_count'].' </td>
|
<td>'.$response['Contracted'].' </td>
|
||||||
<td><span class="status '.$usage_per_status .'">'.$usage_percentage.'</span></td>
|
<td><span class="status '.(($response['Deviation'] < 100) ? 'enabled' : 'disabled').'">'.$response['Deviation'].'</span></td>
|
||||||
<td><a href="index.php?page=contract&rowID='.$response['rowID'].'" class="btn_link">'.$general_view .'</a></td>
|
<td>'.$response['Period'].'</td>
|
||||||
|
<td><a href="index.php?page=contract&rowID='.$response['#'].'" class="btn_link">'.$general_view .'</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user