Updated charge, Invoice improvements and other minor fixes
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides charge capabilities.
|
||||
*
|
||||
* @package Charge
|
||||
* @category Controllers/Admin
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Admin_Charge extends Controller_TemplateDefault_Admin {
|
||||
protected $secure_actions = array(
|
||||
'add'=>TRUE,
|
||||
'list'=>TRUE,
|
||||
'auditinvoiceitems'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Show a list of invoices
|
||||
*/
|
||||
public function action_list() {
|
||||
Block::add(array(
|
||||
'title'=>_('Customer Charges'),
|
||||
'body'=>Table::display(
|
||||
ORM::factory('Charge')->where('sweep_type','>=',0)->order_by('date_orig DESC')->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>URL::link('user','charge/view/')),
|
||||
'date_orig'=>array('label'=>'Date'),
|
||||
'sweep_type'=>array('label'=>'Sweep'),
|
||||
'status'=>array('label'=>'Status'),
|
||||
'quantity'=>array('label'=>'Quantity','class'=>'right'),
|
||||
'amount'=>array('label'=>'Total','class'=>'right'),
|
||||
'description'=>array('label'=>'Description'),
|
||||
'service_id'=>array('label'=>'Service'),
|
||||
'account->accnum()'=>array('label'=>'Cust ID'),
|
||||
'account->name()'=>array('label'=>'Customer'),
|
||||
'attributes'=>array('label'=>'Attributes'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>URL::link('user','charge/view'),
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
public function action_add() {
|
||||
$output = '';
|
||||
|
||||
$co = ORM::factory('Charge');
|
||||
|
||||
if ($_POST) {
|
||||
// Trim down our attributes
|
||||
if (is_array($_POST['attributes']))
|
||||
foreach ($_POST['attributes'] as $k=>$v)
|
||||
if (! trim($v))
|
||||
unset($_POST['attributes'][$k]);
|
||||
|
||||
if ($co->values($_POST)->check()) {
|
||||
$co->status=0;
|
||||
|
||||
// Entry updated
|
||||
if (! $co->save())
|
||||
throw new Kohana_Exception('Unable to save charge');
|
||||
}
|
||||
}
|
||||
|
||||
$output .= Form::open();
|
||||
$output .= View::factory($this->viewpath());
|
||||
$output .= Form::submit('submit','submit');
|
||||
$output .= Form::close();
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'stdin',
|
||||
'data'=>'.ui-autocomplete-loading { background: white url("'.URL::site('media/img/ui-anim_basic_16x16.gif').'") right center no-repeat; }'
|
||||
));
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'media/js/jquery.ui/css/smoothness/jquery-ui-1.8.16.custom.css',
|
||||
));
|
||||
|
||||
Script::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'media/js/jquery-ui-1.8.16.custom.min.js',
|
||||
));
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("input[name=account_id]").autocomplete({
|
||||
source: "'.URL::link('admin','account/ajaxlist').'",
|
||||
minLength: 2,
|
||||
change: function(event,ui) {
|
||||
// Send the request and update sub category dropdown
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
data: "aid="+$(this).val(),
|
||||
dataType: "json",
|
||||
cache: false,
|
||||
url: "'.URL::link('admin','service/ajaxlist',TRUE).'",
|
||||
timeout: 2000,
|
||||
error: function() {
|
||||
alert("Failed to submit");
|
||||
},
|
||||
success: function(data) {
|
||||
// Clear all options from sub category select
|
||||
$("select[name=service_id] option").remove();
|
||||
|
||||
// Prepopulate a blank
|
||||
var row = "<option value=\"\"> </option>";
|
||||
$(row).appendTo("select[name=service_id]");
|
||||
|
||||
// Fill sub category select
|
||||
$.each(data, function(i, j){
|
||||
var row = "<option value=\"" + j.value + "\">" + j.label + "</option>";
|
||||
$(row).appendTo("select[name=service_id]");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});'
|
||||
));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Add Customer Charges'),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
14
modules/charge/classes/Controller/Charge.php
Normal file
14
modules/charge/classes/Controller/Charge.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides item charging management
|
||||
*
|
||||
* @package Charge
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Charge extends Controller_TemplateDefault {
|
||||
}
|
||||
?>
|
171
modules/charge/classes/Controller/Reseller/Charge.php
Normal file
171
modules/charge/classes/Controller/Reseller/Charge.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?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,
|
||||
format : "dd-mm-yyyy",
|
||||
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)
|
||||
->data(ORM::factory('Charge')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->order_by('id DESC')->find_all())
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'date_orig'=>'Processed',
|
||||
'date_charge'=>'Date',
|
||||
'sweep_type'=>'Sweep',
|
||||
'status'=>'Status',
|
||||
'quantity'=>'Quantity',
|
||||
'amount'=>'Amount',
|
||||
'description'=>'Description',
|
||||
'service_id'=>'Service',
|
||||
'account->accnum()'=>'Cust ID',
|
||||
'account->name()'=>'Customer',
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('reseller','charge/edit/')),
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -10,21 +10,25 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Charge extends ORM_OSB {
|
||||
// Charge doesnt use the update column
|
||||
protected $_updated_column = FALSE;
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array(),
|
||||
);
|
||||
|
||||
protected $_nullifempty = array(
|
||||
'attributes',
|
||||
);
|
||||
|
||||
protected $_serialize_column = array(
|
||||
'attributes',
|
||||
);
|
||||
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array(),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'date_orig'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'date_charge'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'amount'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
|
@@ -1,37 +0,0 @@
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td>Account</td>
|
||||
<td><?php echo Form::input('account_id',''); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service</td>
|
||||
<td><?php echo Form::select('service_id',array('NONE')); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sweep</td>
|
||||
<td><?php echo StaticList_SweepType::form('sweep_type',6); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Quantity</td>
|
||||
<td><?php echo Form::input('quantity',NULL); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Amount</td>
|
||||
<td><?php echo Form::input('amount',NULL); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Taxable</td>
|
||||
<td><?php echo StaticList_YesNo::form('taxable',true); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Description</td>
|
||||
<td><?php echo Form::input('description',NULL); ?></td>
|
||||
</tr>
|
||||
<!-- @todo This to be dynamic -->
|
||||
<?php for($x=0;$x<10;$x++) { ?>
|
||||
<tr>
|
||||
<td>Attributes</td>
|
||||
<td><?php echo Form::input('attributes['.$x.']',NULL); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
31
modules/charge/views/charge/reseller/add_edit.php
Normal file
31
modules/charge/views/charge/reseller/add_edit.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<div class="row">
|
||||
<div class="span9 offset1">
|
||||
|
||||
<fieldset>
|
||||
<legend>Charge Details</legend>
|
||||
|
||||
<div class="input-append date" id="date_charge_label">
|
||||
<?php echo Form::input('date_charge_label',$o->display('date_charge'),array('class'=>'span2','label'=>'Date of Charge','add-on'=>'<i class="icon-calendar"></i>','disabled')); ?>
|
||||
</div>
|
||||
|
||||
<?php echo Form::hidden('date_charge',$o->date_charge); ?>
|
||||
<?php echo Form::input('account_id_label',$o->account->name(),array('class'=>'span5','label'=>'Account','placeholder'=>'Account','data-provide'=>'typeahead','required')); ?>
|
||||
<?php echo Form::hidden('account_id',$o->account_id); ?>
|
||||
<?php echo Form::select('service_id',$o->account_id ? $o->account->service->list_select() : array(),$o->service_id,array('class'=>'span5','label'=>'Service')); ?>
|
||||
<?php echo StaticList_SweepType::form('sweep_type',is_null($o->sweep_type) ? 6 : $o->sweep_type,FALSE,array('label'=>'Sweep')); ?>
|
||||
<?php echo StaticList_ItemType::form('type',is_null($o->type) ? 6 : $o->type,FALSE,array('label'=>'Item Type')); ?>
|
||||
|
||||
<?php echo Form::input('quantity',$o->quantity,array('class'=>'span1','label'=>'Quantity','placeholder'=>'Quantity')); ?>
|
||||
<?php echo Form::input('amount',$o->amount,array('class'=>'span1','label'=>'Amount','placeholder'=>'Total',)); ?>
|
||||
<?php echo StaticList_YesNo::form('taxable',is_null($o->taxable) ? TRUE : $o->taxable,FALSE,array('label'=>'Taxable','class'=>'span1')); ?>
|
||||
<?php echo Form::input('description',$o->description,array('class'=>'span5','label'=>'Description','placeholder'=>'Any notes about this charge?')); ?>
|
||||
|
||||
<!-- @todo Use JS to dynamically add more lines as required -->
|
||||
<?php for ($i=0;$i<10;$i++) :
|
||||
echo Form::input("attributes[$i]",isset($o->attributes[$i]) ? $o->attributes[$i] : "",array('class'=>'span5','label'=>'Attributes'));
|
||||
endfor ?>
|
||||
</fieldset>
|
||||
|
||||
<?php echo Form::button('submit','Submit',array('class'=>'btn btn-primary')); ?>
|
||||
</div> <!-- /span -->
|
||||
</div> <!-- /row -->
|
Reference in New Issue
Block a user