Removed redundant functions, some Standardisation work
This commit is contained in:
@@ -10,5 +10,6 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Charge extends Controller_TemplateDefault {
|
||||
protected $icon = 'fa fa-dollar';
|
||||
}
|
||||
?>
|
||||
|
@@ -21,8 +21,8 @@ class Controller_Reseller_Charge extends Controller_Charge {
|
||||
public function action_add() {
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title('Add/View Charge')
|
||||
->title_icon('fa fa-wrench')
|
||||
->title('New Charge')
|
||||
->title_icon($this->icon)
|
||||
->body($this->add_edit());
|
||||
}
|
||||
|
||||
@@ -54,72 +54,11 @@ class Controller_Reseller_Charge extends Controller_Charge {
|
||||
private function add_edit($id=NULL,$output='') {
|
||||
$co = ORM::factory('Charge',$id);
|
||||
|
||||
$this->meta->title = sprintf('Charge: %s (%s)',$co->name(),$co->account->name());
|
||||
$this->meta->title = $co->loaded() ? sprintf('Charge: %s (%s)',$co->name(),$co->account->name()) : 'New Charge';
|
||||
|
||||
if ($this->request->post() AND $co->values($this->request->post())->changed() AND (! $this->save($co)))
|
||||
$co->reload();
|
||||
|
||||
Script::factory()
|
||||
->type('file')
|
||||
->data('media/theme/bootstrap/js/bootstrap.datepicker.js');
|
||||
|
||||
Style::factory()
|
||||
->type('file')
|
||||
->data('media/theme/bootstrap/css/bootstrap.datepicker.css');
|
||||
|
||||
Script::factory()
|
||||
->type('stdin')
|
||||
->data('
|
||||
$(document).ready(function() {
|
||||
$("#date_charge_label").datepicker({
|
||||
autoclose : true,
|
||||
endDate : new Date(),
|
||||
todayHighlight: true,
|
||||
format : "dd-M-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) {
|
||||
$("select[name=service_id]").empty();
|
||||
$.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);
|
||||
}
|
||||
@@ -130,7 +69,7 @@ $(document).ready(function() {
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title(sprintf('%s: %s',_('View Charges'),$id))
|
||||
->title_icon('fa fa-wrench')
|
||||
->title_icon($this->icon)
|
||||
->body($this->add_edit($id,$output));
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Charge extends ORM_OSB implements Invoicable {
|
||||
class Model_Charge extends ORM {
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array(),
|
||||
'product'=>array(),
|
||||
@@ -80,9 +80,6 @@ class Model_Charge extends ORM_OSB implements Invoicable {
|
||||
}
|
||||
|
||||
/** REQUIRED ABSTRACT METHODS **/
|
||||
public function namesub($variable=NULL) {
|
||||
return sprintf('%d@%2.2f - %s (%s)',$this->quantity,$this->amount,($this->description ? ' '.$this->description : '').($this->attributes ? ' ['.join('|',$this->attributes).']' : ''),$this->display('date_charge'));
|
||||
}
|
||||
|
||||
/** LOCAL METHODS **/
|
||||
|
||||
@@ -100,26 +97,9 @@ class Model_Charge extends ORM_OSB implements Invoicable {
|
||||
return $iio;
|
||||
}
|
||||
|
||||
public function invoice_item($item_type) {
|
||||
switch ($item_type) {
|
||||
case 5:
|
||||
return sprintf('%s (%s x %s%s%s) %s',
|
||||
StaticList_ItemType::get($item_type),
|
||||
$this->quantity,
|
||||
$this->display('amount'),
|
||||
($this->description ? ' '.$this->description : ''),
|
||||
($this->attributes ? ' ['.join('|',$this->attributes).']' : ''),
|
||||
$this->display('date_charge'));
|
||||
|
||||
default:
|
||||
return sprintf('%s %s',StaticList_ItemType::get($item_type),$this->display('date_charge')).($this->description ? ' ('.$this->description.')' : '');
|
||||
}
|
||||
public function namesub($variable=NULL) {
|
||||
return sprintf('%d@%2.2f - %s (%s)',$this->quantity,$this->amount,($this->description ? ' '.$this->description : '').($this->attributes ? ' ['.join('|',$this->attributes).']' : ''),$this->display('date_charge'));
|
||||
}
|
||||
|
||||
public function xtitle() {
|
||||
return $this->invoice_item(5);
|
||||
}
|
||||
|
||||
public function total($format=FALSE) {
|
||||
$result = $this->quantity * $this->amount;
|
||||
|
||||
|
@@ -1,39 +1,56 @@
|
||||
<div class="col-md-11">
|
||||
<div class="col-md-12">
|
||||
<fieldset>
|
||||
<legend>Charge Details</legend>
|
||||
|
||||
<label for="date_charge_label">Date Charge</label>
|
||||
<div class="input-group col-md-3">
|
||||
<input type="text" id="date_charge_label" value="<?php echo $o->display('date_charge'); ?>" class="form-control" placeholder="Date Charge">
|
||||
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-calendar"></i></span>
|
||||
</div>
|
||||
<?php echo Form::hidden('date_charge',$o->date_charge); ?>
|
||||
|
||||
<?php echo Form::input('account_id_label',$o->account->name(),array('label'=>'Account','placeholder'=>'Account','data-provide'=>'typeahead')); ?>
|
||||
<?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('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('label'=>'Quantity','placeholder'=>'Quantity')); ?>
|
||||
<?php echo Form::input('amount',$o->amount,array('label'=>'Amount','placeholder'=>'Total',)); ?>
|
||||
<?php echo StaticList_YesNo::form('taxable',is_null($o->taxable) ? TRUE : $o->taxable,FALSE,array('label'=>'Taxable')); ?>
|
||||
<?php echo Form::input('description',$o->description,array('label'=>'Description','placeholder'=>'Any notes about this charge?')); ?>
|
||||
|
||||
<?php
|
||||
echo View::factory('field/date')->set('data',['field'=>'date_charge','value'=>$o->date_charge ? $o->date_charge : time(),'text'=>'Date Charge','enddate'=>'new Date()']);
|
||||
echo View::factory('field/account')->set('data',['field'=>'account_id','value'=>$o->account_id,'text'=>'Account','name'=>sprintf('%s: %s',$o->account->refnum(),$o->account->name()),'ajaxurl'=>URL::link('reseller','charge/ajaxlist')]);
|
||||
echo View::factory('field/select')->set('data',['field'=>'service_id','value'=>$o->account_id ? $o->account->service->list_select() : [],'text'=>'Service','default'=>$o->service_id,'class'=>'col-md-6']);
|
||||
echo View::factory('field/select')->set('data',['field'=>'sweep_type','value'=>Arr::merge([''=>''],StaticList_SweepType::table()),'text'=>'Sweep','default'=>is_null($o->sweep_type) ? 6 : $o->sweep_type,'class'=>'col-md-2']);
|
||||
echo View::factory('field/select')->set('data',['field'=>'type','value'=>Arr::merge([''=>''],StaticList_ItemType::table()),'text'=>'Item Type','default'=>$o->type,'class'=>'col-md-2']);
|
||||
echo View::factory('field/number')->set('data',['field'=>'quantity','value'=>$o->quantity,'text'=>'Quantity','class'=>'col-md-2']);
|
||||
echo View::factory('field/money')->set('data',['field'=>'amount','value'=>$o->amount,'text'=>'Amount','class'=>'col-md-2']);
|
||||
echo View::factory('field/select')->set('data',['field'=>'taxable','value'=>StaticList_YesNo::table(),'text'=>'Taxable','default'=>$o->taxable,'class'=>'col-md-1']);
|
||||
echo View::factory('field/text')->set('data',['field'=>'description','value'=>$o->description,'text'=>'Description','class'=>'col-md-5']);
|
||||
?>
|
||||
<!-- @todo Use JS to dynamically add more lines as required -->
|
||||
<?php $i=0; if ($o->attributes) foreach ($o->attributes as $key => $value) :
|
||||
echo Form::input("attributes[$key]",$value,array('label'=>$key));
|
||||
$i++;
|
||||
endforeach ?>
|
||||
<?php for ($i=$i;$i<10;$i++) :
|
||||
echo Form::input("attributes[$i]",isset($o->attributes[$i]) ? $o->attributes[$i] : '',array('label'=>'Attributes'));
|
||||
echo Form::input("attributes[$i]",isset($o->attributes[$i]) ? $o->attributes[$i] : '',array('label'=>'Attributes'));
|
||||
endfor ?>
|
||||
</fieldset>
|
||||
|
||||
<div class="row">
|
||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||
<button type="button" class="btn">Cancel</button>
|
||||
</div>
|
||||
</div> <!-- /col-md-11 -->
|
||||
<?php echo View::factory('field/submit'); ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
Script::factory()
|
||||
->type('stdin')
|
||||
->data('
|
||||
$(document).ready(function() {
|
||||
$("input[name=account_id]").change(function(){
|
||||
// Send the request and update sub category dropdown
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
data: "key="+$(this).val(),
|
||||
dataType: "json",
|
||||
cache: false,
|
||||
url: "'.URL::link('reseller','charge/ajaxlistservice',TRUE).'",
|
||||
timeout: 2000,
|
||||
error: function(x) {
|
||||
alert("Failed to submit");
|
||||
},
|
||||
success: function(data) {
|
||||
$("select[name=service_id]").empty();
|
||||
$.each(data, function(i, j){
|
||||
var row = "<option value=\"" + j.value + "\">" + j.label + "</option>";
|
||||
$(row).appendTo("select[name=service_id]");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});');
|
||||
?>
|
||||
|
Reference in New Issue
Block a user