Files

278 lines
10 KiB
PHP
Raw Permalink Normal View History

<?php
2011-12-02 17:11:28 +00:00
$bill_id = mres($vars['bill_id']);
if (Auth::user()->hasGlobalAdmin()) {
2019-04-11 23:26:42 -05:00
include 'includes/html/pages/bill/actions.inc.php';
}
2015-07-13 20:10:26 +02:00
if (bill_permitted($bill_id)) {
2020-09-21 15:40:17 +02:00
$bill_data = dbFetchRow('SELECT * FROM bills WHERE bill_id = ?', [$bill_id]);
2011-12-02 22:11:06 +00:00
2015-07-13 20:10:26 +02:00
$bill_name = $bill_data['bill_name'];
2020-09-21 15:40:17 +02:00
$today = str_replace('-', '', dbFetchCell('SELECT CURDATE()'));
$yesterday = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)'));
$tomorrow = str_replace('-', '', dbFetchCell('SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)'));
2015-07-13 20:10:26 +02:00
$last_month = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'));
2020-09-21 15:40:17 +02:00
$rightnow = $today . date('His');
$before = $yesterday . date('His');
$lastmonth = $last_month . date('His');
2020-09-21 15:40:17 +02:00
$bill_name = $bill_data['bill_name'];
2015-07-13 20:10:26 +02:00
$dayofmonth = $bill_data['bill_day'];
2015-07-13 20:10:26 +02:00
$day_data = getDates($dayofmonth);
$datefrom = $day_data['0'];
2020-09-21 15:40:17 +02:00
$dateto = $day_data['1'];
2015-07-13 20:10:26 +02:00
$lastfrom = $day_data['2'];
2020-09-21 15:40:17 +02:00
$lastto = $day_data['3'];
2015-07-13 20:10:26 +02:00
2020-09-21 15:40:17 +02:00
$rate_95th = $bill_data['rate_95th'];
$dir_95th = $bill_data['dir_95th'];
$total_data = $bill_data['total_data'];
2015-07-13 20:10:26 +02:00
$rate_average = $bill_data['rate_average'];
2010-07-31 21:08:35 +00:00
2015-07-13 20:10:26 +02:00
if ($rate_95th > $paid_kb) {
2020-09-21 15:40:17 +02:00
$over = ($rate_95th - $paid_kb);
$bill_text = $over . 'Kbit excess.';
2015-07-13 20:10:26 +02:00
$bill_color = '#cc0000';
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:40:17 +02:00
$under = ($paid_kb - $rate_95th);
$bill_text = $under . 'Kbit headroom.';
2015-07-13 20:10:26 +02:00
$bill_color = '#0000cc';
}
2019-06-23 00:29:12 -05:00
$fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '" . \LibreNMS\Config::get('dateformat.mysql.date') . "')");
$totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '" . \LibreNMS\Config::get('dateformat.mysql.date') . "')");
2015-07-13 20:10:26 +02:00
$unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')");
2020-09-21 15:40:17 +02:00
$unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')");
2015-07-13 20:10:26 +02:00
$unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')");
2020-09-21 15:40:17 +02:00
$unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')");
2015-07-13 20:10:26 +02:00
// Speeds up loading for other included pages by setting it before progessing of mysql data!
$ports = dbFetchRows(
'SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
WHERE B.bill_id = ? AND P.port_id = B.port_id
AND D.device_id = P.device_id',
2020-09-21 15:40:17 +02:00
[$bill_id]
2015-07-13 20:10:26 +02:00
);
2020-09-21 15:40:17 +02:00
if (! $vars['view']) {
2015-07-13 20:10:26 +02:00
$vars['view'] = 'quick';
2011-11-05 14:55:08 +00:00
}
2016-08-18 20:28:22 -05:00
2018-05-14 12:31:46 -05:00
function print_port_list($ports)
2016-08-18 20:28:22 -05:00
{
echo '<div class="panel panel-default">
2016-03-07 12:48:27 +00:00
<div class="panel-heading">
<h3 class="panel-title">Billed Ports</h3>
</div>
2016-08-18 20:28:22 -05:00
<div class="list-group">';
// Collected Earlier
foreach ($ports as $port) {
$port = cleanPort($port);
2020-09-21 15:40:17 +02:00
$portalias = (empty($port['ifAlias']) ? '' : ' - ' . $port['ifAlias'] . '');
2016-08-18 20:28:22 -05:00
echo '<div class="list-group-item">';
2020-09-21 15:40:17 +02:00
echo generate_port_link($port, $port['ifName'] . $portalias) . ' on ' . generate_device_link($port);
2016-08-18 20:28:22 -05:00
echo '</div>';
}
echo '</div></div>';
2020-09-21 15:43:38 +02:00
}//end print_port_list?>
2016-03-07 12:48:27 +00:00
<h2><?php echo "Bill: ${bill_data['bill_name']}"; ?></h2>
2020-04-03 08:41:24 -05:00
<?php
2016-03-07 12:48:27 +00:00
print_optionbar_start();
2020-09-21 15:59:34 +02:00
echo '<strong>Bill</strong> &raquo; ';
2020-09-21 15:40:17 +02:00
$menu_options = [
2016-03-07 12:48:27 +00:00
'quick' => 'Quick Graphs',
'accurate' => 'Accurate Graphs',
'transfer' => 'Transfer Graphs',
2020-09-21 15:40:17 +02:00
'history' => 'Historical Graphs',
];
2020-04-03 08:41:24 -05:00
if (Auth::user()->hasGlobalAdmin()) {
$menu_options['edit'] = 'Edit';
$menu_options['delete'] = 'Delete';
$menu_options['reset'] = 'Reset';
}
2020-04-03 08:41:24 -05:00
$sep = '';
foreach ($menu_options as $option => $text) {
echo $sep;
if ($vars['view'] == $option) {
echo "<span class='pagemenu-selected'>";
}
2020-09-21 15:40:17 +02:00
echo generate_link($text, $vars, ['view' => $option]);
2020-04-03 08:41:24 -05:00
if ($vars['view'] == $option) {
echo '</span>';
}
2020-04-03 08:41:24 -05:00
$sep = ' | ';
}
2020-09-21 15:40:17 +02:00
echo '<div style="font-weight: bold; float: right;"><a href="' . generate_url(['page' => 'bills']) . '/"><i class="fa fa-arrow-left fa-lg icon-theme" aria-hidden="true"></i> Back to Bills</a></div>';
2015-07-13 20:10:26 +02:00
print_optionbar_end();
2010-07-31 21:08:35 +00:00
2020-04-03 08:41:24 -05:00
if ($vars['view'] == 'edit' && Auth::user()->hasGlobalAdmin()) {
include 'includes/html/pages/bill/edit.inc.php';
} elseif ($vars['view'] == 'delete' && Auth::user()->hasGlobalAdmin()) {
include 'includes/html/pages/bill/delete.inc.php';
} elseif ($vars['view'] == 'reset' && Auth::user()->hasGlobalAdmin()) {
include 'includes/html/pages/bill/reset.inc.php';
} elseif ($vars['view'] == 'history') {
include 'includes/html/pages/bill/history.inc.php';
} elseif ($vars['view'] == 'transfer') {
include 'includes/html/pages/bill/transfer.inc.php';
} elseif ($vars['view'] == 'quick' || $vars['view'] == 'accurate') {
?>
<?php if ($bill_data['bill_type'] == 'quota') { ?>
2016-03-07 12:48:27 +00:00
<h3>Quota Bill</h3>
2020-04-03 08:41:24 -05:00
<?php } elseif ($bill_data['bill_type'] == 'cdr') { ?>
2016-03-07 12:48:27 +00:00
<h3>
CDR / 95th Bill
</h3>
2020-04-03 08:41:24 -05:00
<?php } ?>
2016-03-07 12:48:27 +00:00
<strong>Billing Period from <?php echo $fromtext ?> to <?php echo $totext ?></strong>
<br /><br />
<div class="row">
<div class="col-lg-6 col-lg-push-6">
2020-04-03 08:41:24 -05:00
<?php print_port_list($ports) ?>
</div>
<div class="col-lg-6 col-lg-pull-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Bill Summary
</h3>
2016-03-07 12:48:27 +00:00
</div>
<table class="table">
<tr>
2020-04-03 08:41:24 -05:00
<?php if ($bill_data['bill_type'] == 'quota') {
2015-07-13 20:10:26 +02:00
// The Customer is billed based on a pre-paid quota with overage in xB
2020-09-21 15:40:17 +02:00
$percent = round((($total_data) / $bill_data['bill_quota'] * 100), 2);
$unit = 'MB';
2015-07-13 20:10:26 +02:00
$total_data = round($total_data, 2);
$background = get_percentage_colours($percent);
2020-09-21 15:40:17 +02:00
$type = '&amp;ave=yes'; ?>
2016-03-07 12:48:27 +00:00
<td>
2020-09-21 15:40:17 +02:00
<?php echo format_bytes_billing($total_data) ?> of <?php echo format_bytes_billing($bill_data['bill_quota']) . ' (' . $percent . '%)' ?>
2016-03-07 12:48:27 +00:00
- Average rate <?php echo formatRates($rate_average) ?>
</td>
2020-09-21 15:40:17 +02:00
<td style="width: 210px;"><?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) ?></td>
</tr>
<tr>
<td colspan="2">
2020-04-03 08:41:24 -05:00
<?php
2020-09-21 15:40:17 +02:00
echo 'Predicted usage: ' . format_bytes_billing(getPredictedUsage($bill_data['bill_day'], $bill_data['total_data'])); ?>
</td>
2020-04-03 08:41:24 -05:00
<?php
} elseif ($bill_data['bill_type'] == 'cdr') {
2015-07-13 20:10:26 +02:00
// The customer is billed based on a CDR with 95th%ile overage
2020-09-21 15:40:17 +02:00
$unit = 'kbps';
$cdr = $bill_data['bill_cdr'];
2015-07-13 20:10:26 +02:00
$rate_95th = round($rate_95th, 2);
$percent = round((($rate_95th) / $cdr * 100), 2);
$background = get_percentage_colours($percent);
2020-09-21 15:40:17 +02:00
$type = '&amp;95th=yes'; ?>
2016-03-07 12:48:27 +00:00
<td>
2020-09-21 15:40:17 +02:00
<?php echo format_si($rate_95th) . 'bps' ?> of <?php echo format_si($cdr) . 'bps (' . $percent . '%)' ?> (95th%ile)
2016-03-07 12:48:27 +00:00
</td>
<td style="width: 210px;">
2020-09-21 15:40:17 +02:00
<?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) ?>
2016-03-07 12:48:27 +00:00
</td>
</tr>
<tr>
<td colspan="2">
2020-04-03 08:41:24 -05:00
<?php
2020-09-21 15:40:17 +02:00
echo 'Predicted usage: ' . format_si(getPredictedUsage($bill_data['bill_day'], $bill_data['rate_95th'])) . 'bps'; ?>
</td>
2016-03-07 12:48:27 +00:00
2020-09-21 15:40:17 +02:00
<?php
2020-09-21 15:43:38 +02:00
}//end if?>
</tr>
</table>
</div>
</div>
</div>
2015-07-13 20:10:26 +02:00
2020-04-03 08:41:24 -05:00
<?php
$lastmonth = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))');
$yesterday = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))');
2020-09-21 15:40:17 +02:00
$rightnow = date('U');
2020-04-03 08:41:24 -05:00
if ($vars['view'] == 'accurate') {
2020-09-21 15:40:17 +02:00
$bi = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . $_GET['bill_code'];
$bi .= '&amp;from=' . $unixfrom . '&amp;to=' . $unixto;
2020-04-03 08:41:24 -05:00
$bi .= '&amp;x=1190&amp;y=250';
$bi .= "$type'>";
2020-09-21 15:40:17 +02:00
$li = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . $_GET['bill_code'];
$li .= '&amp;from=' . $unix_prev_from . '&amp;to=' . $unix_prev_to;
2020-04-03 08:41:24 -05:00
$li .= '&amp;x=1190&amp;y=250';
$li .= "$type'>";
2020-09-21 15:40:17 +02:00
$di = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . $_GET['bill_code'];
2020-04-03 08:41:24 -05:00
$di .= '&amp;from=' . \LibreNMS\Config::get('time.day') . '&amp;to=' . \LibreNMS\Config::get('time.now');
$di .= '&amp;x=1190&amp;y=250';
$di .= "$type'>";
2020-09-21 15:40:17 +02:00
$mi = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . $_GET['bill_code'];
$mi .= '&amp;from=' . $lastmonth . '&amp;to=' . $rightnow;
2020-04-03 08:41:24 -05:00
$mi .= '&amp;x=1190&amp;y=250';
$mi .= "$type'>";
} else {
2020-09-21 15:40:17 +02:00
$bi = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
$bi .= '&amp;from=' . $unixfrom . '&amp;to=' . $unixto;
2020-09-21 15:59:34 +02:00
$bi .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
2020-04-03 08:41:24 -05:00
2020-09-21 15:40:17 +02:00
$li = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
$li .= '&amp;from=' . $unix_prev_from . '&amp;to=' . $unix_prev_to;
2020-09-21 15:59:34 +02:00
$li .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
2020-04-03 08:41:24 -05:00
2020-09-21 15:40:17 +02:00
$di = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
2020-04-03 08:41:24 -05:00
$di .= '&amp;from=' . \LibreNMS\Config::get('time.day') . '&amp;to=' . \LibreNMS\Config::get('time.now');
2020-09-21 15:59:34 +02:00
$di .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
2020-04-03 08:41:24 -05:00
2020-09-21 15:40:17 +02:00
$mi = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
$mi .= '&amp;from=' . $lastmonth . '&amp;to=' . $rightnow;
2020-09-21 15:59:34 +02:00
$mi .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
2020-04-03 08:41:24 -05:00
}//end if
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Billing View</h3>
</div>
2020-04-03 08:41:24 -05:00
<?php echo $bi ?>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">24 Hour View</h3>
</div>
2020-04-03 08:41:24 -05:00
<?php echo $di ?>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Monthly View</h3>
</div>
2020-04-03 08:41:24 -05:00
<?php echo $mi ?>
</div>
2020-04-03 08:41:24 -05:00
<?php
} //end if
2016-08-18 20:28:22 -05:00
} else {
2019-04-11 23:26:42 -05:00
include 'includes/html/error-no-perm.inc.php';
2015-07-13 20:10:26 +02:00
}//end if
?>