diff --git a/api/v2/post/contracts.php b/api/v2/post/contracts.php index 7ecae4a..65b28ad 100644 --- a/api/v2/post/contracts.php +++ b/api/v2/post/contracts.php @@ -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]); } diff --git a/api/v2/post/users.php b/api/v2/post/users.php index f4740fd..16a8f81 100644 --- a/api/v2/post/users.php +++ b/api/v2/post/users.php @@ -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 diff --git a/assets/functions.php b/assets/functions.php index 40dbac6..5cb4860 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -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); + } + } } \ No newline at end of file diff --git a/contract.php b/contract.php index 6e27d19..7967cd0 100644 --- a/contract.php +++ b/contract.php @@ -111,7 +111,7 @@ $view .= '
'.$$contract_status_text.'
+'.(($responses->status == 1)? '': (($responses->status == 3) ? '': '')).''.$$contract_status_text.'