1<?php 2 3use LibreNMS\Util\Number; 4 5$pagetitle[] = 'Historical Usage'; 6// $detail = (isset($vars['detail']) ? $vars['detail'] : ""); 7// $url = $PHP_SELF."/bill/".$bill_id."/history/"; 8$i = 0; 9 10$img['his'] = '<img src="graph.php?id=' . $bill_id; 11$img['his'] .= '&type=bill_historicmonthly'; 12$img['his'] .= '&width=1190&height=250'; 13$img['his'] .= '" style="margin: 15px 5px 25px 5px;" />'; 14?> 15 16<h3>Historical Usage</h3> 17 18<div class="panel panel-default"> 19 <div class="panel-heading"> 20 <h3 class="panel-title">Monthly Usage</h3> 21 </div> 22 <?php echo $img['his'] ?> 23</div> 24 25<?php 26 27function showDetails($bill_id, $imgtype, $bill_hist_id) 28{ 29 $res = '<img src="graph.php?id=' . $bill_id; 30 31 if ($imgtype == 'bitrate') { 32 $res .= '&type=bill_historicbits'; 33 } else { 34 $res .= '&type=bill_historictransfer'; 35 $res .= '&imgtype=' . $imgtype; 36 } 37 $res .= '&width=1190&height=250'; 38 if (is_numeric($bill_hist_id)) { 39 $res .= '&bill_hist_id=' . $bill_hist_id; 40 } 41 $res .= '" style="margin: 15px 5px 25px 5px;" />'; 42 43 return $res; 44}//end showDetails() 45 46// $url = generate_url($vars, array('detail' => 'yes')); 47$url = $PHP_SELF . '/bill/' . $bill_id . '/history/detail=all/'; 48 49echo '<table class="table table-striped"> 50 <thead> 51 <tr style="font-weight: bold; "> 52 <th width="7"></th> 53 <th width="250">Period</th> 54 <th>Type</th> 55 <th>Allowed</th> 56 <th>Inbound</th> 57 <th>Outbound</th> 58 <th>Total</th> 59 <th>95th %ile</th> 60 <th style="text-align: center;">Overusage</th> 61 <th colspan="2" style="text-align: right;"><a href="' . \LibreNMS\Util\Url::generate($vars, ['detail' => 'all']) . '"> 62 <i class="fa fa-bar-chart fa-lg icon-theme" aria-hidden="true" title="Show details"></i> Show details</a> 63 </th> 64 </tr> 65 </thead> 66 <tbody>'; 67 68foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 24', [$bill_id]) as $history) { 69 if (bill_permitted($history['bill_id'])) { 70 unset($class); 71 $datefrom = $history['bill_datefrom']; 72 $dateto = $history['bill_dateto']; 73 $type = $history['bill_type']; 74 $percent = $history['bill_percent']; 75 $dir_95th = $history['dir_95th']; 76 $rate_95th = Number::formatSi($history['rate_95th'], 2, 3, 'bps'); 77 $total_data = Number::formatBase($history['traf_total'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); 78 79 $background = \LibreNMS\Util\Colors::percentage($percent, null); 80 81 if ($type == 'CDR') { 82 $allowed = Number::formatSi($history['bill_allowed'], 2, 3, 'bps'); 83 $used = Number::formatSi($history['rate_95th'], 2, 3, 'bps'); 84 $in = Number::formatSi($history['rate_95th_in'], 2, 3, 'bps'); 85 $out = Number::formatSi($history['rate_95th_out'], 2, 3, 'bps'); 86 $overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . Number::formatSi($history['bill_overuse'], 2, 3, 'bps') . '</span>'); 87 } elseif ($type == 'Quota') { 88 $allowed = Number::formatBase($history['bill_allowed'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); 89 $used = Number::formatBase($history['total_data'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); 90 $in = Number::formatBase($history['traf_in'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); 91 $out = Number::formatBase($history['traf_out'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); 92 $overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . Number::formatBase($history['bill_overuse'], \LibreNMS\Config::get('billing.base')) . '</span>'); 93 } 94 95 $total_data = (($type == 'Quota') ? '<b>' . $total_data . '</b>' : $total_data); 96 $rate_95th = (($type == 'CDR') ? '<b>' . $rate_95th . '</b>' : $rate_95th); 97 98 $url = \LibreNMS\Util\Url::generate($vars, ['detail' => $history['bill_hist_id']]); 99 100 echo ' 101 <tr> 102 <td></td> 103 <td><span style="font-weight: bold;" class="interface">' . strftime('%Y-%m-%d', strtotime($datefrom)) . ' to ' . strftime('%Y-%m-%d', strtotime($dateto)) . "</span></td> 104 <td>$type</td> 105 <td>$allowed</td> 106 <td>$in</td> 107 <td>$out</td> 108 <td>$total_data</td> 109 <td>$rate_95th</td> 110 <td style=\"text-align: center;\">$overuse</td> 111 <td width=\"250\">" . print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) . '</td> 112 <td> 113 <a href="' . $url . '"><i class="fa fa-bar-chart fa-lg icon-theme" aria-hidden="true" title="Show details"></i></a> 114 </td> 115 </tr>'; 116 117 if ($vars['detail'] == $history['bill_hist_id'] || $vars['detail'] == 'all') { 118 $img['bitrate'] = showDetails($bill_id, 'bitrate', $history['bill_hist_id']); 119 $img['bw_day'] = showDetails($bill_id, 'day', $history['bill_hist_id']); 120 $img['bw_hour'] = showDetails($bill_id, 'hour', $history['bill_hist_id']); 121 echo ' 122 <tr style="background: #fff; border-top: 1px solid ' . $row_colour . '; border-bottom: 1px solid #ccc;"> 123 <td colspan="11"> 124 <!-- <b>Accuate Graph</b><br /> //--> 125 ' . $img['bitrate'] . '<br /> 126 <!-- <b>Bandwidth Graph per day</b><br /> //--> 127 ' . $img['bw_day'] . '<br /> 128 <!-- <b>Bandwidth Graph per hour</b><br /> //--> 129 ' . $img['bw_hour'] . ' 130 </td> 131 </tr>'; 132 } 133 } //end if 134}//end foreach 135 136echo '</tbody> 137</table>'; 138