CMXX - block contracts based on usage

This commit is contained in:
“VeLiTi”
2024-10-10 16:34:49 +02:00
parent d2b022a08b
commit 4889402271
12 changed files with 84 additions and 13 deletions

View File

@@ -2728,4 +2728,65 @@ function assetHealthIndex($prof,$pem,$healthdata,$type){
}
//Not allowed or no data return 100% health
return $healthindex;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Block contracts ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
function blockContracts($token){
include dirname(__FILE__,2).'/settings/settings.php';
//CALL TO API
$api_url = '/v2/contracts/status=1&type=1';
$responses = ioAPIv2($api_url,'',$token);
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
foreach ($responses as $response){
//GET BILLING DATA
$billing_plan = $response['billing_plan'];
$billing_max = $response['service_count'];
//DECODE ARRAYs
$servicetools = json_decode($response['servicetool'],true) ?? '';
$assigned_users = json_decode($response['assigned_users'],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);
}
//GET END DATA
$contract_end_date = date('Y-m-d', strtotime('+'.$response['duration'].' months', strtotime($response['start_date'])));
//Return report_usage_servicereports
$api_url = '/v2/application/type=ServiceReport&serialnumber='.substr($url_input,0,-1).$ignored_serialnumbers.'&between='.$response['start_date'].'||'.$contract_end_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;}
//GET USAGE BILLING INFORMATION
$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 )));
//CHECK FOR OVERRUN
if ($billing_cylce_usage >= $billing_max){
//overrun - set contract status to 3 - block and Inactivate service for all assigned users
$data = json_encode(array("rowID" => $response['rowID'], "status" => "3", "assigned_users" => $assigned_users), JSON_UNESCAPED_UNICODE);
//API call
ioAPIv2('/v2/contracts', $data,$token);
}
}
}