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