From e146a966b1b833207d9f37830ebf13f48f414889 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Mon, 3 Nov 2008 14:40:54 +0000 Subject: [PATCH] fixes git-svn-id: http://www.observium.org/svn/observer/trunk@267 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/billing-graph.php | 4 +- html/includes/billing.php | 185 ++++++++++++++++++++++++++++++++ html/includes/print-menubar.php | 2 +- 3 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 html/includes/billing.php diff --git a/html/billing-graph.php b/html/billing-graph.php index d0da35077..b7c501082 100644 --- a/html/billing-graph.php +++ b/html/billing-graph.php @@ -7,7 +7,6 @@ include("../config.php"); include("../includes/functions.php"); -#include("chart.php"); require("includes/jpgraph/jpgraph.php"); include("includes/jpgraph/jpgraph_line.php"); include("includes/jpgraph/jpgraph_utils.inc.php"); @@ -52,7 +51,7 @@ $bi_q = mysql_query("SELECT * FROM bills WHERE bill_id = $bill_id"); $bi_a = mysql_fetch_array($bi_q); $bill_name = $bi_a['bill_name']; -$countsql = mysql_query("SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id AND timestamp >= $datefrom AND timestamp <= $dateto"); +$countsql = mysql_query("SELECT count(`delta`) FROM `bill_data` WHERE `bill_id` = '$bill_id' AND `timestamp` >= '$datefrom' AND `timestamp` <= '$dateto'"); $counttot = mysql_result($countsql,0); $count = round($counttot / (($ysize - 100) * 2), 0); @@ -78,6 +77,7 @@ $sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHE $data = mysql_query($sql); while($row = mysql_fetch_array($data)) { + @$timestamp = $row['formatted_date']; if (!$first) { $first = $timestamp; } @$delta = $row['delta']; diff --git a/html/includes/billing.php b/html/includes/billing.php new file mode 100644 index 000000000..1c345f5f0 --- /dev/null +++ b/html/includes/billing.php @@ -0,0 +1,185 @@ += 1000000) { $paidrate_text = $paid_mb . "Mbps is the CDR."; } + +$day_data = getDates($dayofmonth); +$datefrom = $day_data['0']; +$dateto = $day_data['1']; +$rate_data = getRates($bill_id,$datefrom,$dateto); +$rate_95th = $rate_data['rate_95th']; +$dir_95th = $rate_data['dir_95th']; +$total_data = $rate_data['total_data']; +$rate_average = $rate_data['rate_average']; + +if ($rate_95th > $paid_kb) { + $over = $rate_95th - $paid_kb; + $bill_text = $over . "Kbit excess."; + $bill_color = "#cc0000"; +} else { + $under = $paid_kb - $rate_95th; + $bill_text = $under . "Kbit headroom."; + $bill_color = "#0000cc"; +} + +$fromtext = mysql_result(mysql_query("SELECT DATE_FORMAT($datefrom, '%M %D %Y')"), 0); +$totext = mysql_result(mysql_query("SELECT DATE_FORMAT($dateto, '%M %D %Y')"), 0); +$unixfrom = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP('$datefrom')"), 0); +$unixto = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP('$dateto')"), 0); + +echo("

+" . $bill_name . "

"); + + +echo("

Billed Ports

"); + +$ports = mysql_query("SELECT * FROM interfaces AS I, devices AS D, bill_ports as B WHERE B.bill_id = '$bill_id' AND B.port_id = I.interface_id AND I.device_id = D.device_id"); + +while ($port = mysql_fetch_array($ports)) { + + echo(generateiflink($port) . " on " . generatedevicelink($port) . "
"); + +} + +echo("

Bill Summary

"); + +if($bill_data['bill_type'] == "quota") { + + // The Customer is billed based on a pre-paid quota + + $percent = round(($total_data / 1024) / $bill_data['bill_gb'] * 100, 2); + $unit = "MB"; + $total_data = round($total_data, 2); + echo("Billing Period from " . $fromtext . " to " . $totext . " +
Transferred ".formatStorage($total_data * 1024 * 1024)." of ".formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024)." (".$percent."%) +
Average rate " . formatRates($rate_average * 1000)); + if ($percent > 100) { $percent = "100"; } + echo("

"); + + $type="&ave=yes"; + + +} elseif($bill_data['bill_type'] == "cdr") { + + // The customer is billed based on a CDR with 95th%ile overage + + $unit = "kbps"; + $cdr = $bill_data['bill_cdr']; + if($rate_95th > "1000") { $rate_95th = $rate_95th / 1000; $cdr = $cdr / 1000; $unit = "Mbps"; } + if($rate_95th > "1000") { $rate_95th = $rate_95th / 1000; $cdr = $cdr / 1000; $unit = "Gps"; } + $rate_95th = round($rate_95th, 2); + + $percent = round(($rate_95th) / $cdr * 100, 2); + + $type="&95th=yes"; + + + echo("" . $fromtext . " to " . $totext . " +
Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)"); + if ($percent > 100) { $percent = "100"; } + echo("

"); + +# echo("

Billing Period : " . $fromtext . " to " . $totext . "
+# " . $paidrate_text . "
+# " . $total_data . "MB transfered in the current billing cycle.
+# " . $rate_average . "Kbps Average during the current billing cycle.

+# " . $rate_95th . "Kbps @ 95th Percentile. (" . $dir_95th . ") (" . $bill_text . ") +#
+#
"); + +} + +echo(""); + +$bi = ""; + +$lastmonth = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"), 0); +$yesterday = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))"), 0); +$now = date(U); + +$di = ""; + +$mi = ""; + +if($null) { + +echo(" + + +
+ + + + + + From: + + + To: + + + +
+ +"); + +} + + if ($_GET[all]) { + $ai = ""; + echo("

Entire Data View

$ai"); + } elseif ($_GET[custom]) { + $cg = ""; + echo("

Custom Graph

$cg"); + } else { + echo("

Billing View

$bi

24 Hour View

$di"); + #echo("

Monthly View

$li"); + #echo("
Graph All Data (SLOW)"); + } +} + + + +if($_GET['bill'] && billpermitted($_GET['id'])){ + + $bill_id = $_GET['bill']; + printReport($bill_id); + +} + +?> + diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 477fd47dc..8da6a73bc 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -117,7 +117,7 @@ if($config['show_locations']) { echo("
  • = '5') { echo("

  • "); if($config['int_customers']) { echo("
  • Customers
  • "); $ifbreak = 1;} - if($config['int_bills']) { echo("
  • Traffic Bills
  • "); $ifbreak = 1;} + if($config['enable_billing']) { echo("
  • Traffic Bills
  • "); $ifbreak = 1;} if($config['int_l2tp']) { echo("
  • L2TP
  • "); $ifbreak = 1; } if($config['int_transit']) { echo("
  • Transit
  • "); $ifbreak = 1; } if($config['int_peering']) { echo("
  • Peering
  • "); $ifbreak = 1; }