if ($bill['bill_type'] == 'cdr') { $type = 'CDR'; $allowed = $bill['bill_cdr']; $used = $rate_data['rate_95th']; $allowed_text = format_si($allowed) . 'bps'; $used_text = format_si($used) . 'bps'; $overuse = $used - $allowed; $overuse = $overuse <= 0 ? '0' : $overuse; $percent = round($rate_data['rate_95th'] / $bill['bill_cdr'] * 100, 2); } else { if ($bill['bill_type'] == 'quota') { $type = 'Quota'; $allowed = $bill['bill_quota']; $used = $rate_data['total_data']; $allowed_text = format_bytes_billing($allowed); $used_text = format_bytes_billing($used); $overuse = $used - $allowed; $overuse = $overuse <= 0 ? '0' : $overuse; $percent = round($rate_data['total_data'] / $bill['bill_quota'] * 100, 2); } } echo strftime('%x @ %X', strtotime($datefrom)) . ' to ' . strftime('%x @ %X', strtotime($dateto)) . ' ' . str_pad($type, 8) . ' ' . str_pad($allowed_text, 10) . ' ' . str_pad($used_text, 10) . ' ' . $percent . '%'; if ($i == '0') { $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'])); echo ' Updated! '; } if ($check['bill_id'] == $bill['bill_id']) { $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'], 'rate_average' => $rate_data['rate_average'], 'rate_average_in' => $rate_data['rate_average_in'], 'rate_average_out' => $rate_data['rate_average_out'], 'traf_total' => $rate_data['total_data'], 'traf_in' => $rate_data['total_data_in'], 'traf_out' => $rate_data['total_data_out'], 'bill_used' => $used, 'bill_overuse' => $overuse, 'bill_percent' => $percent, 'updated' => array('NOW()')); dbUpdate($update, 'bill_history', '`bill_hist_id` = ?', array($check['bill_hist_id'])); echo ' Updated history! ';
function list_bills() { global $config; $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); $status = 'ok'; $err_msg = ''; $message = ''; $code = 200; $bills = array(); $bill_id = mres($router['bill_id']); $bill_ref = mres($_GET['ref']); $bill_custid = mres($_GET['custid']); if (!empty($bill_custid)) { $sql = '`bill_custid` = ?'; $param = array($bill_custid); } elseif (!empty($bill_ref)) { $sql = '`bill_ref` = ?'; $param = array($bill_ref); } elseif (is_numeric($bill_id)) { $sql = '`bill_id` = ?'; $param = array($bill_id); } else { $sql = ''; $param = array(); } if (count($param) >= 1) { $sql = "WHERE {$sql}"; } foreach (dbFetchRows("SELECT `bills`.*,COUNT(port_id) AS `ports_total` FROM `bills` LEFT JOIN `bill_ports` ON `bill_ports`.`bill_id`=`bills`.`bill_id` {$sql} GROUP BY `bill_name`,`bill_ref` ORDER BY `bill_name`", $param) as $bill) { $rate_data = $bill; $allowed = ''; $used = ''; $percent = ''; $overuse = ''; if ($bill['bill_type'] == "cdr") { $allowed = format_si($bill['bill_cdr']) . "bps"; $used = format_si($rate_data['rate_95th']) . "bps"; $percent = round($rate_data['rate_95th'] / $bill['bill_cdr'] * 100, 2); $overuse = $rate_data['rate_95th'] - $bill['bill_cdr']; $overuse = $overuse <= 0 ? "-" : format_si($overuse); } elseif ($bill['bill_type'] == "quota") { $allowed = format_bytes_billing($bill['bill_quota']); $used = format_bytes_billing($rate_data['total_data']); $percent = round($rate_data['total_data'] / $bill['bill_quota'] * 100, 2); $overuse = $rate_data['total_data'] - $bill['bill_quota']; $overuse = $overuse <= 0 ? "-" : format_bytes_billing($overuse); } $bill['allowed'] = $allowed; $bill['used'] = $used; $bill['percent'] = $percent; $bill['overuse'] = $overuse; $bills[] = $bill; } $count = count($bills); $output = array('status' => $status, 'message' => $message, 'err-msg' => $err_msg, 'count' => $count, 'bills' => $bills); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
<tr> <?php if ($bill_data['bill_type'] == 'quota') { // The Customer is billed based on a pre-paid quota with overage in xB $percent = round($total_data / $bill_data['bill_quota'] * 100, 2); $unit = 'MB'; $total_data = round($total_data, 2); $background = get_percentage_colours($percent); $type = '&ave=yes'; ?> <td> <?php echo format_bytes_billing($total_data); ?> of <?php echo format_bytes_billing($bill_data['bill_quota']) . ' (' . $percent . '%)'; ?> - Average rate <?php echo formatRates($rate_average); ?> </td> <td style="width: 210px;"><?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']); ?> </td> <?php } else { if ($bill_data['bill_type'] == 'cdr') { // The customer is billed based on a CDR with 95th%ile overage $unit = 'kbps'; $cdr = $bill_data['bill_cdr'];
<?php // Generate a list of ports and then call the multi_bits grapher to generate from the list $i = 0; foreach ($ports as $port) { if (is_file($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"))) { $rrd_list[$i]['filename'] = $config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"); $rrd_list[$i]['descr'] = $port['ifDescr']; $i++; } } $units = 'bps'; $total_units = 'B'; $colours_in = 'greens'; $multiplier = "8"; $colours_out = 'blues'; $nototal = 1; $ds_in = "INOCTETS"; $ds_out = "OUTOCTETS"; #print_r($rates); if ($bill['bill_type'] == "cdr") { $custom_graph = " COMMENT:'\\r' "; $custom_graph .= " HRULE:" . $rates['rate_95th'] . "#cc0000:'95th %ile \\: " . formatRates($rates['rate_95th']) . " (" . $rates['dir_95th'] . ") (CDR\\: " . formatRates($bill['bill_cdr']) . ")'"; $custom_graph .= " HRULE:" . $rates['rate_95th'] * -1 . "#cc0000"; } elseif ($bill['bill_type'] == "quota") { $custom_graph = " COMMENT:'\\r' "; $custom_graph .= " HRULE:" . $rates['rate_average'] . "#cc0000:'Usage \\: " . format_bytes_billing($rates['total_data']) . " (" . formatRates($rates['rate_average']) . ")'"; $custom_graph .= " HRULE:" . $rates['rate_average'] * -1 . "#cc0000"; } include "includes/graphs/generic_multi_bits_separated.inc.php";
if ($bill['bill_type'] == "cdr") { $type = "CDR"; $allowed = format_si($bill['bill_cdr']) . "bps"; $used = format_si($rate_data['rate_95th']) . "bps"; $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 ? "-" : "<span style=\"color: #" . $background['left'] . "; font-weight: bold;\">" . format_si($overuse) . "bps</span>"; } elseif ($bill['bill_type'] == "quota") { $type = "Quota"; $allowed = format_bytes_billing($bill['bill_quota']); $used = format_bytes_billing($rate_data['total_data']); $percent = round($rate_data['total_data'] / $bill['bill_quota'] * 100, 2); $background = get_percentage_colours($percent); $overuse = $rate_data['total_data'] - $bill['bill_quota']; $overuse = $overuse <= 0 ? "-" : "<span style=\"color: #" . $background['left'] . "; font-weight: bold;\">" . format_bytes_billing($overuse) . "</span>"; } $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 "\n <tr bgcolor='{$row_colour}'>\n <td><a href='" . generate_url(array('page' => "bill", 'bill_id' => $bill['bill_id'])) . "'><span style='font-weight: bold;' class=interface>" . $bill['bill_name'] . "</span></a><br />" . strftime("%F", strtotime($datefrom)) . " to " . strftime("%F", strtotime($dateto)) . "</td>\n <td>{$notes}</td>\n <td>{$type}</td>\n <td>{$allowed}</td>\n <td>{$used}</td>\n <td style=\"text-align: center;\">{$overuse}</td>\n <td>" . print_percentage_bar(250, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']) . "</td>\n <td><a href='" . generate_url(array('page' => "bill", 'bill_id' => $bill['bill_id'], 'view' => "edit")) . "'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a></td>\n </tr>\n "; $i++; } // PERMITTED } echo "</table>"; }
$in['ave'] = format_bytes_billing($bill_data['total_data_in'] / $cur_days); $in['est'] = format_bytes_billing($bill_data['total_data_in'] / $cur_days * $total_days); $in['per'] = round($bill_data['total_data_in'] / $bill_data['total_data'] * 100, 2); $in['bg'] = get_percentage_colours($in['per']); $out['data'] = format_bytes_billing($bill_data['total_data_out']); $out['allow'] = $total['allow']; $out['ave'] = format_bytes_billing($bill_data['total_data_out'] / $cur_days); $out['est'] = format_bytes_billing($bill_data['total_data_out'] / $cur_days * $total_days); $out['per'] = round($bill_data['total_data_out'] / $bill_data['total_data'] * 100, 2); $out['bg'] = get_percentage_colours($out['per']); $ousage['over'] = $bill_data['total_data'] - $bill_data['bill_quota']; $ousage['over'] = $ousage['over'] < 0 ? "0" : $ousage['over']; $ousage['data'] = format_number($ousage['over'], $config['billing']['base']); $ousage['allow'] = $total['allow']; $ousage['ave'] = format_bytes_billing($ousage['over'] / $cur_days); $ousage['est'] = format_bytes_billing($ousage['over'] / $cur_days * $total_days); $ousage['per'] = round($bill_data['total_data'] / $bill_data['bill_quota'] * 100 - 100, 2); $ousage['per'] = $ousage['per'] < 0 ? "0" : $ousage['per']; $ousage['bg'] = get_percentage_colours($ousage['per']); function showPercent($per) { $background = get_percentage_colours($per); $right_background = $background['right']; $left_background = $background['left']; $res = print_percentage_bar(350, 20, $per, NULL, "ffffff", $left_background, $per . "%", "ffffff", $right_background); return $res; } echo "<h3>Bill Summary</h3>"; echo "<h4>Quota Bill</h4>"; echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" class=\"devicetable\">"; echo " <tr><td colspan=\"7\">Billing Period from " . $fromtext . " to " . $totext . "</td></tr>";
$type = $bill['bill_type']; $percent = $bill['bill_percent']; $dir_95th = $bill['dir_95th']; $rate_95th = format_si($bill['rate_95th']) . 'bps'; $total_data = format_bytes_billing($bill['traf_total']); $background = get_percentage_colours($percent); if ($type == 'CDR') { $allowed = format_si($bill['bill_allowed']) . 'bps'; $used = format_si($bill['rate_95th']) . 'bps'; $in = format_si($bill['rate_95th_in']) . 'bps'; $out = format_si($bill['rate_95th_out']) . 'bps'; $overuse = $bill['bill_overuse'] <= 0 ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . format_si($bill['bill_overuse']) . 'bps</span>'; } else { if ($type == 'Quota') { $allowed = format_bytes_billing($bill['bill_allowed']); $used = format_bytes_billing($bill['total_data']); $in = format_bytes_billing($bill['traf_in']); $out = format_bytes_billing($bill['traf_out']); $overuse = $bill['bill_overuse'] <= 0 ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . format_bytes_billing($bill['bill_overuse']) . '</span>'; } } $total_data = $type == 'Quota' ? '<b>' . $total_data . '</b>' : $total_data; $rate_95th = $type == 'CDR' ? '<b>' . $rate_95th . '</b>' : $rate_95th; echo "\n <tr>\n <td><a href=\"" . generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'history', detail => $bill['bill_hist_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>\n <td>{$type}</td>\n <td>{$allowed}</td>\n <td>{$in}</td>\n <td>{$out}</td>\n <td>{$total_data}</td>\n <td>{$rate_95th}</td>\n <td style=\"text-align: center;\">{$overuse}</td>\n <td>" . print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) . '</td> </tr>'; } //end if } //end foreach echo '</tbody> </table>';
?> of <?php echo format_si($cdr) . 'bps (' . $percent . '%)'; ?> (95th%ile) </td> <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"> <?php echo 'Predicated usage: ' . format_bytes_billing(getPredictedUsage($bill_data['bill_day'], $bill_data['rate_95th'])); ?> </td> <?php } //end if ?> </tr> </table> </div> </div> </div> <?php $lastmonth = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))');
$active['previous'] = $vars['tab'] == "previous" ? "active" : ""; if (empty($active['billing']) && empty($active['24hour']) && empty($active['monthly']) && empty($active['detail']) && empty($active['previous'])) { $active['billing'] = "active"; } $graph = ""; $cur_days = date('d', $config['time']['now'] - strtotime($datefrom)); $total_days = date('d', strtotime($dateto)); $used = format_bytes_billing($total_data); $average = format_bytes_billing($total_data / $cur_days); $estimated = format_bytes_billing($total_data / $cur_days * $total_days); if ($bill_data['bill_type'] == "quota") { $quota = $bill_data['bill_quota']; $percent = round($total_data / $quota * 100, 2); $allowed = format_si($quota) . "B"; $overuse = $total_data - $quota; $overuse = $overuse <= 0 ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-important\">" . format_bytes_billing($overuse) . "</span>"; $type = "Quota"; } elseif ($bill_data['bill_type'] == "cdr") { $cdr = $bill_data['bill_cdr']; $percent = "0"; $allowed = "-"; $overuse = "<span class=\"badge badge-success\">-</span>"; $type = "CDR / 95th percentile"; } $optional['cust'] = $isAdmin && !empty($bill_data['bill_custid']) ? $bill_data['bill_custid'] : "n/a"; $optional['ref'] = $isAdmin && !empty($bill_data['bill_ref']) ? $bill_data['bill_ref'] : "n/a"; $optional['notes'] = !empty($bill_data['bill_notes']) ? $bill_data['bill_notes'] : "n/a"; $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); $bi = "<img src='bandwidth-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
include "pages/bill/transfer.inc.php"; } elseif ($vars['view'] == "quick" || $vars['view'] == "accurate") { echo "<h3>Billed Ports</h3>"; // Collected Earlier foreach ($ports as $port) { echo generate_port_link($port) . " on " . generate_device_link($port) . "<br />"; } echo "<h3>Bill Summary</h3>"; if ($bill_data['bill_type'] == "quota") { // The Customer is billed based on a pre-paid quota with overage in xB echo "<h4>Quota Bill</h4>"; $percent = round($total_data / $bill_data['bill_quota'] * 100, 2); $unit = "MB"; $total_data = round($total_data, 2); echo "Billing Period from " . $fromtext . " to " . $totext; echo "<br />Transferred " . format_bytes_billing($total_data) . " of " . format_bytes_billing($bill_data['bill_quota']) . " (" . $percent . "%)"; echo "<br />Average rate " . formatRates($rate_average); $background = get_percentage_colours($percent); echo "<p>" . print_percentage_bar(350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']) . "</p>"; $type = "&ave=yes"; } elseif ($bill_data['bill_type'] == "cdr") { // The customer is billed based on a CDR with 95th%ile overage echo "<h4>CDR / 95th Bill</h4>"; $unit = "kbps"; $cdr = $bill_data['bill_cdr']; $rate_95th = round($rate_95th, 2); $percent = round($rate_95th / $cdr * 100, 2); $type = "&95th=yes"; echo "<strong>" . $fromtext . " to " . $totext . "</strong>\n <br />Measured " . format_si($rate_95th) . "bps of " . format_si($cdr) . "bps (" . $percent . "%) @ 95th %ile"; $background = get_percentage_colours($percent); echo "<p>" . print_percentage_bar(350, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']) . "</p>";
if (strtolower($history['bill_type']) == "cdr") { $type = "CDR 95th"; $allowed = format_si($history['bill_allowed']) . "bps"; $used = format_si($rate_data['rate_95th']) . "bps"; $percent = round($rate_data['rate_95th'] / $history['bill_allowed'] * 100, 2); $background = get_percentage_colours($percent); $overuse = $rate_data['rate_95th'] - $history['bill_allowed']; $overuse = $overuse <= 0 ? "-" : format_si($overuse) . "bps"; } elseif (strtolower($history['bill_type']) == "quota") { $type = "限额"; $allowed = format_bytes_billing($history['bill_allowed']); $used = format_bytes_billing($rate_data['traf_total']); $percent = round($rate_data['traf_total'] / $history['bill_allowed'] * 100, 2); $background = get_percentage_colours($percent); $overuse = $rate_data['traf_total'] - $history['bill_allowed']; $overuse = $overuse <= 0 ? "-" : format_bytes_billing($overuse); } switch (true) { case $percent >= 90: $perc['BG'] = "danger"; break; case $percent >= 75: $perc['BG'] = "warning"; break; case $percent >= 50: $perc['BG'] = "success"; break; default: $perc['BG'] = "info"; } $perc['width'] = $percent <= "100" ? $percent : "100";
$overuse = $bill['rate_95th'] - $bill['bill_allowed']; } $overuse_formatted = format_si($overuse) . 'bps'; $used = $rate_95th; $rate_95th = "<b>{$rate_95th}</b>"; } else { if (strtolower($bill['bill_type']) == 'quota') { $type = 'Quota'; $allowed = format_bytes_billing($bill['bill_allowed']); $in = format_bytes_billing($bill['traf_in']); $out = format_bytes_billing($bill['traf_out']); if (!$prev) { $percent = round($bill['total_data'] / $bill['bill_allowed'] * 100, 2); $overuse = $bill['total_data'] - $bill['bill_allowed']; } $overuse_formatted = format_bytes_billing($overuse); $used = $total_data; $total_data = "<b>{$total_data}</b>"; } } $background = get_percentage_colours($percent); $right_background = $background['right']; $left_background = $background['left']; $overuse_formatted = $overuse <= 0 ? '-' : "<span style='color: #{$background['left']}; font-weight: bold;'>{$overuse_formatted}</span>"; $bill_name = "<a href='{$url}'><span style='font-weight: bold;' class='interface'>{$bill['bill_name']}</span></a><br />" . strftime('%F', strtotime($datefrom)) . " to " . strftime('%F', strtotime($dateto)); $bar = print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']); $actions = ""; if (!$prev && is_admin()) { $actions .= "<a href='" . generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'edit')) . "'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a> "; } $response[] = array('bill_name' => $bill_name, 'notes' => $notes, 'bill_type' => $type, 'bill_allowed' => $allowed, 'total_data_in' => $in, 'total_data_out' => $out, 'total_data' => $total_data, 'rate_95th' => $rate_95th, 'used' => $used, 'overusage' => $overuse_formatted, 'graph' => $bar, 'actions' => $actions);
$total_days = date('d', strtotime($dateto)); //$used = format_bytes_billing($total_data); //$average = format_bytes_billing($total_data / $cur_days); //$estimated = format_bytes_billing($total_data / $cur_days * $total_days); if ($bill_data['bill_type'] == "quota") { $quota = $bill_data['bill_quota']; $percent = round($total_data / $quota * 100, 2); $used = format_bytes_billing($total_data); $allowed = format_si($quota) . "B"; $overuse = $total_data - $quota; $overuse = $overuse <= 0 ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-important\">" . format_bytes_billing($overuse) . "</span>"; $type = "Quota"; $imgtype = "&ave=yes"; $current = array('in' => format_bytes_billing($bill_data['total_data_in']), 'out' => format_bytes_billing($bill_data['total_data_out']), 'tot' => format_bytes_billing($bill_data['total_data'])); $average = array('in' => format_bytes_billing($bill_data['total_data_in'] / $cur_days), 'out' => format_bytes_billing($bill_data['total_data_out'] / $cur_days), 'tot' => format_bytes_billing($bill_data['total_data'] / $cur_days)); $estimated = array('in' => format_bytes_billing($bill_data['total_data_in'] / $cur_days * $total_days), 'out' => format_bytes_billing($bill_data['total_data_out'] / $cur_days * $total_days), 'tot' => format_bytes_billing($bill_data['total_data'] / $cur_days * $total_days)); } elseif ($bill_data['bill_type'] == "cdr") { $cdr = $bill_data['bill_cdr']; $percent = round($rate_95th / $cdr * 100, 2); $used = format_si($rate_95th) . "bps"; $allowed = format_si($cdr) . "bps"; $overuse = $rate_95th - $cdr; $overuse = $overuse <= 0 ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-important\">" . format_si($overuse) . "bps</span>"; $type = "CDR / 95th %"; $imgtype = "&95th=yes"; $current = array('in' => format_si($bill_data['rate_95th_in']) . "bps", 'out' => format_si($bill_data['rate_95th_out']) . "bps", 'tot' => format_si($bill_data['rate_95th']) . "bps"); $average = array('in' => format_si($bill_data['rate_average_in']) . "bps", 'out' => format_si($bill_data['rate_average_out']) . "bps", 'tot' => format_si($bill_data['rate_average']) . "bps"); $estimated = array('in' => "n/a", 'out' => "n/a", 'tot' => "n/a"); } $optional['cust'] = $isAdmin && !empty($bill_data['bill_custid']) ? $bill_data['bill_custid'] : "n/a"; $optional['ref'] = $isAdmin && !empty($bill_data['bill_ref']) ? $bill_data['bill_ref'] : "n/a";
} else { if ($vars['view'] == 'quick' || $vars['view'] == 'accurate') { echo '<h3>Billed Ports</h3>'; // Collected Earlier foreach ($ports as $port) { echo generate_port_link($port) . ' on ' . generate_device_link($port) . '<br />'; } echo '<h3>Bill Summary</h3>'; if ($bill_data['bill_type'] == 'quota') { // The Customer is billed based on a pre-paid quota with overage in xB echo '<h4>Quota Bill</h4>'; $percent = round($total_data / $bill_data['bill_quota'] * 100, 2); $unit = 'MB'; $total_data = round($total_data, 2); echo 'Billing Period from ' . $fromtext . ' to ' . $totext; echo '<br />Transferred ' . format_bytes_billing($total_data) . ' of ' . format_bytes_billing($bill_data['bill_quota']) . ' (' . $percent . '%)'; echo '<br />Average rate ' . formatRates($rate_average); $background = get_percentage_colours($percent); echo '<p>' . print_percentage_bar(350, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) . '</p>'; $type = '&ave=yes'; } else { if ($bill_data['bill_type'] == 'cdr') { // The customer is billed based on a CDR with 95th%ile overage echo '<h4>CDR / 95th Bill</h4>'; $unit = 'kbps'; $cdr = $bill_data['bill_cdr']; $rate_95th = round($rate_95th, 2); $percent = round($rate_95th / $cdr * 100, 2); $type = '&95th=yes'; echo '<strong>' . $fromtext . ' to ' . $totext . '</strong> <br />Measured ' . format_si($rate_95th) . 'bps of ' . format_si($cdr) . 'bps (' . $percent . '%) @ 95th %ile';
$tmp_used = $bill['rate_95th']; $rate_95th = "<b>{$rate_95th}</b>"; } elseif (strtolower($bill['bill_type']) == 'quota') { $type = 'Quota'; $allowed = format_bytes_billing($bill['bill_allowed']); $in = format_bytes_billing($bill['traf_in']); $out = format_bytes_billing($bill['traf_out']); if (!$prev) { $percent = round($bill['total_data'] / $bill['bill_allowed'] * 100, 2); $overuse = $bill['total_data'] - $bill['bill_allowed']; } $overuse_formatted = format_bytes_billing($overuse); $used = $total_data; $tmp_used = $bill['total_data']; $total_data = "<b>{$total_data}</b>"; } $background = get_percentage_colours($percent); $right_background = $background['right']; $left_background = $background['left']; $overuse_formatted = $overuse <= 0 ? '-' : "<span style='color: #{$background['left']}; font-weight: bold;'>{$overuse_formatted}</span>"; $bill_name = "<a href='{$url}'><span style='font-weight: bold;' class='interface'>{$bill['bill_name']}</span></a><br />" . strftime('%F', strtotime($datefrom)) . " to " . strftime('%F', strtotime($dateto)); $bar = print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']); $actions = ""; if (!$prev && is_admin()) { $actions .= "<a href='" . generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'edit')) . "'><img src='images/16/wrench.png' align=absmiddle alt='Edit'> Edit</a> "; } $predicted = format_bytes_billing(getPredictedUsage($bill['bill_day'], $tmp_used)); $response[] = array('bill_name' => $bill_name, 'notes' => $notes, 'bill_type' => $type, 'bill_allowed' => $allowed, 'total_data_in' => $in, 'total_data_out' => $out, 'total_data' => $total_data, 'rate_95th' => $rate_95th, 'used' => $used, 'overusage' => $overuse_formatted, 'predicted' => $predicted, 'graph' => $bar, 'actions' => $actions); } $output = array('current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total); echo _json_encode($output);