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

@ -93,7 +93,7 @@ class Controller_Reseller_Welcome extends Controller_Welcome {
'date_payment'=>'Pay Date', 'date_payment'=>'Pay Date',
'account->accnum()'=>'Num', 'account->accnum()'=>'Num',
'account->name()'=>'Account', 'account->name()'=>'Account',
'account->display("status")'=>'Active', 'account->status(TRUE)'=>'Active',
'total(TRUE)'=>'Total', 'total(TRUE)'=>'Total',
'balance(TRUE)'=>'Balance', 'balance(TRUE)'=>'Balance',
)) ))

View File

@ -25,7 +25,7 @@ return array
), ),
'invoice'=>0, // Number of invoices to generate in a pass 'invoice'=>0, // Number of invoices to generate in a pass
'site'=>FALSE, // Glogal site debug 'site'=>FALSE, // Glogal site debug
'show_errors'=>TRUE, // Show errors instead of logging in the DB. 'show_errors'=>FALSE, // Show errors instead of logging in the DB.
'show_inactive'=>FALSE, // Show Inactive Items 'show_inactive'=>FALSE, // Show Inactive Items
'task_sim'=>FALSE, // Simulate running tasks 'task_sim'=>FALSE, // Simulate running tasks
); );

View File

@ -0,0 +1,60 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Admin ADSL Service 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_Service_Adsl extends Controller_Service {
protected $secure_actions = array(
'stat'=>TRUE,
);
public function action_stat() {
// @todo This needs to be configurable.
$traffic = array(1000,2000,5000,10000,25000,50000,75000,100000);
$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()->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]++;
}
Block::factory()
->title('ADSL Traffic Summary Stats - Last Month')
->title_icon('icon-list')
->body(
View::factory('service/admin/adslstat')
->set('stats',$stats)
->set('traffic',$traffic)
->set('ts',$ts)
);
}
}
?>

View File

@ -0,0 +1,35 @@
<table class="table table-striped table-condensed table-hover">
<thead>
<tr>
<th>Speed</th>
<th>#</th>
<th><small>%</small></th>
<?php foreach ($traffic as $i) : ?>
<th><?php echo $i; ?></th>
<th><small>%</small></th>
<?php endforeach ?>
<th>Other</th>
<th><small>%</small></th>
</tr>
</thead>
<tbody>
<?php foreach ($stats as $speed => $details) : ?>
<tr>
<td><?php echo $speed; ?></td>
<td><?php echo $details['c']; ?></td>
<td><small><?php printf('%2.1f',$details['c']/$ts*100); ?></small></td>
<?php foreach ($traffic as $i) : ?>
<td><?php echo $c=isset($details['d'][$i]) ? $details['d'][$i] : 0; ?></td>
<td><small><?php printf('%2.1f',$c/$details['c']*100); ?></small></td>
<?php endforeach ?>
<td><?php echo $c=isset($details['d'][0]) ? $details['d'][0] : 0; ?></td>
<td><small><?php printf('%2.1f',$c/$details['c']*100); ?></small></td>
</tr>
<?php endforeach ?>
</tbody>
</table>

View File

@ -1 +0,0 @@
<td><?php echo $count; ?></td><td><?php echo $percent; ?></td>

View File

@ -1,4 +0,0 @@
<tr class="list-data">
<td><?php echo $speed; ?></td>
<td><?php echo $count; ?></td>
<td><?php echo $percent; ?></td>

View File

@ -1 +0,0 @@
</table>

View File

@ -1,3 +0,0 @@
<table class="list-box-left">
<tr class="list-head">
<th><?php echo $name; ?></th>

View File

@ -1 +0,0 @@
<th><?php echo $name; ?></th><th>%</th>

View File

