Overhaul ADSL traffic reporting/graphing
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
class Controller_Admin_Adsl extends Controller_Adsl {
|
||||
protected $secure_actions = array(
|
||||
'index'=>TRUE,
|
||||
'edit'=>TRUE,
|
||||
'list'=>TRUE,
|
||||
'traffic'=>TRUE,
|
||||
);
|
||||
|
||||
@@ -29,6 +31,94 @@ class Controller_Admin_Adsl extends Controller_Adsl {
|
||||
->body($output);
|
||||
}
|
||||
|
||||
public function action_list() {
|
||||
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',
|
||||
'adsl_supplier_plan->name()'=>'Plan',
|
||||
'adsl_supplier_plan->display("status")'=>'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'));
|
||||
$test_result = array();
|
||||
|
||||
if (! $apo->loaded())
|
||||
HTTP::redirect(URL::link('admin','adsl/list'));
|
||||
|
||||
if ($_POST) {
|
||||
// Entry updated
|
||||
if ($apo->values($_POST)->check() AND $apo->changed()) {
|
||||
try {
|
||||
if ($apo->save())
|
||||
SystemMessage::factory()
|
||||
->title('Record updated')
|
||||
->type('success')
|
||||
->body(_('Your Charge record has been recorded/updated.'));
|
||||
|
||||
} catch (ORM_Validation_Exception $e) {
|
||||
$errors = $e->errors('models');
|
||||
|
||||
SystemMessage::factory()
|
||||
->title('Record NOT updated')
|
||||
->type('error')
|
||||
->body(join('<br/>',array_values($errors)));
|
||||
|
||||
$sco->reload();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['test'])) {
|
||||
$charge = isset($_POST['test']['charge']) ? $_POST['test']['charge'] : FALSE;
|
||||
$test_result = $apo->allowance($_POST['test'],FALSE,$charge,1000);
|
||||
}
|
||||
}
|
||||
|
||||
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()->find_all())
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'title()'=>'Name',
|
||||
'status'=>'Active',
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('admin','product/edit/')),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconcile billing for an ADSL supplier
|
||||
*/
|
||||
|
@@ -31,6 +31,7 @@ class Controller_Reseller_Adsl extends Controller_Adsl {
|
||||
->rule('csv','Upload::type',array(':value',array('csv')))
|
||||
->rule('csv','Upload::size',array(':value','10M'));
|
||||
|
||||
$csv = NULL;
|
||||
if ($files->check())
|
||||
foreach ($files->data() as $file) {
|
||||
$csv = $aso->billing()->process($aso,$file);
|
||||
|
@@ -14,68 +14,64 @@ class Controller_Reseller_Service_Adsl extends Controller_Service {
|
||||
'list'=>TRUE,
|
||||
);
|
||||
|
||||
private function consoltraffic($svs,$date) {
|
||||
$data = array();
|
||||
private function consoltraffic($period) {
|
||||
$result = array();
|
||||
|
||||
foreach ($svs as $so) {
|
||||
$c = array();
|
||||
foreach ($so->plugin()->get_traffic_data_monthly($date) as $metric => $ma) {
|
||||
foreach ($ma as $month => $traffic) {
|
||||
// Only count the service once, not for each metric.
|
||||
if (! isset($c[$month])) {
|
||||
if (isset($data['svs'][$month]))
|
||||
$data['svs'][$month] += 1;
|
||||
else
|
||||
$data['svs'][$month] = 1;
|
||||
$periodstart = mktime(0,0,0,date('m',$period),1,date('Y',$period)-1);
|
||||
|
||||
$c[$month] = 1;
|
||||
}
|
||||
$t = ORM::factory('Service_Plugin_Adsl_Traffic')
|
||||
->select(array('date_format(date,\'%y-%m\')','month'))
|
||||
->selectsummetric()
|
||||
->join('service__adsl','INNER')
|
||||
->on('service__adsl.service_username','=','service_plugin_adsl_traffic.service')
|
||||
->on('service__adsl.site_id','=','service_plugin_adsl_traffic.site_id')
|
||||
->join('service','INNER')
|
||||
->on('service__adsl.service_id','=','service.id')
|
||||
->on('service__adsl.site_id','=','service.site_id')
|
||||
->where_authorised($this->ao,'service.account_id')
|
||||
->and_where('date','>=',date('Y-m-d',$periodstart))
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
||||
->group_by('date_format(date,\'%Y-%m\')');
|
||||
|
||||
if (isset($data['data'][$metric][$month]))
|
||||
$data['data'][$metric][$month] += (int)$traffic;
|
||||
else
|
||||
$data['data'][$metric][$month] = (int)$traffic;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($t->find_all() as $to)
|
||||
foreach ($to->traffic_data() as $metric => $v)
|
||||
$result[$metric][$to->month] = $v;
|
||||
|
||||
ksort($data['svs']);
|
||||
foreach ($data['data'] as $metric => $details)
|
||||
ksort($data['data'][$metric]);
|
||||
|
||||
return $data;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function action_list() {
|
||||
$svs = ORM::factory('Service')->where_authorised($this->ao)->list_byplugin('ADSL');
|
||||
$highchart = HighChart::factory('Combo');
|
||||
$highchart->title(sprintf('Monthly DSL traffic usage as at %s',date('Y-m-d',strtotime('yesterday'))));
|
||||
|
||||
$data = $this->consoltraffic($svs,time());
|
||||
$c = 0;
|
||||
foreach ($this->consoltraffic(time()) as $k => $details) {
|
||||
$highchart->series('column','yl')
|
||||
->name($k)
|
||||
->data($details)
|
||||
->index($c)
|
||||
->order($c++*-1); // This is a kludge to get around highcharts rendering from the bottom up.
|
||||
|
||||
$google = GoogleChart::factory('Legacy')
|
||||
->type('vertical_bar')
|
||||
->title(sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday'))));
|
||||
$highchart->autopie($k);
|
||||
}
|
||||
|
||||
foreach ($data['data'] as $key => $values)
|
||||
$google->sdata(array('yl'=>$key),array($key=>$values));
|
||||
|
||||
$google->sdata(array('yr'=>'services'),array('services'=>$data['svs']));
|
||||
|
||||
Block::add(array('body'=>(string)$google));
|
||||
Block::factory()
|
||||
->body((string)$highchart);
|
||||
|
||||
Block::factory()
|
||||
->title('ADSL Services')
|
||||
->title_icon('icon-th-list')
|
||||
->body(Table::factory()
|
||||
->jssort('adsl')
|
||||
->data($svs)
|
||||
->data(ORM::factory('Service')->where_authorised($this->ao)->list_byplugin('ADSL'))
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'name()'=>'Service',
|
||||
'plugin()->ipaddress()'=>'IP Address',
|
||||
'product->plugin()->adsl_supplier_plan->speed'=>'Speed',
|
||||
'product->plugin()->allowance()'=>'Allowance',
|
||||
'plugin()->traffic_thismonth()'=>'This Month',
|
||||
'plugin()->traffic_lastmonth()'=>'Last Month',
|
||||
'product->plugin()->supplier_plan->speed'=>'Speed',
|
||||
'product->plugin()->allowance(array(),TRUE,TRUE,1000)'=>'Allowance',
|
||||
'plugin()->traffic_month(strtotime("yesterday"),TRUE,1000)'=>'This Month',
|
||||
'plugin()->traffic_month(strtotime("last month"),TRUE,1000)'=>'Last Month',
|
||||
'recur_schedule'=>'Billing',
|
||||
'price(TRUE,TRUE)'=>'Price',
|
||||
'account->accnum()'=>'Cust ID',
|
||||
|
Reference in New Issue
Block a user