2013-09-06 05:39:56 +00:00
|
|
|
<?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('Add/View Charge')
|
2016-07-25 05:47:18 +00:00
|
|
|
->title_icon('fa fa-wrench')
|
2013-09-06 05:39:56 +00:00
|
|
|
->body($this->add_edit());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_ajaxlist() {
|
|
|
|
$result = array();
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
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()'))));
|
2013-09-06 05:39:56 +00:00
|
|
|
|
|
|
|
foreach (array('Service_Plugin_Adsl','Service_Plugin_Domain','Service_Plugin_Host') as $o)
|
2016-08-03 06:20:25 +00:00
|
|
|
$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()'))));
|
2013-09-06 05:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
|
|
$this->response->body(json_encode(array_values($result)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_ajaxlistservice() {
|
|
|
|
$result = array();
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
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')))));
|
2013-09-06 05:39:56 +00:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
2016-07-29 01:19:30 +00:00
|
|
|
$this->meta->title = sprintf('Charge: %s (%s)',$co->name(),$co->account->name());
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post() AND $co->values($this->request->post())->changed() AND (! $this->save($co)))
|
2013-11-22 04:36:50 +00:00
|
|
|
$co->reload();
|
2013-09-06 05:39:56 +00:00
|
|
|
|
|
|
|
Script::factory()
|
|
|
|
->type('file')
|
2016-07-25 05:47:18 +00:00
|
|
|
->data('media/theme/bootstrap/js/bootstrap.datepicker.js');
|
2013-09-06 05:39:56 +00:00
|
|
|
|
|
|
|
Style::factory()
|
|
|
|
->type('file')
|
2016-07-25 05:47:18 +00:00
|
|
|
->data('media/theme/bootstrap/css/bootstrap.datepicker.css');
|
2013-09-06 05:39:56 +00:00
|
|
|
|
|
|
|
Script::factory()
|
|
|
|
->type('stdin')
|
|
|
|
->data('
|
|
|
|
$(document).ready(function() {
|
|
|
|
$("#date_charge_label").datepicker({
|
|
|
|
autoclose : true,
|
2013-11-28 06:41:34 +00:00
|
|
|
endDate : new Date(),
|
2016-07-25 05:47:18 +00:00
|
|
|
todayHighlight: true,
|
2013-11-09 04:51:08 +00:00
|
|
|
format : "dd-M-yyyy",
|
2013-09-06 05:39:56 +00:00
|
|
|
todayBtn : true,
|
|
|
|
}).on("hide",function(ev) {
|
|
|
|
$("input[name=date_charge]").val(ev.date.valueOf()/1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("input[name=account_id_label]").typeahead({
|
|
|
|
minLength: 2,
|
|
|
|
source: function (query,process) {
|
|
|
|
search("'.URL::link('reseller','charge/ajaxlist').'",query,process);
|
|
|
|
},
|
|
|
|
|
|
|
|
matcher: function () { return true; },
|
|
|
|
|
|
|
|
updater: function (item) {
|
|
|
|
$("input[name=account_id]").val(users[item]);
|
|
|
|
|
|
|
|
// Send the request and update sub category dropdown
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
data: "key="+users[item],
|
|
|
|
dataType: "json",
|
|
|
|
cache: false,
|
|
|
|
url: "'.URL::link('reseller','charge/ajaxlistservice',TRUE).'",
|
|
|
|
timeout: 2000,
|
|
|
|
error: function(x) {
|
|
|
|
alert("Failed to submit");
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2016-08-03 04:00:51 +00:00
|
|
|
$("select[name=service_id]").empty();
|
2013-09-06 05:39:56 +00:00
|
|
|
$.each(data, function(i, j){
|
|
|
|
var row = "<option value=\"" + j.value + "\">" + j.label + "</option>";
|
|
|
|
$(row).appendTo("select[name=service_id]");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
');
|
|
|
|
|
|
|
|
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))
|
2016-07-25 05:47:18 +00:00
|
|
|
->title_icon('fa fa-wrench')
|
2013-09-06 05:39:56 +00:00
|
|
|
->body($this->add_edit($id,$output));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a list of invoices
|
|
|
|
*/
|
|
|
|
public function action_list() {
|
2016-07-29 13:04:34 +00:00
|
|
|
$this->meta->title = 'R|Customer Charges';
|
2016-07-29 01:19:30 +00:00
|
|
|
|
2013-09-06 05:39:56 +00:00
|
|
|
Block::factory()
|
|
|
|
->title('Customer Charges')
|
2016-07-25 05:47:18 +00:00
|
|
|
->title_icon('fa fa-list')
|
2016-07-29 13:04:34 +00:00
|
|
|
->body(View::factory('charge/list')->set('o',ORM::factory('Charge')->where_authorised($this->ao)->where('void','is',NULL)->order_by('id','DESC')->find_all()));
|
2013-09-06 05:39:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|