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

View File

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

View File

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

View File

@@ -1,19 +1,46 @@
<?php <?php
$pagetitle[] = "Historical Usage"; $pagetitle[] = "Historical Usage";
$detail = (isset($_GET['detail']) ? $_GET['detail'] : "");
$url = $PHP_SELF."/bill/".$bill_id."/history/";
$i = 0; $i = 0;
$img = "<img src=\"bandwidth-graph.php?bill_id=".$bill_id; $gbconvert = $config['billing']['base'];
$img .= "&amp;imgtype=historical";
$img .= "&amp;x=1190&amp;y=250";
$img .= "\" style=\"margin: 15px 5px 25px 5px;\" />";
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%> echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>
<tr style=\"font-weight: bold; \"> <tr style=\"font-weight: bold; \">
<td width=\"7\"></td> <td width=\"7\"></td>
<td width=\"300\">Period</td> <td width=\"250\">Period</td>
<td>Type</td> <td>Type</td>
<td>Allowed</td> <td>Allowed</td>
<td>Inbound</td> <td>Inbound</td>
@@ -21,7 +48,7 @@
<td>Total</td> <td>Total</td>
<td>95 percentile</td> <td>95 percentile</td>
<td style=\"text-align: center;\">Overusage</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>"); </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) 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']; $percent = $history['bill_percent'];
$dir_95th = $history['dir_95th']; $dir_95th = $history['dir_95th'];
$rate_95th = formatRates($history['rate_95th'] * 1000); $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); $background = get_percentage_colours($percent);
$row_colour = ((!is_integer($i/2)) ? $list_colour_a : $list_colour_b); $row_colour = ((!is_integer($i/2)) ? $list_colour_a : $list_colour_b);
@@ -48,18 +75,18 @@
$out = formatRates($history['rate_95th_out'] * 1000); $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>"); $overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatRates($history['bill_overuse'] * 1000)."</span>");
} elseif ($type == "Quota") { } elseif ($type == "Quota") {
$allowed = formatStorage($history['bill_allowed'] * 1024 * 1024); $allowed = formatStorage($history['bill_allowed'] * $gbconvert * $gbconvert);
$used = formatStorage($history['total_data'] * 1024 * 1024); $used = formatStorage($history['total_data'] * $gbconvert * $gbconvert);
$in = formatStorage($history['traf_in'] * 1024 * 1024); $in = formatStorage($history['traf_in'] * $gbconvert * $gbconvert);
$out = formatStorage($history['traf_out'] * 1024 * 1024); $out = formatStorage($history['traf_out'] * $gbconvert * $gbconvert);
$overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatStorage($history['bill_overuse'] * 1024 * 1024)."</span>"); $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); $total_data = (($type == "Quota") ? "<b>".$total_data."</b>" : $total_data);
$rate_95th = (($type == "CDR") ? "<b>".$rate_95th."</b>" : $rate_95th); $rate_95th = (($type == "CDR") ? "<b>".$rate_95th."</b>" : $rate_95th);
echo(" echo("
<tr style=\"background: $row_colour;\"> <tr style=\"background: ".$row_colour.";\">
<td></td> <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><span style=\"font-weight: bold;\" class=\"interface\">".strftime("%Y-%m-%d", strtotime($datefrom))." -> ".strftime("%Y-%m-%d", strtotime($dateto))."</span></td>
<td>$type</td> <td>$type</td>
@@ -69,9 +96,30 @@
<td>$total_data</td> <td>$total_data</td>
<td>$rate_95th</td> <td>$rate_95th</td>
<td style=\"text-align: center;\">$overuse</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>"); </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++; $i++;
} ### PERMITTED } ### 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']['customer_autoadd'] = 0; # Enable Auto-add bill per customer
$config['billing']['circuit_autoadd'] = 0; # Enable Auto-add bill per circuit_id $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']['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 ### External Integration