This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/service/classes/Controller/Admin/Service.php

263 lines
7.3 KiB
PHP
Raw Normal View History

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
*/
class Controller_Admin_Service extends Controller_Service {
2013-10-10 02:44:53 +00:00
protected $secure_actions = array(
'add'=>TRUE,
'ajaxaddplugin'=>TRUE,
'edit'=>TRUE,
2013-10-10 02:44:53 +00:00
'listdomainservicesbydnshost'=>TRUE,
'listhostservicesbysupplier'=>TRUE,
'view'=>TRUE,
);
public function action_add() {
if ($this->request->post() AND $so=$this->add_edit() AND $so->loaded())
HTTP::redirect(URL::link('admin','service/edit/'.$so->id));
$this->meta->title = 'New Service';
Block::factory()
->type('form-horizontal')
->title('Add New Service')
->title_icon($this->icon)
->body(View::factory('service/admin/add')->set('o',ORM::factory('Service')));
}
public function action_ajaxaddplugin() {
$po = ORM::factory('Product',$this->request->query('key'));
if (! $po->loaded()) {
$output = __('Unable to find product :key',array(':key'=>$this->request->query('key')));
} else {
$output = $po->plugin()->render_order();
}
$this->template->content = $output;
}
public function action_edit() {
list($id,$output) = Table::page(__METHOD__);
$so = $this->request->post() ? $this->add_edit($id) : ORM::factory('Service',$id);
if (! $so->loaded())
HTTP::redirect('welcome/index');
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
2013-11-28 06:41:34 +00:00
$("#service_connect_date_label").datepicker({
autoclose : true,
format : "dd-M-yyyy",
todayBtn : true,
}).on("hide",function(ev) {
$("input[id=service_connect_date]").val(ev.date.valueOf()/1000);
});
$("#service_contract_date_label").datepicker({
autoclose : true,
format : "dd-M-yyyy",
todayBtn : true,
}).on("hide",function(ev) {
$("input[id=service_contract_date]").val(ev.date.valueOf()/1000);
});
});
');
Block::factory()
->type('form-horizontal')
->title(sprintf('%s: %s %s',_('Update Service'),$id,$so->name()))
->title_icon('fa fa-wrench')
->body(View::factory('service/admin/edit')
->set('o',$so)
->set('plugin_form',$so->plugin_edit())
);
}
2013-10-10 02:44:53 +00:00
public function action_listdomainservicesbydnshost() {
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
2013-11-28 06:41:34 +00:00
Sort::MAsort($svs,'plugin()->host,name()');
2013-10-10 02:44:53 +00:00
$list = array();
foreach ($svs as $so)
2013-11-28 06:41:34 +00:00
$list[$so->plugin()->host->host_server_id][] = $so;
2013-10-10 02:44:53 +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(
'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')),
'service_name()'=>array('label'=>'Details'),
2013-11-28 06:41:34 +00:00
'plugin()->registrar->id'=>array('label'=>'SID'),
'plugin()->registrar->name'=>array('label'=>'Supplier'),
2013-10-10 02:44:53 +00:00
'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');
2013-11-28 06:41:34 +00:00
Sort::MAsort($svs,'plugin()->host,name()');
2013-10-10 02:44:53 +00:00
$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_view() {
list($id,$output) = Table::page(__METHOD__);
$so = ORM::factory('Service',$id);
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account))
throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
2013-10-10 02:44:53 +00:00
$doutput = $loutput = '';
2013-11-09 04:51:08 +00:00
$loutput .= View::factory('service/admin/view')
->set('o',$so);
2013-10-10 02:44:53 +00:00
// Validate the transactions
$bt = NULL;
2013-11-28 06:41:34 +00:00
$pr = TRUE; // Next entry is a pro-rata
2013-10-10 02:44:53 +00:00
foreach ($so->transactions()->where('item_type','=',0)->find_all() as $iio) {
// @todo This hard coding of 3070 should be removed.
2013-11-28 06:41:34 +00:00
// $xsid=197;
// if (($iio->service_id == $xsid AND $iio->invoice_id < 3070) OR in_array($iio->id,array(960))) continue;
if (! $iio->invoice->status OR $iio->void)
2013-10-10 02:44:53 +00:00
continue;
2013-11-28 06:41:34 +00:00
if ($iio->quantity < 0 OR $iio->price_base < 0) {
$bt = $iio->date_start;
$pr = TRUE;
continue;
}
2013-10-10 02:44:53 +00:00
if (is_null($bt))
$bt = $iio->date_start;
2013-11-28 06:41:34 +00:00
$a = ($iio->invoice_id > 4000 OR $iio->product->prod_plugin_file == 'ADSL') ? FALSE : TRUE;
$pdata = Period::details($iio->recurring_schedule,$a ? NULL : $iio->product->price_recurr_weekday,$bt,TRUE,$iio->product->price_recurr_strict);
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']) {
2014-08-25 04:41:07 +00:00
$doutput .= sprintf('%s: Set start_time: %s [%s]<br/>',$iio->id,Site::Date($pdata['start_time']),$pdata['start_time']);
2013-10-10 02:44:53 +00:00
$iio->date_start=$pdata['start_time'];
}
2013-11-28 06:41:34 +00:00
if (! $pr AND $iio->date_stop != $pdata['end_time']) {
2014-08-25 04:41:07 +00:00
$doutput .= sprintf('%s: Set end_time: %s [%s] <br/>',$iio->id,Site::Date($pdata['end_time']),$pdata['end_time']);
2013-11-28 06:41:34 +00:00
$iio->date_stop = $pdata['end_time'];
2013-10-10 02:44:53 +00:00
}
2013-11-28 06:41:34 +00:00
$bt = ($pr ? $iio->date_stop : $pdata['end_time'])+86400;
2014-08-25 04:41:07 +00:00
// $doutput .= sprintf('%s: BT now: %s (%s) [%s]<br/>',$iio->id,Site::Date($bt),Site::Date($pdata['end_time']),$bt);
2013-10-10 02:44:53 +00:00
break;
default:
$doutput .= sprintf('%s: %s Not handled',$iio->id,$iio->recurring_schedule);
}
2013-11-28 06:41:34 +00:00
$pr = FALSE;
2013-10-10 02:44:53 +00:00
//$doutput .= '<br/>';
2013-11-28 06:41:34 +00:00
if (($x=$this->request->query('go')) AND $x==1)
2013-10-10 02:44:53 +00:00
$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->refnum(TRUE),$so->name()),
2013-10-10 02:44:53 +00:00
'body'=>$loutput,
));
Block::add(array(
'title'=>sprintf('Transaction Debug for %s: %s',$so->refnum(TRUE),$so->name()),
2013-10-10 02:44:53 +00:00
'body'=>$doutput,
));
$output .= View::factory('service/user/view')
2013-11-09 04:51:08 +00:00
->set('o',$so);
2013-10-10 02:44:53 +00:00
Block::add(array(
'title'=>sprintf('%s: %s',$so->refnum(TRUE),$so->name()),
2013-10-10 02:44:53 +00:00
'body'=>$output,
));
}
private function add_edit($id=NULL,$output='') {
$so = ORM::factory('Service',$id);
if ($_POST) {
if ($so->values($this->request->post())->changed() AND ! ($this->save($so)))
$so->reload();
// Do we have plugin data to save as well
if ($this->request->post('plugin') AND $so->loaded()) {
$x = $so->plugin();
if ($x->values(Arr::merge(array('service_id'=>$so->id),$this->request->post('plugin')))->changed())
$this->save($x);
}
}
return $so;
}
2013-10-10 02:44:53 +00:00
}
?>