Index: billing-calculate.php
===================================================================
--- billing-calculate.php	(revision 6654)
+++ billing-calculate.php	(working copy)
@@ -45,7 +45,6 @@
     $period = getPeriod($bill['bill_id'],$datefrom,$dateto);
 
     $date_updated = str_replace("-", "", str_replace(":", "", str_replace(" ", "", $check['updated'])));
-
     if ($period > 0 && $dateto > $date_updated)
     {
       $rate_data    = getRates($bill['bill_id'],$datefrom,$dateto);
@@ -60,9 +59,23 @@
          $type = "CDR";
          $allowed = $bill['bill_cdr'];
          $used    = $rate_data['rate_95th'];
-         $allowed_text = format_si($allowed)."bps";
-         $used_text    = format_si($used)."bps";
+         $allowed_text = format_number($allowed, $config['billing']['base'])."bps";
+         $used_text    = format_number($used, $config['billing']['base'])."bps";
          $overuse = $used - $allowed;
+         $cost = format_mb($allowed) * $bill['bill_price_base'];
+         if ($overuse > 0)
+         {
+            $rate1 = 0;
+            $rate2 = 0;
+            if ($overuse < ($allowed / 2))
+            {
+              $rate1 = $bill['bill_price_base'] * format_mb($overuse);
+            } else {
+              $rate1 = $bill['bill_price_base'] * (format_mb($allowed) / 2);
+              $rate2 = $bill['bill_price_burst'] * (format_mb($overuse) - (format_mb($allowed)/2));
+            }
+            $cost = $cost + $rate1 + $rate2;
+         }
          $overuse = (($overuse <= 0) ? "0" : $overuse);
          $percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100,2);
       } elseif ($bill['bill_type'] == "quota") {
@@ -72,11 +85,25 @@
          $allowed_text = format_bytes_billing($allowed);
          $used_text    = format_bytes_billing($used);
          $overuse = $used - $allowed;
+         $cost = format_mb($allowed) * $bill['bill_price_base'];
+         if ($overuse > 0)
+         {
+            $rate1 = 0;
+            $rate2 = 0;
+            if ($overuse < ($allowed / 2))
+            {
+              $rate1 = $bill['bill_price_base'] * format_mb($overuse);
+            } else {
+              $rate1 = $bill['bill_price_base'] * (format_mb($allowed) / 2);
+              $rate2 = $bill['bill_price_burst'] * (format_mb($overuse) - (format_mb($allowed)/2));
+            }
+            $cost = $cost + $rate1 + $rate2;
+         }
          $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."%");
+      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."% £".$cost);
 
       if ($i == '0')
       {
@@ -90,6 +117,7 @@
                       'rate_average' => $rate_data['rate_average'],
                       'rate_average_in' => $rate_data['rate_average_in'],
                       'rate_average_out' => $rate_data['rate_average_out'],
+                      'bill_price_total' => $cost,
                       'bill_last_calc' => array('NOW()') );
 
         dbUpdate($update, 'bills', '`bill_id` = ?', array($bill['bill_id']));
@@ -111,6 +139,7 @@
                          'bill_used' => $used,
                          'bill_overuse' => $overuse,
                          'bill_percent' => $percent,
+                         'bill_price_total' => $cost,
                          'updated' => array('NOW()'));
 
         dbUpdate($update, 'bill_history', '`bill_hist_id` = ?', array($check['bill_hist_id']));
@@ -133,6 +162,7 @@
                          'bill_used' => $used,
                          'bill_overuse' => $overuse,
                          'bill_percent' => $percent,
+                         'bill_price_total' => $cost,
                          'bill_datefrom' => $datefrom,
                          'bill_dateto' => $dateto,
                          'bill_id' => $bill['bill_id'] );
Index: html/pages/bill/actions.inc.php
===================================================================
--- html/pages/bill/actions.inc.php	(revision 6654)
+++ html/pages/bill/actions.inc.php	(working copy)
@@ -99,7 +99,8 @@
 
   if (dbUpdate(array('bill_name' => $vars['bill_name'], 'bill_day' => $vars['bill_day'], 'bill_quota' => $bill_quota, 'bill_cdr' => $bill_cdr,
                      'bill_type' => $vars['bill_type'], 'bill_custid' => $vars['bill_custid'], 'bill_ref' => $vars['bill_ref'],
-                     'bill_notes' => $vars['bill_notes'], 'bill_contact' => $bill_contact, 'bill_notify' => $bill_notify), 'bills', '`bill_id` = ?', array($bill_id)))
+                     'bill_notes' => $vars['bill_notes'], 'bill_contact' => $bill_contact, 'bill_notify' => $bill_notify,
+                     'bill_price_base' => $vars['bill_price_base'], 'bill_price_burst' => $vars['bill_price_burst']), 'bills', '`bill_id` = ?', array($bill_id)))
   {
     print_message("Bill Properties Updated");
   }
