From 52011d2ac8c4e62d25581b9a1d0ff924489090ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”>
Date: Thu, 24 Oct 2024 16:08:12 +0200
Subject: [PATCH] CMXX - Report contracts
---
report_contracts_billing.php | 293 ++++++++++++++++++++++
report_healthindex.php | 4 +-
settings/settingsmenu.php | 6 +
settings/settingsviews.php | 1 +
settings/translations/translations_DE.php | 1 +
settings/translations/translations_ES.php | 1 +
settings/translations/translations_NL.php | 1 +
settings/translations/translations_PT.php | 1 +
settings/translations/translations_US.php | 1 +
9 files changed, 307 insertions(+), 2 deletions(-)
create mode 100644 report_contracts_billing.php
diff --git a/report_contracts_billing.php b/report_contracts_billing.php
new file mode 100644
index 0000000..ed48505
--- /dev/null
+++ b/report_contracts_billing.php
@@ -0,0 +1,293 @@
+'.$button_back.'':'';
+
+/*Check if allowed
+if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
+ header('location: index.php');
+ exit;
+}
+*/
+
+//Defaults
+$contract = [
+ 'type' => (isset($_GET['type'])? $_GET['type'] : ''),
+ 'billing_plan' => (isset($_GET['billing_plan'])? $_GET['billing_plan'] : ''),
+ 'year' => (isset($_GET['year'])? $_GET['year'] : ''),
+ 'quarter' => (isset($_GET['quarter'])? $_GET['quarter'] : ''),
+ 'month' => (isset($_GET['month'])? $_GET['month'] : '')
+ ];
+
+//GET PARAMETERS
+$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
+$p = '&p='.$pagination_page;
+$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
+$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
+
+//SET DEFAULT VALUES
+$ye = (isset($_GET['year'])? $_GET['year'] : $curYear);
+$mo = (isset($_GET['month'])? $_GET['month'] : '');
+$qu = ((isset($_GET['month']) ? (int)ceil(date("n",strtotime($mo)) / 3): $curQuarter));
+
+// Determine the URL
+$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_VALUES = urlGETdetails($_GET) ?? '';
+
+//CALL TO API
+$api_url = '/v2/contracts/'.$GET_VALUES;
+$responses = ioServer($api_url,'');
+//Decode Payload
+if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
+
+//Return QueryTotal from API
+$api_url = '/v2/contracts/'.$GET_VALUES.'&totals=';
+$query_total = ioServer($api_url,'');
+//Decode Payload
+if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = 0;}
+
+
+template_header('contracts', 'contracts','view');
+$view = '
+
+
+
+
+
'.$contract_h2.' ('.$query_total.')
+
'.$contract_p .'
+
+
+ '.$back_btn_orgin.'
+
';
+
+
+$view .= '
+
+';
+
+
+
+$view .= '
+
+
+
+
+
+ | '.$contract_id.' |
+ '.$contract_status.' |
+ '.$contract_account.' |
+ '.$contract_type.' |
+ '.$contract_billinglabel.' |
+ '.$contract_start_date.' |
+ '.$contract_end_date.' |
+ '.$contract_reference.' |
+ BillingCount |
+ '.$contract_service.' |
+ '.$general_actions.' |
+
+
+
+ ';
+
+ if (empty($responses)){
+
+ $view .= '
+
+ | '.$message_no_contract.' |
+
';
+ }
+ else {
+ 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);
+
+ $view .= '
+
+ | '.$response['rowID'].' |
+ '.(($response['status'] == 1)? ''.$$status: (($response['status'] == 3) ? ''.$$status : ''.$$status)).' |
+ '.$partner_data['soldto'].' |
+ '.$$type.' |
+ '.$$contract_billingplan_text.' |
+ '.$response['start_date'].' |
+ '.$date.' |
+ '.$response['reference'].' |
+ '.$billing_run.' |
+ '.$response['service_count'].' |
+ '.$general_view .' |
+
+ ';
+ }
+ }
+$view .= '
+
+
+
+
+';
+
+$view.='';
+//OUTPUT
+echo $view;
+
+template_footer();
+?>
\ No newline at end of file
diff --git a/report_healthindex.php b/report_healthindex.php
index 2cd5bf1..a233a5f 100644
--- a/report_healthindex.php
+++ b/report_healthindex.php
@@ -16,11 +16,11 @@ $page = $_SESSION['origin'] = 'report_healthindex';
//create backbutton to prev_origin
$back_btn_orgin = ($prev_page != '')? ''.$button_back.'':'';
-/*Check if allowed
+//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
-}*/
+}
//GET PARAMETERS && STORE in SESSION for FURTHER USE/NAVIGATION
$pagination_page = $_SESSION['p'] = isset($_GET['p']) ? $_GET['p'] : 1;
diff --git a/settings/settingsmenu.php b/settings/settingsmenu.php
index 48ec2a7..8eedf56 100644
--- a/settings/settingsmenu.php
+++ b/settings/settingsmenu.php
@@ -170,6 +170,12 @@ $urls = array(
"icon" => "fa-solid fa-magnifying-glass-chart",
"name" => "menu_report_build"
),
+ "report_contracts_billing" => array(
+ "url" => "report_contracts_billing",
+ "selected" => "report_contracts_billing",
+ "icon" => "fa-solid fa-magnifying-glass-chart",
+ "name" => "menu_report_contracts_billing"
+ ),
"report_healthindex" => array(
"url" => "report_healthindex",
"selected" => "report_healthindex",
diff --git a/settings/settingsviews.php b/settings/settingsviews.php
index 6cdf372..60fa0d6 100644
--- a/settings/settingsviews.php
+++ b/settings/settingsviews.php
@@ -49,6 +49,7 @@ $all_views = [
"marketing",
"reporting",
"report_build",
+ "report_contracts_billing",
"report_healthindex",
"report_usage",
"config",
diff --git a/settings/translations/translations_DE.php b/settings/translations/translations_DE.php
index b89daa5..4714256 100644
--- a/settings/translations/translations_DE.php
+++ b/settings/translations/translations_DE.php
@@ -24,6 +24,7 @@ $menu_cartest = 'Fahrzeugdatenbank';
$menu_report_main = 'Berichte';
$menu_report_build = 'Bestand und Produktion';
$menu_report_healthindex= 'Healthindex';
+$menu_report_contracts_billing = 'Verträge';
$menu_report_usage = 'Systemnutzung';
$menu_maintenance = 'Maintenance';
$menu_profiles = 'Profiles';
diff --git a/settings/translations/translations_ES.php b/settings/translations/translations_ES.php
index 3d0e063..73ca9b9 100644
--- a/settings/translations/translations_ES.php
+++ b/settings/translations/translations_ES.php
@@ -24,6 +24,7 @@ $menu_cartest = 'Base de Datos de Autos';
$menu_report_main = 'Informes';
$menu_report_build = 'Stock y Producción';
$menu_report_healthindex = 'Índice de Salud';
+$menu_report_contracts_billing = 'Contractos';
$menu_report_usage = 'Uso del Sistema';
$menu_maintenance = 'Mantenimiento';
$menu_profiles = 'Perfiles';
diff --git a/settings/translations/translations_NL.php b/settings/translations/translations_NL.php
index 9ad6336..6aec924 100644
--- a/settings/translations/translations_NL.php
+++ b/settings/translations/translations_NL.php
@@ -24,6 +24,7 @@ $menu_cartest = 'Auto database';
$menu_report_main = 'Rapporten';
$menu_report_build = 'Voorraad en Productie';
$menu_report_healthindex= 'Healthindex';
+$menu_report_contracts_billing = 'Contracten';
$menu_report_usage = 'Systeemgebruik';
$menu_maintenance = 'Maintenance';
$menu_profiles = 'Profielen';
diff --git a/settings/translations/translations_PT.php b/settings/translations/translations_PT.php
index 71b6538..54d57c2 100644
--- a/settings/translations/translations_PT.php
+++ b/settings/translations/translations_PT.php
@@ -24,6 +24,7 @@ $menu_cartest = 'Banco de Dados de Carros';
$menu_report_main = 'Relatórios';
$menu_report_build = 'Estoque e Produção';
$menu_report_healthindex = 'Índice de Saúde';
+$menu_report_contracts_billing = 'Contratos';
$menu_report_usage = 'Uso do Sistema';
$menu_maintenance = 'Manutenção';
$menu_profiles = 'Perfis';
diff --git a/settings/translations/translations_US.php b/settings/translations/translations_US.php
index e748be7..7f88bed 100644
--- a/settings/translations/translations_US.php
+++ b/settings/translations/translations_US.php
@@ -24,6 +24,7 @@ $menu_cartest = 'Car database';
$menu_report_main = 'Reports';
$menu_report_build = 'Stock and Production';
$menu_report_healthindex= 'Healthindex';
+$menu_report_contracts_billing = 'Contracts';
$menu_report_usage = 'System usage';
$menu_maintenance = 'Maintenance';
$menu_profiles = 'Profiles';