From c35afb1e1cc616c402df7e1712afe55290f7e209 Mon Sep 17 00:00:00 2001 From: Richard Lawley Date: Thu, 10 Mar 2016 18:11:39 +0000 Subject: [PATCH] Implement Billing Search --- html/pages/bills.inc.php | 27 ++++++- html/pages/bills/pmonth.inc.php | 121 +++++++++++++++++++------------- html/pages/bills/search.inc.php | 23 +++--- 3 files changed, 109 insertions(+), 62 deletions(-) diff --git a/html/pages/bills.inc.php b/html/pages/bills.inc.php index 759a0697d1..be60dfef63 100644 --- a/html/pages/bills.inc.php +++ b/html/pages/bills.inc.php @@ -108,7 +108,32 @@ else { bill_cdr) OR (bill_type = 'quota' AND total_data > bill_quota))"; + } + + $query = 'SELECT * + FROM `bills` + '; + if (sizeof($wheres) > 0) { + $query .= 'WHERE ' . implode(' AND ', $wheres) . "\n"; + } + $query .= 'ORDER BY bills.bill_name'; + + foreach (dbFetchRows($query, $params) as $bill) { if (bill_permitted($bill['bill_id'])) { unset($class); $day_data = getDates($bill['bill_day']); diff --git a/html/pages/bills/pmonth.inc.php b/html/pages/bills/pmonth.inc.php index d7f78fc4d5..adb6996efa 100644 --- a/html/pages/bills/pmonth.inc.php +++ b/html/pages/bills/pmonth.inc.php @@ -1,9 +1,10 @@ +echo ' + @@ -14,58 +15,84 @@ echo '
Billing name Type
- '; + + + '; + +$wheres = array(); +$params = array(); -foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_name`') as $bill) { +if (!empty($_GET['search'])) { + $wheres[] = 'bills.bill_name LIKE ?'; + $params[] = '%'.$_GET['search'].'%'; +} +if (!empty($_GET['bill_type'])) { + $wheres[] = 'bill_history.bill_type = ?'; + $params[] = $_GET['bill_type']; +} +if ($_GET['state'] === 'under') { + $wheres[] = 'bill_history.bill_overuse = 0'; +} else if ($_GET['state'] === 'over') { + $wheres[] = 'bill_history.bill_overuse > 0'; +} + +$query = 'SELECT bills.bill_name, bill_history.* +FROM `bills` + INNER JOIN (SELECT bill_id, MAX(bill_hist_id) AS bill_hist_id FROM bill_history WHERE bill_dateto < NOW() AND bill_dateto > subdate(NOW(), 40) GROUP BY bill_id) qLastBills ON bills.bill_id = qLastBills.bill_id + INNER JOIN bill_history ON qLastBills.bill_hist_id = bill_history.bill_hist_id +'; +if (sizeof($wheres) > 0) { + $query .= 'WHERE ' . implode(' AND ', $wheres) . "\n"; +} +$query .= 'ORDER BY bills.bill_name'; + +foreach (dbFetchRows($query, $params) as $bill) { if (bill_permitted($bill['bill_id'])) { - $day_data = getDates($bill['bill_day']); - $datefrom = $day_data['2']; - $dateto = $day_data['3']; - foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? AND `bill_datefrom` = ? ORDER BY `bill_datefrom` LIMIT 1', array($bill['bill_id'], $datefrom, $dateto)) as $history) { - unset($class); - $type = $history['bill_type']; - $percent = $history['bill_percent']; - $dir_95th = $history['dir_95th']; - $rate_95th = format_si($history['rate_95th']).'bps'; - $total_data = format_bytes_billing($history['traf_total']); + $datefrom = $bill['bill_datefrom']; + $dateto = $bill['bill_dateto']; - $background = get_percentage_colours($percent); - $row_colour = ((!is_integer($i / 2)) ? $list_colour_a : $list_colour_b); + unset($class); + $type = $bill['bill_type']; + $percent = $bill['bill_percent']; + $dir_95th = $bill['dir_95th']; + $rate_95th = format_si($bill['rate_95th']).'bps'; + $total_data = format_bytes_billing($bill['traf_total']); - if ($type == 'CDR') { - $allowed = format_si($history['bill_allowed']).'bps'; - $used = format_si($history['rate_95th']).'bps'; - $in = format_si($history['rate_95th_in']).'bps'; - $out = format_si($history['rate_95th_out']).'bps'; - $overuse = (($history['bill_overuse'] <= 0) ? '-' : ''.format_si($history['bill_overuse']).'bps'); - } - else if ($type == 'Quota') { - $allowed = format_bytes_billing($history['bill_allowed']); - $used = format_bytes_billing($history['total_data']); - $in = format_bytes_billing($history['traf_in']); - $out = format_bytes_billing($history['traf_out']); - $overuse = (($history['bill_overuse'] <= 0) ? '-' : ''.format_bytes_billing($history['bill_overuse']).''); - } + $background = get_percentage_colours($percent); - $total_data = (($type == 'Quota') ? ''.$total_data.'' : $total_data); - $rate_95th = (($type == 'CDR') ? ''.$rate_95th.'' : $rate_95th); + if ($type == 'CDR') { + $allowed = format_si($bill['bill_allowed']).'bps'; + $used = format_si($bill['rate_95th']).'bps'; + $in = format_si($bill['rate_95th_in']).'bps'; + $out = format_si($bill['rate_95th_out']).'bps'; + $overuse = (($bill['bill_overuse'] <= 0) ? '-' : ''.format_si($bill['bill_overuse']).'bps'); + } + else if ($type == 'Quota') { + $allowed = format_bytes_billing($bill['bill_allowed']); + $used = format_bytes_billing($bill['total_data']); + $in = format_bytes_billing($bill['traf_in']); + $out = format_bytes_billing($bill['traf_out']); + $overuse = (($bill['bill_overuse'] <= 0) ? '-' : ''.format_bytes_billing($bill['bill_overuse']).''); + } - echo " - - - - - - - - - - - '; + $total_data = (($type == 'Quota') ? ''.$total_data.'' : $total_data); + $rate_95th = (($type == 'CDR') ? ''.$rate_95th.'' : $rate_95th); + + echo " + + + + + + + + + + + '; - $i++; - } //end foreach }//end if }//end foreach -echo '
95 percentile Overusage
'bill', 'bill_id' => $bill['bill_id'], 'view' => 'history', detail => $history['bill_hist_id'])).'">'.$bill['bill_name'].'
from '.strftime('%x', strtotime($datefrom)).' to '.strftime('%x', strtotime($dateto))."
$type$allowed$in$out$total_data$rate_95th$overuse".print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'
'bill', 'bill_id' => $bill['bill_id'], 'view' => 'history', detail => $bill['bill_hist_id'])).'">'.$bill['bill_name'].'
from '.strftime('%x', strtotime($datefrom)).' to '.strftime('%x', strtotime($dateto))."
$type$allowed$in$out$total_data$rate_95th$overuse".print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'
'; +echo ' +'; diff --git a/html/pages/bills/search.inc.php b/html/pages/bills/search.inc.php index ffa5f6e7f6..3291e3f2fe 100644 --- a/html/pages/bills/search.inc.php +++ b/html/pages/bills/search.inc.php @@ -4,23 +4,19 @@ ?> -
-
+ +
Bills - - + - - - - -
@@ -30,7 +26,6 @@ if ($vars['view'] == 'history') { echo ' Current Billing Period'; } else { - // FIXME - generate_url echo ' Previous Billing Period'; }