Improved service display
This commit is contained in:
@@ -14,10 +14,10 @@ class Model_Service extends ORMOSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'invoice'=>array('through'=>'invoice_item'),
|
||||
'adsl_plan'=>array('through'=>'service__adsl'),
|
||||
);
|
||||
protected $_has_one = array(
|
||||
'service_adsl'=>array('far_key'=>'id'),
|
||||
'service_domain'=>array('far_key'=>'id'),
|
||||
);
|
||||
protected $_belongs_to = array(
|
||||
'product'=>array(),
|
||||
@@ -31,6 +31,9 @@ class Model_Service extends ORMOSB {
|
||||
'active'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
),
|
||||
'date_last_invoice'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'date_next_invoice'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
@@ -43,23 +46,107 @@ class Model_Service extends ORMOSB {
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* The service_name should be implemented in child objects.
|
||||
* It renders the name of the service, typically used on invoice
|
||||
*/
|
||||
protected function _service_name() {
|
||||
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* The service_view should be implemented in child objects.
|
||||
* It renders the details of the ordered service
|
||||
*/
|
||||
protected function _service_view() {
|
||||
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* The _details should be implemented in child objects.
|
||||
*/
|
||||
protected function _details($type) {
|
||||
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
|
||||
}
|
||||
|
||||
protected function _admin_update() {
|
||||
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object of the product plugin
|
||||
*/
|
||||
public function plugin() {
|
||||
if (! $this->product->prod_plugin_file)
|
||||
return NULL;
|
||||
|
||||
if (! is_numeric($this->product->prod_plugin_data))
|
||||
throw new Kohana_Exception('Missing plugin_id for :product (:type)',array(':product'=>$this->product->id,':type'=>$this->product->prod_plugin_file));
|
||||
|
||||
$spn = sprintf('%s_%s',get_class($this),$this->product->prod_plugin_file);
|
||||
return new $spn(array('service_id'=>$this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the service number
|
||||
*/
|
||||
public function svcnum() {
|
||||
public function id() {
|
||||
return sprintf('%05s',$this->id);
|
||||
}
|
||||
|
||||
// Nothing to directly display on invoices for this module.
|
||||
public function invoice_display() {
|
||||
if ($this->sku)
|
||||
return sprintf('%s: %s',_('Service'),$this->sku);
|
||||
else
|
||||
return '';
|
||||
/**
|
||||
* Display the service product name
|
||||
*/
|
||||
public function name() {
|
||||
return $this->product->name();
|
||||
}
|
||||
|
||||
public function name() {
|
||||
return $this->product->product_translate->find()->name;
|
||||
/**
|
||||
* Display the product feature summary
|
||||
*/
|
||||
public function product_feature_summary() {
|
||||
return $this->product->feature_summary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the service details
|
||||
*/
|
||||
public function service_view() {
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return HTML::nbsp('');
|
||||
else
|
||||
return $plugin->_service_view();
|
||||
}
|
||||
|
||||
public function service_name() {
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return $this->name();
|
||||
else
|
||||
return $plugin->_service_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render some details for specific calls, eg: invoice
|
||||
*/
|
||||
public function details($type) {
|
||||
switch ($type) {
|
||||
case 'invoice':
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return array();
|
||||
else
|
||||
return $plugin->_details($type);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
||||
}
|
||||
}
|
||||
|
||||
public function admin_update() {
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return NULL;
|
||||
else
|
||||
return $plugin->_admin_update();
|
||||
}
|
||||
|
||||
// @todo To implement
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Service_ADSL extends ORMOSB {
|
||||
class Model_Service_ADSL extends Model_Service {
|
||||
protected $_table_name = 'service__adsl';
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
@@ -20,6 +20,13 @@ class Model_Service_ADSL extends ORMOSB {
|
||||
'service'=>array(),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'service_connect_date'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* Return the IP Address for the service
|
||||
*/
|
||||
@@ -27,14 +34,8 @@ class Model_Service_ADSL extends ORMOSB {
|
||||
return $this->ipaddress ? $this->ipaddress : _('Dynamic');
|
||||
}
|
||||
|
||||
public function contract_date_start() {
|
||||
//@todo Use the system configured date format
|
||||
return date('Y-m-d',$this->service_connect_date);
|
||||
}
|
||||
|
||||
public function contract_date_end() {
|
||||
//@todo Use the system configured date format
|
||||
return date('Y-m-d',strtotime(sprintf('+%s months',$this->adsl_plan->contract_term),$this->service_connect_date));
|
||||
return Config::date(strtotime(sprintf('+%s months',$this->contract_term),$this->service_connect_date));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,5 +325,79 @@ class Model_Service_ADSL extends ORMOSB {
|
||||
// If we get here, then we dont need to report usage.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
protected function _service_name() {
|
||||
return sprintf('%s - %s',$this->service->product->name(),$this->service_number);
|
||||
}
|
||||
|
||||
protected function _service_view() {
|
||||
return View::factory('service/adsl/view')
|
||||
->set('so',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific service details for use in other modules
|
||||
* For Example: Invoice
|
||||
*
|
||||
* @todo Make the rendered items configurable
|
||||
*/
|
||||
protected function _details($type) {
|
||||
switch ($type) {
|
||||
case 'invoice':
|
||||
return array(
|
||||
_('Service Address')=>$this->display('service_address'),
|
||||
_('Contact Until')=>$this->contract_date_end(),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
||||
}
|
||||
}
|
||||
|
||||
protected function _admin_update() {
|
||||
return View::factory($this->viewpath(strtolower($this->service->prod_plugin_name)))
|
||||
->set('so',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a google chart of traffic
|
||||
*/
|
||||
public function graph_traffic($month=null) {
|
||||
$google = GoogleChart::factory('vertical_bar');
|
||||
|
||||
// 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)) {
|
||||
$google->title = sprintf('DSL traffic usage for %s',$_POST['month']);
|
||||
$traffic_data = $this->get_traffic_data_daily(strtotime($_POST['month'].'-01'));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)),
|
||||
'axis'=>'x',
|
||||
'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k])));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),
|
||||
'axis'=>'r',
|
||||
'data'=>array((isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)=>$this->cumulative($traffic_data[$k]))));
|
||||
|
||||
$graph_data = View::factory('service/view_detail_adsl_traffic')
|
||||
->set('traffic',$this->traffic_month(strtotime($_POST['month'].'-01'),FALSE));
|
||||
|
||||
} else {
|
||||
// @todo Change the date to the last record date
|
||||
$google->title = sprintf('Monthly DSL traffic usage as at %s',Config::date(strtotime('yesterday')));
|
||||
$traffic_data = $this->get_traffic_data_monthly();
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)),
|
||||
'axis'=>'x',
|
||||
'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k])));
|
||||
}
|
||||
|
||||
return (string)$google;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user