From 698bf64ff96284b4c14430e4a0f37b105176446f Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Sun, 9 Mar 2008 17:49:23 +0000 Subject: [PATCH] Adding billing... git-svn-id: http://www.observium.org/svn/observer/trunk@127 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/billing-graph.php | 234 +++++++++++++++++++++++++++++++++++++++++ html/calendar.jpg | Bin 0 -> 1089 bytes html/pages/bills.php | 60 +++++++++++ 3 files changed, 294 insertions(+) create mode 100644 html/billing-graph.php create mode 100644 html/calendar.jpg create mode 100644 html/pages/bills.php diff --git a/html/billing-graph.php b/html/billing-graph.php new file mode 100644 index 0000000000..d0da35077c --- /dev/null +++ b/html/billing-graph.php @@ -0,0 +1,234 @@ += $datefrom AND timestamp <= $dateto"); +$counttot = mysql_result($countsql,0); + +$count = round($counttot / (($ysize - 100) * 2), 0); +if ($count <= 1) { $count = 2; } + + +#$count = 8; + +#$count = round($counttot / 260, 0); +#if ($count <= 1) { $count = 2; } + +$max = mysql_result(mysql_query("SELECT delta FROM bill_data WHERE bill_id = $bill_id AND timestamp >= $datefrom AND timestamp <= $dateto ORDER BY delta DESC LIMIT 0,1"),0); +if($max > 1000000) { $div = "1000000"; $yaxis = "Mbit/sec"; } else { $div = "1000"; $yaxis = "Kbit/sec"; } + +$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); +#$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; + +$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"; +$data = mysql_query($sql); +while($row = mysql_fetch_array($data)) +{ + @$timestamp = $row['formatted_date']; + if (!$first) { $first = $timestamp; } + @$delta = $row['delta']; + @$period = $row['period']; + @$in_delta = $row['in_delta']; + @$out_delta = $row['out_delta']; + @$in_value = round($in_delta * 8 / $period / $div, 2); + @$out_value = round($out_delta * 8 / $period / $div, 2); + + #@$data[] = $in_value + $out_value; + #@$in_data[] = $in_value; + #@$out_data[] = $out_value; + #@$ticks[] = $timestamp; + #@$per_data[] = $rate_95th / 1000; + #@$ave_data[] = $rate_average / 1000; + + @$last = $timestamp; + + $iter_in = $iter_in + $in_delta; + $iter_out = $iter_out + $out_delta; + $iter_period = $iter_period + $period; + + if ($iter == $count) { + + $out_data[$i] = round($iter_out * 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]; +# $ticks[$i] = date('M j g:ia', $timestamp); + $ticks[$i] = $timestamp; + + if($dur < 172800) { + $hour = date('h', $timestamp); + if($hour != $lasthour) { $tickPositions[] = $i; $tickLabels[] = date('ga', $timestamp); } + $lasthour = $hour; + + } elseif ($dur < 604800) { + $day = date('d', $timestamp); + if($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('D', $timestamp); $h = 0; } + $lastday = $day; + + $hour = trim(date('g', $timestamp)); + if($hour != $lasthour) { + if($hour == '12') {$tickMinPositions[] = $i; $h = 0; } $h++; + } + $lasthour = $hour; + + + } else { + $day = date('d', $timestamp); + if($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('dS', $timestamp); } + $lastday = $day; + } + + $per_data[$i] = $rate_95th / $div; + $ave_data[$i] = $rate_average / $div; + $timestamps[$i] = $timestamp; + $iter = "1"; + $i++; + unset($iter_out, $iter_in, $iter_period); + } + + $iter++; + +} + +$graph_name = date('M j g:ia', $start) . " - " . date('M j g:ia', $last); + +$n = count($ticks); +$xmin = $ticks[0]; +$xmax = $ticks[$n-1]; + +$graph_name = date('M j g:ia', $xmin) . " - " . date('M j g:ia', $xmax); + + +$graph = new Graph($xsize, $ysize, $graph_name); +$graph->img->SetImgFormat("png"); +$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->xaxis->SetTickLabels($ticks); + +if(count($tickPositions) > 24) { + $graph->xaxis->SetTextLabelInterval(3); +}elseif(count($tickPositions) > 12) { + $graph->xaxis->SetTextLabelInterval(2); +} + +$graph->xaxis->SetPos('min'); +$graph->xaxis->SetLabelAngle(15); +$graph->yaxis->HideZeroLabel(1); +$graph->yaxis->SetFont(FF_VERDANA); +$graph->yaxis->SetLabelAngle(0); +$graph->xaxis->title->SetFont(FF_VERDANA,FS_NORMAL,10); +$graph->yaxis->title->SetFont(FF_VERDANA,FS_NORMAL,10); +$graph->yaxis->SetTitleMargin(50); +$graph->xaxis->SetTitleMargin(30); +#$graph->xaxis->HideLastTickLabel(); +$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->ygrid->SetFill(true,'#EFEFEF@0.5','#FFFFFF@0.5'); +$graph->xgrid->Show(true,true); +$graph->xgrid->SetColor('#e0e0e0','#efefef'); +$graph->SetMarginColor('white'); +$graph->SetFrame(false); +$graph->SetMargin(75,30,30,45); +$graph->legend->SetFont(FF_VERDANA,FS_NORMAL); + +$lineplot = new LinePlot($tot_data); +#$lineplot->SetLegend("Traffic total"); +$lineplot->SetColor("#d5d5d5"); +$lineplot->SetFillColor("#d5d5d5"); +$lineplot_in = new LinePlot($in_data); +#$lineplot_in->SetLegend("Traffic In"); +$lineplot_in->SetColor("#009900"); +$lineplot_out = new LinePlot($out_data); +#$lineplot_out->SetLegend("Traffic Out"); +$lineplot_out->SetColor("blue"); + +if($_GET['95th']) { + $lineplot_95th = new LinePlot($per_data); + $lineplot_95th ->SetColor("red"); +} + +if($_GET['ave']) { + $lineplot_ave = new LinePlot($ave_data); + $lineplot_ave ->SetColor("red"); +} + +#$graph->legend->SetLayout(LEGEND_HOR); +#$graph->legend->Pos(0.52, 0.85, 'center'); + +$graph->Add($lineplot); +$graph->Add($lineplot_in); +$graph->Add($lineplot_out); +if($_GET['95th']) { + $graph->Add($lineplot_95th); +} +if($_GET['ave']) { + $graph->Add($lineplot_ave); +} + +$graph->stroke(); + +?> diff --git a/html/calendar.jpg b/html/calendar.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7856892f40030841eb52fd3cefcc1c76a43de5f4 GIT binary patch literal 1089 zcmex=7?=bZ znFSgDA7PMZU|?j0n9TqMj7-cdtZeKYoLt;M1zQCem>8LvnOK-vSy@`H|qMvW5}awt1(JSZA;@q>zSQc)8pmzcPOq?D?fx`w8fiK&^ng{76V zi>sTvho@I?NN8AiL}XNQN@`kqMrKxVNoiSmMP*fUOKV$uM`zch$y26In?7UatVN5L zEM2yI#mZHiHgDOwZTpU$yAB;ba`f2o6DLnyx_ss8wd*%--g@}x@sp>|p1*kc>f@)+ zU%r0({^RE_kiQrinBhSN@fe!F1cClyVqsxsVF&q(k*OSrnFU!`6%E;h90S=C3x$=8 z8aYIqCNA7~kW<+>=!0ld(M2vX6_bamA3Z!P~bu=;*@w)ms*&8T_UF|yJN=0NomEjB_+k2+e4qtsAM2a`wh%RX4mot-*a=hw^mI*bpMC`{Xc@;K<9J+ zlgyBM{hJ^qqw+WVPJe6p@%gv< zzkBk0TlSV8ivQq0zi%J&$NNY0W&fmI{+e0Czv$I{!8|*$jC)}VANLD*F3*YrIyZdn zy8Z|9y5UE!i%-`uwXpU1-La#;LwU-@"); + +if($_GET['bill']) { + + $bill_id = $_GET['bill']; + include("includes/billing.php"); + +} else { + + $sql = "SELECT * FROM `bills` ORDER BY `bill_name`"; + $query = mysql_query($sql); + if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; } + echo(""); + while($bill = mysql_fetch_array($query)) { + unset($class); + $day_data = getDates($bill['bill_day']); + $datefrom = $day_data['0']; + $dateto = $day_data['1']; + $rate_data = getRates($bill['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($bill['bill_type'] == "cdr") { + $type = "CDR"; + $allowed = formatRates($bill['bill_cdr'] * 1000); + $used = formatRates($rate_data['rate_95th'] * 1000); + $percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100,2); + + } elseif ($bill['bill_type'] == "quota") { + $type = "Quota"; + $allowed = formatStorage($bill['bill_gb']* 1024 * 1024 * 1024); + $used = formatStorage($rate_data['total_data'] * 1024 * 1024); + $percent = round(($rate_data['total_data'] / ($bill['bill_gb'] * 1024)) * 100,2); + + } + + + echo(" + + + + + + + + + + "); + } + echo("
".$bill['bill_name']."$notes$type$allowed$used $percent%
"); + +} + +echo(""); + +?>