Open Source Billing
This commit is contained in:
38
modules/adsl/classes/Model/ADSL/Plan.php
Normal file
38
modules/adsl/classes/Model/ADSL/Plan.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Plans
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Plan extends ORM_OSB {
|
||||
// Relationships
|
||||
// @todo This model should probably be joined with product_plugin_adsl
|
||||
protected $_belongs_to = array(
|
||||
'adsl_supplier_plan'=>array('model'=>'ADSL_Supplier_Plan'),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'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')),
|
||||
),
|
||||
);
|
||||
}
|
||||
?>
|
72
modules/adsl/classes/Model/ADSL/Supplier.php
Normal file
72
modules/adsl/classes/Model/ADSL/Supplier.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Suppliers
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Supplier extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'adsl_supplier_plan'=>array('model'=>'ADSL_Supplier_Plan','foreign_key'=>'supplier_id','far_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
/**
|
||||
* Return a list of plans that this supplier makes available
|
||||
*/
|
||||
public function plans($active=TRUE) {
|
||||
$a = $this->adsl_supplier_plan;
|
||||
|
||||
if ($active)
|
||||
$a->where_active();
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of plans that we provide by this supplier
|
||||
*/
|
||||
public function adsl_plans($active=TRUE) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->plans($active)->find_all() as $po)
|
||||
foreach ($po->adsl_plan->find_all() as $apo)
|
||||
$result[$apo->id] = $apo;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of services for this supplier
|
||||
*
|
||||
* @param boolean $active TRUE List only active Services|False List all services
|
||||
*/
|
||||
public function services($active=TRUE) {
|
||||
$services = array();
|
||||
|
||||
// Get a list of plans made for this supplier
|
||||
$plans = array_keys($this->adsl_plans(FALSE));
|
||||
|
||||
// Start with all our ADSL Plans
|
||||
foreach (ORM::factory('Service')->list_bylistgroup('ADSL') as $so)
|
||||
if (! $active OR $so->status)
|
||||
if (in_array($so->product->prod_plugin_data,$plans) OR in_array($so->plugin()->provided_adsl_plan_id,$plans))
|
||||
array_push($services,$so);
|
||||
|
||||
// @todo poor cludge, we should find them without using list_bylistgroup()
|
||||
if (! $services)
|
||||
foreach (ORM::factory('Service')->list_bylistgroup('HSPA') as $so)
|
||||
if (! $active OR $so->status)
|
||||
if (in_array($so->product->prod_plugin_data,$plans) OR in_array($so->plugin()->provided_adsl_plan_id,$plans))
|
||||
array_push($services,$so);
|
||||
|
||||
return $services;
|
||||
}
|
||||
}
|
||||
?>
|
38
modules/adsl/classes/Model/ADSL/Supplier/Plan.php
Normal file
38
modules/adsl/classes/Model/ADSL/Supplier/Plan.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Plans
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
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'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Show the ADSL allowance as a peak/offpeak metric
|
||||
*/
|
||||
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 tax() {
|
||||
// @todo This should be taken from the users session
|
||||
// @todo rounding should be a system default
|
||||
return round($this->base_cost*.1,2);
|
||||
}
|
||||
|
||||
public function name() {
|
||||
return $this->product_id;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user