mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 18:38:25 +00:00
billing system fixes (make moar sexypants)
git-svn-id: http://www.observium.org/svn/observer/trunk@1592 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
parent
7c3c0cfbe2
commit
dacdaf7267
@ -11,14 +11,16 @@ if($_GET['debug']) {
|
|||||||
include("../includes/defaults.inc.php");
|
include("../includes/defaults.inc.php");
|
||||||
include("../config.php");
|
include("../config.php");
|
||||||
include("../includes/functions.php");
|
include("../includes/functions.php");
|
||||||
|
include("includes/functions.inc.php");
|
||||||
include("includes/authenticate.inc.php");
|
include("includes/authenticate.inc.php");
|
||||||
if(!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
|
if(!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
|
||||||
require("includes/jpgraph/src/jpgraph.php");
|
require("includes/jpgraph/src/jpgraph.php");
|
||||||
include("includes/jpgraph/src/jpgraph_line.php");
|
include("includes/jpgraph/src/jpgraph_line.php");
|
||||||
include("includes/jpgraph/src/jpgraph_utils.inc.php");
|
include("includes/jpgraph/src/jpgraph_utils.inc.php");
|
||||||
|
|
||||||
if($_GET['bill_id']){
|
if(is_numeric($_GET['bill_id'])){
|
||||||
if(testPassword($_GET['bill_id'],$_GET['bill_code']) == "1") {
|
if(bill_permitted($_GET['bill_id']))
|
||||||
|
{
|
||||||
$bill_id = $_GET['bill_id'];
|
$bill_id = $_GET['bill_id'];
|
||||||
} else {
|
} else {
|
||||||
echo("Unauthorised Access Prohibited.");
|
echo("Unauthorised Access Prohibited.");
|
||||||
@ -76,7 +78,6 @@ $i = '0';
|
|||||||
|
|
||||||
#$start = mysql_result(mysql_query("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >=$datefrom AND timestamp <= $dateto ORDER BY timestamp ASC LIMIT 0,1"),0);
|
#$start = mysql_result(mysql_query("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >=$datefrom AND timestamp <= $dateto ORDER BY timestamp ASC LIMIT 0,1"),0);
|
||||||
#$end = mysql_result(mysql_query("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >=$datefrom AND timestamp <= $dateto ORDER BY timestamp DESC LIMIT 0,1"),0);
|
#$end = mysql_result(mysql_query("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >=$datefrom AND timestamp <= $dateto ORDER BY timestamp DESC LIMIT 0,1"),0);
|
||||||
|
|
||||||
$dur = $end - $start;
|
$dur = $end - $start;
|
||||||
|
|
||||||
$sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >= $datefrom AND timestamp <= $dateto ORDER BY timestamp ASC";
|
$sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = $bill_id AND timestamp >= $datefrom AND timestamp <= $dateto ORDER BY timestamp ASC";
|
||||||
@ -96,7 +97,7 @@ while($row = mysql_fetch_array($data))
|
|||||||
#@$data[] = $in_value + $out_value;
|
#@$data[] = $in_value + $out_value;
|
||||||
#@$in_data[] = $in_value;
|
#@$in_data[] = $in_value;
|
||||||
#@$out_data[] = $out_value;
|
#@$out_data[] = $out_value;
|
||||||
#@$ticks[] = $timestamp;
|
# @$ticks[] = $timestamp;
|
||||||
#@$per_data[] = $rate_95th / 1000;
|
#@$per_data[] = $rate_95th / 1000;
|
||||||
#@$ave_data[] = $rate_average / 1000;
|
#@$ave_data[] = $rate_average / 1000;
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ while($row = mysql_fetch_array($data))
|
|||||||
$out_data[$i] = round($iter_out * 8 / $iter_period / $div, 2);
|
$out_data[$i] = round($iter_out * 8 / $iter_period / $div, 2);
|
||||||
$in_data[$i] = round($iter_in * 8 / $iter_period / $div, 2);
|
$in_data[$i] = round($iter_in * 8 / $iter_period / $div, 2);
|
||||||
$tot_data[$i] = $out_data[$i] + $in_data[$i];
|
$tot_data[$i] = $out_data[$i] + $in_data[$i];
|
||||||
# $ticks[$i] = date('M j g:ia', $timestamp);
|
$ticks[$i] = date('M j g:ia', $timestamp);
|
||||||
$ticks[$i] = $timestamp;
|
$ticks[$i] = $timestamp;
|
||||||
|
|
||||||
if($dur < 172800) {
|
if($dur < 172800) {
|
||||||
@ -170,10 +171,10 @@ $graph->title->Set("$graph_name");
|
|||||||
$graph->title->SetFont(FF_FONT2,FS_BOLD,10);
|
$graph->title->SetFont(FF_FONT2,FS_BOLD,10);
|
||||||
$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
|
$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
|
||||||
|
|
||||||
$graph->xaxis->SetTickLabels($ticks);
|
#$graph->xaxis->SetTickLabels($ticks);
|
||||||
|
|
||||||
if(count($tickPositions) > 24) {
|
if(count($tickPositions) > 24) {
|
||||||
$graph->xaxis->SetTextLabelInterval(3);
|
$graph->xaxis->SetTextLabelInterval(6);
|
||||||
}elseif(count($tickPositions) > 12) {
|
}elseif(count($tickPositions) > 12) {
|
||||||
$graph->xaxis->SetTextLabelInterval(2);
|
$graph->xaxis->SetTextLabelInterval(2);
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,8 @@ if (isset($_SESSION['username']))
|
|||||||
setcookie("username", $_SESSION['username'], time()+60*60*24*100, "/");
|
setcookie("username", $_SESSION['username'], time()+60*60*24*100, "/");
|
||||||
setcookie("password", $_SESSION['password'], time()+60*60*24*100, "/");
|
setcookie("password", $_SESSION['password'], time()+60*60*24*100, "/");
|
||||||
}
|
}
|
||||||
|
$permissions = permissions_cache($_SESSION['user_id']);
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif (isset($_SESSION['username']))
|
elseif (isset($_SESSION['username']))
|
||||||
{
|
{
|
||||||
|
@ -125,7 +125,8 @@ function print_graph_popup($graph_array)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function permissions_cache($user_id) {
|
function permissions_cache($user_id)
|
||||||
|
{
|
||||||
$permissions = array();
|
$permissions = array();
|
||||||
$query = mysql_query("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'");
|
$query = mysql_query("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'");
|
||||||
while($device = mysql_fetch_assoc($query)) {
|
while($device = mysql_fetch_assoc($query)) {
|
||||||
@ -135,9 +136,26 @@ function permissions_cache($user_id) {
|
|||||||
while($port = mysql_fetch_assoc($query)) {
|
while($port = mysql_fetch_assoc($query)) {
|
||||||
$permissions['port'][$port['interface_id']] = 1;
|
$permissions['port'][$port['interface_id']] = 1;
|
||||||
}
|
}
|
||||||
|
$query = mysql_query("SELECT * FROM bill_perms WHERE user_id = '".$user_id."'");
|
||||||
|
while($bill = mysql_fetch_assoc($query)) {
|
||||||
|
$permissions['bill'][$bill['bill_id']] = 1;
|
||||||
|
}
|
||||||
return $permissions;
|
return $permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bill_permitted($bill_id)
|
||||||
|
{
|
||||||
|
global $_SESSION; global $permissions;
|
||||||
|
if ($_SESSION['userlevel'] >= "5") {
|
||||||
|
$allowed = TRUE;
|
||||||
|
} elseif ( $permissions['bill'][$bill_id]) {
|
||||||
|
$allowed = TRUE;
|
||||||
|
} else {
|
||||||
|
$allowed = FALSE;
|
||||||
|
}
|
||||||
|
return $allowed;
|
||||||
|
|
||||||
|
}
|
||||||
function interfacepermitted($interface_id, $device_id = NULL)
|
function interfacepermitted($interface_id, $device_id = NULL)
|
||||||
{
|
{
|
||||||
global $_SESSION; global $permissions;
|
global $_SESSION; global $permissions;
|
||||||
|
17
html/includes/graphs/bill/auth.inc.php
Normal file
17
html/includes/graphs/bill/auth.inc.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
### Authorises bill viewing and sets $ports as reference to mysql query containing ports for this bill
|
||||||
|
|
||||||
|
if(is_numeric($_GET['id']) && bill_permitted($_GET['id']))
|
||||||
|
{
|
||||||
|
|
||||||
|
$ports = mysql_query("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
|
||||||
|
WHERE B.bill_id = '".mres($_GET['id'])."' AND P.interface_id = B.port_id
|
||||||
|
AND D.device_id = P.device_id");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
echo("Unauthorised");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
28
html/includes/graphs/bill/bits.inc.php
Normal file
28
html/includes/graphs/bill/bits.inc.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
## Generate a list of ports and then call the multi_bits grapher to generate from the list
|
||||||
|
|
||||||
|
$i=0;
|
||||||
|
while($port = mysql_fetch_array($ports)) {
|
||||||
|
if(is_file($config['rrd_dir'] . "/" . $port['hostname'] . "/" . safename($port['ifIndex'] . ".rrd"))) {
|
||||||
|
$rrd_list[$i]['filename'] = $config['rrd_dir'] . "/" . $port['hostname'] . "/" . safename($port['ifIndex'] . ".rrd");
|
||||||
|
$rrd_list[$i]['descr'] = $port['ifDescr'];
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$units='bps';
|
||||||
|
$total_units='B';
|
||||||
|
$colours_in='greens';
|
||||||
|
$multiplier = "8";
|
||||||
|
$colours_out = 'blues';
|
||||||
|
|
||||||
|
$nototal = 1;
|
||||||
|
$rra_in = "INOCTETS";
|
||||||
|
$rra_out = "OUTOCTETS";
|
||||||
|
|
||||||
|
include ("includes/graphs/generic_multi_bits_separated.inc.php");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
@ -17,10 +17,6 @@ if(strpos($_SERVER['REQUEST_URI'], "debug")) {
|
|||||||
include("../includes/functions.php");
|
include("../includes/functions.php");
|
||||||
include("includes/functions.inc.php");
|
include("includes/functions.inc.php");
|
||||||
include("includes/authenticate.inc.php");
|
include("includes/authenticate.inc.php");
|
||||||
if($_SESSION['authenticated']) {
|
|
||||||
# Load permissions used my devicepermitted() and interfacepermitted()
|
|
||||||
$permissions = permissions_cache($_SESSION['user_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$start = utime();
|
$start = utime();
|
||||||
$now = time();
|
$now = time();
|
||||||
|
@ -1,202 +1,245 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$bill_id = mres($_GET['opta']);
|
$bill_id = mres($_GET['opta']);
|
||||||
|
|
||||||
|
if(bill_permitted($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));
|
||||||
|
|
||||||
|
$rightnow = $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("<font face=\"Verdana, Arial, Sans-Serif\"><h2>
|
||||||
|
" . $bill_name . "</h2>");
|
||||||
|
|
||||||
|
print_optionbar_start();
|
||||||
|
|
||||||
|
if(!$_GET['optb']) { $_GET['optb'] = "details"; }
|
||||||
|
|
||||||
|
if($_GET['optb'] == "details") { echo("<strong>"); }
|
||||||
|
echo("<a href='".$config['base_url']."/bill/".$bill_id."/details/'>Details</a>");
|
||||||
|
if($_GET['optb'] == "details") { echo("</strong>"); }
|
||||||
|
|
||||||
|
echo(" | ");
|
||||||
|
if($_GET['optb'] == "edit") { echo("<strong>"); }
|
||||||
|
echo("<a href='".$config['base_url']."/bill/".$bill_id."/edit/'>Edit</a>");
|
||||||
|
if($_GET['optb'] == "edit") { echo("</strong>"); }
|
||||||
|
|
||||||
|
print_optionbar_end();
|
||||||
|
|
||||||
|
echo("<table width=715 border=0 cellspace=0 cellpadding=0><tr><td>");
|
||||||
|
|
||||||
|
|
||||||
|
if($_GET['optb'] == "edit") {
|
||||||
|
|
||||||
|
include("pages/bill/edit.php");
|
||||||
|
|
||||||
|
}elseif($_GET['optb'] == "details") {
|
||||||
|
|
||||||
|
|
||||||
|
echo("<h3>Billed Ports</h3>");
|
||||||
|
|
||||||
|
$ports = mysql_query("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
|
||||||
|
WHERE B.bill_id = '".$bill_id."' AND P.interface_id = B.port_id
|
||||||
|
AND D.device_id = P.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
|
||||||
|
|
||||||
|
echo("<h4>Quota Bill</h4>");
|
||||||
|
|
||||||
|
$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) { $perc = "100"; } else { $perc = $percent; }
|
||||||
|
if($perc > '90') { $left_background='c4323f'; $right_background='C96A73';
|
||||||
|
} elseif($perc > '75') { $left_background='bf5d5b'; $right_background='d39392';
|
||||||
|
} elseif($perc > '50') { $left_background='bf875b'; $right_background='d3ae92';
|
||||||
|
} elseif($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3';
|
||||||
|
} else { $left_background='9abf5b'; $right_background='bbd392'; }
|
||||||
|
|
||||||
|
echo("<p>".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."</p>");
|
||||||
|
|
||||||
|
$type="&ave=yes";
|
||||||
|
|
||||||
|
|
||||||
|
} elseif($bill_data['bill_type'] == "cdr") {
|
||||||
|
|
||||||
|
// The customer is billed based on a CDR with 95th%ile overage
|
||||||
|
|
||||||
|
echo("<h4>CDR / 95th Bill</h4>");
|
||||||
|
|
||||||
|
$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) { $perc = "100"; } else { $perc = $percent; }
|
||||||
|
if($perc > '90') { $left_background='c4323f'; $right_background='C96A73';
|
||||||
|
} elseif($perc > '75') { $left_background='bf5d5b'; $right_background='d39392';
|
||||||
|
} elseif($perc > '50') { $left_background='bf875b'; $right_background='d3ae92';
|
||||||
|
} elseif($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3';
|
||||||
|
} else { $left_background='9abf5b'; $right_background='bbd392'; }
|
||||||
|
|
||||||
|
echo("<p>".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."</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'>";
|
||||||
|
|
||||||
|
$bi = "<img src='graph.php?type=bill_bits&id=" . $bill_id;
|
||||||
|
$bi = $bi . "&from=" . $unixfrom . "&to=" . $unixto;
|
||||||
|
$bi = $bi . "&width=715&height=200&total=1'>";
|
||||||
|
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$rightnow = date(U);
|
||||||
|
|
||||||
|
# $di = "<img src='".$config['base_url']."/billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||||
|
# $di = $di . "&from=" . $yesterday . "&to=" . $rightnow . "&x=715&y=250";
|
||||||
|
# $di = $di . "$type'>";
|
||||||
|
|
||||||
|
$di = "<img src='graph.php?type=bill_bits&id=" . $bill_id;
|
||||||
|
$di = $di . "&from=" . $config['day'] . "&to=" . $config['now'];
|
||||||
|
$di = $di . "&width=715&height=200&total=1'>";
|
||||||
|
|
||||||
|
|
||||||
|
# $mi = "<img src='".$config['base_url']."/billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||||
|
# $mi = $mi . "&from=" . $lastmonth . "&to=" . $rightnow . "&x=715&y=250";
|
||||||
|
# $mi = $mi . "$type'>";
|
||||||
|
|
||||||
|
$mi = "<img src='graph.php?type=bill_bits&id=" . $bill_id;
|
||||||
|
$mi = $mi . "&from=" . $lastmonth . "&to=" . $rightnow;
|
||||||
|
$mi = $mi . "&width=715&height=200&total=1'>";
|
||||||
|
|
||||||
|
|
||||||
$bi_q = mysql_query("SELECT * FROM bills WHERE bill_id = $bill_id");
|
if($null) {
|
||||||
$bill_data = mysql_fetch_array($bi_q);
|
|
||||||
|
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=" . $rightnow;
|
||||||
|
$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>$mi");
|
||||||
|
# echo("<br /><a href=\"rate.php?" . $_SERVER['QUERY_STRING'] . "&all=yes\">Graph All Data (SLOW)</a>");
|
||||||
|
}
|
||||||
|
|
||||||
|
} # End if details
|
||||||
|
|
||||||
$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));
|
|
||||||
|
|
||||||
$rightnow = $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 {
|
} 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);
|
include("includes/error-no-perm.inc.php");
|
||||||
$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("<font face=\"Verdana, Arial, Sans-Serif\"><h2>
|
|
||||||
" . $bill_name . "</h2>");
|
|
||||||
|
|
||||||
print_optionbar_start();
|
|
||||||
|
|
||||||
if(!$_GET['optb']) { $_GET['optb'] = "details"; }
|
|
||||||
|
|
||||||
if($_GET['optb'] == "details") { echo("<strong>"); }
|
|
||||||
echo("<a href='".$config['base_url']."/bill/".$bill_id."/details/'>Details</a>");
|
|
||||||
if($_GET['optb'] == "details") { echo("</strong>"); }
|
|
||||||
|
|
||||||
echo(" | ");
|
|
||||||
if($_GET['optb'] == "edit") { echo("<strong>"); }
|
|
||||||
echo("<a href='".$config['base_url']."/bill/".$bill_id."/edit/'>Edit</a>");
|
|
||||||
if($_GET['optb'] == "edit") { echo("</strong>"); }
|
|
||||||
|
|
||||||
print_optionbar_end();
|
|
||||||
|
|
||||||
echo("<table width=715 border=0 cellspace=0 cellpadding=0><tr><td>");
|
|
||||||
|
|
||||||
|
|
||||||
if($_GET['optb'] == "edit") {
|
|
||||||
|
|
||||||
include("pages/bill/edit.php");
|
|
||||||
|
|
||||||
}elseif($_GET['optb'] == "details") {
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
$rightnow = date(U);
|
|
||||||
|
|
||||||
$di = "<img src='".$config['base_url']."/billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
|
||||||
$di = $di . "&from=" . $yesterday . "&to=" . $rightnow . "&x=715&y=250";
|
|
||||||
$di = $di . "$type'>";
|
|
||||||
|
|
||||||
$mi = "<img src='".$config['base_url']."/billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
|
||||||
$mi = $mi . "&from=" . $lastmonth . "&to=" . $rightnow . "&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=" . $rightnow;
|
|
||||||
$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>");
|
|
||||||
}
|
|
||||||
|
|
||||||
} # End if details
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,6 +127,10 @@ print_optionbar_end();
|
|||||||
echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>");
|
echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>");
|
||||||
$i=1;
|
$i=1;
|
||||||
while($bill = mysql_fetch_array($query)) {
|
while($bill = mysql_fetch_array($query)) {
|
||||||
|
#echo("<pre>");
|
||||||
|
#print_r($permissions);
|
||||||
|
#echo("</pre>");
|
||||||
|
if(bill_permitted($bill['bill_id'])) {
|
||||||
unset($class);
|
unset($class);
|
||||||
$day_data = getDates($bill['bill_day']);
|
$day_data = getDates($bill['bill_day']);
|
||||||
$datefrom = $day_data['0'];
|
$datefrom = $day_data['0'];
|
||||||
@ -148,6 +152,14 @@ print_optionbar_end();
|
|||||||
$used = formatStorage($rate_data['total_data'] * 1024 * 1024);
|
$used = formatStorage($rate_data['total_data'] * 1024 * 1024);
|
||||||
$percent = round(($rate_data['total_data'] / ($bill['bill_gb'] * 1024)) * 100,2);
|
$percent = round(($rate_data['total_data'] / ($bill['bill_gb'] * 1024)) * 100,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($percent > 100) { $perc = "100"; } else { $perc = $percent; }
|
||||||
|
if($perc > '90') { $left_background='c4323f'; $right_background='C96A73';
|
||||||
|
} elseif($perc > '75') { $left_background='bf5d5b'; $right_background='d39392';
|
||||||
|
} elseif($perc > '50') { $left_background='bf875b'; $right_background='d3ae92';
|
||||||
|
} elseif($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3';
|
||||||
|
} else { $left_background='9abf5b'; $right_background='bbd392'; }
|
||||||
|
|
||||||
if(!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
|
if(!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
|
||||||
echo("
|
echo("
|
||||||
<tr bgcolor='$row_colour'>
|
<tr bgcolor='$row_colour'>
|
||||||
@ -157,12 +169,12 @@ print_optionbar_end();
|
|||||||
<td>$type</td>
|
<td>$type</td>
|
||||||
<td>$allowed</td>
|
<td>$allowed</td>
|
||||||
<td>$used</td>
|
<td>$used</td>
|
||||||
<td><img src='percentage.php?width=350&per=$percent'> $percent%</td>
|
<td width=370>".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."</td>
|
||||||
<td></td>
|
<td width=60><a href='".$config['base_url']."/bill/".$bill['bill_id']."/edit/'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a></td>
|
||||||
<td width=60><a href='".$config['base_url']."/bill/".$bill['bill_id']."/edit/'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
");
|
");
|
||||||
$i++;
|
$i++;
|
||||||
|
} ### PERMITTED
|
||||||
}
|
}
|
||||||
echo("</table>");
|
echo("</table>");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user