OSB enhancements to date
This commit is contained in:
151
modules/adsl/classes/adsl.php
Normal file
151
modules/adsl/classes/adsl.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class looks after ADSL products
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Product
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class ADSL {
|
||||
// Map the table fields
|
||||
static $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',
|
||||
);
|
||||
|
||||
/**
|
||||
* Return an instance of this class
|
||||
*
|
||||
* @return ADSL
|
||||
*/
|
||||
public static function instance() {
|
||||
return new ADSL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the additional information used by product_view
|
||||
*/
|
||||
public function product_view($data) {
|
||||
// @todo - this test shouldnt be required
|
||||
if (preg_match('/^a:/',$data))
|
||||
throw new Kohana_Exception('Data shouldnt be a serialized array');
|
||||
|
||||
$ao = ORM::factory('adsl_plan',$data);
|
||||
|
||||
$output = View::factory('adsl/product_view')
|
||||
->set('record',$ao);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function contract_view($data,$price_base,$price_setup) {
|
||||
// @todo - this test shouldnt be required
|
||||
if (preg_match('/^a:/',$data))
|
||||
throw new Kohana_Exception('Data shouldnt be a serialized array');
|
||||
|
||||
$ao = ORM::factory('adsl_plan',$data);
|
||||
$output = View::factory('adsl/contract_view')
|
||||
->set('record',$ao)
|
||||
->set('price_base',$price_base)
|
||||
->set('price_setup',$price_setup);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect information for the cart
|
||||
*/
|
||||
public function product_cart() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the metric fields to their excess rate
|
||||
*/
|
||||
public static function map($metric) {
|
||||
return ADSL::$map[$metric];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the allowance array or traffic used array
|
||||
*
|
||||
* If:
|
||||
* + UPLOADS are charged and there are no PEAK/OFFPEAK periods (therefore all
|
||||
* traffic is charged), the allowance will be shown as 1 metric - TRAFFIC.
|
||||
* + UPLOADS are charged and there are PEAK/OFFPEAK periods the allowance
|
||||
* will be shown as 2 metrics - PEAK/OFFPEAK.
|
||||
* + UPLOADS are NOT charged and there are no PEAK/OFFPEAK periods the allowance
|
||||
* will be shown as 1 metrics - TRAFFIC.
|
||||
* + UPLOADS are NOT charged and there are PEAK/OFFPEAK periods the allowance
|
||||
* will be shown as 2 metrics - PEAK/OFFPEAK.
|
||||
*
|
||||
* Thus:
|
||||
* + If base_x_Y is NULL, all Y traffic is FREE (ignore respective extra_x_Y setting).
|
||||
* + If base_x_Y is a number, all Y traffic is FREE up to the number (evaluate extra_x_Y setting).
|
||||
* + If extra_x_Y is a number, charge this amount for traffic over base_x_Y.
|
||||
* + If extra_down_peak is NULL this is invalid, treat base_down_peak as NULL
|
||||
* + If extra_down_offpeak is NULL add traffic_down_offpeak to traffic_down_peak
|
||||
* + If extra_up_peak is NULL add traffic_up_peak to traffic_down_peak
|
||||
* + If extra_up_offpeak is NULL add traffic_up_offpeak to traffic_down_offpeak
|
||||
*
|
||||
* @param array $plan - the allowance plan
|
||||
*/
|
||||
public static function allowance($plan) {
|
||||
// Map the NULL relationships
|
||||
$extras = array(
|
||||
'extra_up_offpeak'=>'base_down_offpeak',
|
||||
'extra_down_offpeak'=>'base_down_peak',
|
||||
'extra_up_peak'=>'base_down_peak',
|
||||
'extra_down_peak'=>'base_down_peak',
|
||||
);
|
||||
|
||||
// Work out if we charge each period
|
||||
$a = array();
|
||||
if (! isset($plan['extra_down_peak']) OR is_null($plan['extra_down_peak']))
|
||||
$a['base_down_peak'] = 0;
|
||||
|
||||
foreach (ADSL::$map as $k => $v) {
|
||||
// Work through attributes we count.
|
||||
if (isset($plan[$k]) AND ! is_null($plan[$k])) {
|
||||
|
||||
// Work through attributes that are merged
|
||||
if (! isset($plan[$v]) OR is_null($plan[$v])) {
|
||||
|
||||
if (isset($a[$k])) {
|
||||
if (isset($a[$extras[$v]]))
|
||||
$a[$extras[$v]] += $a[$k];
|
||||
else
|
||||
$a[$extras[$v]] = $a[$k];
|
||||
|
||||
unset($a[$k]);
|
||||
}
|
||||
|
||||
if (isset($a[$extras[$v]]))
|
||||
$a[$extras[$v]] += $plan[$k];
|
||||
else
|
||||
$a[$extras[$v]] = $plan[$k];
|
||||
|
||||
} else {
|
||||
if (isset($a[$k]))
|
||||
$a[$k] += $plan[$k];
|
||||
else
|
||||
$a[$k] = $plan[$k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the output sorted
|
||||
$return = array();
|
||||
foreach (array('base_down_peak','base_down_offpeak','base_up_peak','base_up_offpeak') as $k)
|
||||
if (isset($a[$k]))
|
||||
$return[$k] = $a[$k];
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
?>
|
59
modules/adsl/classes/model/adsl/plan.php
Normal file
59
modules/adsl/classes/model/adsl/plan.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Plans
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Plan extends ORMOSB {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'adsl_supplier_plan'=>array(),
|
||||
);
|
||||
protected $_has_many = array(
|
||||
'service'=>array('through'=>'service__adsl'),
|
||||
);
|
||||
|
||||
protected $_formats = array(
|
||||
'extra_down_peak'=>array(
|
||||
'Tax::add'=>array(),
|
||||
'Currency::display'=>array(),
|
||||
),
|
||||
'extra_down_offpeak'=>array(
|
||||
'Tax::add'=>array(),
|
||||
'Currency::display'=>array(),
|
||||
),
|
||||
'extra_up_peak'=>array(
|
||||
'Tax::add'=>array(),
|
||||
'Currency::display'=>array(),
|
||||
),
|
||||
'extra_up_offpeak'=>array(
|
||||
'Tax::add'=>array(),
|
||||
'Currency::display'=>array(),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Show the ADSL allowance as a peak/offpeak metric
|
||||
*/
|
||||
public function allowance($string=TRUE) {
|
||||
$output = ADSL::allowance(array(
|
||||
'base_down_peak'=>$this->base_down_peak,
|
||||
'base_down_offpeak'=>$this->base_down_offpeak,
|
||||
'base_up_peak'=>$this->base_up_peak,
|
||||
'base_up_offpeak'=>$this->base_up_offpeak,
|
||||
'extra_down_peak'=>$this->extra_down_peak,
|
||||
'extra_down_offpeak'=>$this->extra_down_offpeak,
|
||||
'extra_up_peak'=>$this->extra_up_peak,
|
||||
'extra_up_offpeak'=>$this->extra_up_offpeak,
|
||||
));
|
||||
|
||||
return $string ? implode('/',$output) : $output;
|
||||
}
|
||||
}
|
||||
?>
|
40
modules/adsl/classes/model/adsl/supplier.php
Normal file
40
modules/adsl/classes/model/adsl/supplier.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Suppliers
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Supplier extends ORMOSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'adsl_supplier_plan'=>array('foreign_key'=>'supplier_id'),
|
||||
);
|
||||
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
/**
|
||||
* 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
|
||||
foreach ($this->adsl_supplier_plan->find_all() as $aspo)
|
||||
// Find all the plan who use this supplier plan
|
||||
foreach ($aspo->adsl_plan->find_all() as $apo)
|
||||
// Find all the services who use this plan
|
||||
foreach ($apo->service->find_all() as $so)
|
||||
array_push($services,$so);
|
||||
|
||||
return $services;
|
||||
}
|
||||
}
|
||||
?>
|
39
modules/adsl/classes/model/adsl/supplier/plan.php
Normal file
39
modules/adsl/classes/model/adsl/supplier/plan.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Plans
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Supplier_Plan extends ORMOSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'adsl_plan'=>array(),
|
||||
);
|
||||
protected $_belongs_to = array(
|
||||
'adsl_supplier'=>array('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