Index: html/pages/bill/edit.inc.php
===================================================================
--- html/pages/bill/edit.inc.php	(revision 6654)
+++ html/pages/bill/edit.inc.php	(working copy)
@@ -106,7 +106,27 @@
         </fieldset>
     </div>
    </div>
+   <div class="well info_box">
+     <div class="title"><i class="oicon-information"></i> Pricing Information</div>
+     <div class="content">
+        <fieldset>
+          <div class="control-group">
+            <label class="control-label" for="bill_price_base"><strong>Base Rate per Mb</strong></label>
+            <div class="controls">
+                <input class="span1" type="text" name="bill_price_base"  value="<?php echo $bill_data["bill_price_base"]; ?>">
+            </div>
+          </div>
+          <div class="control-group">
+            <label class="control-label" for="bill_price_burst"><strong>Burst Rate per Mb</strong></label>
+            <div class="controls">
+                <input class="span1" type="text" name="bill_price_burst" value="<?php echo $bill_data["bill_price_burst"]; ?>">
+            </div>
+          </div>
+        </fieldset>
+    </div>
+   </div>
 
+
 <?php /**
 
    <div class="well info_box">
Index: html/pages/bill/history.inc.php
===================================================================
--- html/pages/bill/history.inc.php	(revision 6654)
+++ html/pages/bill/history.inc.php	(working copy)
@@ -69,6 +69,7 @@
                    <th>Total</th>
                    <th>95th %ile</th>
                    <th style=\"text-align: center;\">Overusage</th>
+                   <th style=\"text-align: center;\">Cost</th>
                    <th colspan=\"2\" style=\"text-align: right;\"><a class=\"btn btn-mini\" style=\"color: #555;\" href=\"".generate_url($vars, array('detail' => "all"))."\"><img src=\"images/16/chart_curve.png\" alt=\"Show details\" title=\"Show details\" /> Show all details</a></th>
                  </tr>
                </thead>
@@ -103,6 +104,7 @@
          $overuse = (($history['bill_overuse'] <= 0) ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-imprtant\">".format_number($history['bill_overuse'], $config['billing']['base'])."B</span>");
          $label   = "info";
       }
+      $cost = $config['billing']['currency_symbol'] . $history['bill_price_total'];
 
       $total_data     = (($type == "Quota") ? "<span class=\"badge badge-warning\"><strong>".$total_data."</strong></span>" : "<span class=\"badge\">".$total_data."</span>");
       $rate_95th      = (($type == "CDR") ? "<span class=\"badge badge-warning\"><strong>".$rate_95th."</strong></span>" : "<span class=\"badge\">".$rate_95th."</span>");
@@ -135,6 +137,7 @@
                   <td>$total_data</td>
                   <td>$rate_95th</td>
                   <td style=\"text-align: center;\">$overuse</td>
+                  <td style=\"text-align: center;\">$cost</td>
                   <td width=\"225\">
                     ".print_percentage_bar (400, 20, $percent, $percent.'%', "ffffff", $background['left'], 100-$percent."%" , "ffffff", $background['right'])."
                   </td>
Index: html/pages/bill/infoboxes.inc.php
===================================================================
--- html/pages/bill/infoboxes.inc.php	(revision 6654)
+++ html/pages/bill/infoboxes.inc.php	(working copy)
@@ -31,7 +31,7 @@
   $quota      = $bill_data['bill_quota'];
   $percent    = round(($total_data) / $quota * 100, 2);
   $used       = format_bytes_billing($total_data);
-  $allowed    = format_si($quota)."B";
+  $allowed    = format_number($quota, $config['billing']['base'])."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";
@@ -56,21 +56,21 @@
 } 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";
+  $used       = format_number($rate_95th, $config['billing']['base'])."bps";
+  $allowed    = format_number($cdr, $config['billing']['base'])."bps";
   $overuse    = $rate_95th - $cdr;
-  $overuse    = (($overuse <= 0) ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-important\">".format_si($overuse)."bps</span>");
+  $overuse    = (($overuse <= 0) ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-important\">".format_number($overuse, $config['billing']['base'])."bps</span>");
   $type       = "CDR / 95th %";
   $imgtype    = "&amp;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"
+                  'in' => format_number($bill_data['rate_95th_in'], $config['billing']['base'])."bps",
+                  'out' => format_number($bill_data['rate_95th_out'], $config['billing']['base'])."bps",
+                  'tot' => format_number($bill_data['rate_95th'], $config['billing']['base'])."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"
+                  'in' => format_number($bill_data['rate_average_in'], $config['billing']['base'])."bps",
+                  'out' => format_number($bill_data['rate_average_out'], $config['billing']['base'])."bps",
+                  'tot' => format_number($bill_data['rate_average'], $config['billing']['base'])."bps"
                 );
   $estimated  = array(
                   'in' => "n/a",
@@ -79,6 +79,11 @@
                 );
 }
 
+$cost = $config['billing']['currency_symbol'] . $bill_data['bill_price_total'];
+
+$pricing['base']  = (($isAdmin && !empty($bill_data['bill_price_base'])) ? $bill_data['bill_price_base'] : "n/a");
+$pricing['burst']  = (($isAdmin && !empty($bill_data['bill_price_burst'])) ? $bill_data['bill_price_burst'] : "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");
 $optional['notes'] = (!empty($bill_data['bill_notes']) ? $bill_data['bill_notes'] : "n/a");
@@ -140,10 +145,11 @@
         <table class="table table-striped table-bordered table-condensed table-rounded">
          <thead>
           <tr>
-            <th style="width: 25%;">Type</th>
-            <th style="width: 25%;">Allowed</th>
-            <th style="width: 25%;">Used</th>
-            <th style="width: 25%;">Overusage</th>
+            <th style="width: 20%;">Type</th>
+            <th style="width: 20%;">Allowed</th>
+            <th style="width: 20%;">Used</th>
+            <th style="width: 20%;">Overusage</th>
+            <th style="width: 20%;">Cost</th>
           </tr>
         </thead>
         <tr>
@@ -151,6 +157,7 @@
             <td style="width: 25%;"><span class="badge badge-success"><?php echo($allowed); ?></span></td>
             <td><span class="badge badge-warning"><?php echo($used); ?></span></td>
             <td><?php echo($overuse); ?></td>
+            <td><?php echo($cost); ?></td>
           </tr>
         </table>
 
@@ -227,6 +234,16 @@
             <td><?php echo($optional['notes']); ?></td>
           </tr>
           <tr>
+            <th><i class="icon-certificate"></i> Base Rate</th>
+
+            <td><?php echo($config['billing']['currency_symbol'] . $pricing['base']); ?></td>
+          </tr>
+          <tr>
+            <th><i class="icon-certificate"></i> Burst Rate</th>
+
+            <td><?php echo($config['billing']['currency_symbol'] . $pricing['burst']); ?></td>
+          </tr>
+          <tr>
             <th style="width: 175px;"><i class="icon-time"></i> Last polled</th>
 
             <td><?php echo(strftime('%A, %e %B %Y @ %H:%M:%S', $optional['poll'])); ?></td>
Index: html/pages/bills/add.inc.php
===================================================================
--- html/pages/bills/add.inc.php	(revision 6654)
+++ html/pages/bills/add.inc.php	(working copy)
@@ -88,6 +88,23 @@
           </div>
         </fieldset>
         <fieldset>
+          <legend>Pricing Information</legend>
+          <div class="control-group">
+            <label class="control-label" for="bill_price_base"><strong>Base Rate per Mb</strong></label>
+            <div class="controls">
+               <?php echo($config['billing']['currency_symbol']); ?>
+               <input class="span1" type="text" name="bill_price_base">
+            </div>
+          </div>
+          <div class="control-group">
+            <label class="control-label" for="bill_price_burst"><strong>Burst Rate per Mb</strong></label>
+            <div class="controls">
+                <?php echo($config['billing']['currency_symbol']); ?>
+               <input class="span1" type="text" name="bill_price_burst">
+            </div>
+          </div>
+        </fieldset>
+        <fieldset>
           <legend>Optional Information</legend>
           <div class="control-group">
             <label class="control-label" for="bill_custid"><strong>Customer&nbsp;Reference</strong></label>
Index: html/pages/bills/month.inc.php
===================================================================
--- html/pages/bills/month.inc.php	(revision 6654)
+++ html/pages/bills/month.inc.php	(working copy)
@@ -20,6 +20,15 @@
 
 include_once('searchaction.inc.php');
 
+$cdr_total_allowed 	= 0;
+$cdr_total_used	 	= 0;
+$cdr_total_overuse 	= 0;
+$cdr_total_cost		= 0;
+$quota_total_allowed 	= 0;
+$quota_total_used 	= 0;
+$quota_total_overuse 	= 0;
+$quota_total_cost 	= 0;
+
 echo '<table class="table table-condensed table-bordered table-striped table-hover table-rounded">
         <thead>
           <tr>
@@ -28,6 +37,7 @@
             <th style="width: 70px; text-align: center;">Allowed</th>
             <th style="width: 70px; text-align: center;">Used</th>
             <th style="width: 70px; text-align: center;">Overusage</th>
+            <th style="width: 70px; text-align: center;">Cost</th>
             <th style="width: 225px;"></th>
             <th style="width: 215px;">
               <div class="btn-group">';
@@ -78,33 +88,64 @@
     if ($bill['bill_type'] == "cdr") {
       $type = "CDR 95th";
       if ($view == 'history') {
-        $allowed = format_si($history['bill_allowed'])."bps";
-        $used    = format_si($rate_data['rate_95th'])."bps";
+        $allowed = format_number($history['bill_allowed'], $config['billing']['base'])."bps";
+        $cdr_total_allowed = $cdr_total_allowed + $history['bill_allowed'];
+        $used    = format_number($rate_data['rate_95th'], $config['billing']['base'])."bps";
+        $cdr_total_used = $cdr_total_used + $rate_data['rate_95th'];
         $overuse = $rate_data['rate_95th'] - $history['bill_allowed'];
-        $overuse = (($overuse <= 0) ? "-" : format_si($overuse)."bps");
+        if ($overuse > 0)
+        {
+          $cdr_total_overuse = $cdr_total_overuse + $overuse;
+        }
+        $overuse = (($overuse <= 0) ? "-" : format_number($overuse, $config['billing']['base'])."bps");
+        $cost = $history['bill_price_total'];
       } else {
-        $allowed = format_si($bill['bill_cdr'])."bps";
-        $used    = format_si($rate_data['rate_95th'])."bps";
+        $allowed = format_number($bill['bill_cdr'], $config['billing']['base'])."bps";
+        $cdr_total_allowed = $cdr_total_allowed + $bill['bill_cdr'];
+        $used    = format_number($rate_data['rate_95th'], $config['billing']['base'])."bps";
+        $cdr_total_used = $cdr_total_used + $rate_data['rate_95th'];
         $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)."bps");
+        if ($overuse > 0)
+        {
+          $cdr_total_overuse = $cdr_total_overuse + $overuse;
+        }
+        $overuse = (($overuse <= 0) ? "-" : format_number($overuse, $config['billing']['base'])."bps");
+        $cost = $bill['bill_price_total'];
       }
+      $cdr_total_cost = $cdr_total_cost + $cost;
     } elseif ($bill['bill_type'] == "quota") {
       $type = "Quota";
       if ($vars['view'] == 'history') {
         $allowed = format_bytes_billing($history['bill_allowed']);
+        $quota_total_allowed = $quota_total_allowed + $history['bill_allowed'];
         $used    = format_bytes_billing($rate_data['traf_total']);
+        $quota_total_used = $quota_total_used + $rate_data['traf_total'];
         $percent = round(($rate_data['traf_total'] / ($history['bill_allowed'])) * 100,2);
         $overuse = $rate_data['traf_total'] - $history['bill_allowed'];
+        if ($overuse > 0)
+        {
+          $quota_total_overuse = $quota_total_overuse + $overuse;
+        }
         $overuse = (($overuse <= 0) ? "-" : format_bytes_billing($overuse));
+        $cost = $history['bill_price_total'];
       } else {
         $allowed = format_bytes_billing($bill['bill_quota']);
+        $quota_total_allowed = $quota_total_allowed + $bill['bill_quota'];
         $used    = format_bytes_billing($rate_data['total_data']);
+        $quota_total_used = $quota_total_used + $rate_data['total_data'];
         $percent = round(($rate_data['total_data'] / ($bill['bill_quota'])) * 100,2);
         $overuse = $rate_data['total_data'] - $bill['bill_quota'];
+        if ($overuse > 0)
+        {
+          $quota_total_overuse = $quota_total_overuse + $overuse;
+        }
         $overuse = (($overuse <= 0) ? "-" : format_bytes_billing($overuse));
+        $cost = $bill['bill_price_total'];
       }
+      $quota_total_cost = $quota_total_cost + $cost;
     }
+    $total_cost = $cdr_total_cost + $quota_total_cost;
 
     $background = get_percentage_colours($percent);
 
@@ -146,6 +187,7 @@
             <td style=\"text-align: center;\">".$allowed."</td>
             <td style=\"text-align: center;\">".$used."</td>
             <td style=\"text-align: center;\">".$overuse."</td>
+           <td style=\"text-align: center;\">".$config['billing']['currency_symbol'].$cost."</td>
             <td>");
      echo(print_percentage_bar (400, 20, $percent, $percent.'%', "ffffff", $background['left'], ($percent < 100 ? 100-$percent."%" : "0%") , "ffffff", $background['right']));
      echo("
@@ -170,6 +212,48 @@
           </tr>\n");
   } // PERMITTED
 }
+echo("
+      <tr>
+        <td>
+          <strong class=\"interface\">CDR Totals</strong><br />
+        </td>
+        <td></td>
+            <td style=\"text-align: center;\"><strong>".format_number($cdr_total_allowed, $config['billing']['base'])."bps</strong></td>
+            <td style=\"text-align: center;\"><strong>".format_number($cdr_total_used, $config['billing']['base'])."bps</strong></td>
+            <td style=\"text-align: center;\"><strong>".format_number($cdr_total_overuse, $config['billing']['base'])."bps</strong></td>
+            <td style=\"text-align: center;\"><strong>".$config['billing']['currency_symbol'].$cdr_total_cost."</strong></td>
+        <td>
+        </td>
+        <td>
+        </td>
+      </tr>
+      <tr>
+        <td>
+          <strong class=\"interface\">Quota Totals</strong><br />
+        </td>
+        <td></td>
+            <td style=\"text-align: center;\"><strong>".format_bytes_billing($quota_total_allowed)."</strong></td>
+            <td style=\"text-align: center;\"><strong>".format_bytes_billing($quota_total_used)."</strong></td>
+            <td style=\"text-align: center;\"><strong>".format_bytes_billing($quota_total_overuse)."</strong></td>
+            <td style=\"text-align: center;\"><strong>".$config['billing']['currency_symbol'].$quota_total_cost."</strong></td>
+        <td>
+        </td>
+        <td>
+        </td>
+      </tr>
+        <td>
+          <strong class=\"interface\">Total Cost</strong><br />
+        </td>
+        <td></td>
+        <td></td>
+        <td></td>
+        <td></td>
+        <td style=\"text-align: center;\"><strong>".$config['billing']['currency_symbol'].$total_cost."</strong></td>
+        <td>
+        </td>
+        <td>
+        </td>
+      </tr>\n");
 
 echo("  </tbody>\n");
 echo("</table>\n");
Index: html/pages/bills.inc.php
===================================================================
--- html/pages/bills.inc.php	(revision 6654)
+++ html/pages/bills.inc.php	(working copy)
@@ -58,7 +58,8 @@
   }
 
   $insert = array('bill_name' => $vars['bill_name'], 'bill_type' => $vars['bill_type'], 'bill_cdr' => $bill_cdr, 'bill_day' => $vars['bill_day'], 'bill_quota' => $bill_quota,
-                  'bill_custid' => $vars['bill_custid'], 'bill_ref' => $vars['bill_ref'], 'bill_notes' => $vars['bill_notes']);
+                  'bill_custid' => $vars['bill_custid'], 'bill_ref' => $vars['bill_ref'], 'bill_notes' => $vars['bill_notes'],
+                  'bill_price_base' => $vars['bill_price_base'], 'bill_price_burst' => $vars['bill_price_burst']);
 
   $bill_id = dbInsert($insert, 'bills');
 
Index: includes/billing.inc.php
===================================================================
--- includes/billing.inc.php	(revision 6654)
+++ includes/billing.inc.php	(working copy)
@@ -32,6 +32,15 @@
 
 // DOCME needs phpdoc block
 // TESTME needs unit testing
+function format_mb($value)
+{
+  global $config;
+
+  return $value / $config['billing']['base'] / $config['billing']['base'];
+}
+
+// DOCME needs phpdoc block
+// TESTME needs unit testing
 function getDates($dayofmonth, $months=0)
 {
   $dayofmonth = zeropad($dayofmonth);
Index: includes/defaults.inc.php
===================================================================
--- includes/defaults.inc.php	(revision 6654)
+++ includes/defaults.inc.php	(working copy)
@@ -388,6 +388,7 @@
 $config['billing']['circuit_autoadd']   = 0; // Enable Auto-add bill per circuit_id
 $config['billing']['bill_autoadd']      = 0; // Enable Auto-add bill per bill_id
 $config['billing']['base']              = 1000; // Set the base to divider bytes to kB, MB, GB ,... (1000|1024)
+$config['billing']['currency_symbol']   = "£"; // Set the currency symbol to GBP
 
 // External Integration
 