@ -222,7 +222,7 @@ class Model_Payment extends ORM_OSB {
$sql = 'SELECT A.id as id, A.total_amt, ROUND(SUM(IF(IFNULL(B.alloc_amt,0)<0,IFNULL(B.alloc_amt,0)*-1,IFNULL(B.alloc_amt,0))),2) as ALLOC'; $sql = 'SELECT A.id as id, A.total_amt, ROUND(SUM(IF(IFNULL(B.alloc_amt,0)<0,IFNULL(B.alloc_amt,0)*-1,IFNULL(B.alloc_amt,0))),2) as ALLOC';
$sql .= ' FROM :prefix_payment A '; $sql .= ' FROM :prefix_payment A ';
$sql .= ' RIGHT JOIN :prefix_payment_item B ON (A.site_id=B.site_id AND A.id=B.payment_id)'; $sql .= ' LEFT JOIN :prefix_payment_item B ON (A.site_id=B.site_id AND A.id=B.payment_id)';
$sql .= ' WHERE A.site_id=:site_id'; $sql .= ' WHERE A.site_id=:site_id';
$sql .= ' GROUP BY A.id'; $sql .= ' GROUP BY A.id';
$sql .= ' HAVING round(A.total_amt-ALLOC,2) <> 0'; $sql .= ' HAVING round(A.total_amt-ALLOC,2) <> 0';

View File

@ -11,93 +11,13 @@
*/ */
class Controller_Admin_Service extends Controller_Service { class Controller_Admin_Service extends Controller_Service {
protected $secure_actions = array( protected $secure_actions = array(
'ajaxjson_traffic'=>TRUE,
'adslstat'=>TRUE,
'listexpiring'=>TRUE,
'listdomainservicesbysupplier'=>TRUE, 'listdomainservicesbysupplier'=>TRUE,
'listdomainservicesbydnshost'=>TRUE, 'listdomainservicesbydnshost'=>TRUE,
'listhostservicesbysupplier'=>TRUE, 'listhostservicesbysupplier'=>TRUE,
'listwebservices'=>TRUE,
'listinvoicesoon'=>TRUE,
'update'=>TRUE, 'update'=>TRUE,
'view'=>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() { public function action_listdomainservicesbysupplier() {
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN'); $svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
Sort::MAsort($svs,'plugin()->domain_registrar_id,name()'); 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() { public function action_update() {
$id = $this->request->param('id'); $id = $this->request->param('id');
$so = ORM::factory('Service',$id); $so = ORM::factory('Service',$id);
@ -382,75 +248,5 @@ class Controller_Admin_Service extends Controller_Service {
'body'=>$output, '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( protected $secure_actions = array(
'list'=>TRUE, 'list'=>TRUE,
'listbycheckout'=>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 // @todo This needs to be configurable
$go = ORM::factory('Group',array('name'=>'Personal')); $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))) if ($ao->has_any('group',array($go)))
foreach ($ao->service->list_active() as $so) foreach ($ao->service->list_active() as $so)
if (! $so->service_billing->checkout_id) 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/')),
))
);
}
} }
?> ?>

View File

@ -0,0 +1,41 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Reseller SSL Service functions
*
* @package SSL
* @category Controllers/Reseller
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Reseller_Service_Ssl extends Controller_Service {
protected $secure_actions = array(
'list'=>TRUE,
);
public function action_list() {
Block::factory()
->title('SSL Services')
->title_icon('icon-th-list')
->body(Table::factory()
->jssort('host')
->data(ORM::factory('Service')->where_authorised($this->ao)->list_byplugin('SSL'))
->columns(array(
'id'=>'ID',
'name()'=>'Service',
'plugin()->expire(TRUE)'=>'Expire',
'recur_schedule'=>'Billing',
'price(TRUE,TRUE)'=>'Price',
'account->accnum()'=>'Cust ID',
'account->name()'=>'Customer',
'date_next_invoice'=>'Next Invoice',
'due(TRUE)'=>'Due Invoices',
))
->prepend(array(
'id'=>array('url'=>URL::link('user','service/view/')),
))
);
}
}
?>

View File

@ -68,8 +68,8 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
return $this; return $this;
} }
public function expire() { public function expire($format=FALSE) {
return $this->_so->get_valid_to(); return $this->_so->get_valid_to($format);
} }
public function name() { public function name() {