diff --git a/billing-calculate.php b/billing-calculate.php index 6b2968a5b..853ab71d7 100755 --- a/billing-calculate.php +++ b/billing-calculate.php @@ -8,9 +8,13 @@ include("includes/functions.php"); foreach (dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_name`") as $bill) { unset($class); + unset($rate_data); $day_data = getDates($bill['bill_day']); $datefrom = $day_data['0']; $dateto = $day_data['1']; + $datefrom_lp = $day_data['2']; + $dateto_lp = $day_data['3']; + $check_lp = dbFetchRow("SELECT * FROM `bill_history` WHERE bill_id = ? AND bill_datefrom = ? AND bill_dateto = ? LIMIT 1", array($bill['bill_id'], $datefrom_lp, $dateto_lp)); $rate_data = getRates($bill['bill_id'],$datefrom,$dateto); $rate_95th = $rate_data['rate_95th']; $dir_95th = $rate_data['dir_95th']; @@ -25,32 +29,82 @@ include("includes/functions.php"); $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); + $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(str_pad($bill['bill_id']." ".$bill['bill_name'], 30)." ".str_pad($type,8)." ".str_pad($allowed,10)." ".str_pad($used,10)." ".$percent."%"); + echo(str_pad($bill['bill_id']." ".$bill['bill_name'], 30)." ".str_pad($type,8)." ".str_pad($allowed,10)." ".str_pad($used,10)." ".$percent."%"); + $update = array('rate_95th' => $rate_data['rate_95th'], + 'rate_95th_in' => $rate_data['rate_95th_in'], + 'rate_95th_out' => $rate_data['rate_95th_out'], + 'dir_95th' => $rate_data['dir_95th'], + 'total_data' => $rate_data['total_data'], + 'total_data_in' => $rate_data['total_data_in'], + 'total_data_out' => $rate_data['total_data_out'], + 'rate_average' => $rate_data['rate_average'], + 'rate_average_in' => $rate_data['rate_average_in'], + 'rate_average_out' => $rate_data['rate_average_out'], + 'bill_last_calc' => array('NOW()') ); -$update = array('rate_95th' => $rate_data['rate_95th'], - 'rate_95th_in' => $rate_data['rate_95th_in'], - 'rate_95th_out' => $rate_data['rate_95th_out'], - 'dir_95th' => $rate_data['dir_95th'], - 'total_data' => $rate_data['total_data'], - 'total_data_in' => $rate_data['total_data_in'], - 'total_data_out' => $rate_data['total_data_out'], - 'rate_average' => $rate_data['rate_average'], - 'rate_average_in' => $rate_data['rate_average_in'], - 'rate_average_out' => $rate_data['rate_average_out'], - 'bill_last_calc' => array('NOW()') ); + dbUpdate($update, 'bills', '`bill_id` = ?', array($bill['bill_id'])); +# print_r($rate_data); + echo("\n"); -dbUpdate($update, 'bills', '`bill_id` = ?', array($bill['bill_id'])); + if (empty($check_lp['id'])) { + unset($rate_data); + $rate_data = getRates($bill['bill_id'],$datefrom_lp,$dateto_lp); + $rate_95th = $rate_data['rate_95th']; + $rate_95th_in = $rate_data['rate_95th_in']; + $rate_95th_out = $rate_data['rate_95th_out']; + $dir_95th = $rate_data['dir_95th']; + //$total_data = formatStorage($rate_data['total_data'] * 1024 * 1024); + //$total_data_in = formatStorage($rate_data['total_data_in'] * 1024 * 1024); + //$total_data_out = formatStorage($rate_data['total_data_out'] * 1024 * 1024); + //$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); + //$overuse = formatRates(($rate_data['rate_95th'] - $bill['bill_cdr'])* 1000); + $allowed = $bill['bill_cdr']; + $used = $rate_data['rate_95th']; + $overuse = $used - $allowed; + $overuse = (($overuse <= 0) ? "0" : $overuse); + $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); + //$overuse = formatStorage(($rate_data['total_data'] - ($bill['bill_gb'] * 1024)) * 1024 * 1024); + $allowed = $bill['bill_gb'] * 1024; + $used = $rate_data['total_data']; + $overuse = $used - $allowed; + $overuse = (($overuse <= 0) ? "0" : $overuse); + $percent = round(($rate_data['total_data'] / ($bill['bill_gb'] * 1024)) * 100,2); + } + $update = array('rate_95th' => $rate_data['rate_95th'], + 'rate_95th_in' => $rate_data['rate_95th_in'], + 'rate_95th_out' => $rate_data['rate_95th_out'], + 'dir_95th' => $rate_data['dir_95th'], + 'traf_total' => $rate_data['total_data'], + 'traf_in' => $rate_data['total_data_in'], + 'traf_out' => $rate_data['total_data_out'], + 'bill_datefrom' => $datefrom_lp, + 'bill_dateto' => $dateto_lp, + 'bill_type' => $type, + 'bill_allowed' => $allowed, + 'bill_used' => $used, + 'bill_overuse' => $overuse, + 'bill_percent' => $percent, + 'bill_id' => $bill['bill_id'] ); +# print_r($update); + dbInsert($update, 'bill_history'); + echo(" * Generated historical data from ".strftime("%x @ %X", strtotime($datefrom_lp))." to ".strftime("%x @ %X", strtotime($dateto_lp))."\n"); + } - -#print_r($rate_data); - - echo("\n"); } ?> diff --git a/database-schema.sql b/database-schema.sql index 63f6a305e..6bd50d49b 100644 --- a/database-schema.sql +++ b/database-schema.sql @@ -1163,3 +1163,31 @@ CREATE TABLE IF NOT EXISTS `vrfs` ( PRIMARY KEY (`vrf_id`), KEY `device_id` (`device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +-- -------------------------------------------------------- + +-- +-- Tabel structuur voor tabel `bill_history` +-- + +CREATE TABLE IF NOT EXISTS `bill_history` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `bill_id` int(11) NOT NULL, + `bill_datefrom` datetime NOT NULL, + `bill_dateto` datetime NOT NULL, + `bill_type` text NOT NULL, + `bill_allowed` int(11) NOT NULL, + `bill_used` int(11) NOT NULL, + `bill_overuse` int(11) NOT NULL, + `bill_percent` DECIMAL(5,2) NOT NULL, + `rate_95th_in` int(11) NOT NULL, + `rate_95th_out` int(11) NOT NULL, + `rate_95th` int(11) NOT NULL, + `dir_95th` varchar(3) NOT NULL, + `traf_in` int(11) NOT NULL, + `traf_out` int(11) NOT NULL, + `traf_total` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `bill_id` (`bill_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; diff --git a/database-update.sql b/database-update.sql index edaaa3319..87d6c7202 100644 --- a/database-update.sql +++ b/database-update.sql @@ -19,3 +19,6 @@ ALTER TABLE `bills` ADD `rate_average_in` int(11) NOT NULL; ALTER TABLE `bills` ADD `rate_average_out` int(11) NOT NULL; ALTER TABLE `bills` ADD `rate_average` int(11) NOT NULL; ALTER TABLE `bills` ADD `bill_last_calc` datetime NOT NULL; + +CREATE TABLE IF NOT EXISTS `bill_history` ( `id` int(11) NOT NULL AUTO_INCREMENT, `bill_id` int(11) NOT NULL, `bill_datefrom` datetime NOT NULL, `bill_dateto` datetime NOT NULL, `bill_type` text NOT NULL, `bill_allowed` int(11) NOT NULL, `bill_used` int(11) NOT NULL, `bill_overuse` int(11) NOT NULL, `bill_percent` decimal(5,2) NOT NULL, `rate_95th_in` int(11) NOT NULL, `rate_95th_out` int(11) NOT NULL, `rate_95th` int(11) NOT NULL, `dir_95th` varchar(3) NOT NULL, `traf_in` int(11) NOT NULL, `traf_out` int(11) NOT NULL, `traf_total` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `bill_id` (`bill_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; + diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php index 9de291862..1a5475b41 100644 --- a/html/pages/bill.inc.php +++ b/html/pages/bill.inc.php @@ -9,7 +9,8 @@ if ($_SESSION['userlevel'] == "10") if (bill_permitted($bill_id)) { - $bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)); + $bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ? LIMIT 1", array($bill_id)); + $bill_name = $bill_data['bill_name']; $today = str_replace("-", "", dbFetchCell("SELECT CURDATE()")); $yesterday = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)")); @@ -68,12 +69,20 @@ if (bill_permitted($bill_id)) $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); + # Speeds up loading for other included pages by setting it before progessing of mysql data! + echo("

