mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 18:38:25 +00:00
fixes
git-svn-id: http://www.observium.org/svn/observer/trunk@267 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
parent
dfbcda6e93
commit
e146a966b1
@ -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'];
|
||||
|
185
html/includes/billing.php
Normal file
185
html/includes/billing.php
Normal file
@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
function printReport ($bill_id) {
|
||||
|
||||
$bi_q = mysql_query("SELECT * FROM bills WHERE bill_id = $bill_id");
|
||||
$bill_data = mysql_fetch_array($bi_q);
|
||||
|
||||
$today = str_replace("-", "", mysql_result(mysql_query("SELECT CURDATE()"), 0));
|
||||
$yesterday = str_replace("-", "", mysql_result(mysql_query("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)"), 0));
|
||||
$tomorrow = str_replace("-", "", mysql_result(mysql_query("SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)"), 0));
|
||||
$last_month = str_replace("-", "", mysql_result(mysql_query("SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)"), 0));
|
||||
|
||||
$now = $today . date(His);
|
||||
$before = $yesterday . date(His);
|
||||
$lastmonth = $last_month . date(His);
|
||||
|
||||
$bill_name = $bill_data['bill_name'];
|
||||
$dayofmonth = $bill_data['bill_day'];
|
||||
$paidrate = $bill_data['bill_paid_rate'];
|
||||
$paid_kb = $paidrate / 1000;
|
||||
$paid_mb = $paid_kb / 1000;
|
||||
|
||||
if ($paidrate < 1000000) { $paidrate_text = $paid_kb . "Kbps is the CDR."; }
|
||||
if ($paidrate >= 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("<table width=715 border=0 cellspace=0 cellpadding=0><tr><td><font face=\"Verdana, Arial, Sans-Serif\"><h2>
|
||||
" . $bill_name . "</h2>");
|
||||
|
||||
|
||||
echo("<h3>Billed Ports</h3>");
|
||||
|
||||
$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) . "<br />");
|
||||
|
||||
}
|
||||
|
||||
echo("<h3>Bill Summary</h3>");
|
||||
|
||||
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 . "
|
||||
<br />Transferred ".formatStorage($total_data * 1024 * 1024)." of ".formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024)." (".$percent."%)
|
||||
<br />Average rate " . formatRates($rate_average * 1000));
|
||||
if ($percent > 100) { $percent = "100"; }
|
||||
echo("<p><img src='percentage.php?per=$percent&width=350'></p>");
|
||||
|
||||
$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("<strong>" . $fromtext . " to " . $totext . "</strong>
|
||||
<br />Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)");
|
||||
if ($percent > 100) { $percent = "100"; }
|
||||
echo("<p><img src='percentage.php?per=$percent&width=350'></p>");
|
||||
|
||||
# echo("<p>Billing Period : " . $fromtext . " to " . $totext . "<br />
|
||||
# " . $paidrate_text . " <br />
|
||||
# " . $total_data . "MB transfered in the current billing cycle. <br />
|
||||
# " . $rate_average . "Kbps Average during the current billing cycle. </p>
|
||||
# <font face=\"Trebuchet MS, Verdana, Arial, Sans-Serif\" color=" . $bill_color . "><B>" . $rate_95th . "Kbps @ 95th Percentile.</b> (" . $dir_95th . ") (" . $bill_text . ")</font>
|
||||
# </td><td><img src=\"images/billing-key.png\"></td></tr></table>
|
||||
# <br />");
|
||||
|
||||
}
|
||||
|
||||
echo("</td><td><img src='images/billing-key.png'></td></tr></table>");
|
||||
|
||||
$bi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||
$bi = $bi . "&from=" . $unixfrom . "&to=" . $unixto;
|
||||
$bi = $bi . "&x=715&y=250";
|
||||
$bi = $bi . "$type'>";
|
||||
|
||||
$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 = "<img src='billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||
$di = $di . "&from=" . $yesterday . "&to=" . $now . "&x=715&y=250";
|
||||
$di = $di . "$type'>";
|
||||
|
||||
$mi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||
$mi = $mi . "&from=" . $lastmonth . "&to=" . $now . "&x=715&y=250";
|
||||
$mi = $mi . "$type'>";
|
||||
|
||||
if($null) {
|
||||
|
||||
echo("
|
||||
<script type='text/javascript' src='js/calendarDateInput.js'>
|
||||
</script>
|
||||
|
||||
<FORM action='/' method='get'>
|
||||
<INPUT type='hidden' name='bill' value='".$_GET['bill']."'>
|
||||
<INPUT type='hidden' name='code' value='".$_GET['code']."'>
|
||||
<INPUT type='hidden' name='page' value='bills'>
|
||||
<INPUT type='hidden' name='custom' value='yes'>
|
||||
|
||||
From:
|
||||
<script>DateInput('fromdate', true, 'YYYYMMDD')</script>
|
||||
|
||||
To:
|
||||
<script>DateInput('todate', true, 'YYYYMMDD')</script>
|
||||
<INPUT type='submit' value='Generate Graph'>
|
||||
|
||||
</FORM>
|
||||
|
||||
");
|
||||
|
||||
}
|
||||
|
||||
if ($_GET[all]) {
|
||||
$ai = "<img src=\"billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||
$ai = $ai . "&from=0&to=" . $now;
|
||||
$ai = $ai . "&x=715&y=250";
|
||||
$ai = $ai . "&count=60\">";
|
||||
echo("<h3>Entire Data View</h3>$ai");
|
||||
} elseif ($_GET[custom]) {
|
||||
$cg = "<img src=\"billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||
$cg = $cg . "&from=" . $_GET['fromdate'] . "000000&to=" . $_GET['todate'] . "235959";
|
||||
$cg = $cg . "&x=715&y=250";
|
||||
$cg = $cg . "&count=60\">";
|
||||
echo("<h3>Custom Graph</h3>$cg");
|
||||
} else {
|
||||
echo("<h3>Billing View</h3>$bi<h3>24 Hour View</h3>$di");
|
||||
#echo("<h3>Monthly View</h3>$li");
|
||||
#echo("<br /><a href=\"rate.php?" . $_SERVER['QUERY_STRING'] . "&all=yes\">Graph All Data (SLOW)</a>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($_GET['bill'] && billpermitted($_GET['id'])){
|
||||
|
||||
$bill_id = $_GET['bill'];
|
||||
printReport($bill_id);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -117,7 +117,7 @@ if($config['show_locations']) { echo("<li><a class='menu2four' href='locations/'
|
||||
if($_SESSION['userlevel'] >= '5') {
|
||||
echo("<li><hr width=140 /></li>");
|
||||
if($config['int_customers']) { echo("<li><a href='customers/'><img src='images/16/group_link.png' border=0 align=absmiddle> Customers</a></li>"); $ifbreak = 1;}
|
||||
if($config['int_bills']) { echo("<li><a href='bills/'><img src='images/16/money_pound.png' border=0 align=absmiddle> Traffic Bills</a></li>"); $ifbreak = 1;}
|
||||
if($config['enable_billing']) { echo("<li><a href='bills/'><img src='images/16/money_pound.png' border=0 align=absmiddle> Traffic Bills</a></li>"); $ifbreak = 1;}
|
||||
if($config['int_l2tp']) { echo("<li><a href='?page=iftype&type=l2tp'><img src='images/16/user.png'border=0 align=absmiddle> L2TP</a></li>"); $ifbreak = 1; }
|
||||
if($config['int_transit']) { echo("<li><a href='?page=iftype&type=transit'><img src='images/16/world_link.png' border=0 align=absmiddle> Transit</a></li>"); $ifbreak = 1; }
|
||||
if($config['int_peering']) { echo("<li><a href='?page=iftype&type=peering'><img src='images/16/bug_link.png' border=0 align=absmiddle> Peering</a></li>"); $ifbreak = 1; }
|
||||
|
Loading…
Reference in New Issue
Block a user