From 019e3c347a9a677d113eacdef3b83c9d1bf51534 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Mon, 21 Jun 2010 04:18:06 +0000 Subject: [PATCH] make billing usable (shonky interface it now has!) git-svn-id: http://www.observium.org/svn/observer/trunk@1227 61d68cd4-352d-0410-923a-c4978735b2b8 --- database-update.sql | 1 + ...list_interfaces.php => ajax_listports.php} | 19 +- html/billing-graph.php | 36 ++-- .../javascript-interfacepicker.inc.php | 28 +++ html/pages/bill.php | 202 ++++++++++++++++++ html/pages/bill/edit.php | 63 ++++++ html/pages/bills.php | 67 +++++- html/pages/edituser.php | 30 +-- 8 files changed, 397 insertions(+), 49 deletions(-) rename html/{ajax/list_interfaces.php => ajax_listports.php} (51%) create mode 100644 html/includes/javascript-interfacepicker.inc.php create mode 100644 html/pages/bill.php create mode 100644 html/pages/bill/edit.php diff --git a/database-update.sql b/database-update.sql index 1db6c1719..966065d38 100644 --- a/database-update.sql +++ b/database-update.sql @@ -14,3 +14,4 @@ ALTER TABLE `temperature` CHANGE `temp_index` `temp_index` VARCHAR(32) NOT NU ALTER TABLE `ports` CHANGE `ifDescr` `ifDescr` VARCHAR(255) NOT NULL; CREATE TABLE IF NOT EXISTS `ucd_diskio` ( `diskio_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `diskio_index` int(11) NOT NULL, `diskio_descr` varchar(32) NOT NULL, PRIMARY KEY (`diskio_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; ALTER TABLE `eventlog` CHANGE `type` `type` VARCHAR( 64 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL; +ALTER TABLE `bills` ADD `bill_custid` VARCHAR( 64 ) NOT NULL ,ADD `bill_ref` VARCHAR( 64 ) NOT NULL ,ADD `bill_notes` VARCHAR( 256 ) NOT NULL; diff --git a/html/ajax/list_interfaces.php b/html/ajax_listports.php similarity index 51% rename from html/ajax/list_interfaces.php rename to html/ajax_listports.php index 06a3d1ae6..0606e056a 100755 --- a/html/ajax/list_interfaces.php +++ b/html/ajax_listports.php @@ -1,9 +1,20 @@ img->SetImgFormat("png"); -$graph->img->SetAntiAliasing(true); +#$graph->img->SetAntiAliasing(true); $graph->SetScale( "intlin"); #$graph->SetScale('intlin',0,0,$xmin,$xmax); $graph->title->Set("$graph_name"); -$graph->title->SetFont(FF_VERDANA,FS_BOLD); -$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL); +$graph->title->SetFont(FF_FONT2,FS_BOLD,10); +$graph->xaxis->SetFont(FF_FONT1,FS_BOLD); -#$graph->xaxis->SetTickLabels($ticks); +$graph->xaxis->SetTickLabels($ticks); if(count($tickPositions) > 24) { $graph->xaxis->SetTextLabelInterval(3); @@ -173,22 +179,22 @@ if(count($tickPositions) > 24) { } $graph->xaxis->SetPos('min'); -$graph->xaxis->SetLabelAngle(15); +#$graph->xaxis->SetLabelAngle(15); $graph->yaxis->HideZeroLabel(1); -$graph->yaxis->SetFont(FF_VERDANA); +$graph->yaxis->SetFont(FF_FONT1); $graph->yaxis->SetLabelAngle(0); -$graph->xaxis->title->SetFont(FF_VERDANA,FS_NORMAL,10); -$graph->yaxis->title->SetFont(FF_VERDANA,FS_NORMAL,10); +$graph->xaxis->title->SetFont(FF_FONT1,FS_NORMAL,10); +$graph->yaxis->title->SetFont(FF_FONT1,FS_NORMAL,10); $graph->yaxis->SetTitleMargin(50); $graph->xaxis->SetTitleMargin(30); #$graph->xaxis->HideLastTickLabel(); -$graph->xaxis->HideFirstTickLabel(); +#$graph->xaxis->HideFirstTickLabel(); #$graph->yaxis->scale->SetAutoMin(1); #$graph->xaxis->title->Set("$type"); $graph->yaxis->title->Set("$yaxis"); $graph->xaxis->SetTickPositions($tickPositions,$tickMinPositions,$tickLabels); -#$graph->xaxis->SetMajTickPositions($tickPositions,$tickLabels); +$graph->xaxis->SetMajTickPositions($tickPositions,$tickLabels); $graph->ygrid->SetFill(true,'#EFEFEF@0.5','#FFFFFF@0.5'); $graph->xgrid->Show(true,true); @@ -196,7 +202,7 @@ $graph->xgrid->SetColor('#e0e0e0','#efefef'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->SetMargin(75,30,30,45); -$graph->legend->SetFont(FF_VERDANA,FS_NORMAL); +$graph->legend->SetFont(FF_FONT1,FS_NORMAL); $lineplot = new LinePlot($tot_data); #$lineplot->SetLegend("Traffic total"); diff --git a/html/includes/javascript-interfacepicker.inc.php b/html/includes/javascript-interfacepicker.inc.php new file mode 100644 index 000000000..835f438bd --- /dev/null +++ b/html/includes/javascript-interfacepicker.inc.php @@ -0,0 +1,28 @@ + + + diff --git a/html/pages/bill.php b/html/pages/bill.php new file mode 100644 index 000000000..486ee2a5f --- /dev/null +++ b/html/pages/bill.php @@ -0,0 +1,202 @@ += 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("