Bill : " . $bill_name . "

"); + print_optionbar_start(); + echo("Bill » "); + + if (!$_GET['optb']) { $_GET['optb'] = "details"; } + if ($_GET['opta'] == "admin_history") { $_GET['optb'] = $_GET['opta']; } + if ($_GET['optb'] == "basic") { echo(""); } echo("Quick Graphs"); @@ -85,8 +94,19 @@ if (bill_permitted($bill_id)) echo("Accurate Graphs"); if ($_GET['optb'] == "details") { echo(""); } + echo(" | "); + + if ($_GET['optb'] == "history") { echo(""); } + echo("Historical Usage"); + if ($_GET['optb'] == "history") { echo(""); } + if ($_SESSION['userlevel'] == "10") { +# echo(" | "); +# if ($_GET['optb'] == "admin_history") { echo(""); } +# echo("Previous Billing Period"); +# if ($_GET['optb'] == "admin_history") { echo(""); } + echo(" | "); if ($_GET['optb'] == "edit") { echo(""); } echo("Edit"); @@ -98,9 +118,10 @@ if (bill_permitted($bill_id)) if ($_GET['optb'] == "delete") { echo(""); } } - print_optionbar_end(); + echo("
Back to Bills
"); -# echo("
"); + + print_optionbar_end(); if ($_GET['optb'] == "edit" && $_SESSION['userlevel'] == "10") { @@ -110,127 +131,188 @@ if (bill_permitted($bill_id)) { include("pages/bill/delete.inc.php"); } - elseif ($_GET['optb'] == "details" || $_GET['optb'] == "basic") + elseif ($_GET['optb'] == "history") { - - echo("

