billing improvements from codekiller.

git-svn-id: http://www.observium.org/svn/observer/trunk@2715 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-11-05 14:55:08 +00:00
parent f3de72be89
commit f7eb392298
9 changed files with 508 additions and 147 deletions
+1
View File
@@ -8,6 +8,7 @@ if ($_POST['action'] == "delete_bill" && $_POST['confirm'] == "confirm")
dbDelete('port_out_measurements', '`port_id` = ?', array($port_data['bill_id']));
}
dbDelete('bill_history', '`bill_id` = ?', array($bill_id));
dbDelete('bill_ports', '`bill_id` = ?', array($bill_id));
dbDelete('bill_data', '`bill_id` = ?', array($bill_id));
dbDelete('bill_perms', '`bill_id` = ?', array($bill_id));
+73
View File
@@ -0,0 +1,73 @@
<?php
$pagetitle[] = "Historical Usage";
$i=0;
echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>
<tr style=\"font-weight: bold; \">
<td width=\"7\"></td>
<td width=\"220\">Period</td>
<td>Type</td>
<td>Allowed</td>
<td>Inbound</td>
<td>Outbound</td>
<td>Total</td>
<td>95 percentile</td>
<td style=\"text-align: center;\">Overusage</td>
<td width=\"250\"></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)
{
if (bill_permitted($history['bill_id']))
{
unset($class);
$datefrom = $history['bill_datefrom'];
$dateto = $history['bill_dateto'];
$type = $history['bill_type'];
$percent = $history['bill_percent'];
$dir_95th = $history['dir_95th'];
$rate_95th = formatRates($history['rate_95th'] * 1000);
$total_data = formatStorage($history['traf_total'] * 1024 * 1024);
$background = get_percentage_colours($percent);
$row_colour = ((!is_integer($i/2)) ? $list_colour_a : $list_colour_b);
if ($type == "CDR")
{
$allowed = formatRates($history['bill_allowed'] * 1000);
$used = formatRates($history['rate_95th'] * 1000);
$in = formatRates($history['rate_95th_in'] * 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>");
} 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>");
}
$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;\">
<td></td>
<td><span style=\"font-weight: bold;\" class=\"interface\">from ".strftime("%x", strtotime($datefrom))." to ".strftime("%x", strtotime($dateto))."</span></td>
<td>$type</td>
<td>$allowed</td>
<td>$in</td>
<td>$out</td>
<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>
</tr>");
$i++;
} ### PERMITTED
}
echo("</table>");
?>
+78
View File
@@ -0,0 +1,78 @@
<?php
$pagetitle[] = "Previous Billing Period";
$i=1;
echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>
<tr style=\"font-weight: bold; border-bottom: ".$list_highlight." 1px solid;\">
<td width=\"7\"></td>
<td width=\"250\">Billing name</td>
<td>Type</td>
<td>Allowed</td>
<td>Inbound</td>
<td>Outbound</td>
<td>Total</td>
<td>95 percentile</td>
<td style=\"text-align: center;\">Overusage</td>
<td width=\"250\"></td>
</tr>");
foreach (dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_name`") as $bill)
{
if (bill_permitted($bill['bill_id']))
{
$day_data = getDates($bill['bill_day']);
$datefrom = $day_data['2'];
$dateto = $day_data['3'];
// foreach (dbFetchRows("SELECT * FROM `bill_history` ORDER BY `bill_datefrom` AND `bill_dateto` DESC LIMIT 24") as $history)
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? AND `bill_datefrom` = ? AND `bill_dateto` = ? ORDER BY `bill_datefrom` AND `bill_dateto` LIMIT 1", array($bill['bill_id'], $datefrom, $dateto)) as $history)
{
unset($class);
$type = $history['bill_type'];
$percent = $history['bill_percent'];
$dir_95th = $history['dir_95th'];
$rate_95th = formatRates($history['rate_95th'] * 1000);
$total_data = formatStorage($history['traf_total'] * 1024 * 1024);
$background = get_percentage_colours($percent);
$row_colour = ((!is_integer($i/2)) ? $list_colour_a : $list_colour_b);
if ($type == "CDR")
{
$allowed = formatRates($history['bill_allowed'] * 1000);
$used = formatRates($history['rate_95th'] * 1000);
$in = formatRates($history['rate_95th_in'] * 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>");
} 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>");
}
$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;\">
<td></td>
<td><a href=\"bill/".$bill['bill_id']."/\"><span style=\"font-weight: bold;\" class=\"interface\">".$bill['bill_name']."</a></span><br />from ".strftime("%x", strtotime($datefrom))." to ".strftime("%x", strtotime($dateto))."</td>
<td>$type</td>
<td>$allowed</td>
<td>$in</td>
<td>$out</td>
<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>
</tr>");
$i++;
} ### PERMITTED
}
}
echo("</table>");
?>