2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
2011-09-28 06:46:22 +00:00
|
|
|
* This class provides Admin Service functions
|
2010-11-29 22:41:08 +00:00
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package Service
|
2010-11-29 22:41:08 +00:00
|
|
|
* @category Controllers/Admin
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
2010-11-29 22:41:08 +00:00
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-06-04 11:50:41 +00:00
|
|
|
class Controller_Admin_Service extends Controller_Service {
|
2011-08-26 01:16:48 +00:00
|
|
|
protected $secure_actions = array(
|
2012-12-19 06:28:39 +00:00
|
|
|
'ajaxlist'=>TRUE,
|
|
|
|
'ajaxjson_traffic'=>TRUE,
|
2012-05-12 23:29:44 +00:00
|
|
|
'adslstat'=>TRUE,
|
2011-08-27 06:33:46 +00:00
|
|
|
'listadslbilling'=>TRUE,
|
2012-10-08 12:52:21 +00:00
|
|
|
'listexpiring'=>TRUE,
|
2011-10-14 05:44:12 +00:00
|
|
|
'listdomainservicesbysupplier'=>TRUE,
|
2012-06-22 12:05:43 +00:00
|
|
|
'listdomainservicesbydnshost'=>TRUE,
|
|
|
|
'listhostservicesbysupplier'=>TRUE,
|
2011-12-26 13:52:46 +00:00
|
|
|
'listwebservices'=>TRUE,
|
2011-10-10 23:38:21 +00:00
|
|
|
'listinvoicesoon'=>TRUE,
|
2011-07-14 09:09:03 +00:00
|
|
|
'update'=>TRUE,
|
2012-01-09 01:35:24 +00:00
|
|
|
'view'=>TRUE,
|
2010-11-29 22:41:08 +00:00
|
|
|
);
|
|
|
|
|
2012-10-07 04:15:34 +00:00
|
|
|
public function action_ajaxlist() {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2011-10-14 05:44:12 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result += ORM::factory('Service')->list_autocomplete(
|
2012-10-07 04:15:34 +00:00
|
|
|
isset($_REQUEST['term']) ? $_REQUEST['term'] : '',
|
|
|
|
'id',
|
|
|
|
isset($_REQUEST['aid']) ? array(array('account_id','=',$_REQUEST['aid'])) : array());
|
2011-10-14 05:44:12 +00:00
|
|
|
|
|
|
|
$this->auto_render = FALSE;
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
2013-04-05 12:50:08 +00:00
|
|
|
$this->response->body(json_encode(array_values($result)));
|
2011-10-14 05:44:12 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 06:28:39 +00:00
|
|
|
public function action_ajaxjson_traffic() {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2012-11-09 23:13:57 +00:00
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
|
2012-12-19 06:28:39 +00:00
|
|
|
$data = $this->consoltraffic($svs,time());
|
|
|
|
|
2013-01-23 11:17:22 +00:00
|
|
|
$google = GoogleChart::factory('ComboChart')
|
|
|
|
->stacked(TRUE);
|
2012-12-19 06:28:39 +00:00
|
|
|
|
|
|
|
foreach ($data['data'] as $key => $values)
|
2013-01-04 04:13:48 +00:00
|
|
|
$google->sdata(array('yl'=>$key),array($key=>$values));
|
2012-12-19 06:28:39 +00:00
|
|
|
|
2013-01-04 04:13:48 +00:00
|
|
|
$google->sdata(array('yr'=>'services'),array('services'=>$data['svs']));
|
2012-12-19 06:28:39 +00:00
|
|
|
|
|
|
|
$this->auto_render = FALSE;
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
|
|
$this->response->body($google->json());
|
|
|
|
}
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
private function consoltraffic($svs,$date) {
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
foreach ($svs as $so) {
|
|
|
|
$c = array();
|
|
|
|
foreach ($so->plugin()->get_traffic_data_monthly($date) as $metric => $ma) {
|
|
|
|
foreach ($ma as $month => $traffic) {
|
|
|
|
// Only count the service once, not for each metric.
|
|
|
|
if (! isset($c[$month])) {
|
|
|
|
if (isset($data['svs'][$month]))
|
|
|
|
$data['svs'][$month] += 1;
|
|
|
|
else
|
|
|
|
$data['svs'][$month] = 1;
|
|
|
|
|
|
|
|
$c[$month] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['data'][$metric][$month]))
|
|
|
|
$data['data'][$metric][$month] += (int)$traffic;
|
|
|
|
else
|
|
|
|
$data['data'][$metric][$month] = (int)$traffic;
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
ksort($data['svs']);
|
|
|
|
foreach ($data['data'] as $metric => $details)
|
|
|
|
ksort($data['data'][$metric]);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
return $data;
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2012-10-08 12:52:21 +00:00
|
|
|
/**
|
|
|
|
* Show a list of services that are expiring or have expired
|
|
|
|
*/
|
|
|
|
public function action_listexpiring() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$svs = ORM::factory('Service')->list_expiring();
|
2012-10-08 12:52:21 +00:00
|
|
|
|
|
|
|
Sort::MAsort($svs,'expire()');
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('ADSL Services'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
|
|
|
NULL,
|
|
|
|
array(
|
2013-02-12 11:14:59 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
2012-10-08 12:52:21 +00:00
|
|
|
'service_name()'=>array('label'=>'Service'),
|
|
|
|
'expire(TRUE)'=>array('label'=>'Expires'),
|
|
|
|
'due(TRUE)'=>array('label'=>'Due'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'type'=>'select',
|
2013-02-12 11:14:59 +00:00
|
|
|
'form'=>URL::link('user','service/view'),
|
2012-10-08 12:52:21 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
public function action_listdomainservicesbysupplier() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
|
2011-10-14 05:44:12 +00:00
|
|
|
Sort::MAsort($svs,'plugin()->domain_registrar_id,name()');
|
|
|
|
|
|
|
|
$list = array();
|
|
|
|
|
|
|
|
foreach ($svs as $so)
|
|
|
|
$list[$so->plugin()->domain_registrar_id][] = $so;
|
|
|
|
|
|
|
|
foreach (array_keys($list) as $sid)
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf(_('Domain Names by Supplier %s'),$sid),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$list[$sid],
|
|
|
|
25,
|
|
|
|
array(
|
2013-02-12 11:14:59 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
2011-10-14 05:44:12 +00:00
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'plugin()->display("domain_expire")'=>array('label'=>'Expire'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2011-10-14 05:44:12 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2013-02-12 11:14:59 +00:00
|
|
|
'form'=>URL::link('user','service/view'),
|
2011-10-14 05:44:12 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-06-22 12:05:43 +00:00
|
|
|
public function action_listdomainservicesbydnshost() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
|
2013-01-10 11:25:19 +00:00
|
|
|
Sort::MAsort($svs,'plugin()->service_plugin_host,name()');
|
2012-06-22 12:05:43 +00:00
|
|
|
|
|
|
|
$list = array();
|
|
|
|
|
|
|
|
foreach ($svs as $so)
|
2013-01-10 11:25:19 +00:00
|
|
|
$list[$so->plugin()->service_plugin_host->host_server_id][] = $so;
|
2012-06-22 12:05:43 +00:00
|
|
|
|
|
|
|
foreach (array_keys($list) as $sid)
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf(_('Domain Names by DNS Host [%s]'),$sid),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$list[$sid],
|
|
|
|
25,
|
|
|
|
array(
|
2013-02-12 11:14:59 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
2012-06-22 12:05:43 +00:00
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'plugin()->domain_registrar->id'=>array('label'=>'SID'),
|
|
|
|
'plugin()->domain_registrar->name'=>array('label'=>'Supplier'),
|
|
|
|
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2013-02-12 11:14:59 +00:00
|
|
|
'form'=>URL::link('user','service/view'),
|
2012-06-22 12:05:43 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_listhostservicesbysupplier() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('HOST');
|
2012-06-22 12:05:43 +00:00
|
|
|
Sort::MAsort($svs,'plugin()->host_server,name()');
|
|
|
|
|
|
|
|
$list = array();
|
|
|
|
|
|
|
|
foreach ($svs as $so)
|
|
|
|
$list[$so->plugin()->host_server_id][] = $so;
|
|
|
|
|
|
|
|
foreach (array_keys($list) as $sid)
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf(_('Hosting by Supplier %s'),$sid),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$list[$sid],
|
|
|
|
25,
|
|
|
|
array(
|
2013-02-12 11:14:59 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
2012-06-22 12:05:43 +00:00
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'plugin()->display("host_expire")'=>array('label'=>'Expire'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2013-02-12 11:14:59 +00:00
|
|
|
'form'=>URL::link('user','service/view'),
|
2012-06-22 12:05:43 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-12-26 13:52:46 +00:00
|
|
|
public function action_listwebservices() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('WEB');
|
2011-12-26 13:52:46 +00:00
|
|
|
Sort::MAsort($svs,'name()');
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('SSL Services'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
|
|
|
25,
|
|
|
|
array(
|
2013-02-12 11:14:59 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
2011-12-26 13:52:46 +00:00
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2011-12-26 13:52:46 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2013-02-12 11:14:59 +00:00
|
|
|
'form'=>URL::link('user','service/view'),
|
2011-12-26 13:52:46 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
|
|
|
* Reconcile billing for an ADSL supplier
|
|
|
|
*
|
|
|
|
* @todo this should really be in a different class, since adsl wont be part of the main app
|
|
|
|
*/
|
2012-11-09 23:13:57 +00:00
|
|
|
public function action_listadslbilling() {
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
|
2013-04-20 01:40:44 +00:00
|
|
|
$aso = ORM::factory('ADSL_Supplier',$id);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
// Process upload
|
|
|
|
// @todo This should be separated out by supplier in case each supplier has a different format
|
2011-07-13 22:59:32 +00:00
|
|
|
if ($_FILES) {
|
|
|
|
$files = Validation::factory($_FILES)
|
|
|
|
->rule('csv','Upload::valid')
|
|
|
|
->rule('csv','Upload::not_empty')
|
|
|
|
->rule('csv','Upload::type',array(':value',array('csv')))
|
|
|
|
->rule('csv','Upload::size',array(':value','10M'));
|
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
if ($files->check())
|
2013-01-23 11:17:22 +00:00
|
|
|
foreach ($files->data() as $file)
|
2011-07-13 22:59:32 +00:00
|
|
|
$csv = $this->process($file);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @todo add a display if there are no items
|
|
|
|
$i = $j = 0;
|
|
|
|
$total = 0;
|
|
|
|
$summary = '';
|
2011-12-21 01:39:21 +00:00
|
|
|
$output = View::factory($this->viewpath().'/head');
|
2010-11-29 22:41:08 +00:00
|
|
|
$output .= '<table class="box-left">';
|
|
|
|
foreach ($aso->services(TRUE) as $so) {
|
2011-09-28 06:46:22 +00:00
|
|
|
$po = $so->plugin()->product();
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
// Reset our uploaded data
|
|
|
|
$uploaded = array();
|
2011-09-28 06:46:22 +00:00
|
|
|
$uploaded['excess'] = empty($csv[$so->plugin()->service_number]['excess']) ? 0 : $csv[$so->plugin()->service_number]['excess'];
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
// If our uploaded file has some cost data.
|
2011-09-28 06:46:22 +00:00
|
|
|
if (! empty($csv[$so->plugin()->service_number])) {
|
2011-10-14 05:44:12 +00:00
|
|
|
$uploaded['amount'] =
|
2011-09-28 06:46:22 +00:00
|
|
|
(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']);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
// Record the the exception if the cost is not expected
|
2011-09-28 06:46:22 +00:00
|
|
|
if (round($po->adsl_supplier_plan->base_cost+$po->adsl_supplier_plan->tax(),2) != $uploaded['amount']) {
|
2011-12-21 01:39:21 +00:00
|
|
|
$summary .= View::factory($this->viewpath().'/summary')
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('service',$so)
|
2011-09-28 06:46:22 +00:00
|
|
|
->set('plan',$po)
|
|
|
|
->set('planoverride',$so->plugin()->provided_adsl_plan_id ? TRUE : FALSE)
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('amount',$uploaded['amount'])
|
|
|
|
->set('i',$j++%2);
|
|
|
|
|
|
|
|
$uploaded['checked'] = '';
|
|
|
|
} else {
|
|
|
|
$uploaded['checked'] = 'checked="checked"';
|
|
|
|
}
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
unset($csv[$so->plugin()->service_number]);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$uploaded['checked'] = '';
|
|
|
|
$uploaded['amount'] = 0;
|
|
|
|
}
|
2011-09-28 06:46:22 +00:00
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
$total += $uploaded['amount'];
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath().'/body')
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('service',$so)
|
2011-09-28 06:46:22 +00:00
|
|
|
->set('plan',$po)
|
|
|
|
->set('planoverride',$so->plugin()->provided_adsl_plan_id ? TRUE : FALSE)
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('checked',$uploaded['checked'])
|
|
|
|
->set('amount',$uploaded['amount'])
|
2011-09-28 06:46:22 +00:00
|
|
|
->set('excess',$uploaded['excess'])
|
|
|
|
->set('adsl',$so->plugin())
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('i',$i++%2);
|
|
|
|
}
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath().'/foot')
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('total',$total);
|
|
|
|
|
|
|
|
$output .= '</table>';
|
|
|
|
|
|
|
|
// Summary Report of remaining CSV items.
|
|
|
|
if (! empty($csv))
|
|
|
|
foreach ($csv as $service => $item) {
|
2011-12-21 01:39:21 +00:00
|
|
|
$summary .= View::factory($this->viewpath().'/summary_exception')
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('service',$service)
|
|
|
|
->set('item',$item)
|
|
|
|
->set('i',$j++%2);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
|
|
|
|
$output .= '<div>';
|
|
|
|
$output .= Form::file('csv');
|
2011-08-31 06:54:44 +00:00
|
|
|
$output .= Form::submit('submit','upload',array('class'=>'form_button'));
|
2010-11-29 22:41:08 +00:00
|
|
|
$output .= '</div>';
|
|
|
|
$output .= Form::close();
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('ADSL Services'),
|
|
|
|
'body'=>$output,
|
2011-07-14 09:09:03 +00:00
|
|
|
));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
if ($summary)
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Exception Charges'),
|
|
|
|
'body'=>'<table class="box-left">'.$summary.'</table>',
|
|
|
|
));
|
|
|
|
|
|
|
|
Style::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'css/list.css',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function process(array $file) {
|
|
|
|
$data = file_get_contents($file['tmp_name']);
|
|
|
|
|
|
|
|
if (! $data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$start = $end = FALSE;
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2010-11-29 22:41:08 +00:00
|
|
|
foreach (preg_split("/\n/",$data) as $line) {
|
|
|
|
// Items start after "Item ID"
|
|
|
|
if (! $start && preg_match('/^Item ID,/',$line)) {
|
|
|
|
$start = true;
|
|
|
|
continue;
|
2013-04-20 01:40:44 +00:00
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
// Items end after "Subtotal"
|
|
|
|
} elseif ($start && ! $end && preg_match('/^Subtotal:,/',$line)) {
|
|
|
|
$end = true;
|
|
|
|
continue;
|
2013-04-20 01:40:44 +00:00
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
// If we havent started or not ended, continue
|
|
|
|
} elseif (! $start || $end) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-04-20 01:40:44 +00:00
|
|
|
$record = explode(',',$line);
|
|
|
|
|
|
|
|
// 1 = Item ID (ignore)
|
|
|
|
// 2 = Reference ID (ignore - its not useful for us)
|
|
|
|
// 3 = Category (always appears blank)
|
|
|
|
// 4 = Item Description (has our service number, rental and excess charges description)
|
|
|
|
// 0nnnnnnnnn - Monthly Internet Charge On Plan XXXXX For billing period (dd/mm/yyyy - dd/mm/yyyy) (7 FIELDED LINES)
|
|
|
|
// 0nnnnnnnnn - Excess usage charges for March 2013 (8 FIELDED LINES)
|
|
|
|
// 5 = Quantity
|
|
|
|
// Always 1 for Plan Fees
|
|
|
|
// 0nnnnnnnnn@graytech.net.au Excess Usage y GB (for excess charges)
|
|
|
|
// 6 = Unit Price
|
|
|
|
// Always 1 for Excess Usage (probably quantity)
|
|
|
|
// 7 = Total Price
|
|
|
|
// Unit price for Excess Usage
|
|
|
|
// 8 = Total Price for Excess Usage
|
|
|
|
|
|
|
|
if (! count($record) >= 7)
|
|
|
|
throw Kohana_Exception('Format of CSV file changed? (:record)',array(':record'=>$record));
|
|
|
|
|
|
|
|
|
|
|
|
if (preg_match('/Monthly Internet Charge On Plan /',$record[3])) {
|
|
|
|
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
|
|
|
|
$result[$service]['cost'] = str_replace('$','',$record[6]);
|
|
|
|
|
|
|
|
} elseif (preg_match('/VISP Credit/',$record[3])) {
|
|
|
|
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
|
|
|
|
$result[$service]['credit'] = str_replace('$','',$record[6]);
|
|
|
|
|
|
|
|
} elseif (preg_match('/Excess usage charges for /',$record[3])) {
|
|
|
|
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
|
|
|
|
$result[$service]['excess'] = str_replace('$','',$record[7]);
|
|
|
|
|
|
|
|
// Ignore Payment For Invoice lines
|
|
|
|
} elseif (preg_match('/Payment For Invoice:/',$record[3])) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
|
|
|
|
$result[$service]['info'] = $line;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$result['000']['info'] = $line;
|
|
|
|
}
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
2011-07-14 09:09:03 +00:00
|
|
|
|
2011-10-10 23:38:21 +00:00
|
|
|
/**
|
|
|
|
* List services that need to be invoiced.
|
|
|
|
*/
|
|
|
|
public function action_listinvoicesoon() {
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Services to Invoice'),
|
|
|
|
'body'=>Table::display(
|
2012-11-09 23:13:57 +00:00
|
|
|
ORM::factory('Service')->list_invoicesoon(ORM::factory('Invoice')->config('GEN_SOON_DAYS')),
|
2011-10-10 23:38:21 +00:00
|
|
|
25,
|
|
|
|
array(
|
2013-02-12 11:14:59 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
2011-10-10 23:38:21 +00:00
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
|
|
|
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2013-06-04 11:50:41 +00:00
|
|
|
'charges()'=>array('label'=>'Charges','class'=>'right'),
|
2012-08-01 12:43:33 +00:00
|
|
|
'status'=>array('label'=>'Active'),
|
2011-10-10 23:38:21 +00:00
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2013-02-12 11:14:59 +00:00
|
|
|
'form'=>URL::link('user','service/view'),
|
2011-10-10 23:38:21 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-12-16 23:31:35 +00:00
|
|
|
public function action_update() {
|
|
|
|
$id = $this->request->param('id');
|
2012-11-09 23:13:57 +00:00
|
|
|
$so = ORM::factory('Service',$id);
|
2011-07-14 09:09:03 +00:00
|
|
|
|
|
|
|
if (! $so->loaded())
|
2012-11-09 23:13:57 +00:00
|
|
|
HTTP::redirect('welcome/index');
|
2011-07-14 09:09:03 +00:00
|
|
|
|
|
|
|
if ($_POST) {
|
|
|
|
if (isset($_POST['plugin']) AND $_POST['plugin'])
|
|
|
|
if (! $so->plugin()->values($_POST['plugin'])->update()->saved())
|
|
|
|
throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id()));
|
|
|
|
|
|
|
|
if (! $so->values($_POST)->update()->saved())
|
2012-03-30 04:13:01 +00:00
|
|
|
throw new Kohana_Exception('Failed to save updates to service data for record :record',array(':record'=>$so->id()));
|
2011-07-14 09:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s %s:%s',_('Update Service'),$so->id(),$so->name()),
|
2011-12-26 13:52:46 +00:00
|
|
|
'body'=>View::factory($this->viewpath())
|
2011-07-14 09:09:03 +00:00
|
|
|
->set('so',$so)
|
2011-07-22 01:04:20 +00:00
|
|
|
->set('mediapath',Route::get('default/media'))
|
2011-07-14 09:09:03 +00:00
|
|
|
->set('plugin_form',$so->admin_update()),
|
|
|
|
));
|
2011-07-22 01:04:20 +00:00
|
|
|
|
|
|
|
// @todo Investigate a better way of preparing for jscalendar
|
|
|
|
Script::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'js/dhtml.calendar.js',
|
|
|
|
));
|
|
|
|
Script::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'js/dhtml.calendar-setup.js',
|
|
|
|
));
|
|
|
|
Script::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'js/dhtml.calendar-en.js',
|
|
|
|
));
|
|
|
|
Script::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'js/dhtml.date_selector.js',
|
|
|
|
));
|
|
|
|
Style::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'css/dhtml.calendar.css',
|
|
|
|
));
|
2011-07-14 09:09:03 +00:00
|
|
|
}
|
2012-01-09 01:35:24 +00:00
|
|
|
|
|
|
|
public function action_view() {
|
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$so = ORM::factory('Service',$id);
|
2012-01-09 01:35:24 +00:00
|
|
|
|
2013-04-04 22:42:29 +00:00
|
|
|
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) {
|
2012-01-09 01:35:24 +00:00
|
|
|
$this->template->content = 'Unauthorised or doesnt exist?';
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-31 03:33:13 +00:00
|
|
|
$doutput = $loutput = '';
|
2012-01-09 01:35:24 +00:00
|
|
|
|
|
|
|
$loutput .= View::factory($this->viewpath())
|
|
|
|
->set('so',$so);
|
|
|
|
|
2012-03-31 03:33:13 +00:00
|
|
|
// Validate the transactions
|
|
|
|
$bt = NULL;
|
|
|
|
$save = (isset($_REQUEST['go']) && $_REQUEST['go']=1) ? 1 : 0;
|
|
|
|
$xsid=197;
|
|
|
|
foreach ($so->transactions()->where('item_type','=',0)->find_all() as $iio) {
|
2013-02-26 03:19:32 +00:00
|
|
|
if (! $iio->invoice->status) continue;
|
|
|
|
// @todo This hard coding of 3070 should be removed.
|
2012-03-31 03:33:13 +00:00
|
|
|
if ($iio->service_id == $xsid AND $iio->invoice_id < 3070) continue;
|
|
|
|
if ($iio->quantity < 0 OR $iio->price_base < 0)
|
|
|
|
continue;
|
|
|
|
if (in_array($iio->id,array(960)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ($iio->invoice_id > 4000 OR $iio->product->prod_plugin_file=="ADSL")
|
|
|
|
$a = FALSE;
|
|
|
|
else
|
|
|
|
$a = TRUE;
|
|
|
|
|
|
|
|
if (is_null($bt))
|
|
|
|
$bt = $iio->date_start;
|
|
|
|
|
|
|
|
$pdata = Period::details($iio->recurring_schedule,$a ? NULL : $iio->product->price_recurr_weekday,$bt,TRUE);
|
|
|
|
|
|
|
|
switch ($iio->recurring_schedule) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
if ($iio->date_start != $pdata['start_time']) {
|
|
|
|
$doutput .= sprintf('%s: Set start_time: %s [%s]<br/>',$iio->id,Config::date($pdata['start_time']),$pdata['start_time']);
|
|
|
|
$iio->date_start=$pdata['start_time'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($iio->date_stop != $pdata['end_time']) {
|
|
|
|
$doutput .= sprintf('%s: Set end_time: %s [%s] <br/>',$iio->id,Config::date($pdata['end_time']),$pdata['end_time']);
|
|
|
|
$iio->date_stop=$pdata['end_time'];
|
|
|
|
}
|
|
|
|
$bt = $pdata['end_time']+86400;
|
|
|
|
|
|
|
|
//$doutput .= sprintf('%s: BT now: %s (%s) [%s]<br/>',$iio->id,Config::date($bt),Config::date($pdata['end_time']),$bt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$doutput .= sprintf('%s: %s Not handled',$iio->id,$iio->recurring_schedule);
|
|
|
|
}
|
|
|
|
//$doutput .= '<br/>';
|
|
|
|
if ($save) {
|
|
|
|
$iio->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_REQUEST['go']))
|
2013-02-12 11:14:59 +00:00
|
|
|
HTTP::redirect(URL::link('admin','service/view/'.$so->id));
|
2012-11-09 23:13:57 +00:00
|
|
|
|
2012-01-09 01:35:24 +00:00
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('Transaction History for %s: %s',$so->id(),$so->name()),
|
|
|
|
'body'=>$loutput,
|
|
|
|
));
|
|
|
|
|
2012-03-31 03:33:13 +00:00
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('Transaction Debug for %s: %s',$so->id(),$so->name()),
|
|
|
|
'body'=>$doutput,
|
|
|
|
));
|
|
|
|
|
2012-01-09 01:35:24 +00:00
|
|
|
$output .= View::factory('service/user/view')
|
|
|
|
->set('so',$so);
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s: %s',$so->id(),$so->service_name()),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
2012-05-12 23:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function action_adslstat() {
|
|
|
|
$output = '';
|
2012-11-09 23:13:57 +00:00
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
|
2012-05-12 23:29:44 +00:00
|
|
|
$stats = array();
|
|
|
|
// @todo This needs to be configurable.
|
|
|
|
$traffic = array(1000,2000,5000,10000,25000,50000,75000,100000);
|
|
|
|
$ts = 0;
|
|
|
|
|
|
|
|
foreach ($svs as $a=>$so) {
|
|
|
|
// Number of services
|
|
|
|
if (! isset($stats[$so->product->plugin()->speed]['c']))
|
|
|
|
$stats[$so->product->plugin()->speed]['c'] = 0;
|
|
|
|
|
|
|
|
$stats[$so->product->plugin()->speed]['c']++;
|
|
|
|
$ts++;
|
|
|
|
|
|
|
|
// Amount of traffic
|
|
|
|
$t = array_sum($so->plugin()->traffic_lastmonth(FALSE));
|
|
|
|
$a = 0;
|
|
|
|
foreach (array_reverse($traffic) as $i) {
|
|
|
|
if ($i < $t)
|
|
|
|
break;
|
|
|
|
$a = $i;
|
|
|
|
}
|
2012-01-09 01:35:24 +00:00
|
|
|
|
2012-05-12 23:29:44 +00:00
|
|
|
if (! isset($stats[$so->product->plugin()->speed]['d'][$a]))
|
|
|
|
$stats[$so->product->plugin()->speed]['d'][$a] = 0;
|
|
|
|
|
|
|
|
$stats[$so->product->plugin()->speed]['d'][$a]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($stats)) {
|
|
|
|
$output .= View::factory($this->viewpath().'/head')
|
|
|
|
->set('name','SPEED');
|
|
|
|
$output .= View::factory($this->viewpath().'/head_data')
|
|
|
|
->set('name','#');
|
|
|
|
foreach ($traffic as $i)
|
|
|
|
$output .= View::factory($this->viewpath().'/head_data')
|
|
|
|
->set('name',$i);
|
|
|
|
$output .= View::factory($this->viewpath().'/head_data')
|
|
|
|
->set('name','Other');
|
|
|
|
$output .= View::factory($this->viewpath().'/head_end');
|
|
|
|
|
|
|
|
foreach ($stats as $speed => $details) {
|
|
|
|
$output .= View::factory($this->viewpath().'/body_head')
|
|
|
|
->set('count',$details['c'])
|
|
|
|
->set('percent',sprintf('%2.1f',$details['c']/$ts*100))
|
|
|
|
->set('speed',$speed);
|
|
|
|
|
|
|
|
foreach ($traffic as $i) {
|
|
|
|
$output .= View::factory($this->viewpath().'/body_data')
|
|
|
|
->set('count',$c=isset($details['d'][$i]) ? $details['d'][$i] : 0)
|
|
|
|
->set('percent',sprintf('%2.1f',$c/$details['c']*100));
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= View::factory($this->viewpath().'/body_data')
|
|
|
|
->set('count',$c=isset($details['d'][0]) ? $details['d'][0] : 0)
|
|
|
|
->set('percent',sprintf('%2.1f',$c/$details['c']*100));
|
|
|
|
$output .= View::factory($this->viewpath().'/body_end');
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= View::factory($this->viewpath().'/foot');
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('ADSL Traffic Summary Stats - Last Month'),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
2012-01-09 01:35:24 +00:00
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
?>
|