= 1000000) { $paidrate_text = $paid_mb . "Mbps is the CDR."; }
  $day_data     = getDates($dayofmonth);
  $datefrom     = $day_data['0'];
  $dateto       = $day_data['1'];
  $lastfrom	= $day_data['2'];
  $lastto	= $day_data['3'];
  $rate_data    = getRates($bill_id,$datefrom,$dateto);
  $rate_95th    = $rate_data['rate_95th'];
  $dir_95th     = $rate_data['dir_95th'];
  $total_data   = $rate_data['total_data'];
  $rate_average = $rate_data['rate_average'];
  if ($rate_95th > $paid_kb)
  {
    $over = $rate_95th - $paid_kb;
    $bill_text = $over . "Kbit excess.";
    $bill_color = "#cc0000";
  }
  else
  {
    $under = $paid_kb - $rate_95th;
    $bill_text = $under . "Kbit headroom.";
    $bill_color = "#0000cc";
  }
  $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '%M %D %Y')");
  $totext   = dbFetchCell("SELECT DATE_FORMAT($dateto, '%M %D %Y')");
  $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')");
  $unixto   = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')");
  $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); 
  $unix_prev_to   = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')");
  echo(" ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)." ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $left_background, $percent . "%", "ffffff", $right_background)." Billing Period : " . $fromtext . " to " . $totext . "
  Bill : " . $bill_name . "
");
  print_optionbar_start();
  if (!$_GET['optb']) { $_GET['optb'] = "details"; }
  if ($_GET['optb'] == "details") { echo(""); }
  if ($_SESSION['userlevel'] == "10")
  {
    echo(" | ");
    if ($_GET['optb'] == "edit") { echo(""); }
    echo(" | ");
    if ($_GET['optb'] == "delete") { echo(""); }
  }
  print_optionbar_end();
#  echo("
  #  ");
  if ($_GET['optb'] == "edit" && $_SESSION['userlevel'] == "10")
  {
    include("pages/bill/edit.inc.php");
  }
  elseif ($_GET['optb'] == "delete" && $_SESSION['userlevel'] == "10")
  {
    include("pages/bill/delete.inc.php");
  }
  elseif ($_GET['optb'] == "details")
  {
  echo(" Billed Ports
");
  $ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
                        WHERE B.bill_id = ? AND P.interface_id = B.port_id
                        AND D.device_id = P.device_id", array($bill_id));
  foreach ($ports as $port)
  {
    echo(generate_port_link($port) . " on " . generate_device_link($port) . "
");
  }
  echo("Bill Summary
");
  if ($bill_data['bill_type'] == "quota")
  {
    // The Customer is billed based on a pre-paid quota
    echo("Quota Bill
");
    $percent = round(($total_data / 1024) / $bill_data['bill_gb'] * 100, 2);
    $unit = "MB";
    $total_data = round($total_data, 2);
    echo("Billing Period from " . $fromtext . " to " . $totext . "
    
Transferred ".formatStorage($total_data * 1024 * 1024)." of ".formatStorage($bill_data['bill_gb'] * 1024 * 1024 * 1024)." (".$percent."%)
    
Average rate " . formatRates($rate_average * 1000));
    $background = get_percentage_colours($percent);
    $right_background = $background['right'];
    $left_background  = $background['left'];
    echo("CDR / 95th Bill
");
    $unit = "kbps";
    $cdr = $bill_data['bill_cdr'];
    if ($rate_95th > "1000") { $rate_95th = $rate_95th / 1000; $cdr = $cdr / 1000; $unit = "Mbps"; }
    if ($rate_95th > "1000") { $rate_95th = $rate_95th / 1000; $cdr = $cdr / 1000; $unit = "Gps"; }
    $rate_95th = round($rate_95th, 2);
    $percent = round(($rate_95th) / $cdr * 100, 2);
    $type="&95th=yes";
    echo("" . $fromtext . " to " . $totext . "
    
Measured ".$rate_95th."$unit of ".$cdr."$unit (".$percent."%)");
   if ($percent > 100) { $perc = "100"; } else { $perc = $percent; }
    if ($perc > '90') { $left_background='c4323f'; $right_background='C96A73';
    } elseif ($perc > '75') { $left_background='bf5d5b'; $right_background='d39392';
    } elseif ($perc > '50') { $left_background='bf875b'; $right_background='d3ae92';
    } elseif ($perc > '25') { $left_background='5b93bf'; $right_background='92b7d3';
    } else { $left_background='9abf5b'; $right_background='bbd392'; }
    echo("
  #  " . $paidrate_text . " 
  #  " . $total_data . "MB transfered in the current billing cycle. 
  #  " . $rate_average . "Kbps Average during the current billing cycle. 
");
  }
#  echo("
