Open Source Billing
This commit is contained in:
133
modules/charge/classes/Controller/Admin/Charge.php
Normal file
133
modules/charge/classes/Controller/Admin/Charge.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?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'=>'js/jquery.ui/css/smoothness/jquery-ui-1.8.16.custom.css',
|
||||
));
|
||||
|
||||
Script::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'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,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
45
modules/charge/classes/Model/Charge.php
Normal file
45
modules/charge/classes/Model/Charge.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides charge item capabilities.
|
||||
*
|
||||
* @package Charge
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Charge extends ORM_OSB {
|
||||
// Charge doesnt use the update column
|
||||
protected $_updated_column = FALSE;
|
||||
protected $_serialize_column = array(
|
||||
'attributes',
|
||||
);
|
||||
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array(),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'date_orig'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'amount'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Render some details for specific calls, eg: invoice
|
||||
*/
|
||||
public function details($type) {
|
||||
switch ($type) {
|
||||
case 'invoice_detail_items':
|
||||
return array('Other Charge'=>sprintf('%s (%s@%s)',$this->description,$this->quantity,Currency::display($this->amount)));
|
||||
|
||||
default:
|
||||
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
37
modules/charge/views/charge/admin/add.php
Normal file
37
modules/charge/views/charge/admin/add.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<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>
|
Reference in New Issue
Block a user