1<?php 2 3$bill_id = $vars['bill_id']; 4 5if (Auth::user()->hasGlobalAdmin()) { 6 include 'includes/html/pages/bill/actions.inc.php'; 7} 8 9if (bill_permitted($bill_id)) { 10 $bill_data = dbFetchRow('SELECT * FROM bills WHERE bill_id = ?', [$bill_id]); 11 12 $bill_name = $bill_data['bill_name']; 13 14 $today = str_replace('-', '', dbFetchCell('SELECT CURDATE()')); 15 $yesterday = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)')); 16 $tomorrow = str_replace('-', '', dbFetchCell('SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)')); 17 $last_month = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)')); 18 19 $rightnow = $today . date('His'); 20 $before = $yesterday . date('His'); 21 $lastmonth = $last_month . date('His'); 22 23 $bill_name = $bill_data['bill_name']; 24 $dayofmonth = $bill_data['bill_day']; 25 26 $day_data = getDates($dayofmonth); 27 28 $datefrom = $day_data['0']; 29 $dateto = $day_data['1']; 30 $lastfrom = $day_data['2']; 31 $lastto = $day_data['3']; 32 33 $rate_95th = $bill_data['rate_95th']; 34 $dir_95th = $bill_data['dir_95th']; 35 $total_data = $bill_data['total_data']; 36 $rate_average = $bill_data['rate_average']; 37 38 if ($rate_95th > $paid_kb) { 39 $over = ($rate_95th - $paid_kb); 40 $bill_text = $over . 'Kbit excess.'; 41 $bill_color = '#cc0000'; 42 } else { 43 $under = ($paid_kb - $rate_95th); 44 $bill_text = $under . 'Kbit headroom.'; 45 $bill_color = '#0000cc'; 46 } 47 48 $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '" . \LibreNMS\Config::get('dateformat.mysql.date') . "')"); 49 $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '" . \LibreNMS\Config::get('dateformat.mysql.date') . "')"); 50 $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); 51 $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); 52 53 $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); 54 $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); 55 // Speeds up loading for other included pages by setting it before progessing of mysql data! 56 $ports = dbFetchRows( 57 'SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D 58 WHERE B.bill_id = ? AND P.port_id = B.port_id 59 AND D.device_id = P.device_id', 60 [$bill_id] 61 ); 62 63 if (! $vars['view']) { 64 $vars['view'] = 'quick'; 65 } 66 67 function print_port_list($ports) 68 { 69 echo '<div class="panel panel-default"> 70 <div class="panel-heading"> 71 <h3 class="panel-title">Billed Ports</h3> 72 </div> 73 <div class="list-group">'; 74 75 // Collected Earlier 76 foreach ($ports as $port) { 77 $port = cleanPort($port); 78 $portalias = (empty($port['ifAlias']) ? '' : ' - ' . $port['ifAlias'] . ''); 79 80 echo '<div class="list-group-item">'; 81 echo generate_port_link($port, $port['ifName'] . $portalias) . ' on ' . generate_device_link($port); 82 echo '</div>'; 83 } 84 85 echo '</div></div>'; 86 }//end print_port_list?> 87 88 <h2><?php echo "Bill: ${bill_data['bill_name']}"; ?></h2> 89 90 <?php 91 print_optionbar_start(); 92 echo '<strong>Bill</strong> » '; 93 $menu_options = [ 94 'quick' => 'Quick Graphs', 95 'accurate' => 'Accurate Graphs', 96 'transfer' => 'Transfer Graphs', 97 'history' => 'Historical Graphs', 98 ]; 99 if (Auth::user()->hasGlobalAdmin()) { 100 $menu_options['edit'] = 'Edit'; 101 $menu_options['delete'] = 'Delete'; 102 $menu_options['reset'] = 'Reset'; 103 } 104 $sep = ''; 105 foreach ($menu_options as $option => $text) { 106 echo $sep; 107 if ($vars['view'] == $option) { 108 echo "<span class='pagemenu-selected'>"; 109 } 110 111 echo generate_link($text, $vars, ['view' => $option]); 112 if ($vars['view'] == $option) { 113 echo '</span>'; 114 } 115 116 $sep = ' | '; 117 } 118 119 echo '<div style="font-weight: bold; float: right;"><a href="' . \LibreNMS\Util\Url::generate(['page' => 'bills']) . '/"><i class="fa fa-arrow-left fa-lg icon-theme" aria-hidden="true"></i> Back to Bills</a></div>'; 120 121 print_optionbar_end(); 122 123 if ($vars['view'] == 'edit' && Auth::user()->hasGlobalAdmin()) { 124 include 'includes/html/pages/bill/edit.inc.php'; 125 } elseif ($vars['view'] == 'delete' && Auth::user()->hasGlobalAdmin()) { 126 include 'includes/html/pages/bill/delete.inc.php'; 127 } elseif ($vars['view'] == 'reset' && Auth::user()->hasGlobalAdmin()) { 128 include 'includes/html/pages/bill/reset.inc.php'; 129 } elseif ($vars['view'] == 'history') { 130 include 'includes/html/pages/bill/history.inc.php'; 131 } elseif ($vars['view'] == 'transfer') { 132 include 'includes/html/pages/bill/transfer.inc.php'; 133 } elseif ($vars['view'] == 'quick' || $vars['view'] == 'accurate') { 134 ?> 135 136 <?php if ($bill_data['bill_type'] == 'quota') { ?> 137 <h3>Quota Bill</h3> 138 <?php } elseif ($bill_data['bill_type'] == 'cdr') { ?> 139 <h3> 140 CDR / 95th Bill 141 </h3> 142 <?php } ?> 143<strong>Billing Period from <?php echo $fromtext ?> to <?php echo $totext ?></strong> 144<br /><br /> 145 146<div class="row"> 147<div class="col-lg-6 col-lg-push-6"> 148 <?php print_port_list($ports) ?> 149</div> 150<div class="col-lg-6 col-lg-pull-6"> 151<div class="panel panel-default"> 152 <div class="panel-heading"> 153 <h3 class="panel-title"> 154 Bill Summary 155 </h3> 156 </div> 157 <table class="table"> 158 <tr> 159 <?php if ($bill_data['bill_type'] == 'quota') { 160 // The Customer is billed based on a pre-paid quota with overage in xB 161 $percent = round((($total_data) / $bill_data['bill_quota'] * 100), 2); 162 $unit = 'MB'; 163 $total_data = round($total_data, 2); 164 $background = \LibreNMS\Util\Colors::percentage($percent, null); 165 $type = '&ave=yes'; ?> 166 <td> 167 <?php echo format_bytes_billing($total_data) ?> of <?php echo format_bytes_billing($bill_data['bill_quota']) . ' (' . $percent . '%)' ?> 168 - Average rate <?php echo \LibreNMS\Util\Number::formatSi($rate_average, 2, 3, 'bps') ?> 169 </td> 170 <td style="width: 210px;"><?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) ?></td> 171 </tr> 172 <tr> 173 <td colspan="2"> 174 <?php 175 echo 'Predicted usage: ' . format_bytes_billing(getPredictedUsage($bill_data['bill_day'], $bill_data['total_data'])); ?> 176 </td> 177 <?php 178 } elseif ($bill_data['bill_type'] == 'cdr') { 179 // The customer is billed based on a CDR with 95th%ile overage 180 $unit = 'kbps'; 181 $cdr = $bill_data['bill_cdr']; 182 $rate_95th = round($rate_95th, 2); 183 $percent = round((($rate_95th) / $cdr * 100), 2); 184 $background = \LibreNMS\Util\Colors::percentage($percent, null); 185 $type = '&95th=yes'; ?> 186 <td> 187 <?php echo \LibreNMS\Util\Number::formatSi($rate_95th, 2, 3, '') . 'bps' ?> of <?php echo \LibreNMS\Util\Number::formatSi($cdr, 2, 3, '') . 'bps (' . $percent . '%)' ?> (95th%ile) 188 </td> 189 <td style="width: 210px;"> 190 <?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) ?> 191 </td> 192 </tr> 193 <tr> 194 <td colspan="2"> 195 <?php 196 echo 'Predicted usage: ' . \LibreNMS\Util\Number::formatSi(getPredictedUsage($bill_data['bill_day'], $bill_data['rate_95th']), 2, 3, '') . 'bps'; ?> 197 </td> 198 199 <?php 200 }//end if?> 201 </tr> 202 </table> 203</div> 204</div> 205</div> 206 207 <?php 208 209 $lastmonth = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))'); 210 $yesterday = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))'); 211 $rightnow = date('U'); 212 213 if ($vars['view'] == 'accurate') { 214 $bi = "<img src='billing-graph.php?bill_id=" . $bill_id . '&bill_code=' . $_GET['bill_code']; 215 $bi .= '&from=' . $unixfrom . '&to=' . $unixto; 216 $bi .= '&x=1190&y=250'; 217 $bi .= "$type'>"; 218 219 $li = "<img src='billing-graph.php?bill_id=" . $bill_id . '&bill_code=' . $_GET['bill_code']; 220 $li .= '&from=' . $unix_prev_from . '&to=' . $unix_prev_to; 221 $li .= '&x=1190&y=250'; 222 $li .= "$type'>"; 223 224 $di = "<img src='billing-graph.php?bill_id=" . $bill_id . '&bill_code=' . $_GET['bill_code']; 225 $di .= '&from=' . \LibreNMS\Config::get('time.day') . '&to=' . \LibreNMS\Config::get('time.now'); 226 $di .= '&x=1190&y=250'; 227 $di .= "$type'>"; 228 229 $mi = "<img src='billing-graph.php?bill_id=" . $bill_id . '&bill_code=' . $_GET['bill_code']; 230 $mi .= '&from=' . $lastmonth . '&to=' . $rightnow; 231 $mi .= '&x=1190&y=250'; 232 $mi .= "$type'>"; 233 } else { 234 $bi = "<img src='graph.php?type=bill_bits&id=" . $bill_id; 235 $bi .= '&from=' . $unixfrom . '&to=' . $unixto; 236 $bi .= '&width=1000&height=200&total=1&dir=' . $dir_95th . "'>"; 237 238 $li = "<img src='graph.php?type=bill_bits&id=" . $bill_id; 239 $li .= '&from=' . $unix_prev_from . '&to=' . $unix_prev_to; 240 $li .= '&width=1000&height=200&total=1&dir=' . $dir_95th . "'>"; 241 242 $di = "<img src='graph.php?type=bill_bits&id=" . $bill_id; 243 $di .= '&from=' . \LibreNMS\Config::get('time.day') . '&to=' . \LibreNMS\Config::get('time.now'); 244 $di .= '&width=1000&height=200&total=1&dir=' . $dir_95th . "'>"; 245 246 $mi = "<img src='graph.php?type=bill_bits&id=" . $bill_id; 247 $mi .= '&from=' . $lastmonth . '&to=' . $rightnow; 248 $mi .= '&width=1000&height=200&total=1&dir=' . $dir_95th . "'>"; 249 }//end if 250 251 ?> 252<div class="panel panel-default"> 253<div class="panel-heading"> 254 <h3 class="panel-title">Billing View</h3> 255</div> 256 <?php echo $bi ?> 257</div> 258 259<div class="panel panel-default"> 260<div class="panel-heading"> 261 <h3 class="panel-title">24 Hour View</h3> 262</div> 263 <?php echo $di ?> 264</div> 265 266<div class="panel panel-default"> 267<div class="panel-heading"> 268 <h3 class="panel-title">Monthly View</h3> 269</div> 270 <?php echo $mi ?> 271</div> 272 <?php 273 } //end if 274} else { 275 include 'includes/html/error-no-perm.inc.php'; 276}//end if 277?> 278