315 lines
9.4 KiB
PHP
315 lines
9.4 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class provides Admin ADSL functions
|
|
*
|
|
* @package ADSL
|
|
* @category Controllers/Admin
|
|
* @author Deon George
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
* @license http://dev.osbill.net/license.html
|
|
*/
|
|
class Controller_Admin_Adsl extends Controller_Adsl {
|
|
protected $secure_actions = array(
|
|
'index'=>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]<br>',$o->id);
|
|
if (! array_key_exists($o->product_id,$products)) {
|
|
$products[$o->product_id] = $o->product;
|
|
}
|
|
}
|
|
// $output .= sprintf('Products [%s]<br>',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]<br>',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 .= '<hr>';
|
|
//if ($po->id == 87) $output .= Debug::vars($plans[$po->prod_plugin_data]);
|
|
//if ($po->id == 87) $output .= '<hr>';
|
|
if (! array_key_exists($plans[$po->prod_plugin_data]->adsl_supplier_plan_id,$supplierplans)) {
|
|
$supplierplans[$plans[$po->prod_plugin_data]->adsl_supplier_plan_id] = $plans[$po->prod_plugin_data]->supplier_plan;
|
|
//if ($po->id == 87) $output .= Debug::vars($plans[$po->prod_plugin_data]->supplier_plan);
|
|
}
|
|
}
|
|
|
|
// Get a list of our supplier ADSL plans that are active
|
|
$aspo = ORM::factory('ADSL_Supplier_Plan')->where('id','NOT IN',array_keys($supplierplans))->where_active()->find_all();
|
|
foreach ($aspo as $o) {
|
|
if (! array_key_exists($o->id,$supplierplans)) {
|
|
$supplierplans[$o->id] = $o;
|
|
}
|
|
}
|
|
|
|
|
|
$output .= '<table class="table table-striped table-condensed table-hover" border=0>';
|
|
|
|
$output .= sprintf('<tr><th colspan="5">%s</th><th>%s</th><th>%s</th></tr>','NAME','COST','ACTIVE');
|
|
|
|
// List our Supplier Plans
|
|
foreach ($supplierplans as $spo) {
|
|
$output .= '<tr>';
|
|
$output .= sprintf('<td colspan="5">%s: %s</td>',$spo->id,$spo->name());
|
|
$output .= sprintf('<td>%s</td>',$spo->display('base_cost'));
|
|
$output .= sprintf('<td>%s</td>',$spo->display('active'));
|
|
$output .= '</tr>';
|
|
|
|
// List our plans that use this supplier plans.
|
|
foreach ($plans as $po) {
|
|
if ($po->adsl_supplier_plan_id != $spo->id) continue;
|
|
|
|
$output .= '<tr>';
|
|
$output .= '<td> </td>';
|
|
$output .= '<td> </td>';
|
|
$output .= sprintf('<td colspan="3">%s</td>',$po->id);
|
|
$output .= '<td> </td>';
|
|
$output .= '<td> </td>';
|
|
$output .= '</tr>';
|
|
|
|
// List our products that use these plan
|
|
foreach ($products as $pro) {
|
|
if ($pro->prod_plugin_data != $po->id) continue;
|
|
|
|
$output .= '<tr>';
|
|
$output .= '<td> </td>';
|
|
$output .= '<td> </td>';
|
|
$output .= '<td> </td>';
|
|
$output .= sprintf('<td colspan="2"><a href="/a/product/edit/%s">%s</a>: ',$pro->id,$pro->id);
|
|
try {
|
|
$output .= sprintf('%s</td>',$pro->name($lo));
|
|
} catch (Exception $e) {
|
|
$output .= sprintf('%s</td>','Unavailable');
|
|
}
|
|
|
|
$output .= sprintf('<td>%s</td>',$pro->price(0,1,'base',true));
|
|
$output .= sprintf('<td>%s</td>',$pro->display('active'));
|
|
$output .= '</tr>';
|
|
|
|
// List our services using these products
|
|
foreach ($aso as $so) {
|
|
if ($so->product_id != $pro->id) continue;
|
|
$output .= '<tr>';
|
|
$output .= '<td colspan="1"> </td>';
|
|
$output .= '<td colspan="1"> </td>';
|
|
$output .= '<td colspan="1"> </td>';
|
|
$output .= '<td colspan="1"> </td>';
|
|
$output .= sprintf('<td><a href="/u/service/view/%s">%s</a>: %s</td>',$so->id,$so->id,$so->name($lo));
|
|
$output .= sprintf('<td>%s</td>',$so->price());
|
|
$output .= sprintf('<td>%s</td>',$so->display('active'));
|
|
$output .= '</tr>';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$output .= '</table>';
|
|
|
|
$this->template->content = $output;
|
|
}
|
|
|
|
/**
|
|
* Usage statistics for the previous moth
|
|
*/
|
|
public function action_stat() {
|
|
$this->meta->title = 'ADSL Stats';
|
|
|
|
// @todo This needs to be configurable.
|
|
$traffic = array(1,2,5,10,25,50,75,100,150,200);
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
|
|
$stats = array();
|
|
$output = '';
|
|
$ts = 0;
|
|
|
|
foreach ($svs as $a=>$so) {
|
|
// Number of services
|
|
if (! isset($stats[$so->product->plugin()->supplier_plan->speed]['c']))
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['c'] = 0;
|
|
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['c']++;
|
|
$ts++;
|
|
|
|
$a = 0;
|
|
foreach (array_reverse($traffic) as $i) {
|
|
if ($i < $so->plugin()->traffic_month(strtotime('first day of last month'),TRUE))
|
|
break;
|
|
|
|
$a = $i;
|
|
}
|
|
|
|
if (! isset($stats[$so->product->plugin()->supplier_plan->speed]['d'][$a]))
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['d'][$a] = 0;
|
|
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['d'][$a]++;
|
|
}
|
|
|
|
Block::factory()
|
|
->title('ADSL Traffic Summary Stats - Last Month')
|
|
->title_icon('icon-list')
|
|
->body(
|
|
View::factory('adsl/admin/stats')
|
|
->set('stats',$stats)
|
|
->set('traffic',$traffic)
|
|
->set('ts',$ts)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Reconcile billing for an ADSL supplier
|
|
*/
|
|
public function action_traffic() {
|
|
if (! $this->request->post('sid'))
|
|
HTTP::redirect(URL::link('admin','adsl/index'));
|
|
|
|
$aso = ORM::factory('ADSL_Supplier',$this->request->post('sid'));
|
|
if (! $aso->loaded())
|
|
HTTP::redirect(URL::link('admin','adsl/index'));
|
|
|
|
$t = ORM::factory('Service_Plugin_Adsl_Traffic');
|
|
$date = date('Y-m-d',time()-86400);
|
|
|
|
Block::factory()
|
|
->title(sprintf('ADSL Traffic for %s',$date))
|
|
->title_icon('icon-th-list')
|
|
->body(Table::factory()
|
|
->jssort('traffic')
|
|
->data($aso->traffic->where('date','=',$date)->find_all())
|
|
->columns(array(
|
|
'service'=>'Service Login',
|
|
'plan->service->id'=>'Service',
|
|
'plan->service_number'=>'Service',
|
|
'plan->service->active'=>'Active',
|
|
'up_peak'=>'Up Peak',
|
|
'down_peak'=>'Down Peak',
|
|
'up_offpeak'=>'Up OffPeak',
|
|
'down_offpeak'=>'Down OffPeak',
|
|
'peer'=>'Peer',
|
|
'internal'=>'Internal',
|
|
))
|
|
->prepend(array(
|
|
'plan->service->id'=>array('url'=>URL::link('user','service/view/')),
|
|
))
|
|
);
|
|
}
|
|
}
|
|
?>
|