Billed Ports

"); - - $ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D - WHERE B.bill_id = ? AND P.interface_id = B.port_id - AND D.device_id = P.device_id", array($bill_id)); - - foreach ($ports as $port) - { - echo(generate_port_link($port) . " on " . generate_device_link($port) . "
"); + include("pages/bill/history.inc.php"); } + elseif ($_GET['optb'] == "details" || $_GET['optb'] == "basic") { - echo("

Bill Summary

"); + $bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)); - if ($bill_data['bill_type'] == "quota") - { - // The Customer is billed based on a pre-paid quota + $today = str_replace("-", "", dbFetchCell("SELECT CURDATE()")); + $tomorrow = str_replace("-", "", dbFetchCell("SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)")); + $last_month = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")); - echo("

Quota Bill

"); + $rightnow = $today . date(His); + $before = $yesterday . date(His); + $lastmonth = $last_month . date(His); - $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)); +# $bill_name = $bill_data['bill_name']; + $dayofmonth = $bill_data['bill_day']; + $paidrate = $bill_data['bill_paid_rate']; + $paid_kb = $paidrate / 1000; + $paid_mb = $paid_kb / 1000; - $background = get_percentage_colours($percent); - $right_background = $background['right']; - $left_background = $background['left']; + if ($paidrate < 1000000) { $paidrate_text = $paid_kb . "Kbps is the CDR."; } + if ($paidrate >= 1000000) { $paidrate_text = $paid_mb . "Mbps is the CDR."; } - echo("

".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."

"); + $day_data = getDates($dayofmonth); - $type="&ave=yes"; - } - elseif ($bill_data['bill_type'] == "cdr") - { - // The customer is billed based on a CDR with 95th%ile overage + $datefrom = $day_data['0']; + $dateto = $day_data['1']; - echo("

CDR / 95th Bill

"); + $lastfrom = $day_data['2']; + $lastto = $day_data['3']; - $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); +# $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']; + $rate_95th = $bill_data['rate_95th']; + $dir_95th = $bill_data['dir_95th']; + $total_data = $bill_data['total_data']; + $rate_average = $bill_data['rate_average']; - $percent = round(($rate_95th) / $cdr * 100, 2); + 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"; + } - $type="&95th=yes"; + $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '%M %D %Y')"); + $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '%M %D %Y')"); + $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); + $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); - echo("" . $fromtext . " to " . $totext . " -
Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)"); + $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); + $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); - if ($percent > 100) { $perc = "100"; } else { $perc = $percent; } - if ($perc > '90') { $left_background='c4323f'; $right_background='C96A73'; - } elseif ($perc > '75') { $left_background='bf5d5b'; $right_background='d39392'; - } elseif ($perc > '50') { $left_background='bf875b'; $right_background='d3ae92'; - } elseif ($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3'; - } else { $left_background='9abf5b'; $right_background='bbd392'; } + echo("

