This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Deon George 130a87aa9a Major work to domain and hosting
Minor updates for ADSL services
Updates to Sort::MAsort()
Move core OSB items under application/
Moved ACCOUNT functions under application
Minor updates to task
2012-01-12 19:53:55 +11:00

276 lines
8.8 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Affiliate Service functions
*
* @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,
'listdomainservices'=>TRUE,
'listhostservices'=>TRUE,
'listhspaservices'=>TRUE,
);
/**
* Show a list of services
*/
public function action_list() {
Block::add(array(
'title'=>_('Customer Services'),
'body'=>Table::display(
$this->filter(ORM::factory('service')->list_active(),$this->ao->affiliate->id),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/service/view',
)),
));
}
/**
* List all services by their default checkout method
*/
public function action_listbycheckout() {
// @todo need to add the DB prefix here
// @todo need to remove the explicit references to the group_id
// @todo need to restrict this to affiliate services
$services = DB::query(Database::SELECT,'
SELECT c.id AS cid,c.name as checkout_plugin_name,s.id AS sid,a.company,a.first_name,a.last_name,a.id as aid
FROM ab_service s LEFT JOIN ab_account_billing ab ON (s.account_billing_id=ab.id) LEFT JOIN ab_checkout c ON (ab.checkout_plugin_id=c.id),ab_account a, ab_account_group ag
WHERE s.active=1 AND s.price > 0 AND s.account_id=a.id AND a.id=ag.account_id AND ((s.account_billing_id IS NOT NULL AND ag.group_id!=2 ) OR (a.id=ag.account_id and ag.group_id=1003))
ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
')
->execute();
// @todo If no items, show a nice message. This is not correct for ORM.
if (! count($services)) {
echo Kohana::debug('No services with account_billing');
die();
}
$last_checkout = '';
$last_account = '';
$i = 0;
$sc = $st = 0;
$output = '<table class="box-left">';
foreach ($services as $service) {
$so = ORM::factory('service',$service['sid']);
$si = $so->account_id.$so->recur_schedule;
if (($si != $last_account) AND $last_account) {
if ($sc > 1)
$output .= View::factory('service/admin/list/bycheckout_subtotal')
->set('subtotal',Currency::display($st))
->set('i',$i++%2);
$sc = $st = 0;
}
if (($service['cid'] != $last_checkout) OR (! is_null($last_checkout) AND ! $last_checkout)) {
$output .= View::factory('service/admin/list/bycheckout_header')
->set('checkout_name',$service['checkout_plugin_name'])
->set('last_checkout',$last_checkout);
}
$last_checkout = $service['cid'];
$last_account = $si;
// @todo This rounding should be a system default
$st += round($so->price+$so->tax(),2);
$sc++;
$output .= View::factory('service/admin/list/bycheckout_body')
->set('service',$so)
->set('i',$i++%2);
}
// Last subtotal
if ($sc > 1)
$output .= View::factory('service/admin/list/bycheckout_subtotal')
->set('subtotal',$st)
->set('i',$i++%2);
$output .= '</table>';
Block::add(array(
'title'=>_('List all Services by Default Payment Method'),
'body'=>$output,
));
Style::add(array(
'type'=>'file',
'data'=>'css/list.css',
));
}
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;
}
public function action_listadslservices() {
$svs = $this->filter(ORM::factory('service')->list_bylistgroup('ADSL'),$this->ao->affiliate->id,'name()');
$data = $this->consoltraffic($svs,time());
$google = GoogleChart::factory('vertical_bar');
$google->title = sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday')));
$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));
Block::add(array(
'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'),
'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'),
'price'=>array('label'=>'Price','class'=>'right'),
'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',
)),
));
}
public function action_listhspaservices() {
$svs = $this->filter(ORM::factory('service')->list_bylistgroup('HSPA'),$this->ao->affiliate->id,'name()');
$data = $this->consoltraffic($svs,time());
$google = GoogleChart::factory('vertical_bar');
$google->title = sprintf('HSPA traffic as at %s',date('Y-m-d',strtotime('yesterday')));
$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));
Block::add(array(
'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'),
'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'),
'price'=>array('label'=>'Price','class'=>'right'),
'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',
)),
));
}
public function action_listdomainservices() {
Block::add(array(
'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'),
'price'=>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'=>'user/service/view',
)),
));
}
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'),
'price'=>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'=>'user/service/view',
)),
));
}
}
?>