| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $pagetitle[] = "Historical Usage"; | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  | //  $detail      = (isset($vars['detail']) ? $vars['detail'] : "");
 | 
					
						
							|  |  |  | //  $url         = $PHP_SELF."/bill/".$bill_id."/history/";
 | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |   $i           = 0; | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |   $gbconvert   = $config['billing']['base']; | 
					
						
							| 
									
										
										
										
											2011-11-30 12:45:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |   $img['his']  = "<img src=\"bandwidth-graph.php?bill_id=".$bill_id; | 
					
						
							|  |  |  |   $img['his'] .= "&type=historical"; | 
					
						
							|  |  |  |   $img['his'] .= "&x=1190&y=250"; | 
					
						
							|  |  |  |   $img['his'] .= "\" style=\"margin: 15px 5px 25px 5px;\" />"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   echo($img['his']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  |   function showDetails($bill_id, $imgtype, $from, $to, $bittype = "Quota") | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |     if ($imgtype == "bitrate") { | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  |       $res  = "<img src=\"billing-graph.php?bill_id=".$bill_id; | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |       if ($bittype == "Quota") | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         $res .= "&ave=yes"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       elseif ($bittype == "CDR") { | 
					
						
							|  |  |  |         $res .= "&95th=yes"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  |       $res  = "<img src=\"bandwidth-graph.php?bill_id=".$bill_id; | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     //$res .= "&type=".$type;
 | 
					
						
							|  |  |  |     $res .= "&type=".$imgtype; | 
					
						
							|  |  |  |     $res .= "&x=1190&y=250"; | 
					
						
							|  |  |  |     $res .= "&from=".$from."&to=".$to; | 
					
						
							|  |  |  |     $res .= "\" style=\"margin: 15px 5px 25px 5px;\" />"; | 
					
						
							|  |  |  |     return $res; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-30 12:45:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  | //  $url        = generate_url($vars, array('detail' => 'yes'));
 | 
					
						
							|  |  |  |   $url        = $PHP_SELF."/bill/".$bill_id."/history/detail=all/"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |   echo("<table border=0 cellspacing=0 cellpadding=5 class=devicetable width=100%>
 | 
					
						
							|  |  |  |            <tr style=\"font-weight: bold; \">
 | 
					
						
							|  |  |  |              <td width=\"7\"></td>
 | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |              <td width=\"250\">Period</td>
 | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |              <td>Type</td> | 
					
						
							|  |  |  |              <td>Allowed</td> | 
					
						
							|  |  |  |              <td>Inbound</td> | 
					
						
							|  |  |  |              <td>Outbound</td> | 
					
						
							|  |  |  |              <td>Total</td> | 
					
						
							|  |  |  |              <td>95 percentile</td> | 
					
						
							|  |  |  |              <td style=\"text-align: center;\">Overusage</td>
 | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  |              <td colspan=\"2\" style=\"text-align: right;\"><a href=\"".generate_url($vars, array('detail' => "all"))."\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\" /> Show all details</a></td>
 | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |            </tr>");
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-06 22:26:47 +00:00
										 |  |  |   foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 24", array($bill_id)) as $history) | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |     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']; | 
					
						
							| 
									
										
										
										
											2011-12-06 22:17:37 +00:00
										 |  |  |       $rate_95th      = formatRates($history['rate_95th']); | 
					
						
							|  |  |  |       $total_data     = format_number($history['traf_total'], $config['billing']['base']); | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $background = get_percentage_colours($percent); | 
					
						
							|  |  |  |       $row_colour = ((!is_integer($i/2)) ? $list_colour_a : $list_colour_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ($type == "CDR") | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2011-12-06 22:17:37 +00:00
										 |  |  |          $allowed = formatRates($history['bill_allowed']); | 
					
						
							|  |  |  |          $used    = formatRates($history['rate_95th']); | 
					
						
							|  |  |  |          $in      = formatRates($history['rate_95th_in']); | 
					
						
							|  |  |  |          $out     = formatRates($history['rate_95th_out']); | 
					
						
							|  |  |  |          $overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".formatRates($history['bill_overuse'])."</span>"); | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |       } elseif ($type == "Quota") { | 
					
						
							| 
									
										
										
										
											2011-12-06 22:17:37 +00:00
										 |  |  |          $allowed = format_number($history['bill_allowed'], $config['billing']['base']); | 
					
						
							|  |  |  |          $used    = format_number($history['total_data'], $config['billing']['base']); | 
					
						
							|  |  |  |          $in      = format_number($history['traf_in'], $config['billing']['base']); | 
					
						
							|  |  |  |          $out     = format_number($history['traf_out'], $config['billing']['base']); | 
					
						
							|  |  |  |          $overuse = (($history['bill_overuse'] <= 0) ? "-" : "<span style=\"color: #".$background['left']."; font-weight: bold;\">".format_number($history['bill_overuse'], $config['billing']['base'])."B</span>"); | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $total_data     = (($type == "Quota") ? "<b>".$total_data."</b>" : $total_data); | 
					
						
							|  |  |  |       $rate_95th      = (($type == "CDR") ? "<b>".$rate_95th."</b>" : $rate_95th); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-06 22:17:37 +00:00
										 |  |  |       $url            = generate_url($vars, array('detail' => $history['bill_hist_id'])); | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |       echo("
 | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |            <tr style=\"background: ".$row_colour.";\">
 | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |              <td></td> | 
					
						
							| 
									
										
										
										
											2011-11-14 18:28:00 +00:00
										 |  |  |              <td><span style=\"font-weight: bold;\" class=\"interface\">".strftime("%Y-%m-%d", strtotime($datefrom))." -> ".strftime("%Y-%m-%d", strtotime($dateto))."</span></td>
 | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |              <td>$type</td> | 
					
						
							|  |  |  |              <td>$allowed</td> | 
					
						
							|  |  |  |              <td>$in</td> | 
					
						
							|  |  |  |              <td>$out</td> | 
					
						
							|  |  |  |              <td>$total_data</td> | 
					
						
							|  |  |  |              <td>$rate_95th</td> | 
					
						
							|  |  |  |              <td style=\"text-align: center;\">$overuse</td>
 | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |              <td width=\"250\">".print_percentage_bar(250, 20, $perc, NULL, "ffffff", $background['left'], $percent."%", "ffffff", $background['right'])."</td>
 | 
					
						
							|  |  |  |              <td> | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  |                 <a href=\"".$url."\"><img src=\"images/16/chart_curve.png\" border=\"0\" align=\"absmiddle\" alt=\"Show details\" title=\"Show details\"/></a>
 | 
					
						
							| 
									
										
										
										
											2011-12-06 23:06:02 +00:00
										 |  |  |                 <a href=\"pdf.php?type=billing&report=history&bill_id=".$bill_id."&history_id=".$history['bill_hist_id']."\"><img src=\"images/16/page_white_acrobat.png\" border=\"0\" align=\"absmiddle\" alt=\"PDF Report\" title=\"PDF Report\"/></a>
 | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |              </td> | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |            </tr>");
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-06 22:17:37 +00:00
										 |  |  |       if ($vars['detail'] == $history['bill_hist_id'] || $vars['detail'] == "all") { | 
					
						
							| 
									
										
										
										
											2011-12-02 17:11:28 +00:00
										 |  |  |         $img['bitrate'] = showDetails($bill_id, "bitrate", strtotime($datefrom), strtotime($dateto), $type); | 
					
						
							|  |  |  |         $img['bw_day']  = showDetails($bill_id, "day", strtotime($datefrom), strtotime($dateto)); | 
					
						
							|  |  |  |         $img['bw_hour'] = showDetails($bill_id, "hour", strtotime($datefrom), strtotime($dateto)); | 
					
						
							| 
									
										
										
										
											2011-12-02 15:53:50 +00:00
										 |  |  |         echo("
 | 
					
						
							|  |  |  |            <tr style=\"background: #fff; border-top: 1px solid ".$row_colour."; border-bottom: 1px solid #ccc;\">
 | 
					
						
							|  |  |  |              <td colspan=\"11\">
 | 
					
						
							|  |  |  |                <!-- <b>Accuate Graph</b><br /> //-->
 | 
					
						
							|  |  |  |                ".$img['bitrate']."<br /> | 
					
						
							|  |  |  |                <!-- <b>Bandwidth Graph per day</b><br /> //-->
 | 
					
						
							|  |  |  |                ".$img['bw_day']."<br /> | 
					
						
							|  |  |  |                <!-- <b>Bandwidth Graph per hour</b><br /> //-->
 | 
					
						
							|  |  |  |                ".$img['bw_hour']." | 
					
						
							|  |  |  |              </td> | 
					
						
							|  |  |  |            </tr>");
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-05 14:55:08 +00:00
										 |  |  |       $i++; | 
					
						
							|  |  |  |     } ### PERMITTED
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   echo("</table>"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |