improved billing

git-svn-id: http://www.observium.org/svn/observer/trunk@2752 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong 2011-12-02 15:53:50 +00:00
parent 4c497337c2
commit 05e0d54677
5 changed files with 108 additions and 51 deletions

View File

@ -47,7 +47,7 @@
// $dur = $end - $start;
// $datefrom = date('Ymthis', $start);
// $dateto = date('Ymthis', $end);
$imgtype = (isset($_GET['imgtype']) ? $_GET['imgtype'] : "historical" );
$imgtype = (isset($_GET['type']) ? $_GET['type'] : "historical" );
$imgbill = (isset($_GET['imgbill']) ? $_GET['imgbill'] : false);
$yaxistitle = "Bytes";
@ -218,7 +218,7 @@
$gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out, $barplot_over));
} else {
$lineplot_allow = new LinePlot($ave_data);
$lineplot_allow->SetLegend("Average per day");
$lineplot_allow->SetLegend("Average per ".$imgtype);
$lineplot_allow->SetColor('black');
$lineplot_allow->SetWeight(1);

View File

@ -278,22 +278,29 @@ if (bill_permitted($bill_id))
if ($_GET['optb'] == "details") {
$bi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$bi = $bi . "&amp;from=" . $unixfrom . "&amp;to=" . $unixto;
$bi = $bi . "&amp;x=800&amp;y=250";
$bi = $bi . "$type'>";
$bi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$bi .= "&amp;from=" . $unixfrom . "&amp;to=" . $unixto;
// $bi .= "&amp;x=800&amp;y=250";
$bi .= "&amp;x=1190&amp;y=250";
$bi .= "$type'>";
$li = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$li = $li . "&amp;from=" . $unix_prev_from . "&amp;to=" . $unix_prev_to . "&amp;x=800&amp;y=250";
$li = $li . "$type'>";
$li = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$li .= "&amp;from=" . $unix_prev_from . "&amp;to=" . $unix_prev_to;
// $li .= "&amp;x=800&amp;y=250";
$li .= "&amp;x=1190&amp;y=250";
$li .= "$type'>";
$di = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$di = $di . "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'] . "&amp;x=800&amp;y=250";
$di = $di . "$type'>";
$di = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$di .= "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'];
// $di .= "&amp;x=800&amp;y=250";
$di .= "&amp;x=1190&amp;y=250";
$di .= "$type'>";
$mi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$mi = $mi . "&amp;from=" . $lastmonth . "&amp;to=" . $rightnow . "&amp;x=800&amp;y=250";
$mi = $mi . "$type'>";
$mi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$mi .= "&amp;from=" . $lastmonth . "&amp;to=" . $rightnow;
// $mi .= "&amp;x=800&amp;y=250";
$mi .= "&amp;x=1190&amp;y=250";
$mi .= "$type'>";
} else {

View File

@ -3,6 +3,7 @@
$pagetitle[] = "Bandwidth Graphs";
$bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id));
$gbconvert = $config['billing']['base'];
$today = str_replace("-", "", dbFetchCell("SELECT CURDATE()"));
$tomorrow = str_replace("-", "", dbFetchCell("SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)"));
@ -47,38 +48,38 @@
$cur_days = date('d', (strtotime("now") - strtotime($datefrom)));
$total_days = date('d', (strtotime($dateto) - strtotime($datefrom)));
$total['data'] = formatStorage($bill_data['total_data'] * 1024 * 1024);
$total['data'] = formatStorage($bill_data['total_data'] * $gbconvert * $gbconvert);
if ($bill_data['bill_type'] == "quota") {
$total['allow'] = formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024);
$total['allow'] = formatStorage($bill_data['bill_gb'] * $gbconvert * $gbconvert * $gbconvert);
} else {
$total['allow'] = "-";
}
$total['ave'] = formatStorage(($bill_data['total_data'] / $cur_days) * 1024 * 1024);
$total['est'] = formatStorage(($bill_data['total_data'] / $cur_days * $total_days) * 1024 * 1024);
$total['per'] = round((($bill_data['total_data'] / 1024) / $bill_data['bill_gb'] * 100), 2);
$total['ave'] = formatStorage(($bill_data['total_data'] / $cur_days) * $gbconvert * $gbconvert);
$total['est'] = formatStorage(($bill_data['total_data'] / $cur_days * $total_days) * $gbconvert * $gbconvert);
$total['per'] = round((($bill_data['total_data'] / $gbconvert) / $bill_data['bill_gb'] * 100), 2);
$total['bg'] = get_percentage_colours($total['per']);
$in['data'] = formatStorage($bill_data['total_data_in'] * 1024 * 1024);
$in['data'] = formatStorage($bill_data['total_data_in'] * $gbconvert * $gbconvert);
$in['allow'] = $total['data'];
$in['ave'] = formatStorage(($bill_data['total_data_in'] / $cur_days) * 1024 * 1024);
$in['est'] = formatStorage(($bill_data['total_data_in'] / $cur_days * $total_days) * 1024 * 1024);
$in['ave'] = formatStorage(($bill_data['total_data_in'] / $cur_days) * $gbconvert * $gbconvert);
$in['est'] = formatStorage(($bill_data['total_data_in'] / $cur_days * $total_days) * $gbconvert * $gbconvert);
$in['per'] = round(($bill_data['total_data_in'] / $bill_data['total_data'] * 100), 2);
$in['bg'] = get_percentage_colours($in['per']);
$out['data'] = formatStorage($bill_data['total_data_out'] * 1024 * 1024);
$out['data'] = formatStorage($bill_data['total_data_out'] * $gbconvert * $gbconvert);
$out['allow'] = $total['data'];
$out['ave'] = formatStorage(($bill_data['total_data_out'] / $cur_days) * 1024 * 1024);
$out['est'] = formatStorage(($bill_data['total_data_out'] / $cur_days * $total_days) * 1024 * 1024);
$out['ave'] = formatStorage(($bill_data['total_data_out'] / $cur_days) * $gbconvert * $gbconvert);
$out['est'] = formatStorage(($bill_data['total_data_out'] / $cur_days * $total_days) * $gbconvert * $gbconvert);
$out['per'] = round(($bill_data['total_data_out'] / $bill_data['total_data'] * 100), 2);
$out['bg'] = get_percentage_colours($out['per']);
$ousage['over'] = $bill_data['total_data'] - ($bill_data['bill_gb'] * 1024);
$ousage['over'] = $bill_data['total_data'] - ($bill_data['bill_gb'] * $gbconvert);
$ousage['over'] = (($ousage['over'] < 0) ? "0" : $ousage['over']);
$ousage['data'] = formatStorage($ousage['over'] * 1024 * 1024);
$ousage['data'] = formatStorage($ousage['over'] * $gbconvert * $gbconvert);
$ousage['allow'] = $total['allow'];
$ousage['ave'] = formatStorage(($ousage['over'] / $cur_days ) * 1024 * 1024);
$ousage['est'] = formatStorage(($ousage['over'] / $cur_days * $total_days) * 1024 * 1024);
$ousage['per'] = round(((($bill_data['total_data'] / 1024) / $bill_data['bill_gb'] * 100) - 100), 2);
$ousage['ave'] = formatStorage(($ousage['over'] / $cur_days ) * $gbconvert * $gbconvert);
$ousage['est'] = formatStorage(($ousage['over'] / $cur_days * $total_days) * $gbconvert * $gbconvert);
$ousage['per'] = round(((($bill_data['total_data'] / $gbconvert) / $bill_data['bill_gb'] * 100) - 100), 2);
$ousage['per'] = (($ousage['per'] < 0) ? "0" : $ousage['per']);
$ousage['bg'] = get_percentage_colours($ousage['per']);
@ -144,25 +145,25 @@
$bi = "<img src='bandwidth-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$bi .= "&amp;from=" . $unixfrom . "&amp;to=" . $unixto;
$bi .= "&amp;imgtype=day&imgbill=1";
$bi .= "&amp;type=day&imgbill=1";
$bi .= "&amp;x=1190&amp;y=250";
$bi .= "$type'>";
$li = "<img src='bandwidth-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$li .= "&amp;from=" . $unix_prev_from . "&amp;to=" . $unix_prev_to;
$li .= "&amp;imgtype=day";
$li .= "&amp;type=day";
$li .= "&amp;x=1190&amp;y=250";
$li .= "$type'>";
$di = "<img src='bandwidth-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$di .= "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'];
$di .= "&amp;imgtype=hour";
$di .= "&amp;type=hour";
$di .= "&amp;x=1190&amp;y=250";
$di .= "$type'>";
$mi = "<img src='bandwidth-graph.php?bill_id=" . $bill_id . "&amp;bill_code=" . $_GET['bill_code'];
$mi .= "&amp;from=" . $lastmonth . "&amp;to=" . $rightnow;
$mi .= "&amp;&imgtype=day";
$mi .= "&amp;&type=day";
$mi .= "&amp;x=1190&amp;y=250";
$mi .= "$type'>";

