Moved GB/MB configuration for ADSL into database
This commit is contained in:
parent
a711e70b60
commit
89deb9c97b
@ -126,6 +126,16 @@ class Period {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a date is in the same month as another date
|
||||
*/
|
||||
public static function inMonth($date,$period=NULL) {
|
||||
if (is_null($period))
|
||||
$period = time();
|
||||
|
||||
return ($date >= strtotime('first day of',$period) AND $date <= strtotime('last day of',$period));
|
||||
}
|
||||
|
||||
public static function multiple($rs) {
|
||||
switch($rs) {
|
||||
case 0: $multiple=52; break;
|
||||
|
@ -91,7 +91,7 @@ class Controller_Admin_Adsl extends Controller_Adsl {
|
||||
|
||||
if (isset($_POST['test'])) {
|
||||
$charge = isset($_POST['test']['charge']) ? $_POST['test']['charge'] : FALSE;
|
||||
$test_result = $apo->allowance($_POST['test'],FALSE,$charge,1000);
|
||||
$test_result = $apo->allowance($_POST['test'],FALSE,$charge,TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ class Controller_Admin_Adsl extends Controller_Adsl {
|
||||
*/
|
||||
public function action_stat() {
|
||||
// @todo This needs to be configurable.
|
||||
$traffic = array(1000,2000,5000,10000,25000,50000,75000,100000);
|
||||
$traffic = array(1,2,5,10,25,50,75,100,150,200);
|
||||
|
||||
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
|
||||
$stats = array();
|
||||
|
@ -43,6 +43,7 @@ class Controller_Reseller_Service_Adsl extends Controller_Service {
|
||||
public function action_list() {
|
||||
$highchart = HighChart::factory('Combo');
|
||||
$highchart->title(sprintf('Monthly DSL traffic usage as at %s',date('Y-m-d',strtotime('yesterday'))));
|
||||
$highchart->xmetric('MB');
|
||||
|
||||
$c = 0;
|
||||
foreach ($this->consoltraffic(time()) as $k => $details) {
|
||||
@ -69,9 +70,9 @@ class Controller_Reseller_Service_Adsl extends Controller_Service {
|
||||
'name()'=>'Service',
|
||||
'plugin()->ipaddress()'=>'IP Address',
|
||||
'product->plugin()->supplier_plan->speed'=>'Speed',
|
||||
'product->plugin()->allowance(array(),TRUE,TRUE,1000)'=>'Allowance',
|
||||
'plugin()->traffic_month(strtotime("yesterday"),TRUE,1000)'=>'This Month',
|
||||
'plugin()->traffic_month(strtotime("last month"),TRUE,1000)'=>'Last Month',
|
||||
'product->plugin()->allowance(array(),TRUE,TRUE,TRUE)'=>'Allowance',
|
||||
'plugin()->traffic_month(strtotime("yesterday"),TRUE,TRUE)'=>'This Month',
|
||||
'plugin()->traffic_month(strtotime("last month"),TRUE,TRUE)'=>'Last Month',
|
||||
'recur_schedule'=>'Billing',
|
||||
'price(TRUE,TRUE)'=>'Price',
|
||||
'account->accnum()'=>'Cust ID',
|
||||
|
@ -118,7 +118,7 @@ class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
|
||||
* @param bool Display the over allowance numbers
|
||||
* @param int Divide the numbers
|
||||
*/
|
||||
public function allowance(array $data=array(),$format=FALSE,$over=FALSE,$divide=0) {
|
||||
public function allowance(array $data=array(),$format=FALSE,$over=FALSE,$ceil=FALSE) {
|
||||
$result = $x = array();
|
||||
|
||||
// Do we invert the result - showing allowance
|
||||
@ -172,8 +172,12 @@ class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
|
||||
foreach (array_keys(Model_Service_Plugin_Adsl_Traffic::$metrics) as $k) {
|
||||
$k = 'base_'.$k;
|
||||
|
||||
if (isset($x[$k]))
|
||||
$result[$k] = $divide ? ceil($x[$k]/$divide) : $x[$k];
|
||||
if (isset($x[$k])) {
|
||||
$result[$k] = $this->metric ? round($x[$k]/$this->metric,2) : $x[$k];
|
||||
|
||||
if ($ceil)
|
||||
$result[$k] = ceil($result[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return $format ? join('/',array_values($result)) : $result;
|
||||
|
@ -160,7 +160,7 @@ $(document).ready(function() {
|
||||
* Get monthly traffic data, broken down by type
|
||||
* @todo This needs to get the plan that was invoiced, not the current plan..
|
||||
*/
|
||||
public function get_traffic_monthlytype($period=NULL,$periodstart=NULL,$format=FALSE,$divide=0) {
|
||||
public function get_traffic_monthlytype($period=NULL,$periodstart=NULL,$format=FALSE,$ceil=FALSE) {
|
||||
$result = array();
|
||||
|
||||
if (is_null($period))
|
||||
@ -178,7 +178,7 @@ $(document).ready(function() {
|
||||
foreach ($t->find_all() as $to) {
|
||||
$index = $to->month;
|
||||
|
||||
$result[$index] = $this->plan()->allowance($to->traffic_data(),$format,FALSE,$divide);
|
||||
$result[$index] = $this->plan()->allowance($to->traffic_data(),$format,FALSE,$ceil);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -203,13 +203,13 @@ $(document).ready(function() {
|
||||
/**
|
||||
* Get traffic type data, broken down by month
|
||||
*/
|
||||
public function get_traffic_typemonthly($period=NULL) {
|
||||
public function get_traffic_typemonthly($period=NULL,$ceil=FALSE) {
|
||||
$result = array();
|
||||
|
||||
if (is_null($period))
|
||||
$period = strtotime('yesterday');
|
||||
|
||||
foreach ($this->get_traffic_monthlytype($period) as $day => $data)
|
||||
foreach ($this->get_traffic_monthlytype($period,NULL,FALSE,$ceil) as $day => $data)
|
||||
foreach ($data as $metric => $value)
|
||||
$result[$metric][$day] = $value;
|
||||
|
||||
@ -329,7 +329,7 @@ $(document).ready(function() {
|
||||
if ($x=$this->get_traffic_monthlytype(strtotime('last day of '.date('M Y',$period)),strtotime('first day of '.date('M Y',$period)))) {
|
||||
|
||||
$c = $this->plan()->cost_extra();
|
||||
foreach ($this->plan()->allowance(array_pop($x),FALSE,TRUE,1000) as $k=>$v)
|
||||
foreach ($this->plan()->allowance(array_pop($x),FALSE,TRUE,TRUE) as $k=>$v)
|
||||
if (isset($c[$k]) AND $v > 0) {
|
||||
$result[$k] = $charge ? $c[$k]*$v : $v;
|
||||
|
||||
@ -351,6 +351,12 @@ $(document).ready(function() {
|
||||
public function traffic_graph($month=NULL) {
|
||||
$highchart = HighChart::factory('Combo');
|
||||
|
||||
switch ($this->plan()->metric) {
|
||||
case '1000' : $highchart->xmetric('GB'); break;
|
||||
case '1' : $highchart->xmetric('MB'); break;
|
||||
default: $highchart->xmetric('?');
|
||||
}
|
||||
|
||||
$c=0;
|
||||
// If we came in via a post to show a particular month, then show that, otherwise show the yearly result
|
||||
if (! is_null($month) AND trim($month)) {
|
||||
@ -359,7 +365,7 @@ $(document).ready(function() {
|
||||
|
||||
} else {
|
||||
$highchart->title(sprintf('Monthly DSL traffic usage as at %s',$this->traffic->find_last()->date));
|
||||
$x = $this->get_traffic_typemonthly();
|
||||
$x = $this->get_traffic_typemonthly(NULL,TRUE);
|
||||
}
|
||||
|
||||
foreach ($x as $k => $details) {
|
||||
@ -379,8 +385,8 @@ $(document).ready(function() {
|
||||
/**
|
||||
* Get the traffic for a month
|
||||
*/
|
||||
public function traffic_month($period,$format=FALSE,$divide=0) {
|
||||
$x = $this->get_traffic_monthlytype(strtotime('last day of '.date('M Y',$period)),strtotime('first day of '.date('M Y',$period)),$format,$divide);
|
||||
public function traffic_month($period,$format=FALSE,$ceil=FALSE) {
|
||||
$x = $this->get_traffic_monthlytype(strtotime('last day of '.date('M Y',$period)),strtotime('first day of '.date('M Y',$period)),$format,$ceil);
|
||||
|
||||
return $x ? array_pop($x) : 0;
|
||||
}
|
||||
@ -400,25 +406,30 @@ $(document).ready(function() {
|
||||
|
||||
$result['day'] = date('d',strtotime('yesterday'));
|
||||
$result['last'] = $this->traffic->find_last()->date();
|
||||
|
||||
if (! Period::inMonth($result['last'],strtotime('yesterday')))
|
||||
return array();
|
||||
|
||||
$lastday = date('d',strtotime('last day of',$result['last']));
|
||||
|
||||
$result['allow'] = $this->plan()->allowance(array(),FALSE,TRUE);
|
||||
$result['used'] = $this->traffic_month($result['last']);
|
||||
|
||||
if (! $result['used'])
|
||||
if (! array_sum($result['used']))
|
||||
return array();
|
||||
|
||||
$result['day'] = 3;
|
||||
// If we are the last day of the period, and we had traffic
|
||||
if ($result['day'] == $lastday)
|
||||
return $result;
|
||||
|
||||
foreach ($result['used'] as $k => $v) {
|
||||
// If we are at 80% usage
|
||||
// @todo This should be a setup config item
|
||||
if ($v/($result['allow'][$k] > 0 ? $result['allow'][$k] : 1) >= .8 AND $result['day']%3 == 0)
|
||||
return $result;
|
||||
|
||||
// If our average is greater than our allowance
|
||||
// @todo This should be a setup config item
|
||||
if ($result['day']%5 == 0 AND ($v/$result['day'] > $result['allow'][$k]/$result['day']))
|
||||
return $result;
|
||||
}
|
||||
@ -437,7 +448,7 @@ $result['day'] = 3;
|
||||
$index = 'Date';
|
||||
|
||||
} else {
|
||||
$x = $this->get_traffic_monthlytype();
|
||||
$x = $this->get_traffic_monthlytype(NULL,NULL,FALSE,TRUE);
|
||||
$index = 'Month';
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ class Task_Adsl_Trafficcharge extends Minion_Task {
|
||||
if ($x=$so->plugin()->traffic_excess($date)) {
|
||||
$po = $so->plugin()->plan();
|
||||
$cost = $po->cost_extra();
|
||||
$allowance = $po->allowance(array(),FALSE,TRUE,1000);
|
||||
$used = $so->plugin()->traffic_month($date,FALSE,1000);
|
||||
$allowance = $po->allowance(array(),FALSE,TRUE,TRUE);
|
||||
$used = $so->plugin()->traffic_month($date,FALSE,TRUE);
|
||||
|
||||
foreach ($x as $k=>$v) {
|
||||
$co = ORM::factory('Charge');
|
||||
|
@ -40,10 +40,10 @@
|
||||
|
||||
<div class="dl-horizontal">
|
||||
<dt>Last Month</dt>
|
||||
<dd> <?php echo $o->traffic_month(strtotime('last month'),TRUE,1000); ?> GB</dd>
|
||||
<dd> <?php echo $o->traffic_month(strtotime('last month'),TRUE,TRUE); ?></dd>
|
||||
|
||||
<dt>This Month</dt>
|
||||
<dd> <?php echo $o->traffic_month(strtotime('yesterday'),TRUE,1000); ?> GB</dd>
|
||||
<dd> <?php echo $o->traffic_month(strtotime('yesterday'),TRUE,TRUE); ?></dd>
|
||||
|
||||
<dt>Excess Traffic</dt>
|
||||
<dd> $<?php echo $o->traffic_excess(strtotime('yesterday'),TRUE,TRUE); ?></dd>
|
||||
|
Reference in New Issue
Block a user