+" . $bill_name . "

"); + +print_optionbar_start(); + +if(!$_GET['optb']) { $_GET['optb'] = "details"; } + +if($_GET['optb'] == "details") { echo(""); } +echo("Details"); +if($_GET['optb'] == "details") { echo(""); } + +echo(" | "); +if($_GET['optb'] == "edit") { echo(""); } +echo("Edit"); +if($_GET['optb'] == "edit") { echo(""); } + +print_optionbar_end(); + +echo("
"); + + +if($_GET['optb'] == "edit") { + + include("pages/bill/edit.php"); + +}elseif($_GET['optb'] == "details") { + + +echo("

Billed Ports

"); + +$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) . "
"); + +} + +echo("

Bill Summary

"); + +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 . " +
Transferred ".formatStorage($total_data * 1024 * 1024)." of ".formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024)." (".$percent."%) +
Average rate " . formatRates($rate_average * 1000)); + if ($percent > 100) { $percent = "100"; } + echo("

"); + + $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("" . $fromtext . " to " . $totext . " +
Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)"); + if ($percent > 100) { $percent = "100"; } + echo("

"); + +# echo("

Billing Period : " . $fromtext . " to " . $totext . "
+# " . $paidrate_text . "
+# " . $total_data . "MB transfered in the current billing cycle.
+# " . $rate_average . "Kbps Average during the current billing cycle.

+# " . $rate_95th . "Kbps @ 95th Percentile. (" . $dir_95th . ") (" . $bill_text . ") +#
+#
"); + +} + +echo(""); + +$bi = ""; + +$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 = ""; + +$mi = ""; + +if($null) { + +echo(" + + +
+ + + + + + From: + + + To: + + + +
+ +"); + +} + + if ($_GET[all]) { + $ai = ""; + echo("

Entire Data View

$ai"); + } elseif ($_GET[custom]) { + $cg = ""; + echo("

Custom Graph

$cg"); + } else { + echo("

Billing View

$bi

24 Hour View

$di"); + #echo("

Monthly View

$li"); + #echo("
Graph All Data (SLOW)"); + } + +} # End if details + +?> + diff --git a/html/pages/bill/edit.php b/html/pages/bill/edit.php new file mode 100644 index 000000000..210e99808 --- /dev/null +++ b/html/pages/bill/edit.php @@ -0,0 +1,63 @@ +Billed Ports"); + + echo(""); + while($port = mysql_fetch_array($ports_array)) + { + if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } + echo(""); + echo(""); + } + echo("
"); + echo(generatedevicelink($port) . " - " . generateiflink($port)); + if($port['ifAlias']) { echo(" - " . $port['ifAlias']); } + echo(""); + echo("
+ +
"); + echo("
"); +} + + echo("

Add Billed Port

"); + + echo("
+ + + + + + +
Device:
Interface:
"); + + + +?> diff --git a/html/pages/bills.php b/html/pages/bills.php index 6bf30a8ed..32777db33 100644 --- a/html/pages/bills.php +++ b/html/pages/bills.php @@ -1,12 +1,75 @@ "; + +} + + +echo(""); + if($_GET['opta'] == "add") { ?>
Add Bill
-
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Description
Billing Type + CDR 95th: KBps +
+ Quota: GB + +
Billing Day

Optional Information

Customer Reference
Billing Reference
Notes
+
+
$used $percent% - Edit Edit + Edit Edit "); $i++; diff --git a/html/pages/edituser.php b/html/pages/edituser.php index 1164d6191..6ea56c983 100644 --- a/html/pages/edituser.php +++ b/html/pages/edituser.php @@ -1,33 +1,7 @@ - - - "); if($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php"); } else {