Work on Service Reports

This commit is contained in:
Deon George
2013-10-11 00:08:02 +11:00
parent 91980b891e
commit 6f855fb32d
18 changed files with 198 additions and 225 deletions

View File

@@ -11,93 +11,13 @@
*/
class Controller_Admin_Service extends Controller_Service {
protected $secure_actions = array(
'ajaxjson_traffic'=>TRUE,
'adslstat'=>TRUE,
'listexpiring'=>TRUE,
'listdomainservicesbysupplier'=>TRUE,
'listdomainservicesbydnshost'=>TRUE,
'listhostservicesbysupplier'=>TRUE,
'listwebservices'=>TRUE,
'listinvoicesoon'=>TRUE,
'update'=>TRUE,
'view'=>TRUE,
);
public function action_ajaxjson_traffic() {
$result = array();
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
$data = $this->consoltraffic($svs,time());
$google = GoogleChart::factory('ComboChart')
->stacked(TRUE);
foreach ($data['data'] as $key => $values)
$google->sdata(array('yl'=>$key),array($key=>$values));
$google->sdata(array('yr'=>'services'),array('services'=>$data['svs']));
$this->response->headers('Content-Type','application/json');
$this->response->body($google->json());
}
private function consoltraffic($svs,$date) {
$data = 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;
$c[$month] = 1;
}
if (isset($data['data'][$metric][$month]))
$data['data'][$metric][$month] += (int)$traffic;
else
$data['data'][$metric][$month] = (int)$traffic;
}
}
}
ksort($data['svs']);
foreach ($data['data'] as $metric => $details)
ksort($data['data'][$metric]);
return $data;
}
/**
* Show a list of services that are expiring or have expired
*/
public function action_listexpiring() {
$svs = ORM::factory('Service')->list_expiring();
Sort::MAsort($svs,'expire()');
Block::add(array(
'title'=>_('ADSL Services'),
'body'=>Table::display(
$svs,
50,
array(
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
'service_name()'=>array('label'=>'Service'),
'expire(TRUE)'=>array('label'=>'Expires'),
'due(TRUE)'=>array('label'=>'Due'),
),
array(
'type'=>'select',
'form'=>URL::link('user','service/view'),
)),
));
}
public function action_listdomainservicesbysupplier() {
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
Sort::MAsort($svs,'plugin()->domain_registrar_id,name()');
@@ -194,60 +114,6 @@ class Controller_Admin_Service extends Controller_Service {
));
}
public function action_listwebservices() {
$svs = ORM::factory('Service')->list_bylistgroup('WEB');
Sort::MAsort($svs,'name()');
Block::add(array(
'title'=>_('SSL Services'),
'body'=>Table::display(
$svs,
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>URL::link('user','service/view'),
)),
));
}
/**
* List services that need to be invoiced.
*/
public function action_listinvoicesoon() {
Block::add(array(
'title'=>_('Services to Invoice'),
'body'=>Table::display(
ORM::factory('Service')->list_invoicesoon(ORM::factory('Invoice')->config('GEN_SOON_DAYS')),
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'date_next_invoice'=>array('label'=>'Next Invoice'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'charges()'=>array('label'=>'Charges','class'=>'right'),
'status'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>URL::link('user','service/view'),
)),
));
}
public function action_update() {
$id = $this->request->param('id');
$so = ORM::factory('Service',$id);
@@ -382,75 +248,5 @@ class Controller_Admin_Service extends Controller_Service {
'body'=>$output,
));
}
public function action_adslstat() {
$output = '';
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
$stats = array();
// @todo This needs to be configurable.
$traffic = array(1000,2000,5000,10000,25000,50000,75000,100000);
$ts = 0;
foreach ($svs as $a=>$so) {
// Number of services
if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['c']))
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'] = 0;
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['c']++;
$ts++;
// Amount of traffic
$t = array_sum($so->plugin()->traffic_lastmonth(FALSE));
$a = 0;
foreach (array_reverse($traffic) as $i) {
if ($i < $t)
break;
$a = $i;
}
if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a]))
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a] = 0;
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a]++;
}
if (count($stats)) {
$output .= View::factory($this->viewpath().'/head')
->set('name','SPEED');
$output .= View::factory($this->viewpath().'/head_data')
->set('name','#');
foreach ($traffic as $i)
$output .= View::factory($this->viewpath().'/head_data')
->set('name',$i);
$output .= View::factory($this->viewpath().'/head_data')
->set('name','Other');
$output .= View::factory($this->viewpath().'/head_end');
foreach ($stats as $speed => $details) {
$output .= View::factory($this->viewpath().'/body_head')
->set('count',$details['c'])
->set('percent',sprintf('%2.1f',$details['c']/$ts*100))
->set('speed',$speed);
foreach ($traffic as $i) {
$output .= View::factory($this->viewpath().'/body_data')
->set('count',$c=isset($details['d'][$i]) ? $details['d'][$i] : 0)
->set('percent',sprintf('%2.1f',$c/$details['c']*100));
}
$output .= View::factory($this->viewpath().'/body_data')
->set('count',$c=isset($details['d'][0]) ? $details['d'][0] : 0)
->set('percent',sprintf('%2.1f',$c/$details['c']*100));
$output .= View::factory($this->viewpath().'/body_end');
}
$output .= View::factory($this->viewpath().'/foot');
}
Block::add(array(
'title'=>_('ADSL Traffic Summary Stats - Last Month'),
'body'=>$output,
));
}
}
?>

