93 lines
3.0 KiB
PHP
93 lines
3.0 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class provides charge capabilities.
|
|
*
|
|
* @package Charge
|
|
* @category Controllers/Reseller
|
|
* @author Deon George
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
* @license http://dev.osbill.net/license.html
|
|
*/
|
|
class Controller_Reseller_Charge extends Controller_Charge {
|
|
protected $secure_actions = array(
|
|
'add'=>TRUE,
|
|
'ajaxlist'=>TRUE,
|
|
'ajaxlistservice'=>TRUE,
|
|
'edit'=>TRUE,
|
|
'list'=>TRUE,
|
|
);
|
|
|
|
public function action_add() {
|
|
Block::factory()
|
|
->type('form-horizontal')
|
|
->title('New Charge')
|
|
->title_icon($this->icon)
|
|
->body($this->add_edit());
|
|
}
|
|
|
|
public function action_ajaxlist() {
|
|
$result = array();
|
|
|
|
if ($this->request->query('term')) {
|
|
$result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($this->request->query('term'),'id','id',array('%s: %s'=>array('refnum()','name()'))));
|
|
$result = Arr::merge($result,ORM::factory('Service')->list_autocomplete($this->request->query('term'),'account_id','id',array('%s: %s (%s)'=>array('account->refnum()','account->name()','name()'))));
|
|
|
|
foreach (array('Service_Plugin_Adsl','Service_Plugin_Domain','Service_Plugin_Host') as $o)
|
|
$result = Arr::merge($result,ORM::factory($o)->list_autocomplete($this->request->query('term'),'account_id','service->account_id',array('%s: %s (%s)'=>array('service->account->refnum()','service->account->name()','service->name()'))));
|
|
}
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
$this->response->body(json_encode(array_values($result)));
|
|
}
|
|
|
|
public function action_ajaxlistservice() {
|
|
$result = array();
|
|
|
|
if ($this->request->query('key'))
|
|
$result = Arr::merge($result,ORM::factory('Service')->list_autocomplete('','id','id',array('%s: %s'=>array('refnum(TRUE)','name()')),array(array('account_id','=',$this->request->query('key')))));
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
$this->response->body(json_encode(array_values($result)));
|
|
}
|
|
|
|
private function add_edit($id=NULL,$output='') {
|
|
$co = ORM::factory('Charge',$id);
|
|
|
|
$this->meta->title = $co->loaded() ? sprintf('Charge: %s (%s)',$co->name(),$co->account->name()) : 'New Charge';
|
|
|
|
// New charges
|
|
if (! $co->loaded())
|
|
$co->active = TRUE;
|
|
|
|
if ($this->request->post() AND $co->values($this->request->post())->changed() AND (! $this->save($co)))
|
|
$co->reload();
|
|
|
|
return View::factory('charge/reseller/add_edit')
|
|
->set('o',$co);
|
|
}
|
|
|
|
public function action_edit() {
|
|
list($id,$output) = Table::page(__METHOD__);
|
|
|
|
Block::factory()
|
|
->type('form-horizontal')
|
|
->title(sprintf('%s: %s',_('View Charges'),$id))
|
|
->title_icon($this->icon)
|
|
->body($this->add_edit($id,$output));
|
|
}
|
|
|
|
/**
|
|
* Show a list of invoices
|
|
*/
|
|
public function action_list() {
|
|
$this->meta->title = 'R|Customer Charges';
|
|
|
|
Block::factory()
|
|
->title('Customer Charges')
|
|
->title_icon('fa fa-list')
|
|
->body(View::factory('charge/list')->set('o',ORM::factory('Charge')->where_authorised($this->ao)->where_active()->order_by('id','DESC')->find_all()));
|
|
}
|
|
}
|
|
?>
|