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(" Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)"); + if ($percent > 100) { $percent = "100"; } + echo(" Billing Period : " . $fromtext . " to " . $totext . " | ![]() |

Customers
Traffic Bills
Traffic Bills
L2TP
Transit
Peering