View File

@@ -13,7 +13,8 @@ class Controller_Reseller_Service extends Controller_Service {
protected $secure_actions = array(
'list'=>TRUE,
'listbycheckout'=>TRUE,
'listhostservices'=>TRUE,
'listexpiring'=>TRUE,
'listinvoicesoon'=>TRUE,
);
/**
@@ -49,7 +50,7 @@ class Controller_Reseller_Service extends Controller_Service {
// @todo This needs to be configurable
$go = ORM::factory('Group',array('name'=>'Personal'));
foreach (ORM::factory('Account')->where_active()->where_authoised($this->ao,'id')->find_all() as $ao)
foreach (ORM::factory('Account')->where_active()->where_authorised($this->ao,'id')->find_all() as $ao)
if ($ao->has_any('group',array($go)))
foreach ($ao->service->list_active() as $so)
if (! $so->service_billing->checkout_id)
@@ -108,5 +109,57 @@ class Controller_Reseller_Service extends Controller_Service {
);
}
}
/**
* Show a list of expring services
*/
public function action_listexpiring() {
Block::factory()
->title('Customer Services Expiring')
->title_icon('icon-th-list')
->body(Table::factory()
->jssort('services')
->data(ORM::factory('Service')->where_authorised($this->ao)->list_expiring())
->columns(array(
'id'=>'ID',
'expire(TRUE)'=>'Expiry',
'service_name()'=>'Service',
'recur_schedule'=>'Billing',
'price(TRUE,TRUE)'=>'Price',
'account->accnum()'=>'Cust ID',
'account->name()'=>'Customer',
))
->prepend(array(
'id'=>array('url'=>URL::link('user','service/view/')),
))
);
}
/**
* Show a list of expring services
*/
public function action_listinvoicesoon() {
Block::factory()
->title('Customer Services soon to be Invoiced')
->title_icon('icon-th-list')
->body(Table::factory()
->jssort('services')
->data(ORM::factory('Service')->where_authorised($this->ao)->list_invoicesoon(ORM::factory('Invoice')->config('GEN_SOON_DAYS')+30))
->columns(array(
'id'=>'ID',
'expire(TRUE)'=>'Expiry',
'service_name()'=>'Service',
'recur_schedule'=>'Billing',
'price(TRUE,TRUE)'=>'Price',
'charges(TRUE,TRUE)'=>'Charges',
'account->accnum()'=>'Cust ID',
'account->name()'=>'Customer',
'date_next_invoice'=>'Next Invoice',
))
->prepend(array(
'id'=>array('url'=>URL::link('user','service/view/')),
))
);
}
}
?>