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')
|
|
|
|
->title_icon('icon-wrench')
|
|
|
|
->body($this->add_edit());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_ajaxlist() {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
|
|
|
|
$result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'id','id',array('ACC %s: %s'=>array('id','name(TRUE)'))));
|
|
|
|
$result = Arr::merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'account_id','id',array('ACC %s: %s (%s)'=>array('account_id','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($_REQUEST['term'],'account_id','service->account_id',array('ACC %s: %s (%s)'=>array('service->account_id','service->account->name()','name()'))));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
|
|
$this->response->body(json_encode(array_values($result)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_ajaxlistservice() {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
if (isset($_REQUEST['key']) AND trim($_REQUEST['key']))
|
|
|
|
$result = Arr::merge($result,ORM::factory('Service')->list_autocomplete('','id','id',array('SVC %s: %s'=>array('id','service_name()')),array(array('account_id','=',$_REQUEST['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);
|
|
|
|
|
|
|
|
if ($_POST) {
|
|
|
|
// Entry updated
|
|
|
|
if ($co->values($_POST)->check() AND $co->save())
|
|
|
|
SystemMessage::factory()
|
|
|
|
->title('Record updated')
|
|
|
|
->type('success')
|
|
|
|
->body(_('Your Charge record has been recorded/updated.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
Script::factory()
|
|
|
|
->type('file')
|
|
|
|
->data('media/theme/bootstrap/vendor/datepicker/js/bootstrap-datepicker.js');
|
|
|
|
|
|
|
|
Style::factory()
|
|
|
|
->type('file')
|
|
|
|
->data('media/theme/bootstrap/vendor/datepicker/css/datepicker.css');
|
|
|
|
|
|
|
|
Script::factory()
|
|
|
|
->type('stdin')
|
|
|
|
->data('
|
|
|
|
$(document).ready(function() {
|
|
|
|
var nowTemp = new Date();
|
|
|
|
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
|
|
|
|
|
|
|
|
$("#date_charge_label").datepicker({
|
|
|
|
autoclose : true,
|
|
|
|
endDate : now,
|
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) {
|
|
|
|
$.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))
|
|
|
|
->title_icon('icon-wrench')
|
|
|
|
->body($this->add_edit($id,$output));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a list of invoices
|
|
|
|
*/
|
|
|
|
public function action_list() {
|
|
|
|
Block::factory()
|
|
|
|
->title('Customer Charges')
|
|
|
|
->title_icon('icon-th-list')
|
|
|
|
->body(Table::factory()
|
|
|
|
->page_items(50)
|
2013-10-14 00:26:08 +00:00
|
|
|
->data(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
|
|
|
->columns(array(
|
|
|
|
'id'=>'ID',
|
|
|
|
'date_charge'=>'Date',
|
2013-11-09 04:51:08 +00:00
|
|
|
'processed'=>'Processed',
|
2013-10-09 05:43:41 +00:00
|
|
|
'invoice_item->invoice_id'=>'Invoice',
|
2013-09-06 05:39:56 +00:00
|
|
|
'sweep_type'=>'Sweep',
|
|
|
|
'quantity'=>'Quantity',
|
|
|
|
'amount'=>'Amount',
|
2013-10-09 05:43:41 +00:00
|
|
|
'total(TRUE)'=>'Total',
|
2013-09-06 05:39:56 +00:00
|
|
|
'description'=>'Description',
|
|
|
|
'service_id'=>'Service',
|
|
|
|
'account->accnum()'=>'Cust ID',
|
|
|
|
'account->name()'=>'Customer',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'id'=>array('url'=>URL::link('reseller','charge/edit/')),
|
2013-10-09 05:43:41 +00:00
|
|
|
'invoice_item->invoice_id'=>array('url'=>URL::link('user','invoice/view/')),
|
2013-09-06 05:39:56 +00:00
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|