Billed Ports

"); - echo("

".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."

"); + $ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D + WHERE B.bill_id = ? AND P.interface_id = B.port_id + AND D.device_id = P.device_id", array($bill_id)); - # 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 . ") - #
- #
"); + foreach ($ports as $port) + { + echo(generate_port_link($port) . " on " . generate_device_link($port) . "
"); + } - } + echo("

Bill Summary

"); - $lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"); - $yesterday = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))"); - $rightnow = date(U); + if ($bill_data['bill_type'] == "quota") + { + // The Customer is billed based on a pre-paid quota - if ($_GET['optb'] == "details") { + echo("

Quota Bill

"); - $bi = ""; + $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)); - $li = ""; + $background = get_percentage_colours($percent); + $right_background = $background['right']; + $left_background = $background['left']; - $di = ""; + echo("

".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."

"); - $mi = ""; + $type="&ave=yes"; + } + elseif ($bill_data['bill_type'] == "cdr") + { + // The customer is billed based on a CDR with 95th%ile overage - } else { + echo("

CDR / 95th Bill

"); - $bi = ""; + $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); - $li = ""; + $percent = round(($rate_95th) / $cdr * 100, 2); - $di = ""; + $type="&95th=yes"; - $mi = ""; + echo("" . $fromtext . " to " . $totext . " +
Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)"); - } + if ($percent > 100) { $perc = "100"; } else { $perc = $percent; } + if ($perc > '90') { $left_background='c4323f'; $right_background='C96A73'; + } elseif ($perc > '75') { $left_background='bf5d5b'; $right_background='d39392'; + } elseif ($perc > '50') { $left_background='bf875b'; $right_background='d3ae92'; + } elseif ($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3'; + } else { $left_background='9abf5b'; $right_background='bbd392'; } - if ($null) - { - echo(" + echo("

".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)."

"); + + # 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 . ") + # + #
"); + + } + + $lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"); + $yesterday = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))"); + $rightnow = date(U); + + if ($_GET['optb'] == "details") { + + $bi = ""; + + $li = ""; + + $di = ""; + + $mi = ""; + + } else { + + $bi = ""; + + $li = ""; + + $di = ""; + + $mi = ""; + + } + + if ($null) + { + echo(" @@ -251,32 +333,32 @@ if (bill_permitted($bill_id)) "); - } + } - if ($_GET['all']) - { - $ai = ""; - echo("

