CM90 - Bug report_contracts

This commit is contained in:
“VeLiTi”
2024-11-05 16:32:12 +01:00
parent f51af664cf
commit 0c5bd3f83e
3 changed files with 126 additions and 4 deletions

View File

@@ -28,7 +28,7 @@ if(isset($get_content) && $get_content!=''){
}
elseif ($v[0] == 'search') {
//build up search
$clause .= ' AND (carbrand like :'.$v[0].' OR createdby like :'.$v[0].')';
$clause .= ' AND (carbrand like :'.$v[0].' OR createdby like :'.$v[0].' OR rowID like :'.$v[0].')';
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];

122
api/v2/get/billing.php Normal file
View File

@@ -0,0 +1,122 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// contracts_billing
//------------------------------------------
//GET PARAMETERS
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
//SET DEFAULT VALUES
$ye = ((isset($_GET['year']) && $_GET['year'] !='' )? $_GET['year'] : $curYear);
$mo = ((isset($_GET['month']) && $_GET['month'] !='')? $_GET['month'] : $curMonth_name);
$qu = ((isset($_GET['month']) ? (int)ceil(date("n",strtotime($mo)) / 3): $curQuarter));
//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 = ioAPIv2($api_url,'',$token);
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
$output[] = '';
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 = 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;}
$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);
//SHOW USAGE PERCENTAGE
$usage_service_count = ($response['service_count'] != 0 || $response['service_count'] !='') ? $response['service_count']:1;
$usage_percentage = ($billing_run != 0) ? round((($billing_run/$usage_service_count)*100),2) : 0;
$usage_per_status = ($usage_percentage < 100) ? 'enabled' : 'disabled';
$output[] = array(
"#" => $response['rowID'] ,
$contract_status => $$status,
$contract_account => $partner_data['soldto'],
$contract_type => $$type,
$contract_billinglabel =>$$contract_billingplan_text,
$contract_start_date =>$response['start_date'],
$contract_end_date => $date,
$contract_reference =>$response['reference'],
$contract_billing_count =>$billing_run,
$contract_service_2 =>$response['service_count'],
$contract_overrun => $usage_percentage
);
}
//------------------------------------------
//JSON_ENCODE
//------------------------------------------
$messages = json_encode($output, JSON_UNESCAPED_UNICODE);
//Send results
echo $messages;
?>

View File

@@ -17,12 +17,12 @@ $prev_page = ($_SESSION['origin'] == 'equipments') ? $_SESSION['prev_origin_equi
//create backbutton to prev_origin
$back_btn_orgin = ($prev_page != '')? '<a href="'.$prev_page.'" class="btn alt mar-right-2">'.$button_back.'</a>':'';
/*Check if allowed
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
*/
//Defaults
$contract = [
@@ -250,7 +250,7 @@ $view .= '
$partner_data = json_decode($response['accounthierarchy'],true);
//SHOW USAGE PERCENTAGE
$usage_service_count = ($response['service_count'] != 0 || $response['service_count'] !='') ? $response['service_count']:1;
$usage_service_count = ($response['service_count'] > 0) ? $response['service_count']:1;
$usage_percentage = ($billing_run != 0) ? round((($billing_run/$usage_service_count)*100),2) : 0;
$usage_per_status = ($usage_percentage < 100) ? 'enabled' : 'disabled';
$view .= '