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
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides OSB service admin capabilities.
|
||||
* This class provides Admin Service functions
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
@@ -11,13 +11,13 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
|
||||
protected $control = array('Services'=>'services');
|
||||
|
||||
protected $secure_actions = array(
|
||||
'list'=>TRUE,
|
||||
'listbycheckout'=>TRUE,
|
||||
'listadslbilling'=>TRUE,
|
||||
'listadslservices'=>TRUE,
|
||||
'listdomainservices'=>TRUE,
|
||||
'listhostservices'=>TRUE,
|
||||
'listhspaservices'=>TRUE,
|
||||
'update'=>TRUE,
|
||||
);
|
||||
@@ -26,17 +26,14 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
|
||||
* Show a list of services
|
||||
*/
|
||||
public function action_list() {
|
||||
$so = ORM::factory('service');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('System Customer Services'),
|
||||
'title'=>_('Customer Services'),
|
||||
'body'=>Table::display(
|
||||
$so->find_all(),
|
||||
ORM::factory('service')->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
||||
'type'=>array('label'=>'Type'),
|
||||
'name()'=>array('label'=>'Details'),
|
||||
'service_name()'=>array('label'=>'Details'),
|
||||
'recur_schedule'=>array('label'=>'Billing'),
|
||||
'price'=>array('label'=>'Price','class'=>'right'),
|
||||
'active'=>array('label'=>'Active'),
|
||||
@@ -46,7 +43,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>'user/email/view',
|
||||
'form'=>'user/service/view',
|
||||
)),
|
||||
));
|
||||
}
|
||||
@@ -124,181 +121,163 @@ ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
|
||||
));
|
||||
}
|
||||
|
||||
//@todo this should really be in a different class, since adsl wont be part of the main app
|
||||
public function action_listadslservices() {
|
||||
// @todo need to add the DB prefix here
|
||||
$services = DB::query(Database::SELECT,'
|
||||
SELECT A.service_id
|
||||
FROM ab_service__adsl A,ab_service B,ab_account C,ab_service D,ab_product E
|
||||
WHERE B.active=1 AND A.service_id=B.id AND A.site_id=B.site_id
|
||||
AND B.account_id=C.id AND B.site_id=C.site_id
|
||||
AND A.service_id=D.id AND A.site_id=D.site_id
|
||||
AND D.product_id=E.id AND D.site_id=E.site_id
|
||||
AND E.sku like "%ADSL%"
|
||||
ORDER BY C.last_name,B.account_id,A.service_number
|
||||
')
|
||||
->execute();
|
||||
private function consoltraffic($svs,$date) {
|
||||
$data = array();
|
||||
|
||||
// @todo If no items, show a nice message. This is not correct for ORM.
|
||||
if (! count($services)) {
|
||||
echo Kohana::debug('No services for ADSL');
|
||||
die();
|
||||
}
|
||||
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;
|
||||
|
||||
$last_account = '';
|
||||
$i = 0;
|
||||
$output = '<table class="box-left">';
|
||||
foreach ($services as $service) {
|
||||
$so = ORM::factory('service',$service['service_id']);
|
||||
$c[$month] = 1;
|
||||
}
|
||||
|
||||
if ($last_account != $so->account_id) {
|
||||
if ($i)
|
||||
$output .= '<tr><td colspan="10"> </td></tr>';
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_header')
|
||||
->set('service',$so);
|
||||
|
||||
$last_account = $so->account_id;
|
||||
if (isset($data['data'][$metric][$month]))
|
||||
$data['data'][$metric][$month] += (int)$traffic;
|
||||
else
|
||||
$data['data'][$metric][$month] = (int)$traffic;
|
||||
}
|
||||
}
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_body')
|
||||
->set('service',$so)
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
$output .= '</table>';
|
||||
|
||||
// Chart the traffic for the last 12 months.
|
||||
// @todo need to add the DB prefix here
|
||||
$traffic = DB::query(Database::SELECT,sprintf('
|
||||
SELECT DATE_FORMAT(DATE,"%%y-%%m") AS MONTH,SID,MAX(NUM) AS NUM,SUM(DOWN_PEAK) AS DOWN_PEAK,SUM(IFNULL(DOWN_OFFPEAK,0)+IFNULL(PEER,0)+IFNULL(INTERNAL,0)) AS DOWN_OFFPEAK
|
||||
FROM ab_view_traffic_adsl_daily
|
||||
WHERE SID in (%s) AND DATE>"%s"
|
||||
GROUP BY DATE_FORMAT(DATE,"%%Y-%%m"),SID
|
||||
','1,2',date('Y-m',time()-365*86400)))
|
||||
->execute();
|
||||
ksort($data['svs']);
|
||||
foreach ($data['data'] as $metric => $details)
|
||||
ksort($data['data'][$metric]);
|
||||
|
||||
$peak = $offpeak = $services = array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ($traffic as $a => $v) {
|
||||
$peak[$v['SID']]['Peak'][$v['MONTH']] = $v['DOWN_PEAK'];
|
||||
$peak[$v['SID']]['OffPeak'][$v['MONTH']] = $v['DOWN_OFFPEAK'];
|
||||
$peak[$v['SID']]['Services'][$v['MONTH']] = $v['NUM'];
|
||||
}
|
||||
public function action_listadslservices() {
|
||||
$svs = ORM::factory('service')->list_bylistgroup('ADSL');
|
||||
$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('Exetel-Peak','Exetel-Offpeak'),
|
||||
'axis'=>'x',
|
||||
'data'=>array('Exetel-Peak'=>$peak[1]['Peak'],'Exetel-OffPeak'=>$peak[1]['OffPeak'])));
|
||||
$google->series(array(
|
||||
'title'=>array('People-Peak','People-Offpeak'),
|
||||
'axis'=>'x',
|
||||
'data'=>array('People-Peak'=>$peak[2]['Peak'],'People-OffPeak'=>$peak[2]['OffPeak'])));
|
||||
$google->series(array(
|
||||
'title'=>'Exetel-Services',
|
||||
'axis'=>'r',
|
||||
'data'=>array('Exetel-Services'=>$peak[1]['Services'])));
|
||||
$google->series(array(
|
||||
'title'=>'People-Services',
|
||||
'axis'=>'r',
|
||||
'data'=>array('People-Services'=>$peak[2]['Services'])));
|
||||
$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(
|
||||
'body'=>$google,
|
||||
'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',
|
||||
)),
|
||||
));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('List all ADSL Services'),
|
||||
'body'=>$output,
|
||||
));
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
}
|
||||
|
||||
public function action_listhspaservices() {
|
||||
// @todo need to add the DB prefix here
|
||||
$services = DB::query(Database::SELECT,'
|
||||
SELECT A.service_id
|
||||
FROM ab_service__adsl A,ab_service B,ab_account C,ab_service D,ab_product E
|
||||
WHERE B.active=1 AND A.service_id=B.id AND A.site_id=B.site_id
|
||||
AND B.account_id=C.id AND B.site_id=C.site_id
|
||||
AND A.service_id=D.id AND A.site_id=D.site_id
|
||||
AND D.product_id=E.id AND D.site_id=E.site_id
|
||||
AND E.sku like "%HSPA%"
|
||||
ORDER BY C.last_name,B.account_id,A.service_number
|
||||
')
|
||||
->execute();
|
||||
|
||||
// @todo If no items, show a nice message. This is not correct for ORM.
|
||||
if (! count($services)) {
|
||||
echo Kohana::debug('No services for HSPA');
|
||||
die();
|
||||
}
|
||||
|
||||
$last_account = '';
|
||||
$i = 0;
|
||||
$output = '<table class="box-left">';
|
||||
foreach ($services as $service) {
|
||||
$so = ORM::factory('service',$service['service_id']);
|
||||
|
||||
if ($last_account != $so->account_id) {
|
||||
if ($i)
|
||||
$output .= '<tr><td colspan="10"> </td></tr>';
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_header')
|
||||
->set('service',$so);
|
||||
|
||||
$last_account = $so->account_id;
|
||||
}
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_body')
|
||||
->set('service',$so)
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
$output .= '</table>';
|
||||
|
||||
// Chart the traffic for the last 12 months.
|
||||
// @todo need to add the DB prefix here
|
||||
$traffic = DB::query(Database::SELECT,sprintf('
|
||||
SELECT DATE_FORMAT(DATE,"%%y-%%m") AS MONTH,SID,MAX(NUM) AS NUM,SUM(DOWN_PEAK)*1000 AS DOWN_PEAK,SUM(IFNULL(DOWN_OFFPEAK,0)+IFNULL(PEER,0)+IFNULL(INTERNAL,0))*1000 AS DOWN_OFFPEAK
|
||||
FROM ab_view_traffic_adsl_daily
|
||||
WHERE SID=%s AND DATE>"%s"
|
||||
GROUP BY DATE_FORMAT(DATE,"%%Y-%%m"),SID
|
||||
',3,date('Y-m',time()-365*86400)))
|
||||
->execute();
|
||||
|
||||
$peak = $offpeak = $services = array();
|
||||
|
||||
foreach ($traffic as $a => $v) {
|
||||
$peak['Peak'][$v['MONTH']] = $v['DOWN_PEAK'];
|
||||
$peak['OffPeak'][$v['MONTH']] = $v['DOWN_OFFPEAK'];
|
||||
$peak['Services'][$v['MONTH']] = $v['NUM'];
|
||||
}
|
||||
$svs = ORM::factory('service')->list_bylistgroup('HSPA');
|
||||
$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('Peak','Offpeak'),'axis'=>'x','data'=>array('Peak'=>$peak['Peak'],'OffPeak'=>$peak['OffPeak'])));
|
||||
$google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$peak['Services'])));
|
||||
$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(
|
||||
'body'=>$google,
|
||||
'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',
|
||||
)),
|
||||
));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('List all HSPA Services'),
|
||||
'body'=>$output,
|
||||
));
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
}
|
||||
|
||||
public function action_listdomainservices() {
|
||||
$svs = ORM::factory('service')->list_bylistgroup('DOMAIN');
|
||||
Sort::MAsort($svs,'name()');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Domain Names'),
|
||||
'body'=>Table::display(
|
||||
$svs,
|
||||
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() {
|
||||
$svs = ORM::factory('service')->list_bylistgroup('HOST');
|
||||
Sort::MAsort($svs,'name()');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Hosting Services'),
|
||||
'body'=>Table::display(
|
||||
$svs,
|
||||
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',
|
||||
)),
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Reconcile billing for an ADSL supplier
|
||||
*
|
||||
@@ -328,18 +307,24 @@ GROUP BY DATE_FORMAT(DATE,"%%Y-%%m"),SID
|
||||
$output = View::factory('service/admin/list/adslbilling_head');
|
||||
$output .= '<table class="box-left">';
|
||||
foreach ($aso->services(TRUE) as $so) {
|
||||
$po = $so->plugin()->product();
|
||||
|
||||
// Reset our uploaded data
|
||||
$uploaded = array();
|
||||
$uploaded['excess'] = empty($csv[$so->plugin()->service_number]['excess']) ? 0 : $csv[$so->plugin()->service_number]['excess'];
|
||||
|
||||
// If our uploaded file has some cost data.
|
||||
if (! empty($csv[$so->service_adsl->service_number])) {
|
||||
if (! empty($csv[$so->plugin()->service_number])) {
|
||||
$uploaded['amount'] =
|
||||
(empty($csv[$so->service_adsl->service_number]['cost']) ? 0 : $csv[$so->service_adsl->service_number]['cost']) +
|
||||
(empty($csv[$so->service_adsl->service_number]['credit']) ? 0 : $csv[$so->service_adsl->service_number]['credit']);
|
||||
(empty($csv[$so->plugin()->service_number]['cost']) ? 0 : $csv[$so->plugin()->service_number]['cost']) +
|
||||
(empty($csv[$so->plugin()->service_number]['credit']) ? 0 : $csv[$so->plugin()->service_number]['credit']);
|
||||
|
||||
// Record the the exception if the cost is not expected
|
||||
if (round($so->service_adsl->adsl_plan->adsl_supplier_plan->base_cost+$so->service_adsl->adsl_plan->adsl_supplier_plan->tax(),2) != $uploaded['amount']) {
|
||||
if (round($po->adsl_supplier_plan->base_cost+$po->adsl_supplier_plan->tax(),2) != $uploaded['amount']) {
|
||||
$summary .= View::factory('service/admin/list/adslbilling_summary')
|
||||
->set('service',$so)
|
||||
->set('plan',$po)
|
||||
->set('planoverride',$so->plugin()->provided_adsl_plan_id ? TRUE : FALSE)
|
||||
->set('amount',$uploaded['amount'])
|
||||
->set('i',$j++%2);
|
||||
|
||||
@@ -348,19 +333,23 @@ GROUP BY DATE_FORMAT(DATE,"%%Y-%%m"),SID
|
||||
$uploaded['checked'] = 'checked="checked"';
|
||||
}
|
||||
|
||||
unset($csv[$so->service_adsl->service_number]);
|
||||
unset($csv[$so->plugin()->service_number]);
|
||||
|
||||
} else {
|
||||
$uploaded['checked'] = '';
|
||||
$uploaded['amount'] = 0;
|
||||
}
|
||||
|
||||
$total += $uploaded['amount'];
|
||||
|
||||
$output .= View::factory('service/admin/list/adslbilling_body')
|
||||
->set('service',$so)
|
||||
->set('plan',$po)
|
||||
->set('planoverride',$so->plugin()->provided_adsl_plan_id ? TRUE : FALSE)
|
||||
->set('checked',$uploaded['checked'])
|
||||
->set('amount',$uploaded['amount'])
|
||||
->set('adsl',$so->service_adsl)
|
||||
->set('excess',$uploaded['excess'])
|
||||
->set('adsl',$so->plugin())
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
|
||||
@@ -435,7 +424,7 @@ GROUP BY DATE_FORMAT(DATE,"%%Y-%%m"),SID
|
||||
// If the description says VISP credit, we know this is commission.
|
||||
elseif (preg_match('/^VISP Credit/',$description))
|
||||
$return[$service]['credit'] = preg_replace('/\$/','',$total);
|
||||
// If the description says Excess, we know this is commission.
|
||||
// If the description says Excess, we know this is excess charges.
|
||||
elseif (preg_match('/^Excess usage/',$description))
|
||||
$return[$service]['excess'] = preg_replace('/\$/','',$total);
|
||||
else
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides OSB service affiliate capabilities.
|
||||
* This class provides Affiliate Service functions
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
@@ -11,12 +11,12 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate {
|
||||
protected $control = array('Services'=>'services');
|
||||
|
||||
protected $secure_actions = array(
|
||||
'list'=>TRUE,
|
||||
'listbycheckout'=>TRUE,
|
||||
'listadslservices'=>TRUE,
|
||||
'listdomainservices'=>TRUE,
|
||||
'listhostservices'=>TRUE,
|
||||
'listhspaservices'=>TRUE,
|
||||
);
|
||||
|
||||
@@ -24,17 +24,14 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
|
||||
* Show a list of services
|
||||
*/
|
||||
public function action_list() {
|
||||
$so = ORM::factory('service');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('System Customer Services'),
|
||||
'title'=>_('Customer Services'),
|
||||
'body'=>Table::display(
|
||||
$so->where('affiliate_id','=',$this->ao->affiliate->id)->find_all(),
|
||||
$this->filter(ORM::factory('service')->list_active(),$this->ao->affiliate->id),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
||||
'type'=>array('label'=>'Type'),
|
||||
'name()'=>array('label'=>'Details'),
|
||||
'service_name()'=>array('label'=>'Details'),
|
||||
'recur_schedule'=>array('label'=>'Billing'),
|
||||
'price'=>array('label'=>'Price','class'=>'right'),
|
||||
'active'=>array('label'=>'Active'),
|
||||
@@ -44,7 +41,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>'user/email/view',
|
||||
'form'=>'user/service/view',
|
||||
)),
|
||||
));
|
||||
}
|
||||
@@ -123,181 +120,156 @@ ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
|
||||
));
|
||||
}
|
||||
|
||||
//@todo this should really be in a different class, since adsl wont be part of the main app
|
||||
public function action_listadslservices() {
|
||||
// @todo need to add the DB prefix here
|
||||
// @todo need to restrict this to affiliate services
|
||||
$services = DB::query(Database::SELECT,'
|
||||
SELECT A.service_id
|
||||
FROM ab_service__adsl A,ab_service B,ab_account C,ab_service D,ab_product E
|
||||
WHERE B.active=1 AND A.service_id=B.id AND A.site_id=B.site_id
|
||||
AND B.account_id=C.id AND B.site_id=C.site_id
|
||||
AND A.service_id=D.id AND A.site_id=D.site_id
|
||||
AND D.product_id=E.id AND D.site_id=E.site_id
|
||||
AND E.sku like "%ADSL%"
|
||||
ORDER BY C.last_name,B.account_id,A.service_number
|
||||
')
|
||||
->execute();
|
||||
private function consoltraffic($svs,$date) {
|
||||
$data = array();
|
||||
|
||||
// @todo If no items, show a nice message. This is not correct for ORM.
|
||||
if (! count($services)) {
|
||||
echo Kohana::debug('No services for ADSL');
|
||||
die();
|
||||
}
|
||||
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;
|
||||
|
||||
$last_account = '';
|
||||
$i = 0;
|
||||
$output = '<table class="box-left">';
|
||||
foreach ($services as $service) {
|
||||
$so = ORM::factory('service',$service['service_id']);
|
||||
$c[$month] = 1;
|
||||
}
|
||||
|
||||
if ($last_account != $so->account_id) {
|
||||
if ($i)
|
||||
$output .= '<tr><td colspan="10"> </td></tr>';
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_header')
|
||||
->set('service',$so);
|
||||
|
||||
$last_account = $so->account_id;
|
||||
if (isset($data['data'][$metric][$month]))
|
||||
$data['data'][$metric][$month] += (int)$traffic;
|
||||
else
|
||||
$data['data'][$metric][$month] = (int)$traffic;
|
||||
}
|
||||
}
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_body')
|
||||
->set('service',$so)
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
$output .= '</table>';
|
||||
|
||||
// Chart the traffic for the last 12 months.
|
||||
// @todo need to add the DB prefix here
|
||||
$traffic = DB::query(Database::SELECT,sprintf('
|
||||
SELECT DATE_FORMAT(DATE,"%%y-%%m") AS MONTH,SID,MAX(NUM) AS NUM,SUM(DOWN_PEAK) AS DOWN_PEAK,SUM(IFNULL(DOWN_OFFPEAK,0)+IFNULL(PEER,0)+IFNULL(INTERNAL,0)) AS DOWN_OFFPEAK
|
||||
FROM ab_view_traffic_adsl_daily
|
||||
WHERE SID in (%s) AND DATE>"%s"
|
||||
GROUP BY DATE_FORMAT(DATE,"%%Y-%%m"),SID
|
||||
','1,2',date('Y-m',time()-365*86400)))
|
||||
->execute();
|
||||
ksort($data['svs']);
|
||||
foreach ($data['data'] as $metric => $details)
|
||||
ksort($data['data'][$metric]);
|
||||
|
||||
$peak = $offpeak = $services = array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ($traffic as $a => $v) {
|
||||
$peak[$v['SID']]['Peak'][$v['MONTH']] = $v['DOWN_PEAK'];
|
||||
$peak[$v['SID']]['OffPeak'][$v['MONTH']] = $v['DOWN_OFFPEAK'];
|
||||
$peak[$v['SID']]['Services'][$v['MONTH']] = $v['NUM'];
|
||||
}
|
||||
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('Exetel-Peak','Exetel-Offpeak'),
|
||||
'axis'=>'x',
|
||||
'data'=>array('Exetel-Peak'=>$peak[1]['Peak'],'Exetel-OffPeak'=>$peak[1]['OffPeak'])));
|
||||
$google->series(array(
|
||||
'title'=>array('People-Peak','People-Offpeak'),
|
||||
'axis'=>'x',
|
||||
'data'=>array('People-Peak'=>$peak[2]['Peak'],'People-OffPeak'=>$peak[2]['OffPeak'])));
|
||||
$google->series(array(
|
||||
'title'=>'Exetel-Services',
|
||||
'axis'=>'r',
|
||||
'data'=>array('Exetel-Services'=>$peak[1]['Services'])));
|
||||
$google->series(array(
|
||||
'title'=>'People-Services',
|
||||
'axis'=>'r',
|
||||
'data'=>array('People-Services'=>$peak[2]['Services'])));
|
||||
$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(
|
||||
'body'=>$google,
|
||||
'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',
|
||||
)),
|
||||
));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('List all ADSL Services'),
|
||||
'body'=>$output,
|
||||
));
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
}
|
||||
|
||||
public function action_listhspaservices() {
|
||||
// @todo need to add the DB prefix here
|
||||
// @todo need to restrict this to affiliate services
|
||||
$services = DB::query(Database::SELECT,'
|
||||
SELECT A.service_id
|
||||
FROM ab_service__adsl A,ab_service B,ab_account C,ab_service D,ab_product E
|
||||
WHERE B.active=1 AND A.service_id=B.id AND A.site_id=B.site_id
|
||||
AND B.account_id=C.id AND B.site_id=C.site_id
|
||||
AND A.service_id=D.id AND A.site_id=D.site_id
|
||||
AND D.product_id=E.id AND D.site_id=E.site_id
|
||||
AND E.sku like "%HSPA%"
|
||||
ORDER BY C.last_name,B.account_id,A.service_number
|
||||
')
|
||||
->execute();
|
||||
|
||||
// @todo If no items, show a nice message. This is not correct for ORM.
|
||||
if (! count($services)) {
|
||||
echo Kohana::debug('No services for HSPA');
|
||||
die();
|
||||
}
|
||||
|
||||
$last_account = '';
|
||||
$i = 0;
|
||||
$output = '<table class="box-left">';
|
||||
foreach ($services as $service) {
|
||||
$so = ORM::factory('service',$service['service_id']);
|
||||
|
||||
if ($last_account != $so->account_id) {
|
||||
if ($i)
|
||||
$output .= '<tr><td colspan="10"> </td></tr>';
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_header')
|
||||
->set('service',$so);
|
||||
|
||||
$last_account = $so->account_id;
|
||||
}
|
||||
|
||||
$output .= View::factory('service/admin/list/adslservices_body')
|
||||
->set('service',$so)
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
$output .= '</table>';
|
||||
|
||||
// Chart the traffic for the last 12 months.
|
||||
// @todo need to add the DB prefix here
|
||||
$traffic = DB::query(Database::SELECT,sprintf('
|
||||
SELECT DATE_FORMAT(DATE,"%%y-%%m") AS MONTH,SID,MAX(NUM) AS NUM,SUM(DOWN_PEAK)*1000 AS DOWN_PEAK,SUM(IFNULL(DOWN_OFFPEAK,0)+IFNULL(PEER,0)+IFNULL(INTERNAL,0))*1000 AS DOWN_OFFPEAK
|
||||
FROM ab_view_traffic_adsl_daily
|
||||
WHERE SID=%s AND DATE>"%s"
|
||||
GROUP BY DATE_FORMAT(DATE,"%%Y-%%m"),SID
|
||||
',3,date('Y-m',time()-365*86400)))
|
||||
->execute();
|
||||
|
||||
$peak = $offpeak = $services = array();
|
||||
|
||||
foreach ($traffic as $a => $v) {
|
||||
$peak['Peak'][$v['MONTH']] = $v['DOWN_PEAK'];
|
||||
$peak['OffPeak'][$v['MONTH']] = $v['DOWN_OFFPEAK'];
|
||||
$peak['Services'][$v['MONTH']] = $v['NUM'];
|
||||
}
|
||||
$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('Peak','Offpeak'),'axis'=>'x','data'=>array('Peak'=>$peak['Peak'],'OffPeak'=>$peak['OffPeak'])));
|
||||
$google->series(array('title'=>'Services','axis'=>'r','data'=>array('Services'=>$peak['Services'])));
|
||||
$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(
|
||||
'body'=>$google,
|
||||
'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'=>_('List all HSPA Services'),
|
||||
'body'=>$output,
|
||||
'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',
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
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',
|
||||
)),
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -7,8 +7,8 @@
|
||||
* @subpackage Service
|
||||
* @category Controllers/User
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_User_Service extends Controller_TemplateDefault_User {
|
||||
protected $secure_actions = array(
|
||||
@@ -27,8 +27,7 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
||||
'type'=>array('label'=>'Type'),
|
||||
'name()'=>array('label'=>'Details'),
|
||||
'service_name()'=>array('label'=>'Details'),
|
||||
'recur_schedule'=>array('label'=>'Billing'),
|
||||
'price'=>array('label'=>'Price','class'=>'right'),
|
||||
'active'=>array('label'=>'Active'),
|
||||
@@ -65,7 +64,7 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
|
||||
->set('so',$so);
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',$so->id(),$so->product->name()),
|
||||
'title'=>sprintf('%s: %s',$so->id(),$so->service_name()),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
|
@@ -15,10 +15,6 @@ class Model_Service extends ORMOSB {
|
||||
protected $_has_many = array(
|
||||
'invoice'=>array('through'=>'invoice_item'),
|
||||
);
|
||||
protected $_has_one = array(
|
||||
'service_adsl'=>array('far_key'=>'id'),
|
||||
'service_domain'=>array('far_key'=>'id'),
|
||||
);
|
||||
protected $_belongs_to = array(
|
||||
'product'=>array(),
|
||||
'account'=>array(),
|
||||
@@ -76,15 +72,14 @@ class Model_Service extends ORMOSB {
|
||||
/**
|
||||
* Return the object of the product plugin
|
||||
*/
|
||||
private function plugin() {
|
||||
public function plugin() {
|
||||
if (! $this->product->prod_plugin_file)
|
||||
return NULL;
|
||||
|
||||
if (! is_numeric($this->product->prod_plugin_data))
|
||||
throw new Kohana_Exception('Missing plugin_id for :product (:type)',array(':product'=>$this->product->id,':type'=>$this->product->prod_plugin_file));
|
||||
|
||||
$spn = sprintf('%s_%s',get_class($this),$this->product->prod_plugin_file);
|
||||
return new $spn(array('service_id'=>$this->id));
|
||||
return ORM::factory(sprintf('service_plugin_%s',$this->product->prod_plugin_file),array('service_id'=>$this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +93,15 @@ class Model_Service extends ORMOSB {
|
||||
* Display the service product name
|
||||
*/
|
||||
public function name() {
|
||||
return $this->product->name();
|
||||
return is_null($plugin=$this->plugin()) ? $this->product->name() : $plugin->name();
|
||||
}
|
||||
|
||||
public function service_name() {
|
||||
return is_null($plugin=$this->plugin()) ? $this->name() : $plugin->service_name();
|
||||
}
|
||||
|
||||
public function service_view() {
|
||||
return is_null($plugin=$this->plugin()) ? HTML::nbsp('') : $plugin->service_view();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,29 +111,12 @@ class Model_Service extends ORMOSB {
|
||||
return $this->product->feature_summary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the service details
|
||||
*/
|
||||
public function service_view() {
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return HTML::nbsp('');
|
||||
else
|
||||
return $plugin->_service_view();
|
||||
}
|
||||
|
||||
public function service_name() {
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return $this->name();
|
||||
else
|
||||
return $plugin->_service_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render some details for specific calls, eg: invoice
|
||||
*/
|
||||
public function details($type) {
|
||||
switch ($type) {
|
||||
case 'invoice':
|
||||
case 'invoice_detail_items':
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return array();
|
||||
else
|
||||
@@ -156,5 +142,26 @@ class Model_Service extends ORMOSB {
|
||||
public function tax() {
|
||||
return $this->price * .1;
|
||||
}
|
||||
|
||||
public function list_active() {
|
||||
return $this->where('active','=','1')->find_all();
|
||||
}
|
||||
|
||||
public function list_bylistgroup($cat) {
|
||||
$result = array();
|
||||
|
||||
$cats = ORM::factory('product_category')->list_bylistgroup($cat);
|
||||
|
||||
foreach ($this->list_active() as $so) {
|
||||
if (! $so->product->avail_category_id OR ! preg_match('/^a:/',$so->product->avail_category_id))
|
||||
continue;
|
||||
|
||||
$pc = unserialize($so->product->avail_category_id);
|
||||
if (array_intersect($pc,array_keys($cats)))
|
||||
array_push($result,$so);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,420 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Services
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Service_ADSL extends Model_Service {
|
||||
protected $_table_name = 'service__adsl';
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'adsl_plan'=>array('foreign_key'=>'adsl_plan_id'),
|
||||
'service'=>array(),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'service_connect_date'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Return the IP Address for the service
|
||||
*/
|
||||
public function ipaddress() {
|
||||
return $this->ipaddress ? $this->ipaddress : _('Dynamic');
|
||||
}
|
||||
|
||||
public function contract_date_start() {
|
||||
return Config::date($this->service_connect_date);
|
||||
}
|
||||
|
||||
public function contract_date_end() {
|
||||
return Config::date(strtotime(sprintf('+%s months',$this->contract_term),$this->service_connect_date));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will return the months that have traffic data.
|
||||
* This array can be used in a select list to display the traffic for that month
|
||||
*/
|
||||
public function get_traffic_months() {
|
||||
$keys = $months = array();
|
||||
|
||||
foreach ($this->get_traffic_data_monthly() as $metric => $data)
|
||||
$keys = array_unique(array_merge($keys,array_keys($data)));
|
||||
|
||||
foreach ($keys as $v)
|
||||
$months[$v] = $v;
|
||||
|
||||
arsort($months);
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the total traffic used in a month
|
||||
*/
|
||||
private function get_traffic_data_month($period=NULL) {
|
||||
$return = array();
|
||||
|
||||
foreach ($this->get_traffic_data_daily($period,TRUE) as $tdata)
|
||||
foreach ($tdata as $k => $v)
|
||||
if (isset($return[$k]))
|
||||
$return[$k] += $v;
|
||||
else
|
||||
$return[$k] = $v;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of the data used in a month by day
|
||||
*/
|
||||
public function get_traffic_data_daily($period=NULL,$bydate=FALSE) {
|
||||
$cacheable = TRUE;
|
||||
if (is_null($period))
|
||||
$period = strtotime('yesterday');
|
||||
|
||||
$cache = $this->service_id.date('M-Y',$period).$bydate;
|
||||
|
||||
// @todo This cache needs to be improved, so that we cache the query regardless of bydate setting
|
||||
if ($cacheable AND $return = Cache::instance(Config::cachetype())->get($cache))
|
||||
return $return;
|
||||
|
||||
$return = array();
|
||||
|
||||
$to = ORM::factory('service_adsl_traffic')
|
||||
->where('service','=',$this->service_username)
|
||||
->and_where('date','>=',date('Y-m-d',mktime(0,0,0,date('m',$period),1,date('Y',$period))))
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))));
|
||||
|
||||
foreach ($to->find_all() as $traffic) {
|
||||
// Roll up the charges according to the configuration
|
||||
$data = ADSL::allowance(array(
|
||||
'base_down_peak'=>is_null($this->adsl_plan->base_down_peak) ? NULL : $traffic->down_peak,
|
||||
'base_down_offpeak'=>is_null($this->adsl_plan->base_down_offpeak) ? NULL : $traffic->down_offpeak,
|
||||
'base_up_peak'=>is_null($this->adsl_plan->base_up_peak) ? NULL : $traffic->up_peak,
|
||||
'base_up_offpeak'=>is_null($this->adsl_plan->base_up_offpeak) ? NULL : $traffic->up_offpeak,
|
||||
'extra_down_peak'=>$this->adsl_plan->extra_down_peak,
|
||||
'extra_down_offpeak'=>$this->adsl_plan->extra_down_offpeak,
|
||||
'extra_up_peak'=>$this->adsl_plan->extra_up_peak,
|
||||
'extra_up_offpeak'=>$this->adsl_plan->extra_up_offpeak,
|
||||
));
|
||||
|
||||
$day = date('d',strtotime($traffic->date));
|
||||
if ($bydate)
|
||||
$return[$day] = $data;
|
||||
else
|
||||
foreach ($data as $k => $v)
|
||||
$return[$k][$day] = $v;
|
||||
}
|
||||
|
||||
// Cache our data
|
||||
// @todo Our cache time should be a configuration parameter
|
||||
Cache::instance(Config::cachetype())->set($cache,$return,43200);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of the data used in a year by month
|
||||
*/
|
||||
public function get_traffic_data_monthly($period=NULL,$bydate=FALSE) {
|
||||
$cacheable = FALSE;
|
||||
if (is_null($period))
|
||||
$period = strtotime('yesterday');
|
||||
|
||||
$cache = $this->service_id.date('M-Y',$period).$bydate.__METHOD__;
|
||||
|
||||
// @todo This cache needs to be improved, so that we cache the query regardless of bydate setting
|
||||
if ($cacheable AND $return = Cache::instance(Config::cachetype())->get($cache))
|
||||
return $return;
|
||||
|
||||
$return = array();
|
||||
|
||||
$to = ORM::factory('service_adsl_traffic')
|
||||
->select(
|
||||
array('date_format(date,\'%y-%m\')','month'),
|
||||
array('sum(up_peak)','up_peak'),
|
||||
array('sum(up_offpeak)','up_offpeak'),
|
||||
array('sum(down_peak)','down_peak'),
|
||||
array('sum(down_offpeak)','down_offpeak')
|
||||
)
|
||||
->where('service','=',$this->service_username)
|
||||
->and_where('date','>=',date('Y-m-d',mktime(0,0,0,date('m',$period),1,date('Y',$period)-1)))
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
||||
->group_by('date_format(date,\'%Y-%m\')');
|
||||
|
||||
foreach ($to->find_all() as $traffic) {
|
||||
// Roll up the charges according to the configuration
|
||||
$data = ADSL::allowance(array(
|
||||
'base_down_peak'=>is_null($this->adsl_plan->base_down_peak) ? NULL : $traffic->down_peak,
|
||||
'base_down_offpeak'=>is_null($this->adsl_plan->base_down_offpeak) ? NULL : $traffic->down_offpeak,
|
||||
'base_up_peak'=>is_null($this->adsl_plan->base_up_peak) ? NULL : $traffic->up_peak,
|
||||
'base_up_offpeak'=>is_null($this->adsl_plan->base_up_offpeak) ? NULL : $traffic->up_offpeak,
|
||||
'extra_down_peak'=>$this->adsl_plan->extra_down_peak,
|
||||
'extra_down_offpeak'=>$this->adsl_plan->extra_down_offpeak,
|
||||
'extra_up_peak'=>$this->adsl_plan->extra_up_peak,
|
||||
'extra_up_offpeak'=>$this->adsl_plan->extra_up_offpeak,
|
||||
));
|
||||
|
||||
if ($bydate)
|
||||
$return[$traffic->month] = $data;
|
||||
else
|
||||
foreach ($data as $k => $v)
|
||||
$return[$k][$traffic->month] = $v;
|
||||
}
|
||||
|
||||
// Cache our data
|
||||
// @todo Our cache time should be a configuration parameter
|
||||
Cache::instance(Config::cachetype())->set($cache,$return,43200);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function traffic_month($month,$string=TRUE) {
|
||||
return $string ? implode('/',$this->get_traffic_data_month($month)) :
|
||||
$this->get_traffic_data_month($month);
|
||||
}
|
||||
|
||||
public function traffic_lastmonth($string=TRUE) {
|
||||
// We need it to be last month as of yesterday
|
||||
return $this->traffic_month(strtotime('last month')-86400,$string);
|
||||
}
|
||||
|
||||
public function traffic_thismonth($string=TRUE) {
|
||||
return $this->traffic_month(strtotime('yesterday'),$string);
|
||||
}
|
||||
|
||||
public function traffic_lastmonth_exceed($all=FALSE,$date=NULL) {
|
||||
$return = array();
|
||||
|
||||
if (is_null($date))
|
||||
$date = strtotime('last month');
|
||||
|
||||
foreach ($this->traffic_month($date,FALSE) as $k => $v) {
|
||||
// We shouldnt need to eval for nulls, since the traffic calc does that
|
||||
if ($all OR ($v > $this->adsl_plan->$k)) {
|
||||
$return[$k]['allowance'] = $this->adsl_plan->$k;
|
||||
$return[$k]['used'] = $v;
|
||||
$return[$k]['shaped'] = (! empty($this->adsl_plan->extra_shaped) AND $this->adsl_plan->extra_shaped AND $v > $this->adsl_plan->$k) ? TRUE : FALSE;
|
||||
$return[$k]['excess'] = (! empty($this->adsl_plan->extra_charged) AND $this->adsl_plan->extra_charged AND $v > $this->adsl_plan->$k) ? $v-$this->adsl_plan->$k : 0;
|
||||
$return[$k]['rate'] = $this->adsl_plan->{ADSL::map($k)};
|
||||
$return[$k]['charge'] = ceil(($return[$k]['excess'])/1000)*$return[$k]['rate'];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function template_variables($array) {
|
||||
$friendly = array(
|
||||
'base_down_peak'=>'Peak',
|
||||
'base_down_offpeak'=>'OffPeak',
|
||||
'cumulative_base_down_peak'=>'Total Peak',
|
||||
'cumulative_base_down_offpeak'=>'Total OffPeak',
|
||||
);
|
||||
|
||||
$return = array();
|
||||
if ($this->service->product->prod_plugin_file != 'ADSL')
|
||||
throw new Kohana_Exception('Huh? How did this get called, for a non ADSL product (:ppf)',array(':ppf'=>$this->service_id));
|
||||
|
||||
$allowance = $this->service->product->plugin()->allowance(FALSE);
|
||||
|
||||
$period = strtotime('yesterday');
|
||||
$traffic_data = $this->get_traffic_data_daily($period,FALSE);
|
||||
$traffic = $this->get_traffic_data_month($period);
|
||||
|
||||
$traffic_type = $this->get_traffic_data_daily($period,TRUE);
|
||||
$day = count($traffic_type) ? max(array_keys($traffic_type)) : 1;
|
||||
$date = mktime(0,0,0,date('n',$period),$day,date('Y',$period));
|
||||
$daysleft = date('d',strtotime('last day of',$date))-$day;
|
||||
|
||||
$google = GoogleChart::factory('vertical_bar');
|
||||
$google->title = sprintf('DSL traffic usage as at %s',Config::date($date));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)),
|
||||
'axis'=>'x',
|
||||
'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k])));
|
||||
|
||||
// Work out comulative numbers
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly['cumulative_'.$k]) ? $friendly['cumulative_'.$k] : 'cumulative_'.$k)),
|
||||
'axis'=>'r',
|
||||
'data'=>array((isset($friendly['cumulative_'.$k]) ? $friendly['cumulative_'.$k] : 'cumulative_'.$k)=>$this->cumulative($traffic_data[$k]))));
|
||||
|
||||
foreach ($array as $item) {
|
||||
switch ($item) {
|
||||
case 'MONTH_GRAPH': $value = (string)$google; break;
|
||||
case 'MONTH_TABLE': $value = $google->html_table(FALSE,array(
|
||||
'table'=>'style="border: 1px solid #bebcb7; padding: 5px 5px; background: none repeat scroll 0% 0% #f8f7f5; font-size: 70%;"',
|
||||
)); break;
|
||||
|
||||
case 'OFFPEAK_ALLOWANCE': $value = isset($allowance['base_down_offpeak']) ? $allowance['base_down_offpeak'].' MB' : '-'; break;
|
||||
case 'OFFPEAK_USAGE': $value = isset($traffic['base_down_offpeak']) ? $traffic['base_down_offpeak'].' MB' : '-'; break;
|
||||
|
||||
case 'PEAK_ALLOWANCE': $value = isset($allowance['base_down_peak']) ? $allowance['base_down_peak'].' MB' : '-'; break;
|
||||
case 'PEAK_USAGE': $value = isset($traffic['base_down_peak']) ? $traffic['base_down_peak'].' MB' : '-'; break;
|
||||
|
||||
case 'OFFPEAK_AVERAGE': $value = isset($traffic['base_down_offpeak']) ? round($traffic['base_down_offpeak']/$day,2).' MB' : '-'; break;
|
||||
case 'OFFPEAK_AVERAGE_REMAIN': $value = ((isset($traffic['base_down_offpeak']) AND ($allowance['base_down_offpeak'] > $traffic['base_down_offpeak']) AND $daysleft) ? round(($allowance['base_down_offpeak']-$traffic['base_down_offpeak'])/$daysleft,2).' MB' : '-'); break;
|
||||
|
||||
case 'PEAK_AVERAGE': $value = isset($traffic['base_down_peak']) ? round($traffic['base_down_peak']/$day,2).' MB' : '-'; break;
|
||||
case 'PEAK_AVERAGE_REMAIN': $value = ((isset($traffic['base_down_peak']) AND ($allowance['base_down_peak'] > $traffic['base_down_peak']) AND $daysleft) ? round(($allowance['base_down_peak']-$traffic['base_down_peak'])/$daysleft,2).' MB' : '-'); break;
|
||||
|
||||
case 'SERVICE_NUMBER': $value = $this->service_number; break;
|
||||
case 'USAGE_DATE': $value = Config::date($date); break;
|
||||
case 'USER_NAME': $value = $this->service->account->name(); break;
|
||||
default:
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$return[$item] = $value;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will take an array of numbers and change it into a cumulative array
|
||||
*/
|
||||
public function cumulative($array) {
|
||||
$result = array();
|
||||
$s = 0;
|
||||
|
||||
foreach ($array as $k => $v)
|
||||
$result[$k] = ($s += $v);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we alert traffic
|
||||
*
|
||||
* We alert traffic if:
|
||||
* + 80% of usage every 3 days
|
||||
* + average daily usage > allowance every 5 days
|
||||
* + last day of the period
|
||||
*/
|
||||
public function report_traffic() {
|
||||
if ($this->service->product->prod_plugin_file != 'ADSL')
|
||||
throw new Kohana_Exception('Huh? How did this get called, for a non ADSL product (:ppf)',array(':ppf'=>$this->service_id));
|
||||
|
||||
$allowance = $this->service->product->plugin()->allowance(FALSE);
|
||||
|
||||
$period = strtotime('yesterday');
|
||||
$traffic_data = $this->get_traffic_data_daily($period,FALSE);
|
||||
$traffic = $this->get_traffic_data_month($period);
|
||||
|
||||
$traffic_type = $this->get_traffic_data_daily($period,TRUE);
|
||||
// @todo If no data comes in, then this can be stuck reporting traffic for an old date.
|
||||
$day = count($traffic_type) ? max(array_keys($traffic_type)) : 1;
|
||||
$lastday = date('d',strtotime('last day of',$period));
|
||||
|
||||
foreach ($traffic as $k => $v) {
|
||||
// If we are the last day of the period
|
||||
if ($day == $lastday AND $v)
|
||||
return TRUE;
|
||||
|
||||
// If we are at 80% usage
|
||||
if ($v/($allowance[$k] > 0 ? $allowance[$k] : 1) >= .8 AND $day%3 == 0)
|
||||
return TRUE;
|
||||
|
||||
// If our average is greater than our allowance
|
||||
if ($day%5 == 0 AND ($v/$day > $allowance[$k]/$day))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// If we get here, then we dont need to report usage.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
protected function _service_name() {
|
||||
return sprintf('%s - %s',$this->service->product->name(),$this->service_number);
|
||||
}
|
||||
|
||||
protected function _service_view() {
|
||||
return View::factory('service/user/adsl/view')
|
||||
->set('so',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific service details for use in other modules
|
||||
* For Example: Invoice
|
||||
*
|
||||
* @todo Make the rendered items configurable
|
||||
*/
|
||||
protected function _details($type) {
|
||||
switch ($type) {
|
||||
case 'invoice':
|
||||
return array(
|
||||
_('Service Address')=>$this->display('service_address'),
|
||||
_('Contract Until')=>$this->contract_date_end(),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
||||
}
|
||||
}
|
||||
|
||||
protected function _admin_update() {
|
||||
return View::factory($this->viewpath(strtolower($this->service->prod_plugin_name)))
|
||||
->set('mediapath',Route::get('default/media'))
|
||||
->set('so',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a google chart of traffic
|
||||
*/
|
||||
public function graph_traffic($month=NULL) {
|
||||
$google = GoogleChart::factory('vertical_bar');
|
||||
|
||||
// If we came in via a post to show a particular month, then show that, otherwise show the yearly result
|
||||
if (! is_null($month) AND trim($month)) {
|
||||
$google->title = sprintf('DSL traffic usage for %s',$_POST['month']);
|
||||
$traffic_data = $this->get_traffic_data_daily(strtotime($_POST['month'].'-01'));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)),
|
||||
'axis'=>'x',
|
||||
'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k])));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),
|
||||
'axis'=>'r',
|
||||
'data'=>array((isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)=>$this->cumulative($traffic_data[$k]))));
|
||||
|
||||
} else {
|
||||
// @todo Change the date to the last record date
|
||||
$google->title = sprintf('Monthly DSL traffic usage as at %s',Config::date(strtotime('yesterday')));
|
||||
$traffic_data = $this->get_traffic_data_monthly();
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->series(array(
|
||||
'title'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)),
|
||||
'axis'=>'x',
|
||||
'data'=>array((isset($friendly[$k]) ? $friendly[$k] : $k)=>$traffic_data[$k])));
|
||||
}
|
||||
|
||||
return (string)$google;
|
||||
}
|
||||
|
||||
public function table_traffic($month=NULL) {
|
||||
return View::factory('service/user/adsl/table_traffic')
|
||||
->set('traffic',$this->traffic_month((! is_null($month) AND trim($month)) ? strtotime($month.'-01') : NULL,FALSE));
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,28 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Services Traffic for ADSL
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Service_ADSL_Traffic extends ORMOSB {
|
||||
protected $_table_name = 'service__adsl_traffic';
|
||||
protected $_primary_key = 'service';
|
||||
|
||||
protected $_created_column = FALSE;
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
public function rules() {
|
||||
return array(
|
||||
'site_id'=>array(
|
||||
array('ORMOSB::set_site_id',array(':validation',':model',':field')),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,59 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Services
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage DOMAIN
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Service_DOMAIN extends Model_Service {
|
||||
protected $_table_name = 'service__domain';
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
// Relationships
|
||||
protected $_has_one = array(
|
||||
'host_tld'=>array('foreign_key'=>'id','far_key'=>'domain_tld_id'),
|
||||
'host_registrar_plugin'=>array('foreign_key'=>'id','far_key'=>'domain_registrar_id'),
|
||||
);
|
||||
protected $_belongs_to = array(
|
||||
'service'=>array(),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'domain_expire'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
protected function _service_name() {
|
||||
return sprintf('%s - %s','Domain',$this->name());
|
||||
}
|
||||
|
||||
protected function _service_view() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific service details for use in other modules
|
||||
* For Example: Invoice
|
||||
*
|
||||
* @todo Make the rendered items configurable
|
||||
*/
|
||||
protected function _details($type) {
|
||||
switch ($type) {
|
||||
default:
|
||||
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
||||
}
|
||||
}
|
||||
|
||||
protected function _admin_update() {
|
||||
}
|
||||
|
||||
public function name() {
|
||||
return sprintf('%s.%s',$this->domain_name,$this->host_tld->name);
|
||||
}
|
||||
}
|
||||
?>
|
52
modules/service/classes/model/service/plugin.php
Normal file
52
modules/service/classes/model/service/plugin.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Service Plugins.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Product/Service
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
abstract class Model_Service_Plugin extends ORMOSB {
|
||||
// Reset any sorting that may be defined in our parent
|
||||
protected $_sorting = array();
|
||||
|
||||
/**
|
||||
* View details of the service
|
||||
*/
|
||||
abstract public function service_view();
|
||||
|
||||
/**
|
||||
* Our service name as defined in the DB
|
||||
*/
|
||||
abstract public function name();
|
||||
|
||||
/**
|
||||
* Show our service name as defined in the DB with product suffix.
|
||||
*/
|
||||
public function service_name() {
|
||||
return sprintf('%s - %s',$this->service->product->name(),$this->name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific service details for use in other modules
|
||||
* For Example: Invoice
|
||||
*
|
||||
* @todo Make the rendered items configurable
|
||||
* @todo Change this method name, now that it is public
|
||||
*/
|
||||
public function _details($type) {
|
||||
switch ($type) {
|
||||
// Nothing to add for invoices
|
||||
case 'invoice_detail_items':
|
||||
return array();
|
||||
|
||||
default:
|
||||
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,158 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class will take care of ADSL Traffic.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL {
|
||||
protected $so;
|
||||
protected $today;
|
||||
protected $fetchresult = NULL;
|
||||
protected $curlopts = array(
|
||||
CURLOPT_CONNECTTIMEOUT => 60,
|
||||
CURLOPT_FAILONERROR => TRUE,
|
||||
CURLOPT_FOLLOWLOCATION => FALSE,
|
||||
CURLOPT_HEADER => FALSE,
|
||||
CURLOPT_HTTPPROXYTUNNEL => FALSE,
|
||||
CURLOPT_RETURNTRANSFER => TRUE,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_SSL_VERIFYHOST => FALSE,
|
||||
CURLOPT_SSL_VERIFYPEER => FALSE,
|
||||
CURLOPT_VERBOSE => FALSE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Setup this class. We need to get our supplier details out of the database.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Our DB record must be the suffix of this class name
|
||||
$supplier = preg_replace('/^'.get_parent_class($this).'_/','',get_class($this));
|
||||
|
||||
$so = ORM::factory('adsl_supplier')
|
||||
->where('name','=',$supplier)
|
||||
->find();
|
||||
|
||||
if (! $so->loaded())
|
||||
throw new Kohana_Exception('Supplier :supplier not defined in the database',array(':supplier'=>$supplier));
|
||||
|
||||
$this->so = $so;
|
||||
$this->today = date('Y-m-d',strtotime('yesterday'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of this class
|
||||
*
|
||||
* @return HeadImage
|
||||
*/
|
||||
public static function instance($supplier) {
|
||||
$sc = sprintf('%s_%s',get_called_class(),$supplier);
|
||||
|
||||
if (! class_exists($sc))
|
||||
throw new Kohana_Exception('Class doesnt exist for :supplier',array(':supplier'=>$supplier));
|
||||
else
|
||||
return new $sc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last date we obtained the stats.
|
||||
*/
|
||||
private function last_update() {
|
||||
return $this->so->stats_lastupdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traffic data from supplier
|
||||
*/
|
||||
public function update_traffic() {
|
||||
$alreadyrun = FALSE;
|
||||
for ($querydate=date('Y-m-d',strtotime($this->last_update().'+1 day'));
|
||||
$querydate<=$this->today;
|
||||
$querydate=date('Y-m-d',strtotime($querydate.'+1 day'))) {
|
||||
|
||||
$goodfetch = false;
|
||||
// @todo log this fetch in a "log"
|
||||
|
||||
// Supplier specific output
|
||||
// Data returned should be in MB's
|
||||
$data = $this->getdata($querydate);
|
||||
|
||||
if (! $this->fetchresult) {
|
||||
echo 'Bad fetch'.get_class($this);
|
||||
break;
|
||||
}
|
||||
|
||||
$traffic = ORM::factory('service_adsl_traffic');
|
||||
foreach ($data as $item) {
|
||||
$traffic->values($item,array_keys($item));
|
||||
$traffic->supplier_id = $this->so->id;
|
||||
|
||||
if ($traffic->check())
|
||||
$traffic->save();
|
||||
|
||||
if (! $traffic->saved())
|
||||
throw new Kohana_Exception('Unable to save traffic record');
|
||||
|
||||
$traffic->clear();
|
||||
}
|
||||
}
|
||||
|
||||
$this->so->stats_lastupdate = $this->today;
|
||||
$this->so->save();
|
||||
}
|
||||
|
||||
public function charge_excess_traffic() {
|
||||
$date = strtotime('last month');
|
||||
|
||||
// @todo need a way to find out services that have traffic charges dynamically.
|
||||
foreach ($this->so->services() as $so) {
|
||||
if ($charge = $so->service_adsl->traffic_lastmonth_exceed(FALSE,$date)) {
|
||||
foreach ($charge as $metric => $details) {
|
||||
$co = ORM::factory('charge');
|
||||
|
||||
$co->status = 0;
|
||||
$co->sweep_type = 6;
|
||||
$co->account_id = $so->account_id;
|
||||
$co->service_id = $so->id;
|
||||
$co->amount = $details['rate'];
|
||||
// @todo This needs to be calculated.
|
||||
$co->taxable = TRUE;
|
||||
$co->quantity = ceil($details['excess']/1000);
|
||||
$co->description = _('Excess Traffic');
|
||||
// @todo This need to be improved = strtotime function should be the one used in the function call
|
||||
$co->attributes = implode("\n",array(
|
||||
sprintf('ADSL Service==%s',$so->service_adsl->service_number),
|
||||
sprintf('Allowance==%s',$details['allowance']),
|
||||
sprintf('Metric==%s',$metric),
|
||||
sprintf('Used==%s',$details['used']),
|
||||
sprintf('Month==%s',date('Y-m',$date)),
|
||||
));
|
||||
|
||||
$co->check();
|
||||
$co->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function alert_traffic() {
|
||||
$et = Email_Template::instance('adsl_traffic_notice');
|
||||
|
||||
foreach ($this->so->services() as $so) {
|
||||
if (! $so->service_adsl->report_traffic())
|
||||
continue;
|
||||
|
||||
// Get our variable data
|
||||
$et->to = array('account'=>array($so->account_id));
|
||||
$et->variables = $so->service_adsl->template_variables($et->variables());
|
||||
|
||||
$et->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,181 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for Exetel HSPA
|
||||
*
|
||||
* Traffic information is collected by each service, and cached,
|
||||
* returning just the date in question.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL_ExetelHSPA extends Service_Traffic_ADSL {
|
||||
private $login_user_field = 'login_name';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
static $return = array();
|
||||
|
||||
/**
|
||||
* Get the data for Exetel HSPA services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getdata($date) {
|
||||
// Assume we have a good fetch, unless otherwise specified.
|
||||
$this->fetchresult = TRUE;
|
||||
|
||||
// If we have already collected the date data, return it.
|
||||
if (! empty(Service_Traffic_ADSL_ExetelHSPA::$return[$date]))
|
||||
return Service_Traffic_ADSL_ExetelHSPA::$return[$date];
|
||||
|
||||
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
|
||||
|
||||
// Find our services that need to be collected this way.
|
||||
$update = array();
|
||||
|
||||
foreach ($this->so->services() as $so) {
|
||||
if ($so->service_adsl->service_stats_collect AND $so->service_adsl->service_stats_lastupdate < $date) {
|
||||
// Start Session
|
||||
$request = Request::factory($this->so->stats_url)
|
||||
->method('POST')
|
||||
->post($this->login_user_field,$so->service_adsl->service_username)
|
||||
->post($this->login_pass_field,$so->service_adsl->service_password)
|
||||
->post('doLogin',1)
|
||||
->post('submit','Login');
|
||||
|
||||
$request->get_client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->service_adsl->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$data = $response->body();
|
||||
|
||||
if (! $data) {
|
||||
// @todo Log into a log file
|
||||
printf('Bad fetch for %s [%s]',$so->service_adsl->service_number,$this->so->stats_lastupdate);
|
||||
#$html = new simple_html_dom();
|
||||
#$html->load($data);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.login.html',$so->service_adsl->service_number,'login'));
|
||||
continue;
|
||||
}
|
||||
|
||||
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
|
||||
$servicedate <= $this->today;
|
||||
$servicedate=date('Y-m-d',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01')))) {
|
||||
|
||||
$lastday = date('Y-m-d',strtotime('-1 second',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01'))));
|
||||
if (strtotime($lastday) > time())
|
||||
$lastday = date('Y-m-d',strtotime('yesterday'));
|
||||
|
||||
$html = new simple_html_dom();
|
||||
$notdebug = TRUE;
|
||||
if ($notdebug) {
|
||||
$request = Request::factory($this->so->stats_url.'usage_customize_query.php')
|
||||
->method('POST')
|
||||
->post('year_search_key',date('Y',strtotime($servicedate)))
|
||||
->post('month_search_key',date('m',strtotime($servicedate)))
|
||||
->post('start_day_search_key',date('d',strtotime($servicedate)))
|
||||
->post('end_day_search_key',date('d',strtotime($lastday)))
|
||||
->post('do_usage_search',1);
|
||||
|
||||
$request->get_client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEFILE=>sprintf('/tmp/usage.cookies.%s.txt',$so->service_adsl->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$result = $response->body();
|
||||
|
||||
$html->load($result);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->service_adsl->service_number,$servicedate));
|
||||
} else {
|
||||
$html->load_file(sprintf('/tmp/usage.%s.%s.txt',$so->service_adsl->service_number,$servicedate));
|
||||
}
|
||||
|
||||
$header = array();
|
||||
$data = array();
|
||||
|
||||
foreach ($html->find('fieldset') as $index => $fieldset) {
|
||||
if (! preg_match('/^Usage Detail/',$fieldset->find('legend',0)->plaintext))
|
||||
continue;
|
||||
|
||||
#echo "X:";print_r($fieldset->find('legend',0)->plaintext); echo "\n";
|
||||
foreach ($fieldset->find('table',0)->find('tr') as $key => $values) {
|
||||
foreach ($values->children() as $a => $b) {
|
||||
#print_r(array('a'=>$a,'b'=>$b));
|
||||
|
||||
# Header
|
||||
if ($key == 0) {
|
||||
switch ($b->plaintext) {
|
||||
case 'Date': $header[$a] = 'date'; break;
|
||||
case 'OffPeak Upload': $header[$a] = 'up_offpeak'; break;
|
||||
case 'Peak Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'OffPeak Download': $header[$a] = 'down_offpeak'; break;
|
||||
case 'Peak Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Duration': break;
|
||||
default:
|
||||
printf('Unkown header :%s',$b->plaintext);
|
||||
$this->fetchresult = FALSE;
|
||||
continue;
|
||||
}
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "HEADER: ".$b->plaintext."\n";
|
||||
|
||||
# Data
|
||||
} else {
|
||||
if (isset($header[$a]))
|
||||
$data[$header[$a]] = $b->plaintext;
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "VALUES: ".$b->plaintext."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['date']) && preg_match('/^[0-9]{4}/',$data['date'])) {
|
||||
$sdate = date('Y-m-d',strtotime($data['date']));
|
||||
unset($data['date']);
|
||||
|
||||
if (isset($update[$so->service_adsl->service_number][$sdate]))
|
||||
foreach ($data as $key => $value)
|
||||
$update[$so->service_adsl->service_number][$sdate][$key] += $value;
|
||||
else
|
||||
$update[$so->service_adsl->service_number][$sdate] = $data;
|
||||
|
||||
$update[$so->service_adsl->service_number][$sdate]['service'] = $so->service_adsl->service_number;
|
||||
$update[$so->service_adsl->service_number][$sdate]['date'] = $sdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here and have data, we had a good fetch, update the stats date
|
||||
$so->service_adsl->service_stats_lastupdate = $lastday;
|
||||
$so->service_adsl->save();
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no updates, return an empty array
|
||||
if (! $update)
|
||||
return array();
|
||||
|
||||
// Reformat the data into date order.
|
||||
foreach ($update as $service => $sdata)
|
||||
foreach ($sdata as $sdate => $details)
|
||||
Service_Traffic_ADSL_ExetelHSPA::$return[$sdate][$service] = $details;
|
||||
|
||||
// If the date we want is empty, return an array
|
||||
if (empty(Service_Traffic_ADSL_ExetelHSPA::$return[$date]))
|
||||
return array();
|
||||
|
||||
// Return the date we asked for
|
||||
return Service_Traffic_ADSL_ExetelHSPA::$return[$date];
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,180 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for Exetel PE
|
||||
*
|
||||
* Traffic information is collected by each service, and cached,
|
||||
* returning just the date in question.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL_ExetelPE extends Service_Traffic_ADSL {
|
||||
private $login_user_field = 'login_name';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
static $return = array();
|
||||
|
||||
/**
|
||||
* Get the data for Exetel PE services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getdata($date) {
|
||||
// Assume we have a good fetch, unless otherwise specified.
|
||||
$this->fetchresult = TRUE;
|
||||
|
||||
// If we have already collected the date data, return it.
|
||||
if (! empty(Service_Traffic_ADSL_ExetelPE::$return[$date]))
|
||||
return Service_Traffic_ADSL_ExetelPE::$return[$date];
|
||||
|
||||
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
|
||||
|
||||
// Find our services that need to be collected this way.
|
||||
$update = array();
|
||||
|
||||
foreach ($this->so->services() as $so) {
|
||||
if ($so->service_adsl->service_stats_collect AND $so->service_adsl->service_stats_lastupdate < $date) {
|
||||
// Start Session
|
||||
$request = Request::factory($this->so->stats_url)
|
||||
->method('POST')
|
||||
->post($this->login_user_field,$so->service_adsl->service_username)
|
||||
->post($this->login_pass_field,$so->service_adsl->service_password)
|
||||
->post('doLogin',1)
|
||||
->post('submit','Login');
|
||||
|
||||
$request->get_client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->service_adsl->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$data = $response->body();
|
||||
|
||||
if (! $data) {
|
||||
// @todo Log into a log file
|
||||
printf('Bad fetch for %s [%s]',$so->service_adsl->service_number,$this->so->stats_lastupdate);
|
||||
#$html = new simple_html_dom();
|
||||
#$html->load($data);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.login.html',$so->service_adsl->service_number,'login'));
|
||||
continue;
|
||||
}
|
||||
|
||||
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
|
||||
$servicedate <= $this->today;
|
||||
$servicedate=date('Y-m-d',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01')))) {
|
||||
|
||||
$lastday = date('Y-m-d',strtotime('-1 second',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01'))));
|
||||
if (strtotime($lastday) > time())
|
||||
$lastday = date('Y-m-d',strtotime('yesterday'));
|
||||
|
||||
$html = new simple_html_dom();
|
||||
$notdebug = TRUE;
|
||||
if ($notdebug) {
|
||||
$request = Request::factory($this->so->stats_url.'usage_customize_query.php')
|
||||
->method('POST')
|
||||
->post('year_search_key',date('Y',strtotime($servicedate)))
|
||||
->post('month_search_key',date('m',strtotime($servicedate)))
|
||||
->post('start_day_search_key',date('d',strtotime($servicedate)))
|
||||
->post('end_day_search_key',date('d',strtotime($lastday)))
|
||||
->post('do_usage_search',1);
|
||||
|
||||
$request->get_client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEFILE=>sprintf('/tmp/usage.cookies.%s.txt',$so->service_adsl->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$result = $response->body();
|
||||
|
||||
$html->load($result);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->service_adsl->service_number,$servicedate));
|
||||
} else {
|
||||
$html->load_file(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->service_adsl->service_number,$servicedate));
|
||||
}
|
||||
|
||||
$header = array();
|
||||
$data = array();
|
||||
|
||||
foreach ($html->find('td') as $index => $fieldset) {
|
||||
if (! preg_match('/Usage Detail/',$fieldset->plaintext))
|
||||
continue;
|
||||
|
||||
foreach ($fieldset->find('table',0)->find('tr',0)->find('td',0)->find('table',0)->find('tr') as $key => $values) {
|
||||
foreach ($values->children() as $a => $b) {
|
||||
#print_r(array('a'=>$a,'b'=>$b->plaintext));
|
||||
|
||||
# Header
|
||||
if ($key == 0) {
|
||||
switch ($b->plaintext) {
|
||||
case 'Date': $header[$a] = 'date'; break;
|
||||
case 'OffPeak Upload': $header[$a] = 'up_offpeak'; break;
|
||||
case 'Peak Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'OffPeak Download': $header[$a] = 'down_offpeak'; break;
|
||||
case 'Peak Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Duration': break;
|
||||
default:
|
||||
printf('Unkown header :%s',$b->plaintext);
|
||||
$this->fetchresult = FALSE;
|
||||
continue;
|
||||
}
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "HEADER: ".$b->plaintext."\n";
|
||||
|
||||
# Data
|
||||
} else {
|
||||
if (isset($header[$a]))
|
||||
$data[$header[$a]] = $b->plaintext;
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "VALUES: ".$b->plaintext."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['date']) && preg_match('/[0-9]{4}$/',$data['date'])) {
|
||||
$sdate = date('Y-m-d',strtotime(str_replace('/','-',$data['date'])));
|
||||
unset($data['date']);
|
||||
|
||||
if (isset($update[$so->service_adsl->service_number][$sdate]))
|
||||
foreach ($data as $key => $value)
|
||||
$update[$so->service_adsl->service_number][$sdate][$key] += $value;
|
||||
else
|
||||
$update[$so->service_adsl->service_number][$sdate] = $data;
|
||||
|
||||
$update[$so->service_adsl->service_number][$sdate]['service'] = $so->service_adsl->service_number;
|
||||
$update[$so->service_adsl->service_number][$sdate]['date'] = $sdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here and have data, we had a good fetch, update the stats date
|
||||
$so->service_adsl->service_stats_lastupdate = $lastday;
|
||||
$so->service_adsl->save();
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no updates, return an empty array
|
||||
if (! $update)
|
||||
return array();
|
||||
|
||||
// Reformat the data into date order.
|
||||
foreach ($update as $service => $sdata)
|
||||
foreach ($sdata as $sdate => $details)
|
||||
Service_Traffic_ADSL_ExetelPE::$return[$sdate][$service] = $details;
|
||||
|
||||
// If the date we want is empty, return an array
|
||||
if (empty(Service_Traffic_ADSL_ExetelPE::$return[$date]))
|
||||
return array();
|
||||
|
||||
// Return the date we asked for
|
||||
return Service_Traffic_ADSL_ExetelPE::$return[$date];
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,68 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for Exetel VISP
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL_ExetelVisp extends Service_Traffic_ADSL {
|
||||
private $login_user_field = 'username';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
protected function getdata($date) {
|
||||
$return = array();
|
||||
|
||||
// Assume we have a bad fetch, unless otherwise specified.
|
||||
$this->fetchresult = FALSE;
|
||||
|
||||
$request = Request::factory($this->so->stats_url)
|
||||
->method('POST')
|
||||
->post($this->login_user_field,$this->so->stats_username)
|
||||
->post($this->login_pass_field,$this->so->stats_password)
|
||||
->post($this->date_field,$date);
|
||||
|
||||
$request->get_client()->options($this->curlopts+array(
|
||||
CURLOPT_POST => TRUE,
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$data = $response->body();
|
||||
|
||||
$resultarray = explode("\n",$data);
|
||||
|
||||
// The first field should be a header, so we can ignore it:
|
||||
if (preg_match('/^Login/',$resultarray[0])) {
|
||||
array_shift($resultarray);
|
||||
$this->fetchresult = TRUE;
|
||||
}
|
||||
|
||||
// If we got the expected data, we can parse it.
|
||||
if ($this->fetchresult)
|
||||
foreach ($resultarray as $details) {
|
||||
if (! trim($details))
|
||||
continue;
|
||||
|
||||
$valuesarray = explode(',',$details);
|
||||
|
||||
// Extel VISP stores data in MB's*100.
|
||||
$attrs = array();
|
||||
$attrs['service'] = $valuesarray[0];
|
||||
$attrs['date'] = $valuesarray[1];
|
||||
$attrs['up_peak'] = $valuesarray[2]/100;
|
||||
$attrs['down_peak'] = $valuesarray[3]/100;
|
||||
$attrs['up_offpeak'] = $valuesarray[4]/100;
|
||||
$attrs['down_offpeak'] = $valuesarray[5]/100;
|
||||
|
||||
array_push($return,$attrs);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,124 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for iiNet ADSL
|
||||
*
|
||||
* Traffic information is collected by each service, and cached,
|
||||
* returning just the date in question.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
|
||||
private $login_user_field = 'username';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'period';
|
||||
|
||||
static $return = array();
|
||||
|
||||
// The fields in the XML which are translated into database columns
|
||||
private $fields = array(
|
||||
'peak'=>'down_peak',
|
||||
'offpeak'=>'down_offpeak',
|
||||
'uploads'=>'up_peak',
|
||||
'freezone'=>'internal',
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the data for iiNet ADSL services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getdata($date) {
|
||||
// Assume we have a bad fetch, unless otherwise specified.
|
||||
$this->fetchresult = FALSE;
|
||||
|
||||
// If we have already collected the date data, return it.
|
||||
if (! empty(Service_Traffic_ADSL_iiNetADSL::$return[$date]))
|
||||
return Service_Traffic_ADSL_iiNetADSL::$return[$date];
|
||||
|
||||
// Find our services that need to be collected this way.
|
||||
$update = array();
|
||||
foreach ($this->so->services() as $so) {
|
||||
if ($so->service_adsl->service_stats_collect AND $so->service_adsl->service_stats_lastupdate < $date) {
|
||||
$lastperiod = '';
|
||||
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
|
||||
$servicedate <= $this->today;
|
||||
$servicedate=date('Y-m-d',strtotime('+1 day',strtotime($servicedate)))) {
|
||||
|
||||
$debug = FALSE;
|
||||
$debug_file = '/tmp/data';
|
||||
|
||||
// IINET gives us data a month at a time.
|
||||
if ($lastperiod != date('Ym',strtotime($servicedate))) {
|
||||
$lastperiod = date('Ym',strtotime($servicedate));
|
||||
|
||||
$postfields = http_build_query(array(
|
||||
$this->login_user_field=>$so->service_adsl->service_username,
|
||||
$this->login_pass_field=>$so->service_adsl->service_password,
|
||||
'period'=>$lastperiod,
|
||||
'usage_view'=>'month',
|
||||
'action'=>'login',
|
||||
));
|
||||
|
||||
if ($debug AND file_exists($debug_file))
|
||||
$data = file_get_contents($debug_file);
|
||||
else
|
||||
$data = Remote::get($this->so->stats_url,$this->curlopts+array(CURLOPT_POSTFIELDS=>$postfields));
|
||||
|
||||
// @todo There exists a possibility to skip a month, if we get a bad fetch on a previous month.
|
||||
if ($data)
|
||||
$this->fetchresult = TRUE;
|
||||
|
||||
if ($debug AND ! file_exists($debug_file))
|
||||
file_put_contents($debug_file,$data);
|
||||
}
|
||||
|
||||
$return = array();
|
||||
foreach (XML::factory(null,'ii_feed',$data)->volume_usage->volume_usage->get('day_hour') as $day_hour) {
|
||||
$attrs = array();
|
||||
|
||||
$period = $day_hour->attributes();
|
||||
// If we find a field we dont understand, we'll return.
|
||||
if (empty($period['period']))
|
||||
return array();
|
||||
|
||||
foreach ($day_hour->get('usage') as $usage) {
|
||||
$fields = $usage->attributes();
|
||||
|
||||
// If we find a field we dont understand, we'll return.
|
||||
if (empty($fields['type']) OR empty($this->fields[$fields['type']]))
|
||||
return array();
|
||||
|
||||
// Traffic is in bytes, need to convert to MB
|
||||
if (empty($attrs[$this->fields[$fields['type']]]))
|
||||
$attrs[$this->fields[$fields['type']]] = $usage->value()/1000/1000;
|
||||
else
|
||||
$attrs[$this->fields[$fields['type']]] += $usage->value()/1000/1000;
|
||||
}
|
||||
|
||||
Service_Traffic_ADSL_iiNetADSL::$return[$period['period']][$so->service_adsl->service_username] = $attrs;
|
||||
Service_Traffic_ADSL_iiNetADSL::$return[$period['period']][$so->service_adsl->service_username]['date'] = $period['period'];
|
||||
Service_Traffic_ADSL_iiNetADSL::$return[$period['period']][$so->service_adsl->service_username]['service'] = $so->service_adsl->service_username;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here and have data, we had a good fetch, update the stats date
|
||||
$so->service_adsl->service_stats_lastupdate = $date;
|
||||
$so->service_adsl->save();
|
||||
}
|
||||
}
|
||||
|
||||
// If the date we want is empty, return an array
|
||||
if (empty(Service_Traffic_ADSL_iiNetADSL::$return[$date]))
|
||||
return array();
|
||||
|
||||
// Return the date we asked for
|
||||
return Service_Traffic_ADSL_iiNetADSL::$return[$date];
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,62 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for People Agent
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Service
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL_PeopleAgent extends Service_Traffic_ADSL {
|
||||
private $login_user_field = 'username';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
protected function getdata($date) {
|
||||
// Assume we have a bad fetch, unless otherwise specified.
|
||||
$this->fetchresult = FALSE;
|
||||
|
||||
$return = array();
|
||||
$url_suffix = sprintf('traffic_V34_%s.xml',date('Ymd',strtotime($date)));
|
||||
|
||||
try {
|
||||
$data = Remote::get($this->so->stats_url.$url_suffix,$this->curlopts+array(
|
||||
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
||||
CURLOPT_USERPWD => sprintf('%s:%s',$this->so->stats_username,$this->so->stats_password),
|
||||
));
|
||||
}
|
||||
|
||||
catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fetchresult = TRUE;
|
||||
foreach (XML::factory(null,null,$data)->get('user') as $user) {
|
||||
$attrs = array();
|
||||
|
||||
$userattrs = $user->attributes();
|
||||
$attrs['service'] = $userattrs['username'];
|
||||
$attrs['date'] = $date;
|
||||
|
||||
foreach ($user->year->month->day->get('hour') as $hour => $traffic) {
|
||||
foreach (array('external'=>'down_peak','internal'=>'internal','peering'=>'peer') as $t => $k) {
|
||||
$tatters = $traffic->$t->attributes();
|
||||
|
||||
// Traffic is in bytes, need to convert to MB
|
||||
if (empty($attrs[$k]))
|
||||
$attrs[$k] = $tatters['bytes']/1000/1000;
|
||||
else
|
||||
$attrs[$k] += $tatters['bytes']/1000/1000;
|
||||
}
|
||||
}
|
||||
|
||||
array_push($return,$attrs);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,36 +0,0 @@
|
||||
<!-- @todo NEEDS TO BE TRANSLATED -->
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td class="head" colspan="2">Plugin Details</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 40%;">Service Number</td>
|
||||
<td style="width: 60%;" class="data"><?php echo Form::input('plugin[service_number]',$so->service_number); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Address</td>
|
||||
<td class="data"><?php echo Form::input('plugin[service_address]',$so->service_address); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Connect Date</td>
|
||||
<td class="data">
|
||||
<?php echo Form::input('plugin[service_connect_date]',$so->service_connect_date,array('id'=>'service_connect_date')); ?>
|
||||
<?php echo HTML::anchor('#',
|
||||
HTML::image($mediapath->uri(array('file'=>'img/calendar.png')),array('alt'=>_('Calendar'),'style'=>'cursor: pointer;')),
|
||||
array('title'=>'Click to popup a dialog to select a date graphically','onclick'=>"dateSelector('service_connect_date')")); ?>
|
||||
<script type="text/javascript">defaults['service_connect_date'] = '%s';</script>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Username</td>
|
||||
<td class="data"><?php echo Form::input('plugin[service_username]',$so->service_username); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Password</td>
|
||||
<td class="data"><?php echo Form::input('plugin[service_password]',$so->service_password); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service IP Address</td>
|
||||
<td class="data"><?php echo Form::input('plugin[ipaddress]',$so->ipaddress); ?></td>
|
||||
</tr>
|
||||
</table>
|
@@ -1,10 +0,0 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $service->service_adsl->display('service_number'); ?></td>
|
||||
<td><?php echo $service->service_adsl->adsl_plan->adsl_supplier_plan->name(); ?></td>
|
||||
<td><?php echo $service->service_adsl->contract_date_start(); ?></td>
|
||||
<td><?php echo $service->service_adsl->contract_date_end(); ?></td>
|
||||
<td><?php echo Currency::display($service->service_adsl->adsl_plan->adsl_supplier_plan->base_cost); ?></td>
|
||||
<td><?php echo Currency::display($service->service_adsl->adsl_plan->adsl_supplier_plan->base_cost+$service->service_adsl->adsl_plan->adsl_supplier_plan->tax()); ?></td>
|
||||
<td><input type="checkbox" <?php echo $checked; ?> onchange="paid(this);"/></td>
|
||||
<td><input type="text" name="payment[<?php echo $service->service_adsl->service_number; ?>]" value="<?php echo $amount; ?>" id="p<?php echo $service->service_adsl->id; ?>" size="8"/></td>
|
||||
</tr>
|
@@ -1,4 +0,0 @@
|
||||
<tr class="head">
|
||||
<td colspan="7"> </td>
|
||||
<td><?php echo $total; ?></td>
|
||||
</tr>
|
@@ -1,7 +0,0 @@
|
||||
<script type="text/javascript" >
|
||||
<!--
|
||||
function paid(form) {
|
||||
alert(form);
|
||||
}
|
||||
//-->
|
||||
</script>
|
@@ -1,10 +0,0 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $service->service_adsl->display('service_number'); ?></td>
|
||||
<td><?php echo $service->service_adsl->adsl_plan->adsl_supplier_plan->name(); ?></td>
|
||||
<td><?php echo $service->service_adsl->contract_date_start(); ?></td>
|
||||
<td><?php echo $service->service_adsl->contract_date_end(); ?></td>
|
||||
<td><?php echo Currency::display($service->service_adsl->adsl_plan->adsl_supplier_plan->base_cost); ?></td>
|
||||
<td><?php echo Currency::display($service->service_adsl->adsl_plan->adsl_supplier_plan->base_cost+$service->service_adsl->adsl_plan->adsl_supplier_plan->tax()); ?></td>
|
||||
<td><?php echo $amount; ?></td>
|
||||
<td><?php echo $service->service_adsl->adsl_plan->adsl_supplier_plan->base_cost+$service->service_adsl->adsl_plan->adsl_supplier_plan->tax()-$amount; ?></td>
|
||||
</tr>
|
@@ -1,6 +0,0 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $service; ?></td>
|
||||
<td><?php echo empty($item['info']) ? ' ' : $item['info']; ?></td>
|
||||
<td><?php echo empty($item['cost']) ? ' ' : $item['cost']; ?></td>
|
||||
<td><?php echo empty($item['credit']) ? ' ' : $item['credit']; ?></td>
|
||||
</tr>
|
@@ -1,12 +0,0 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $service->service_adsl->display('service_number'); ?></td>
|
||||
<td><?php echo $service->service_adsl->ipaddress(); ?></td>
|
||||
<td><?php printf('%s (%s)',$service->name(),$service->id); ?></td>
|
||||
<td><?php echo $service->product->prod_plugin_file ? $service->product->plugin()->allowance() : 'No Details'; ?></td>
|
||||
<td><?php echo $service->service_adsl->traffic_thismonth(); ?></td>
|
||||
<td><?php echo $service->service_adsl->traffic_lastmonth(); ?></td>
|
||||
<td><?php echo $service->display('price'); ?></td>
|
||||
<td><?php echo $service->display('recur_schedule'); ?></td>
|
||||
<td><?php echo $service->display('date_next_invoice'); ?></td>
|
||||
<td><input type="checkbox"/></td>
|
||||
</tr>
|
@@ -1,23 +0,0 @@
|
||||
<!-- Print out the heading for the first record -->
|
||||
<!-- // @todo This needs to be translated -->
|
||||
<tr class="title">
|
||||
<td colspan="10" style="padding: 0px;">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td style="border: 0px;"><?php printf('%s %s',$service->account->accnum(),$service->account->name()); ?></td>
|
||||
<td style="border: 0px; text-align: right;"><?php printf('(%s: %s)',_('Invoices Due'),Currency::display($service->account->invoices_due_total())); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="head">
|
||||
<td>Service</td>
|
||||
<td>IP Address</td>
|
||||
<td>Plan</td>
|
||||
<td>Plan Allowance</td>
|
||||
<td>This Month</td>
|
||||
<td>Last Month</td>
|
||||
<td>Amount</td>
|
||||
<td>Freq</td>
|
||||
<td>Next Invoice Date</td>
|
||||
</tr>
|
@@ -1,9 +0,0 @@
|
||||
<!-- @todo NEEDS TO BE TRANSLATED -->
|
||||
<table class="box-left">
|
||||
<?php foreach ($traffic as $metric => $usage) { ?>
|
||||
<tr>
|
||||
<td><?php echo $metric; ?></td>
|
||||
<td class="head"><?php echo $usage; ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
@@ -1,73 +0,0 @@
|
||||
<!-- //@todo To translate -->
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td class="head" colspan="2">Service Details</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 50%">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width: 40%;">Service Number</td>
|
||||
<td style="width: 60%;" class="data"><?php echo $so->display('service_number'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Address</td>
|
||||
<td class="data"><?php echo $so->display('service_address'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Contract Term</td>
|
||||
<td class="data"><?php echo $so->display('contract_term'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Connect Date</td>
|
||||
<td class="data"><?php echo $so->display('service_connect_date'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Contract End Date</td>
|
||||
<td class="data"><?php echo $so->contract_date_end(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Username</td>
|
||||
<td class="data"><?php echo $so->display('service_username'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Password</td>
|
||||
<td class="data"><?php echo $so->display('service_password'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service IP</td>
|
||||
<td class="data"><?php echo $so->ipaddress(); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td style="width: 50%; vertical-align: top;">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td style="width: 40%;">Traffic Used This Month</td>
|
||||
<td style="width: 60%;" class="data"><?php echo $so->traffic_month(null); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 40%;">Traffic Used Last Month</td>
|
||||
<td style="width: 60%;" class="data"><?php echo $so->traffic_lastmonth(); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>View Daily Traffic for Month</td>
|
||||
<td><?php echo Form::open(); echo Form::select('month',array_merge(array(''),$so->get_traffic_months()),(isset($_POST['month']) ? $_POST['month'] : '')); echo Form::submit('submit',_('Show'),array('class'=>'form_button')); echo Form::close(); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php echo $so->graph_traffic(isset($_POST['month']) ? $_POST['month'] : ''); ?><td>
|
||||
<td><?php echo $so->table_traffic(isset($_POST['month']) ? $_POST['month'] : ''); ?><td>
|
||||
</tr>
|
||||
</table>
|
Reference in New Issue
Block a user