TRUE,
'edit'=>TRUE,
'list'=>TRUE,
'stat'=>TRUE,
'traffic'=>TRUE,
'product'=>TRUE,
);
public function action_index() {
$output = '';
$output .= Form::open(URL::link('admin','adsl/traffic'));
$output .= Form::select('sid',ORM::factory('ADSL_Supplier')->list_select());
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
$output .= Form::close();
Block::factory()
->title('Select ADSL Supplier')
->title_icon('icon-share')
->body($output);
}
public function action_list() {
$this->meta->title = 'ADSL Plans';
Block::factory()
->title('ADSL Plans')
->title_icon('icon-th-list')
->body(Table::factory()
->data(ORM::factory('Product_Plugin_Adsl')->find_all())
->jssort('adsl')
->columns(array(
'id'=>'ID',
'supplier_plan->name()'=>'Plan',
'supplier_plan->display("active")'=>'Avail',
'base_down_peak'=>'PD',
'base_down_offpeak'=>'OPD',
'base_up_peak'=>'PU',
'base_up_offpeak'=>'OPU',
'extra_charged'=>'$',
'extra_down_peak'=>'EPD',
'extra_down_offpeak'=>'EOPD',
'extra_up_peak'=>'EPU',
'extra_up_offpeak'=>'EOPU',
'contract_term'=>'Cont',
))
->prepend(array(
'id'=>array('url'=>URL::link('admin','adsl/edit/')),
))
);
}
public function action_edit() {
$apo = ORM::factory('Product_Plugin_Adsl',$this->request->param('id'));
if (! $apo->loaded())
throw HTTP_Exception::factory(403,'Plan either doesnt exist, or you are not authorised to see it');
$this->meta->title = 'ADSL Plan: '.$apo->name();
$test_result = array();
if (! $apo->loaded())
HTTP::redirect(URL::link('admin','adsl/list'));
if ($this->request->post()) {
if ($apo->values($this->request->post())->changed() AND (! $this->save($apo)))
$apo->reload();
if ($this->request->post('test')) {
$charge = $this->request->post('test.charge');
$test_result = $apo->allowance($this->request->post('test'),FALSE,$charge,TRUE);
}
}
Block::factory()
->type('form-horizontal')
->title('Update ADSL Plan')
->title_icon('icon-wrench')
->body(View::factory('adsl/admin/edit')
->set('test_result',$test_result)
->set('o',$apo));
Block::factory()
->title('Products Using this Plan')
->title_icon('icon-th-list')
->body(Table::factory()
->jssort('traffic')
->data($apo->products())
->columns(array(
'id'=>'ID',
'name(Site::language())'=>'Name',
'status'=>'Active',
))
->prepend(array(
'id'=>array('url'=>URL::link('admin','product/edit/')),
))
);
}
public function action_product() {
$lo = ORM::factory('Language',['name'=>'English']);
$aso = ORM::factory('Service')->where_authorised($this->ao)->list_byplugin('ADSL');
$output = '';
// Process our active services
$products = array();
foreach ($aso as $o) {
// $output .= sprintf('Got Service [%s]
',$o->id);
if (! array_key_exists($o->product_id,$products)) {
$products[$o->product_id] = $o->product;
}
}
// $output .= sprintf('Products [%s]
',join('|',array_keys($products)));
// Find our products without services.
$po = ORM::factory('Product')->where('prod_plugin_file','=','ADSL')->and_where('id','NOT IN',array_keys($products))->where_active()->find_all();
foreach ($po as $o) {
if (! array_key_exists($o->id,$products)) {
$products[$o->id] = $o;
}
}
// $output .= sprintf('Now Products [%s]
',join('|',array_keys($products)));
// Get a list of our ADSL plans that support these products
$supplierplans = $plans = array();
foreach ($products as $id => $po) {
if (! array_key_exists($po->prod_plugin_data,$plans)) {
$plans[$po->prod_plugin_data] = ORM::factory('ADSL_Plan',$po->prod_plugin_data);
}
//if ($po->id == 87) $output .= Debug::vars($po);
//if ($po->id == 87) $output .= '
%s | %s | %s | ||||
---|---|---|---|---|---|---|
%s: %s | ',$spo->id,$spo->name()); $output .= sprintf('%s | ',$spo->display('base_cost')); $output .= sprintf('%s | ',$spo->display('active')); $output .= '||||
'; $output .= ' | '; $output .= sprintf(' | %s | ',$po->id); $output .= ''; $output .= ' | '; $output .= ' | ||
'; $output .= ' | '; $output .= ' | '; $output .= sprintf(' | %s: ',$pro->id,$pro->id); try { $output .= sprintf('%s | ',$pro->name($lo)); } catch (Exception $e) { $output .= sprintf('%s','Unavailable'); } $output .= sprintf('%s | ',$pro->price(0,1,'base',true)); $output .= sprintf('%s | ',$pro->display('active')); $output .= '|
'; $output .= ' | '; $output .= ' | '; $output .= ' | '; $output .= sprintf(' | %s: %s | ',$so->id,$so->id,$so->name($lo)); $output .= sprintf('%s | ',$so->price()); $output .= sprintf('%s | ',$so->display('active')); $output .= '