This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/charge/classes/Controller/Admin/Charge.php

134 lines
3.6 KiB
PHP
Raw Normal View History

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides charge capabilities.
*
2013-03-19 22:35:19 +00:00
* @package Charge
* @category Controllers/Admin
* @author Deon George
2013-03-19 22:35:19 +00:00
* @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(
2012-11-09 23:13:57 +00:00
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 = '';
2012-11-09 23:13:57 +00:00
$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) {
2012-08-01 12:43:33 +00:00
// 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).'",
2012-08-01 12:43:33 +00:00
timeout: 2000,
error: function() {
alert("Failed to submit");
},
success: function(data) {
2012-08-01 12:43:33 +00:00
// Clear all options from sub category select
$("select[name=service_id] option").remove();
// Prepopulate a blank
2012-08-01 12:43:33 +00:00
var row = "<option value=\"\">&nbsp;</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>";
2012-08-01 12:43:33 +00:00
$(row).appendTo("select[name=service_id]");
});
}
});
}
});
});'
));
Block::add(array(
'title'=>_('Add Customer Charges'),
'body'=>$output,
));
}
}
?>