Entire Data View

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

Custom Graph

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

Billing View

$bi"); - echo("

Previous Bill View

$li"); - echo("

24 Hour View

$di"); - echo("

Monthly View

$mi"); -# echo("
Graph All Data (SLOW)"); - } + if ($_GET['all']) + { + $ai = ""; + echo("

Entire Data View

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

Custom Graph

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

Billing View

$bi"); + echo("

Previous Bill View

$li"); + echo("

24 Hour View

$di"); + echo("

Monthly View

$mi"); +# echo("
Graph All Data (SLOW)"); + } } # End if details } else diff --git a/html/pages/bill/actions.inc.php b/html/pages/bill/actions.inc.php index 93f1ebd8c..d306c6907 100644 --- a/html/pages/bill/actions.inc.php +++ b/html/pages/bill/actions.inc.php @@ -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)); diff --git a/html/pages/bill/history.inc.php b/html/pages/bill/history.inc.php new file mode 100644 index 000000000..ddf2f97c3 --- /dev/null +++ b/html/pages/bill/history.inc.php @@ -0,0 +1,73 @@ + + + + Period + Type + Allowed + Inbound + Outbound + Total + 95 percentile + Overusage + + "); + + 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) ? "-" : "".formatRates($history['bill_overuse'] * 1000).""); + } 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) ? "-" : "".formatStorage($history['bill_overuse'] * 1024 * 1024).""); + } + + $total_data = (($type == "Quota") ? "".$total_data."" : $total_data); + $rate_95th = (($type == "CDR") ? "".$rate_95th."" : $rate_95th); + + echo(" + + + from ".strftime("%x", strtotime($datefrom))." to ".strftime("%x", strtotime($dateto))." + $type + $allowed + $in + $out + $total_data + $rate_95th + $overuse + ".print_percentage_bar (250, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])." + "); + + $i++; + } ### PERMITTED + } + echo(""); + +?> diff --git a/html/pages/bill/pmonth.inc.php b/html/pages/bill/pmonth.inc.php new file mode 100644 index 000000000..ea4c71303 --- /dev/null +++ b/html/pages/bill/pmonth.inc.php @@ -0,0 +1,78 @@ + + + + Billing name + Type + Allowed + Inbound + Outbound + Total + 95 percentile + Overusage + + "); + + 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) ? "-" : "".formatRates($history['bill_overuse'] * 1000).""); + } 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) ? "-" : "".formatStorage($history['bill_overuse'] * 1024 * 1024).""); + } + + $total_data = (($type == "Quota") ? "".$total_data."" : $total_data); + $rate_95th = (($type == "CDR") ? "".$rate_95th."" : $rate_95th); + + echo(" + + + ".$bill['bill_name']."
from ".strftime("%x", strtotime($datefrom))." to ".strftime("%x", strtotime($dateto))." + $type + $allowed + $in + $out + $total_data + $rate_95th + $overuse + ".print_percentage_bar (250, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])." + "); + + $i++; + } ### PERMITTED + } + } + echo(""); + +?> diff --git a/html/pages/bills.inc.php b/html/pages/bills.inc.php index 31e26a994..6f5fa6b04 100644 --- a/html/pages/bills.inc.php +++ b/html/pages/bills.inc.php @@ -15,9 +15,15 @@ if ($_POST['addbill'] == "yes") $pagetitle[] = "Billing"; + echo(""); -if ($_GET['opta'] == "add") +if ($_GET['opta'] == "history") +{ + include("pages/bill/search.inc.php"); + include("pages/bill/pmonth.inc.php"); +} +elseif ($_GET['opta'] == "add") { ?> @@ -70,6 +76,8 @@ if ($_GET['opta'] == "add") } else { + include("pages/bill/search.inc.php"); + /* print_optionbar_start('40'); ?> @@ -104,6 +112,9 @@ if ($_GET['opta'] == "add") + + Previous Billing Period Previous Billing Period + Add Add Bill @@ -114,9 +125,21 @@ if ($_GET['opta'] == "add") "); - $i=1; + $i=0; + echo(" + + + + + + + + + + + "); foreach (dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_name`") as $bill) { if (bill_permitted($bill['bill_id'])) @@ -126,7 +149,7 @@ if ($_GET['opta'] == "add") $datefrom = $day_data['0']; $dateto = $day_data['1']; # $rate_data = getRates($bill['bill_id'],$datefrom,$dateto); - $rate_data = $bill; + $rate_data = $bill; $rate_95th = $rate_data['rate_95th']; $dir_95th = $rate_data['dir_95th']; $total_data = $rate_data['total_data']; @@ -138,28 +161,34 @@ if ($_GET['opta'] == "add") $allowed = formatRates($bill['bill_cdr'] * 1000); $used = formatRates($rate_data['rate_95th'] * 1000); $percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100,2); + $background = get_percentage_colours($percent); + $overuse = $rate_data['rate_95th'] - $bill['bill_cdr']; + $overuse = (($overuse <= 0) ? "-" : "".formatRates($overuse * 1000).""); } 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); + $background = get_percentage_colours($percent); + $overuse = $rate_data['total_data'] - ($bill['bill_gb'] * 1024); + $overuse = (($overuse <= 0) ? "-" : "".formatStorage($overuse * 1024 * 1024).""); } - $background = get_percentage_colours($percent); $right_background = $background['right']; $left_background = $background['left']; if (!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } echo(" - - + + - - + + + "); diff --git a/includes/billing.php b/includes/billing.php index 8d59ec2be..45d76f22a 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -171,8 +171,13 @@ function getRates($bill_id,$datefrom,$dateto) $a_95th = dbFetchColumn($q_95_sql); $m_95th = $a_95th[$measurement_95th]; - $mtot = getTotal($bill_id,$datefrom,$dateto); - $ptot = getPeriod($bill_id,$datefrom,$dateto); + $sum_data = getSum($bill_id,$datefrom,$dateto); +# $mtot = getTotal($bill_id,$datefrom,$dateto); + $mtot = $sum_data['total']; + $mtot_in = $sum_data['inbound']; + $mtot_out = $sum_data['outbound']; +# $ptot = getPeriod($bill_id,$datefrom,$dateto); + $ptot = $sum_data['period']; $data['rate_95th_in'] = get95thIn($bill_id,$datefrom,$dateto); $data['rate_95th_out'] = get95thOut($bill_id,$datefrom,$dateto); @@ -187,6 +192,8 @@ function getRates($bill_id,$datefrom,$dateto) } $data['total_data'] = round($mtot / 1000 / 1000, 2); + $data['total_data_in'] = round($mtot_in / 1000 / 1000, 2); + $data['total_data_out'] = round($mtot_out / 1000 / 1000, 2); $data['rate_average'] = round($mtot / $ptot / 1000 * 8, 2); # print_r($data); @@ -200,6 +207,12 @@ function getTotal($bill_id,$datefrom,$dateto) return($mtot); } +function getSum($bill_id,$datefrom,$dateto) +{ + $sum = dbFetchRow("SELECT SUM(period) as period, SUM(delta) as total, SUM(in_delta) as inbound, SUM(out_delta) as outbound FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"); + return($sum); +} + function getPeriod($bill_id,$datefrom,$dateto) { $ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'");
Billing nameTypeAllowedUsedOverusage
".$bill['bill_name']."".$bill['bill_name']."
".strftime("%F", strtotime($datefrom))." to ".strftime("%F", strtotime($dateto))."
$notes $type $allowed $used".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."Edit Edit$overuse".print_percentage_bar (250, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."Edit Edit