CMXX - block contracts based on usage
This commit is contained in:
@@ -66,10 +66,10 @@ if ($id != ''){
|
||||
$contract_data = $stmt->fetch();
|
||||
|
||||
$contract_old = json_decode($contract_data['accounthierarchy']);
|
||||
$salesid_new = (($post_content['salesid'] != '' && $post_content['salesid'] != $contract_old->salesid)? $post_content['salesid'] : $contract_old->salesid);
|
||||
$soldto_new = (($post_content['soldto'] != '' && $post_content['soldto'] != $contract_old->soldto)? $post_content['soldto'] : $contract_old->soldto);
|
||||
$shipto_new = (($post_content['shipto'] != '' && $post_content['shipto'] != $contract_old->shipto)? $post_content['shipto'] : $contract_old->shipto);
|
||||
$location_new = (($post_content['location'] != '' && $post_content['location'] != $contract_old->location)? $post_content['location'] : $contract_old->location);
|
||||
$salesid_new = ((isset($post_content['salesid']) && $post_content['salesid'] != '' && $post_content['salesid'] != $contract_old->salesid)? $post_content['salesid'] : $contract_old->salesid);
|
||||
$soldto_new = ((isset($post_content['soldto']) && $post_content['soldto'] != '' && $post_content['soldto'] != $contract_old->soldto)? $post_content['soldto'] : $contract_old->soldto);
|
||||
$shipto_new = ((isset($post_content['shipto']) && $post_content['shipto'] != '' && $post_content['shipto'] != $contract_old->shipto)? $post_content['shipto'] : $contract_old->shipto);
|
||||
$location_new = ((isset($post_content['location']) && $post_content['location'] != '' && $post_content['location'] != $contract_old->location)? $post_content['location'] : $contract_old->location);
|
||||
|
||||
if ($permission == 4){
|
||||
//ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD
|
||||
@@ -193,7 +193,7 @@ if (isset($post_content['assigned_users'])){
|
||||
|
||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
if (isset($post_content['status']) && $post_content['status'] != 2){
|
||||
if (isset($post_content['status']) && $post_content['status'] < 2){
|
||||
//Add serviceflag from user
|
||||
$stmt->execute([$generate_service,$id_exist_user]);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ $partnerhierarchy_old = json_decode($user_data['partnerhierarchy']);
|
||||
|
||||
$salesid_new = ((isset($post_content['salesid']) && $post_content['salesid'] != '' && $post_content['salesid'] != $partnerhierarchy_old->salesid)? $post_content['salesid'] : $partnerhierarchy_old->salesid);
|
||||
$soldto_new = ((isset($post_content['soldto']) && $post_content['soldto'] != '' && $post_content['soldto'] != $partnerhierarchy_old->soldto)? $post_content['soldto'] : $partnerhierarchy_old->soldto);
|
||||
$shipto_new = (($post_content['shipto'] != '' && $post_content['shipto'] != $partnerhierarchy_old->shipto)? $post_content['shipto'] : $partnerhierarchy_old->shipto);
|
||||
$location_new = (($post_content['location'] != '' && $post_content['location'] != $partnerhierarchy_old->location)? $post_content['location'] : $partnerhierarchy_old->location);
|
||||
$shipto_new = ((isset($post_content['shipto']) && $post_content['shipto'] != '' && $post_content['shipto'] != $partnerhierarchy_old->shipto)? $post_content['shipto'] : $partnerhierarchy_old->shipto);
|
||||
$location_new = ((isset($post_content['location']) && $post_content['location'] != '' && $post_content['location'] != $partnerhierarchy_old->location)? $post_content['location'] : $partnerhierarchy_old->location);
|
||||
|
||||
if ($permission == 4){
|
||||
//ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD
|
||||
|
||||
@@ -2729,3 +2729,64 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ $view .= ' <div class="content-block order-details">
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_status.'</h3>
|
||||
<p><span class="status id'.$responses->status.'">'.$$contract_status_text.'</span></p>
|
||||
<p>'.(($responses->status == 1)? '<span class="status enabled">': (($responses->status == 3) ? '<span class="status disabled">': '<span class="status">')).''.$$contract_status_text.'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_type.'</h3>
|
||||
|
||||
@@ -91,6 +91,7 @@ $view .= '
|
||||
<option value="0">'.$contract_status0.'</option>
|
||||
<option value="1">'.$contract_status1.'</option>
|
||||
<option value="2">'.$contract_status2.'</option>
|
||||
<option value="3">'.$contract_status3.'</option>
|
||||
</select>
|
||||
<button type="submit">'.$button_apply.'</button>
|
||||
</div>
|
||||
@@ -145,7 +146,7 @@ $view .= '
|
||||
$view .= '
|
||||
<tr>
|
||||
<td>'.$response->rowID.'</td>
|
||||
<td>'.(($response->status == 1)? '<span class="status enabled">'.$$status:'<span class="status">'.$$status).'</td>
|
||||
<td>'.(($response->status == 1)? '<span class="status enabled">'.$$status: (($response->status == 3) ? '<span class="status disabled">'.$$status : '<span class="status">'.$$status)).'</td>
|
||||
<td>'.$partner_data->soldto.'</td>
|
||||
<td>'.$$type.'</td>
|
||||
<td>'.$response->start_date.'</td>
|
||||
|
||||
@@ -80,10 +80,14 @@ else {
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// close Contracts ++++++++++++++
|
||||
// Contracts ++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//close contracts past due
|
||||
closeContract();
|
||||
|
||||
//block contract where usage limit is reached
|
||||
blockContracts($token);
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Machine learning ++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
@@ -8,7 +8,7 @@ define('service','dashboard,profile,assets,equipments,equipment,equipment_manage
|
||||
/*Admin*/
|
||||
define('admin_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,buildtool,products,products_versions,product,product_manage,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_healthindex,application');
|
||||
/*AdminPlus*/
|
||||
define('adminplus_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,buildtool,products,products_versions,product,product_manage,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_healthindex,report_usage,config,settings,logfile,changelog,language,application,maintenance,profiles');
|
||||
define('adminplus_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,buildtool,products,products_versions,products_software,product,product_manage,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_healthindex,report_usage,config,settings,logfile,changelog,language,application,maintenance,profiles');
|
||||
/*Build*/
|
||||
define('build','buildtool,buildtool,application');
|
||||
/*Distribution*/
|
||||
@@ -16,5 +16,5 @@ define('distribution','dashboard,profile,assets,equipments,equipment,equipment_m
|
||||
/*Firmware*/
|
||||
define('firmware','firmwaretool,application');
|
||||
/*Interface*/
|
||||
define('interface','equipments,equipment_manage,firmwaretool,products_versions,application');
|
||||
define('interface','contracts,contract,equipments,equipment_manage,firmwaretool,products_versions,users,application');
|
||||
?>
|
||||
@@ -511,6 +511,7 @@ $contract_search = 'Referenz suchen';
|
||||
$contract_status0 = 'Entwurf';
|
||||
$contract_status1 = 'Aktiv';
|
||||
$contract_status2 = 'Abgeschlossen';
|
||||
$contract_status3 = 'Block';
|
||||
|
||||
$contract_type0 = 'Fest';
|
||||
$contract_type1 = 'Abonnement';
|
||||
|
||||
@@ -510,6 +510,7 @@ $contract_search = 'Buscar referencia';
|
||||
$contract_status0 = 'Borrador';
|
||||
$contract_status1 = 'Activo';
|
||||
$contract_status2 = 'Cerrado';
|
||||
$contract_status3 = 'Block';
|
||||
|
||||
$contract_type0 = 'Fijo';
|
||||
$contract_type1 = 'Suscripción';
|
||||
|
||||
@@ -516,6 +516,7 @@ $contract_search = 'Zoek referentie';
|
||||
$contract_status0 = 'Draft';
|
||||
$contract_status1 = 'Actief';
|
||||
$contract_status2 = 'Gesloten';
|
||||
$contract_status3 = 'Block';
|
||||
|
||||
$contract_type0 = 'Vast';
|
||||
$contract_type1 = 'Abonnement';
|
||||
|
||||
@@ -509,6 +509,7 @@ $contract_search = 'Buscar referência';
|
||||
$contract_status0 = 'Rascunho';
|
||||
$contract_status1 = 'Ativo';
|
||||
$contract_status2 = 'Fechado';
|
||||
$contract_status3 = 'Block';
|
||||
|
||||
$contract_type0 = 'Fixo';
|
||||
$contract_type1 = 'Assinatura';
|
||||
|
||||
@@ -511,6 +511,7 @@ $contract_search = 'Search reference';
|
||||
$contract_status0 = 'Draft';
|
||||
$contract_status1 = 'Active';
|
||||
$contract_status2 = 'Closed';
|
||||
$contract_status3 = 'Block';
|
||||
|
||||
$contract_type0 = 'Fixed';
|
||||
$contract_type1 = 'Subscription';
|
||||
|
||||
Reference in New Issue
Block a user