Internal overhaul

This commit is contained in:
Deon George
2013-11-28 17:41:34 +11:00
parent 0ed5e5163d
commit f8a5b153cf
91 changed files with 1570 additions and 1619 deletions

View File

@@ -149,7 +149,7 @@ class ADSL_Billing_Exetelvisp {
// @todo This could be optimised better.
foreach ($aso->services(TRUE) as $so)
$this->haveService($so->plugin()->service_number,$so->plugin()->admin_plan()->adsl_supplier_plan->display('base_cost'));
$this->haveService($so->plugin()->service_number,$so->plugin()->admin_plan()->supplier_plan->display('base_cost'));
return $this;
}

View File

@@ -90,7 +90,7 @@ class Controller_Admin_Adsl extends Controller_Adsl {
->title_icon('icon-th-list')
->body(Table::factory()
->jssort('traffic')
->data($apo->products()->find_all())
->data($apo->products())
->columns(array(
'id'=>'ID',
'title()'=>'Name',

View File

@@ -14,7 +14,7 @@ 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'),
'plan'=>array('model'=>'ADSL_Supplier_Plan','foreign_key'=>'supplier_id','far_key'=>'id'),
'traffic'=>array('model'=>'Service_Plugin_Adsl_Traffic','foreign_key'=>'supplier_id','far_key'=>'id'),
);
@@ -50,7 +50,7 @@ class Model_ADSL_Supplier extends ORM_OSB {
* Return a list of plans that this supplier makes available
*/
public function find_plans($active=TRUE) {
return $active ? $this->adsl_supplier_plan->where_active() : $this->adsl_supplier_plan;
return $active ? $this->plan->where_active() : $this->plan;
}
/**
@@ -63,8 +63,8 @@ class Model_ADSL_Supplier extends ORM_OSB {
foreach ($this->find_plans(FALSE)->find_all() as $aspo) {
foreach ($aspo->plan->find_all() as $apo) {
foreach ($apo->products(FALSE)->find_all() as $po) {
foreach ($po->services($active)->find_all() as $so) {
foreach ($apo->products(FALSE) as $po) {
foreach ($po->service->list_active() as $so) {
array_push($result,$so);
}
}

View File

@@ -19,9 +19,6 @@ class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
protected $_belongs_to = array(
'supplier_plan'=>array('model'=>'ADSL_Supplier_Plan','foreign_key'=>'adsl_supplier_plan_id'),
);
protected $_has_many = array(
'product'=>array('far_key'=>'id','foreign_key'=>'prod_plugin_data'),
);
/**
* Filters used to format the display of values into friendlier values
@@ -59,14 +56,6 @@ class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
'extra_up_offpeak',
);
// 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',
);
// Our required abstract methods
public function cost($annual=FALSE) {
@@ -75,25 +64,24 @@ class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
return $annual ? $x*12 : $x;
}
public function feature_summary() {
return View::factory(sprintf('product/plugin/%s/feature_summary',$this->plugin()))
->set('o',$this);
}
// @todo Select the ADSL Plan for this product.
public function render_edit() {
return '';
}
public function render_order() {
return View::factory(sprintf('product/plugin/%s/order',$this->plugin()));
}
public function supplier() {
return $this->supplier_plan->supplier_id;
}
/** LOCAL FUNCTIONS **/
// Local functions
// 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',
);
/**
* Calculate the allowance array or traffic used array
@@ -204,19 +192,5 @@ class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
return TRUE;
}
/**
* Get all the products using this plan
*/
public function products($active=FALSE) {
$x = ORM::factory('Product')
->where('prod_plugin_file','=','ADSL')
->and_where('prod_plugin_data','=',$this);
if ($active)
$x->where_active();
return $x;
}
}
?>

View File

@@ -15,10 +15,6 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
protected $_updated_column = FALSE;
// Relationships
protected $_belongs_to = array(
'service'=>array(),
);
protected $_has_one = array(
'provided_plan'=>array('model'=>'Product_Plugin_Adsl','far_key'=>'provided_adsl_plan_id','foreign_key'=>'id'),
);
@@ -36,7 +32,10 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
),
);
protected $_save_message = TRUE;
// Required abstract functions
public function expire() {
// We'll leave it to the Service record to determine when this service expires
return NULL;
@@ -46,43 +45,15 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
return $this->service_number;
}
public function username_value() {
return $this->service_username;
}
public function password_value() {
public function password() {
return $this->service_password;
}
// Override our parent function to include some JS.
public function admin_update() {
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
$("#service_connect_date_label").datepicker({
autoclose : true,
startDate : now,
format : "dd-M-yyyy",
todayBtn : true,
}).on("hide",function(ev) {
$("input[id=service_connect_date]").val(ev.date.valueOf()/1000);
});
$("#service_contract_date_label").datepicker({
autoclose : true,
startDate : now,
format : "dd-M-yyyy",
todayBtn : true,
}).on("hide",function(ev) {
$("input[id=service_contract_date]").val(ev.date.valueOf()/1000);
});
});
');
return parent::admin_update();
public function username() {
return $this->service_username;
}
/** LOCAL FUNCTIONS **/
// Local functions
/**
* If we override the plan that the customers gets (from what the supplier provides).
@@ -99,7 +70,8 @@ $(document).ready(function() {
}
public function contract_date_end($format=FALSE) {
$x = strtotime(sprintf('+%s months',$this->contract_term),$this->service_contract_date);
// ADSL Contract Terms are held in the ADSL Plan
$x = strtotime(sprintf('+%s months',$this->service->plugin()->contract_term),$this->service_contract_date);
return $format ? Config::date($x) : $x;
}
@@ -475,6 +447,7 @@ $(document).ready(function() {
->where_open()
->and_where($this->_table_name.'.service_number','like','%'.$term.'%')
->or_where($this->_table_name.'.service_address','like','%'.$term.'%')
->or_where($this->_table_name.'.ipaddress','like','%'.$term.'%')
->where_close();
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);

View File

@@ -42,10 +42,10 @@ class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
// Find our services that need to be collected this way.
$update = array();
foreach ($this->so->services() as $so) {
foreach ($this->aso->services() as $so) {
if ($so->service_adsl->service_stats_collect AND $so->service_adsl->service_stats_lastupdate < $date) {
$lastperiod = '';
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
for ($servicedate=date('Y-m-d',strtotime($this->aso->stats_lastupdate.'+1 day'));
$servicedate <= $this->today;
$servicedate=date('Y-m-d',strtotime('+1 day',strtotime($servicedate)))) {
@@ -67,7 +67,7 @@ class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
if ($debug AND file_exists($debug_file))
$data = file_get_contents($debug_file);
else
$data = Remote::get($this->so->stats_url,$this->curlopts+array(CURLOPT_POSTFIELDS=>$postfields));
$data = Remote::get($this->aso->stats_url,$this->curlopts+array(CURLOPT_POSTFIELDS=>$postfields));
// @todo There exists a possibility to skip a month, if we get a bad fetch on a previous month.
if ($data)