2011-09-26 10:12:54 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
2011-09-28 06:46:22 +00:00
|
|
|
* This class provides Affiliate Service functions
|
2011-09-26 10:12:54 +00:00
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage Service
|
|
|
|
* @category Controllers/Affiliate
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate {
|
|
|
|
protected $secure_actions = array(
|
|
|
|
'list'=>TRUE,
|
|
|
|
'listbycheckout'=>TRUE,
|
|
|
|
'listadslservices'=>TRUE,
|
2011-09-28 06:46:22 +00:00
|
|
|
'listdomainservices'=>TRUE,
|
|
|
|
'listhostservices'=>TRUE,
|
2011-09-26 10:12:54 +00:00
|
|
|
'listhspaservices'=>TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a list of services
|
|
|
|
*/
|
|
|
|
public function action_list() {
|
|
|
|
Block::add(array(
|
2011-09-28 06:46:22 +00:00
|
|
|
'title'=>_('Customer Services'),
|
2011-09-26 10:12:54 +00:00
|
|
|
'body'=>Table::display(
|
2011-09-28 06:46:22 +00:00
|
|
|
$this->filter(ORM::factory('service')->list_active(),$this->ao->affiliate->id),
|
2011-09-26 10:12:54 +00:00
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
2011-09-28 06:46:22 +00:00
|
|
|
'service_name()'=>array('label'=>'Details'),
|
2011-09-26 10:12:54 +00:00
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2012-08-01 12:43:33 +00:00
|
|
|
'status'=>array('label'=>'Active'),
|
2011-09-26 10:12:54 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2011-09-28 06:46:22 +00:00
|
|
|
'form'=>'user/service/view',
|
2011-09-26 10:12:54 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List all services by their default checkout method
|
|
|
|
*/
|
|
|
|
public function action_listbycheckout() {
|
2011-10-14 05:44:12 +00:00
|
|
|
$svs = array();
|
|
|
|
// @todo This needs to be configurable
|
|
|
|
$go = ORM::factory('group',array('name'=>'Personal'));
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2012-10-07 04:15:34 +00:00
|
|
|
foreach (ORM::factory('account')->list_active() as $ao)
|
2011-10-14 05:44:12 +00:00
|
|
|
if ($ao->has_any('group',array($go)))
|
|
|
|
foreach ($this->filter($ao->service->list_active(),$this->ao->affiliate->id,'name()') as $so)
|
|
|
|
if (! $so->service_billing->checkout_plugin_id)
|
|
|
|
array_push($svs,$so);
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
if ($svs)
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>'Services that should be auto-billed',
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2012-08-01 12:43:33 +00:00
|
|
|
'status'=>array('label'=>'Active'),
|
2011-10-14 05:44:12 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
|
|
|
'account->invoices_due_total(NULL,TRUE)'=>array('label'=>'Due Invoices'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>'user/service/view',
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
else
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>'Services that should be auto-billed',
|
|
|
|
'body'=>_('None found'),
|
|
|
|
));
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2012-08-01 12:43:33 +00:00
|
|
|
foreach (ORM::factory('checkout')->list_active() as $co) {
|
2011-10-14 05:44:12 +00:00
|
|
|
$svs = array();
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
foreach ($co->account->find_all() as $ao)
|
|
|
|
foreach ($this->filter($ao->service->list_active(),$this->ao->affiliate->id,'name()') as $so)
|
|
|
|
if ($so->service_billing->checkout_plugin_id == $co->id)
|
|
|
|
array_push($svs,$so);
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
if ($svs)
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>$co->name,
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2012-08-01 12:43:33 +00:00
|
|
|
'status'=>array('label'=>'Active'),
|
2011-10-14 05:44:12 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
|
|
|
'account->invoices_due_total(NULL,TRUE)'=>array('label'=>'Due Invoices'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>'user/service/view',
|
|
|
|
)),
|
|
|
|
));
|
2011-09-26 10:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-09-26 10:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
ksort($data['svs']);
|
|
|
|
foreach ($data['data'] as $metric => $details)
|
|
|
|
ksort($data['data'][$metric]);
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
return $data;
|
|
|
|
}
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
public function action_listadslservices() {
|
|
|
|
$svs = $this->filter(ORM::factory('service')->list_bylistgroup('ADSL'),$this->ao->affiliate->id,'name()');
|
|
|
|
$data = $this->consoltraffic($svs,time());
|
2011-09-26 10:12:54 +00:00
|
|
|
|
|
|
|
$google = GoogleChart::factory('vertical_bar');
|
|
|
|
$google->title = sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday')));
|
2011-09-28 06:46:22 +00:00
|
|
|
$google->series(array('title'=>array_keys($data['data']),'axis'=>'x','data'=>$data['data']));
|
|
|
|
$google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$data['svs'])));
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
Block::add(array('body'=>$google));
|
2011-09-26 10:12:54 +00:00
|
|
|
|
|
|
|
Block::add(array(
|
2011-09-28 06:46:22 +00:00
|
|
|
'title'=>_('ADSL Services'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
|
|
|
NULL,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
|
|
|
'name()'=>array('label'=>'Service'),
|
|
|
|
'plugin()->ipaddress()'=>array('label'=>'IP Address'),
|
2011-10-12 22:20:08 +00:00
|
|
|
'product->plugin()->speed'=>array('label'=>'Speed'),
|
2011-09-28 06:46:22 +00:00
|
|
|
'product->plugin()->allowance()'=>array('label'=>'Allowance'),
|
|
|
|
'plugin()->traffic_thismonth()'=>array('label'=>'This Month'),
|
|
|
|
'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2011-09-28 06:46:22 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>'user/service/view',
|
|
|
|
)),
|
2011-09-26 10:12:54 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_listhspaservices() {
|
2011-09-28 06:46:22 +00:00
|
|
|
$svs = $this->filter(ORM::factory('service')->list_bylistgroup('HSPA'),$this->ao->affiliate->id,'name()');
|
|
|
|
$data = $this->consoltraffic($svs,time());
|
2011-09-26 10:12:54 +00:00
|
|
|
|
|
|
|
$google = GoogleChart::factory('vertical_bar');
|
|
|
|
$google->title = sprintf('HSPA traffic as at %s',date('Y-m-d',strtotime('yesterday')));
|
2011-09-28 06:46:22 +00:00
|
|
|
$google->series(array('title'=>array_keys($data['data']),'axis'=>'x','data'=>$data['data']));
|
|
|
|
$google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$data['svs'])));
|
|
|
|
|
|
|
|
Block::add(array('body'=>$google));
|
2011-09-26 10:12:54 +00:00
|
|
|
|
|
|
|
Block::add(array(
|
2011-09-28 06:46:22 +00:00
|
|
|
'title'=>_('HSPA Services'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
|
|
|
NULL,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
|
|
|
'name()'=>array('label'=>'Service'),
|
|
|
|
'plugin()->ipaddress()'=>array('label'=>'IP Address'),
|
2011-10-12 22:20:08 +00:00
|
|
|
'product->plugin()->speed'=>array('label'=>'Speed'),
|
2011-09-28 06:46:22 +00:00
|
|
|
'product->plugin()->allowance()'=>array('label'=>'Allowance'),
|
|
|
|
'plugin()->traffic_thismonth()'=>array('label'=>'This Month'),
|
|
|
|
'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2011-09-28 06:46:22 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>'user/service/view',
|
|
|
|
)),
|
2011-09-26 10:12:54 +00:00
|
|
|
));
|
2011-09-28 06:46:22 +00:00
|
|
|
}
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
public function action_listdomainservices() {
|
2011-09-26 10:12:54 +00:00
|
|
|
Block::add(array(
|
2011-09-28 06:46:22 +00:00
|
|
|
'title'=>_('Domain Names'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$this->filter(ORM::factory('service')->list_bylistgroup('DOMAIN'),$this->ao->affiliate->id,'name()'),
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'plugin()->display("domain_expire")'=>array('label'=>'Expire'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2011-09-28 06:46:22 +00:00
|
|
|
'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'=>'user/service/view',
|
|
|
|
)),
|
2011-09-26 10:12:54 +00:00
|
|
|
));
|
2011-09-28 06:46:22 +00:00
|
|
|
}
|
2011-09-26 10:12:54 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
public function action_listhostservices() {
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Hosting Services'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$this->filter(ORM::factory('service')->list_bylistgroup('HOST'),$this->ao->affiliate->id,'name()'),
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'plugin()->display("host_expire")'=>array('label'=>'Expire'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2011-09-28 06:46:22 +00:00
|
|
|
'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'=>'user/service/view',
|
|
|
|
)),
|
|
|
|
));
|
2011-09-26 10:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|