Moved GB/MB configuration for ADSL into database

This commit is contained in:
Deon George
2013-11-18 15:18:50 +11:00
parent a711e70b60
commit 89deb9c97b
7 changed files with 49 additions and 23 deletions

View File

@@ -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;

View File

@@ -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';
}