2013-10-10 02:44:53 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides Admin Service functions
|
|
|
|
*
|
|
|
|
* @package Service
|
|
|
|
* @category Controllers/Admin
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-06-04 11:50:41 +00:00
|
|
|
class Controller_Admin_Service extends Controller_Service {
|
2013-10-10 02:44:53 +00:00
|
|
|
protected $secure_actions = array(
|
|
|
|
'ajaxjson_traffic'=>TRUE,
|
|
|
|
'adslstat'=>TRUE,
|
|
|
|
'listexpiring'=>TRUE,
|
|
|
|
'listdomainservicesbysupplier'=>TRUE,
|
|
|
|
'listdomainservicesbydnshost'=>TRUE,
|
|
|
|
'listhostservicesbysupplier'=>TRUE,
|
|
|
|
'listwebservices'=>TRUE,
|
|
|
|
'listinvoicesoon'=>TRUE,
|
|
|
|
'update'=>TRUE,
|
|
|
|
'view'=>TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
public function action_ajaxjson_traffic() {
|
|
|
|
$result = array();
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
|
|
|
|
$data = $this->consoltraffic($svs,time());
|
|
|
|
|
|
|
|
$google = GoogleChart::factory('ComboChart')
|
|
|
|
->stacked(TRUE);
|
|
|
|
|
|
|
|
foreach ($data['data'] as $key => $values)
|
|
|
|
$google->sdata(array('yl'=>$key),array($key=>$values));
|
|
|
|
|
|
|
|
$google->sdata(array('yr'=>'services'),array('services'=>$data['svs']));
|
|
|
|
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
|
|
$this->response->body($google->json());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function consoltraffic($svs,$date) {
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
foreach ($svs as $so) {
|
|
|
|
$c = array();
|
|
|
|
foreach ($so->plugin()->get_traffic_data_monthly($date) as $metric => $ma) {
|
|
|
|
foreach ($ma as $month => $traffic) {
|
|
|
|
// Only count the service once, not for each metric.
|
|
|
|
if (! isset($c[$month])) {
|
|
|
|
if (isset($data['svs'][$month]))
|
|
|
|
$data['svs'][$month] += 1;
|
|
|
|
else
|
|
|
|
$data['svs'][$month] = 1;
|
|
|
|
|
|
|
|
$c[$month] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['data'][$metric][$month]))
|
|
|
|
$data['data'][$metric][$month] += (int)$traffic;
|
|
|
|
else
|
|
|
|
$data['data'][$metric][$month] = (int)$traffic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($data['svs']);
|
|
|
|
foreach ($data['data'] as $metric => $details)
|
|
|
|
ksort($data['data'][$metric]);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a list of services that are expiring or have expired
|
|
|
|
*/
|
|
|
|
public function action_listexpiring() {
|
|
|
|
$svs = ORM::factory('Service')->list_expiring();
|
|
|
|
|
|
|
|
Sort::MAsort($svs,'expire()');
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('ADSL Services'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
2013-06-05 03:42:55 +00:00
|
|
|
50,
|
2013-10-10 02:44:53 +00:00
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
|
|
|
'service_name()'=>array('label'=>'Service'),
|
|
|
|
'expire(TRUE)'=>array('label'=>'Expires'),
|
|
|
|
'due(TRUE)'=>array('label'=>'Due'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>URL::link('user','service/view'),
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_listdomainservicesbysupplier() {
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
|
|
|
|
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(
|
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'plugin()->display("domain_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',
|
|
|
|
'form'=>URL::link('user','service/view'),
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_listdomainservicesbydnshost() {
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
|
|
|
|
Sort::MAsort($svs,'plugin()->service_plugin_host,name()');
|
|
|
|
|
|
|
|
$list = array();
|
|
|
|
|
|
|
|
foreach ($svs as $so)
|
|
|
|
$list[$so->plugin()->service_plugin_host->host_server_id][] = $so;
|
|
|
|
|
|
|
|
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(
|
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
|
|
|
'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',
|
|
|
|
'form'=>URL::link('user','service/view'),
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_listhostservicesbysupplier() {
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('HOST');
|
|
|
|
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(
|
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
|
|
|
'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',
|
|
|
|
'form'=>URL::link('user','service/view'),
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_listwebservices() {
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('WEB');
|
|
|
|
Sort::MAsort($svs,'name()');
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('SSL Services'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
$svs,
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>URL::link('user','service/view'),
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List services that need to be invoiced.
|
|
|
|
*/
|
|
|
|
public function action_listinvoicesoon() {
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Services to Invoice'),
|
|
|
|
'body'=>Table::display(
|
|
|
|
ORM::factory('Service')->list_invoicesoon(ORM::factory('Invoice')->config('GEN_SOON_DAYS')),
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
|
|
|
|
'service_name()'=>array('label'=>'Details'),
|
|
|
|
'recur_schedule'=>array('label'=>'Billing'),
|
|
|
|
'date_next_invoice'=>array('label'=>'Next Invoice'),
|
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
|
2013-06-04 11:50:41 +00:00
|
|
|
'charges()'=>array('label'=>'Charges','class'=>'right'),
|
2013-10-10 02:44:53 +00:00
|
|
|
'status'=>array('label'=>'Active'),
|
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>URL::link('user','service/view'),
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_update() {
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
$so = ORM::factory('Service',$id);
|
|
|
|
|
|
|
|
if (! $so->loaded())
|
|
|
|
HTTP::redirect('welcome/index');
|
|
|
|
|
|
|
|
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())
|
|
|
|
throw new Kohana_Exception('Failed to save updates to service data for record :record',array(':record'=>$so->id()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s %s:%s',_('Update Service'),$so->id(),$so->name()),
|
|
|
|
'body'=>View::factory($this->viewpath())
|
|
|
|
->set('so',$so)
|
|
|
|
->set('mediapath',Route::get('default/media'))
|
|
|
|
->set('plugin_form',$so->admin_update()),
|
|
|
|
));
|
|
|
|
|
|
|
|
// @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',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_view() {
|
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
|
|
|
|
|
|
|
$so = ORM::factory('Service',$id);
|
|
|
|
|
|
|
|
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) {
|
|
|
|
$this->template->content = 'Unauthorised or doesnt exist?';
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$doutput = $loutput = '';
|
|
|
|
|
|
|
|
$loutput .= View::factory($this->viewpath())
|
|
|
|
->set('so',$so);
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
if (! $iio->invoice->status) continue;
|
|
|
|
// @todo This hard coding of 3070 should be removed.
|
|
|
|
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;
|
|
|
|
|
2013-09-06 05:39:56 +00:00
|
|
|
$pdata = Period::details($iio->recurring_schedule,$a ? NULL : $iio->product->price_recurr_weekday,$bt,TRUE,TRUE);
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
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']))
|
|
|
|
HTTP::redirect(URL::link('admin','service/view/'.$so->id));
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('Transaction History for %s: %s',$so->id(),$so->name()),
|
|
|
|
'body'=>$loutput,
|
|
|
|
));
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('Transaction Debug for %s: %s',$so->id(),$so->name()),
|
|
|
|
'body'=>$doutput,
|
|
|
|
));
|
|
|
|
|
|
|
|
$output .= View::factory('service/user/view')
|
|
|
|
->set('so',$so);
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s: %s',$so->id(),$so->service_name()),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_adslstat() {
|
|
|
|
$output = '';
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
|
|
|
|
$stats = array();
|
|
|
|
// @todo This needs to be configurable.
|
|
|
|
$traffic = array(1000,2000,5000,10000,25000,50000,75000,100000);
|
|
|
|
$ts = 0;
|
|
|
|
|
|
|
|
foreach ($svs as $a=>$so) {
|
|
|
|
// Number of services
|
2013-06-17 12:47:44 +00:00
|
|
|
if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['c']))
|
|
|
|
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'] = 0;
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-06-17 12:47:44 +00:00
|
|
|
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['c']++;
|
2013-10-10 02:44:53 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2013-06-17 12:47:44 +00:00
|
|
|
if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a]))
|
|
|
|
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a] = 0;
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-06-17 12:47:44 +00:00
|
|
|
$stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a]++;
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|