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.'

-

'.$$contract_status_text.'

+

'.(($responses->status == 1)? '': (($responses->status == 3) ? '': '')).''.$$contract_status_text.'

'.$contract_type.'

diff --git a/contracts.php b/contracts.php index 7864d28..eaf1a51 100644 --- a/contracts.php +++ b/contracts.php @@ -90,7 +90,8 @@ $view .= ' - + +
@@ -145,7 +146,7 @@ $view .= ' $view .= ' '.$response->rowID.' - '.(($response->status == 1)? ''.$$status:''.$$status).' + '.(($response->status == 1)? ''.$$status: (($response->status == 3) ? ''.$$status : ''.$$status)).' '.$partner_data->soldto.' '.$$type.' '.$response->start_date.' diff --git a/cronjob.php b/cronjob.php index 8ffe377..9a74ca5 100644 --- a/cronjob.php +++ b/cronjob.php @@ -80,10 +80,14 @@ else { } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// close Contracts ++++++++++++++ +// Contracts ++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//close contracts past due closeContract(); +//block contract where usage limit is reached +blockContracts($token); + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Machine learning ++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/settings/settingsprofiles.php b/settings/settingsprofiles.php index b01b652..c58f3ed 100644 --- a/settings/settingsprofiles.php +++ b/settings/settingsprofiles.php @@ -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'); ?> \ No newline at end of file diff --git a/settings/translations/translations_DE.php b/settings/translations/translations_DE.php index 7e806f4..b89daa5 100644 --- a/settings/translations/translations_DE.php +++ b/settings/translations/translations_DE.php @@ -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'; diff --git a/settings/translations/translations_ES.php b/settings/translations/translations_ES.php index 65e7d40..3d0e063 100644 --- a/settings/translations/translations_ES.php +++ b/settings/translations/translations_ES.php @@ -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'; diff --git a/settings/translations/translations_NL.php b/settings/translations/translations_NL.php index d442e0a..9ad6336 100644 --- a/settings/translations/translations_NL.php +++ b/settings/translations/translations_NL.php @@ -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'; diff --git a/settings/translations/translations_PT.php b/settings/translations/translations_PT.php index 6709316..71b6538 100644 --- a/settings/translations/translations_PT.php +++ b/settings/translations/translations_PT.php @@ -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'; diff --git a/settings/translations/translations_US.php b/settings/translations/translations_US.php index abe96e4..e748be7 100644 --- a/settings/translations/translations_US.php +++ b/settings/translations/translations_US.php @@ -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';