diff --git a/api/v2/get/billing.php b/api/v2/get/billing.php index 468db75..3ea674c 100644 --- a/api/v2/get/billing.php +++ b/api/v2/get/billing.php @@ -1,121 +1,173 @@ $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 - ); + $usage_billing = usageBilling($contract_usage_servicereports); + + //Initial billing_run value + $billing_run = 0; + $period = 'n/a'; + + switch ($response['billing_plan']) { + case 1: + # month + //CONVERT KEY TO MONTH NAME + $monthObj = DateTime::createFromFormat('!m', $mo); + $period = $monthObj->format('F'); + + if (isset($usage_billing[$ye]['quarters'][$qu]['months'][$mo])){ + $billing_run = $usage_billing[$ye]['quarters'][$qu]['months'][$mo]; + } + break; + case 2: + # quarter + $period = 'Q'.$qu; + + if (isset($usage_billing[$ye]['quarters'][$qu]['total'])){ + $billing_run = $usage_billing[$ye]['quarters'][$qu]['total']; + } + break; + case 3: + # year + $period = $ye; + + 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']: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, + "Snapshot_date" => $da, + "Period" => $period + + ); + } } -//------------------------------------------ -//JSON_ENCODE -//------------------------------------------ -$messages = json_encode($output, JSON_UNESCAPED_UNICODE); +$total = count( $output ); + +//SEND TOTALS WHEN REQUESTED +if(isset($criterias['totals']) && $criterias['totals'] ==''){ + + $messages = json_encode($total, JSON_UNESCAPED_UNICODE); +} +else { + + //------------------------------------------ + //Paging + //------------------------------------------ + $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; + $offset = ($current_page - 1) * $page_rows_contracts; + $output = array_slice( $output, $offset, $page_rows_contracts ); + + //------------------------------------------ + //JSON_ENCODE + //------------------------------------------ + $messages = json_encode($output, JSON_UNESCAPED_UNICODE); +} //Send results echo $messages; diff --git a/api/v2/get/contracts.php b/api/v2/get/contracts.php index 55461a7..79c76b0 100644 --- a/api/v2/get/contracts.php +++ b/api/v2/get/contracts.php @@ -78,6 +78,10 @@ elseif (isset($criterias['list']) && $criterias['list'] =='') { //SQL for Paging $sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.''; } +elseif (isset($criterias['p']) && $criterias['p'] =='all') { + //SQL for Paging + $sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.''; +} else { //SQL for Paging $sql = 'SELECT * FROM contracts c JOIN users u ON c.createdby = u.username '.$whereclause.' LIMIT :page,:num_products'; @@ -115,7 +119,7 @@ if(isset($criterias['totals']) && $criterias['totals']==''){ $messages = $stmt->fetch(); $messages = $messages[0]; } -elseif(isset($criterias['list']) && $criterias['list']==''){ +elseif((isset($criterias['list']) && $criterias['list']=='') || (isset($criterias['p']) && $criterias['p'] =='all')){ //Excute Query $stmt->execute(); //Get results diff --git a/assets/functions.php b/assets/functions.php index 5cb4860..c76aef7 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -2421,8 +2421,9 @@ function usageBilling($messages){ foreach ($messages as $entry) { $year = $entry['year']; $quarter = $entry['quarter']; - $dateObj = DateTime::createFromFormat('!m', $entry['month']); - $month = $dateObj->format('F'); + //$dateObj = DateTime::createFromFormat('!m', $entry['month']); + //$month = $dateObj->format('F'); + $month = $entry['month']; $count = $entry['count']; // Initialize arrays if not already set for year, quarter, and month @@ -2779,7 +2780,7 @@ function blockContracts($token){ //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 ))); + $billing_cylce_usage = (($billing_plan == 1 && isset($usage_billing[$curYear]['quarters'][$curQuarter]['months'][$curMonth])) ? $usage_billing[$curYear]['quarters'][$curQuarter]['months'][$curMonth] : (($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){ @@ -2789,4 +2790,18 @@ function blockContracts($token){ ioAPIv2('/v2/contracts', $data,$token); } } +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// check date is in range ++++++++++++++ +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +function dateInRange($start_date, $end_date, $date_check) +{ + // Convert to timestamp + $start_ts = strtotime($start_date); + $end_ts = strtotime($end_date); + $check_ts = strtotime($date_check); + + // Check that user date is between start & end + return (($check_ts >= $start_ts) && ($check_ts <= $end_ts)); } \ No newline at end of file diff --git a/contract.php b/contract.php index f8a551a..aa8a03e 100644 --- a/contract.php +++ b/contract.php @@ -257,6 +257,10 @@ $view .= '
| '.$contract_billing_count.' | '.$contract_service_2.' | '.$contract_overrun.' | +'.$contract_reference.' | '.$general_actions.' | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| '.$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'].' | -'.$usage_percentage.' | -'.$general_view .' | +'.$response['#'].' | +'.(($response['Status'] == $contract_status1)? ''.$response['Status']: (($response['Status'] == $contract_status3) ? ''.$response['Status'] : ''.$response['Status'])).' | +'.$response['Account'].' | +'.$response['Type'].' | +'.$response['Billingplan'].' | +'.$response['Start date'].' | +'.$response['End date'].' | +'.$response['Reference'].' | +'.$response['Consumed'].' | +'.$response['Contracted'].' | +'.$response['Deviation'].' | +'.$response['Period'].' | +'.$general_view .' |