View File

@ -1,19 +1,46 @@
<?php
$pagetitle[] = "Historical Usage";
$i=0;
$detail = (isset($_GET['detail']) ? $_GET['detail'] : "");
$url = $PHP_SELF."/bill/".$bill_id."/history/";
$i = 0;
$img = "<img src=\"bandwidth-graph.php?bill_id=".$bill_id;
$img .= "&amp;imgtype=historical";
$img .= "&amp;x=1190&amp;y=250";
$img .= "\" style=\"margin: 15px 5px 25px 5px;\" />";
$gbconvert = $config['billing']['base'];
echo($img);
$img['his'] = "<img src=\"bandwidth-graph.php?bill_id=".$bill_id;
$img['his'] .= "&amp;type=historical";
$img['his'] .= "&amp;x=1190&amp;y=250";
$img['his'] .= "\" style=\"margin: 15px 5px 25px 5px;\" />";
echo($img['his']);
function showDetails($id, $imgtype, $from, $to, $bittype = "Quota")
{
if ($imgtype == "bitrate") {
$res = "<img src=\"billing-graph.php?bill_id=".$id;
if ($bittype == "Quota")
{
$res .= "&amp;ave=yes";
}
elseif ($bittype == "CDR") {
$res .= "&amp;95th=yes";
}
} else
{
$res = "<img src=\"bandwidth-graph.php?bill_id=".$id;
}
//$res .= "&amp;type=".$type;
$res .= "&amp;type=".$imgtype;
$res .= "&amp;x=1190&amp;y=250";
$res .= "&amp;from=".$from."&amp;to=".$to;
$res .= "\" style=\"margin: 15px 5px 25px 5px;\" />";
return $res;
}
echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>
<tr style=\"font-weight: bold; \">
<td width=\"7\"></td>
<td width=\"300\">Period</td>
<td width=\"250\">Period</td>
<td>Type</td>
<td>Allowed</td>
<td>Inbound</td>
@ -21,7 +48,7 @@
<td>Total</td>
<td>95 percentile</td>
<td style=\"text-align: center;\">Overusage</td>
<td width=\"250\"></td>
<td colspan=\"2\" style=\"text-align: right;\"><a href=\"".$url."?detail=all\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\" /> Show all details</a></td>
</tr>");
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` AND `bill_dateto` DESC LIMIT 24", array($bill_id)) as $history)
@ -35,7 +62,7 @@
$percent = $history['bill_percent'];
$dir_95th = $history['dir_95th'];
$rate_95th = formatRates($history['rate_95th'] * 1000);
$total_data = formatStorage($history['traf_total'] * 1024 * 1024);
$total_data = formatStorage($history['traf_total'] * $gbconvert * $gbconvert);
$background = get_percentage_colours($percent);
$row_colour = ((!is_integer($i/2)) ? $list_colour_a : $list_colour_b);
@ -48,18 +75,18 @@
$out = formatRates($history['rate_95th_out'] * 1000);
$overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatRates($history['bill_overuse'] * 1000)."</span>");
} elseif ($type == "Quota") {
$allowed = formatStorage($history['bill_allowed'] * 1024 * 1024);
$used = formatStorage($history['total_data'] * 1024 * 1024);
$in = formatStorage($history['traf_in'] * 1024 * 1024);
$out = formatStorage($history['traf_out'] * 1024 * 1024);
$overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatStorage($history['bill_overuse'] * 1024 * 1024)."</span>");
$allowed = formatStorage($history['bill_allowed'] * $gbconvert * $gbconvert);
$used = formatStorage($history['total_data'] * $gbconvert * $gbconvert);
$in = formatStorage($history['traf_in'] * $gbconvert * $gbconvert);
$out = formatStorage($history['traf_out'] * $gbconvert * $gbconvert);
$overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatStorage($history['bill_overuse'] * $gbconvert * $gbconvert)."</span>");
}
$total_data = (($type == "Quota") ? "<b>".$total_data."</b>" : $total_data);
$rate_95th = (($type == "CDR") ? "<b>".$rate_95th."</b>" : $rate_95th);
echo("
<tr style=\"background: $row_colour;\">
<tr style=\"background: ".$row_colour.";\">
<td></td>
<td><span style=\"font-weight: bold;\" class=\"interface\">".strftime("%Y-%m-%d", strtotime($datefrom))." -> ".strftime("%Y-%m-%d", strtotime($dateto))."</span></td>
<td>$type</td>
@ -69,9 +96,30 @@
<td>$total_data</td>
<td>$rate_95th</td>
<td style=\"text-align: center;\">$overuse</td>
<td>".print_percentage_bar(250, 20, $perc, NULL, "ffffff", $background['left'], $percent."%", "ffffff", $background['right'])."</td>
<td width=\"250\">".print_percentage_bar(250, 20, $perc, NULL, "ffffff", $background['left'], $percent."%", "ffffff", $background['right'])."</td>
<td>
<a href=\"".$url."?detail=".($i+1)."\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\"/></a>
<a href=\"#\"><img src=\"images/16/page_white_acrobat.png\" border=\"0\" align=\"absmiddle\" alt=\"PDF Report\" title=\"PDF Report\"/></a>
</td>
</tr>");
if ($detail == ($i+1) || $detail == "all") {
$img['bitrate'] = showDetails($history['bill_id'], "bitrate", strtotime($datefrom), strtotime($dateto), $type);
$img['bw_day'] = showDetails($history['bill_id'], "day", strtotime($datefrom), strtotime($dateto));
$img['bw_hour'] = showDetails($history['bill_id'], "hour", strtotime($datefrom), strtotime($dateto));
echo("
<tr style=\"background: #fff; border-top: 1px solid ".$row_colour."; border-bottom: 1px solid #ccc;\">
<td colspan=\"11\">
<!-- <b>Accuate Graph</b><br /> //-->
".$img['bitrate']."<br />
<!-- <b>Bandwidth Graph per day</b><br /> //-->
".$img['bw_day']."<br />
<!-- <b>Bandwidth Graph per hour</b><br /> //-->
".$img['bw_hour']."
</td>
</tr>");
}
$i++;
} ### PERMITTED
}

View File

@ -173,6 +173,7 @@ $config['enable_billing'] = 0; # Enable Billing
$config['billing']['customer_autoadd'] = 0; # Enable Auto-add bill per customer
$config['billing']['circuit_autoadd'] = 0; # Enable Auto-add bill per circuit_id
$config['billing']['bill_autoadd'] = 0; # Enable Auto-add bill per bill_id
$config['billing']['base'] = 1000; # Set the base to divider bytes to kb, mb, gb ,... (this only works for the text based conversion and not for the graphs)
### External Integration