diff --git a/html/includes/table/bills.inc.php b/html/includes/table/bills.inc.php new file mode 100644 index 0000000000..399bfd6c33 --- /dev/null +++ b/html/includes/table/bills.inc.php @@ -0,0 +1,165 @@ + bill_history.bill_allowed) OR (bill_history.bill_type = 'quota' AND bill_history.traf_total > bill_allowed))"; + } + else { + $wheres[] = "((bill_type = 'cdr' AND rate_95th > bill_cdr) OR (bill_type = 'quota' AND total_data > bill_quota))"; + } + } +} + +if ($prev) { + $select = "SELECT bills.bill_name, bill_history.*, bill_history.traf_total as total_data, bill_history.traf_in as total_data_in, bill_history.traf_out as total_data_out "; + $query = '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 +'; +} +else { + $select = "SELECT bills.*, + IF(bills.bill_type = 'CDR', bill_cdr, bill_quota) AS bill_allowed + "; + $query = "FROM `bills`\n"; +} + +// Permissions check +if (is_admin() === false && is_read() === false) { + $query .= ' INNER JOIN `bill_perms` AS `BP` ON `bills`.`bill_id` = `BP`.`bill_id` '; + $wheres[] = '`BP`.`user_id`=?'; + $param[] = $_SESSION['user_id']; +} + +if (sizeof($wheres) > 0) { + $query .= "WHERE " . implode(' AND ', $wheres) . "\n"; +} +$orderby = "ORDER BY bills.bill_name"; + +$total = dbFetchCell("SELECT COUNT(bills.bill_id) $query", $param); + +$sql = "$select +$query"; + +if (!isset($sort) || empty($sort)) { + $sort = 'bills.bill_name'; +} + +$sql .= "\nORDER BY $sort"; + +if (isset($current)) { + $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_high = $rowCount; +} + +if ($rowCount != -1) { + $sql .= " LIMIT $limit_low,$limit_high"; +} + +foreach (dbFetchRows($sql, $param) as $bill) { + $day_data = getDates($bill['bill_day']); + $datefrom = $day_data['0']; + $dateto = $day_data['1']; + $rate_95th = format_si($bill['rate_95th']) . 'bps'; + $dir_95th = $bill['dir_95th']; + $total_data = format_bytes_billing($bill['total_data']); + $rate_average = $bill['rate_average']; + $url = generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'])); + $used95th = format_si($bill['rate_95th']).'bps'; + + if ($prev) { + $percent = $bill['bill_percent']; + $overuse = $bill['bill_overuse']; + } + else { + + } + + if (strtolower($bill['bill_type']) == 'cdr') { + $type = 'CDR'; + $allowed = format_si($bill['bill_allowed']).'bps'; + $in = format_si($bill['rate_95th_in']).'bps'; + $out = format_si($bill['rate_95th_out']).'bps'; + if (!$prev) { + $percent = round((($bill['rate_95th'] / $bill['bill_allowed']) * 100), 2); + $overuse = ($bill['rate_95th'] - $bill['bill_allowed']); + } + + $overuse_formatted = format_si($overuse).'bps'; + $used = $rate_95th; + $rate_95th = "$rate_95th"; + } + else if (strtolower($bill['bill_type']) == 'quota') { + $type = 'Quota'; + $allowed = format_bytes_billing($bill['bill_allowed']); + $in = format_bytes_billing($bill['traf_in']); + $out = format_bytes_billing($bill['traf_out']); + if (!$prev) { + $percent = round((($bill['total_data'] / ($bill['bill_allowed'])) * 100), 2); + $overuse = ($bill['total_data'] - $bill['bill_allowed']); + } + + $overuse_formatted = format_bytes_billing($overuse); + $used = $total_data; + $total_data = "$total_data"; + } + + $background = get_percentage_colours($percent); + $right_background = $background['right']; + $left_background = $background['left']; + $overuse_formatted = (($overuse <= 0) ? '-' : "$overuse_formatted"); + + $bill_name = "${bill['bill_name']}
" . + strftime('%F', strtotime($datefrom)) . " to " . strftime('%F', strtotime($dateto)); + $bar = print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']); + $actions = ""; + + if (!$prev && is_admin()) { + $actions .= " 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'edit')) . + "'>Edit Edit "; + } + + $response[] = array( + 'bill_name' => $bill_name, + 'notes' => $notes, + 'bill_type' => $type, + 'bill_allowed' => $allowed, + 'total_data_in' => $in, + 'total_data_out'=> $out, + 'total_data' => $total_data, + 'rate_95th' => $rate_95th, + 'used' => $used, + 'overusage' => $overuse_formatted, + 'graph' => $bar, + 'actions' => $actions + ); +} + +$output = array('current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total); +echo _json_encode($output); \ No newline at end of file diff --git a/html/pages/bills.inc.php b/html/pages/bills.inc.php index be60dfef63..d2a734dff9 100644 --- a/html/pages/bills.inc.php +++ b/html/pages/bills.inc.php @@ -87,116 +87,90 @@ $pagetitle[] = 'Billing'; echo ""; -if ($vars['view'] == 'history') { - include 'pages/bills/search.inc.php'; - include 'pages/bills/pmonth.inc.php'; -} -else { - include 'pages/bills/search.inc.php'; - include 'includes/modal/new_bill.inc.php'; +include 'includes/modal/new_bill.inc.php'; ?> - - - - - - - - - - - - - bill_cdr) OR (bill_type = 'quota' AND total_data > bill_quota))"; - } +
+
+
Billing nameTypeAllowedUsedOverusage
+ + + + + + + + + + + + + +
Billing nameTypeAllowedInboundOutboundTotal95th PercentileOverusage
+ + + + + + + \ No newline at end of file diff --git a/html/pages/bills/pmonth.inc.php b/html/pages/bills/pmonth.inc.php deleted file mode 100644 index adb6996efa..0000000000 --- a/html/pages/bills/pmonth.inc.php +++ /dev/null @@ -1,98 +0,0 @@ - - - - Billing name - Type - Allowed - Inbound - Outbound - Total - 95 percentile - Overusage - - - - '; - -$wheres = array(); -$params = array(); - -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'])) { - $datefrom = $bill['bill_datefrom']; - $dateto = $bill['bill_dateto']; - - 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']); - - $background = get_percentage_colours($percent); - - 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']).''); - } - - $total_data = (($type == 'Quota') ? ''.$total_data.'' : $total_data); - $rate_95th = (($type == 'CDR') ? ''.$rate_95th.'' : $rate_95th); - - echo " - - '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']).' - '; - - }//end if -}//end foreach - -echo ' -'; diff --git a/html/pages/bills/search.inc.php b/html/pages/bills/search.inc.php deleted file mode 100644 index 3291e3f2fe..0000000000 --- a/html/pages/bills/search.inc.php +++ /dev/null @@ -1,40 +0,0 @@ - - -
-
- Bills - - - - -
-
- Current Billing Period'; -} -else { - echo ' Previous Billing Period'; -} - -?> -= 10) { ?> - - -
-
- -