Overhaul ADSL traffic reporting/graphing
This commit is contained in:
@@ -11,30 +11,100 @@
|
||||
*/
|
||||
class Model_ADSL_Supplier_Plan extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'adsl_plan'=>array('model'=>'ADSL_Plan','far_key'=>'id'),
|
||||
);
|
||||
protected $_belongs_to = array(
|
||||
'adsl_supplier'=>array('model'=>'ADSL_Supplier','foreign_key'=>'supplier_id'),
|
||||
'supplier'=>array('model'=>'ADSL_Supplier'),
|
||||
);
|
||||
protected $_has_many = array(
|
||||
'plan'=>array('model'=>'Product_Plugin_Adsl','far_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_sorting = array(
|
||||
'product_id'=>'ASC',
|
||||
'product_desc'=>'ASC',
|
||||
);
|
||||
|
||||
protected $_form = array('id'=>'id','value'=>'name()');
|
||||
|
||||
/**
|
||||
* Filters used to format the display of values into friendlier values
|
||||
*/
|
||||
protected $_display_filters = array(
|
||||
'base_cost'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_down_peak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_down_offpeak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_up_peak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_up_offpeak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::get',array(':value',TRUE)),
|
||||
),
|
||||
);
|
||||
|
||||
// Map the table fields
|
||||
private $_map = array(
|
||||
'base_up_offpeak'=>'extra_up_offpeak',
|
||||
'base_down_offpeak'=>'extra_down_offpeak',
|
||||
'base_up_peak'=>'extra_up_peak',
|
||||
'base_down_peak'=>'extra_down_peak',
|
||||
);
|
||||
|
||||
private $_metrics = array(
|
||||
'base_up_peak'=>'base_up_peak',
|
||||
'base_up_offpeak'=>'base_up_offpeak',
|
||||
'base_down_peak'=>'base_down_peak',
|
||||
'base_down_offpeak'=>'base_down_offpeak',
|
||||
);
|
||||
|
||||
/**
|
||||
* Show the ADSL allowance as a peak/offpeak metric
|
||||
* Display the cost for extra traffic
|
||||
*/
|
||||
public function allowance() {
|
||||
return sprintf('%s/%s',$this->base_down_peak+$this->base_up_peak,$this->base_down_offpeak+$this->base_up_offpeak);
|
||||
public function cost_extra(array $data=array(),$format=FALSE) {
|
||||
$result = array();
|
||||
|
||||
if (! $data)
|
||||
$data = $this->traffic_data();
|
||||
|
||||
foreach ($data as $k => $v)
|
||||
$result[$k] = $this->display($this->_map[$k]);
|
||||
|
||||
return $format ? join('/',array_values($result)) : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* ADSL Plan Name
|
||||
*/
|
||||
public function name() {
|
||||
return $this->product_id;
|
||||
return sprintf('%s: %s',$this->product_id,$this->product_desc);
|
||||
}
|
||||
|
||||
public function tax() {
|
||||
return Tax::amount($this->base_cost);
|
||||
}
|
||||
/**
|
||||
* Collapse our traffic data into an array as per $this->_metric
|
||||
*/
|
||||
public function traffic_data() {
|
||||
$result = array();
|
||||
|
||||
public function total($format=FALSE) {
|
||||
return $format ? Currency::display($this->base_cost+$this->tax()) : Currency::round($this->base_cost+$this->tax());
|
||||
foreach ($this->_metrics as $metric=>$v) {
|
||||
if (! isset($result[$v]))
|
||||
$result[$v] = 0;
|
||||
|
||||
$result[$v] += $this->{$metric};
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user