Improvements to payment and other misc items
This commit is contained in:
@@ -9,229 +9,195 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
|
||||
class Controller_Admin_Payment extends Controller_Payment {
|
||||
protected $secure_actions = array(
|
||||
'add'=>TRUE,
|
||||
'addbulk'=>TRUE,
|
||||
'list'=>TRUE,
|
||||
'view'=>TRUE,
|
||||
'ajaxlist'=>FALSE,
|
||||
'autoitemlist'=>FALSE,
|
||||
'ajaxitemlist'=>TRUE,
|
||||
'ajaxlist'=>TRUE,
|
||||
'edit'=>TRUE,
|
||||
);
|
||||
|
||||
public function action_add() {
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title('Add/View Payment')
|
||||
->title_icon('icon-wrench')
|
||||
->body($this->add_edit());
|
||||
}
|
||||
|
||||
public function action_addbulk() {
|
||||
$output = '';
|
||||
|
||||
if ($_POST AND isset($_POST['payer'])) {
|
||||
$c = Kohana::classname('Payment_Bulk_'.$_POST['payer']);
|
||||
$o = new $c();
|
||||
|
||||
$output .= (! $_FILES) ? $o->form() : $o->process();
|
||||
|
||||
// We dont know what sort of payment type yet
|
||||
} else {
|
||||
$output .= Form::open();
|
||||
$output .= Form::select('payer',$this->templates());
|
||||
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
|
||||
$output .= Form::close();
|
||||
}
|
||||
|
||||
Block::factory()
|
||||
->title('Bulk Payments Received')
|
||||
->title_icon('icon-share')
|
||||
->body($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return rendered invoices paid by this payment, and outstanding invoices
|
||||
*/
|
||||
public function action_ajaxitemlist() {
|
||||
$invoices = array();
|
||||
|
||||
// Get our invoices paid by this payment ID
|
||||
$po = ORM::factory('Payment',isset($_REQUEST['pid']) ? $_REQUEST['pid'] : NULL);
|
||||
|
||||
// Get all our other outstanding invoices
|
||||
foreach (ORM::factory('Account',$_REQUEST['key'])->invoices_due() as $io) {
|
||||
$pio = $po->payment_item;
|
||||
$pio->invoice_id = $io->id;
|
||||
|
||||
$po->add_item($pio);
|
||||
}
|
||||
|
||||
$this->response->body(View::factory('payment/admin/ajaxitemlist')
|
||||
->set('o',$po));
|
||||
}
|
||||
|
||||
public function action_ajaxlist() {
|
||||
$result = array();
|
||||
|
||||
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
|
||||
$result += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
|
||||
$result += ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'account_id');
|
||||
$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('Invoice')->list_autocomplete($_REQUEST['term'],'id','account_id',array('INV %s: %s'=>array('id','account->name(TRUE)'))));
|
||||
}
|
||||
|
||||
$this->auto_render = FALSE;
|
||||
$this->response->headers('Content-Type','application/json');
|
||||
$this->response->body(json_encode(array_values($result)));
|
||||
}
|
||||
|
||||
public function action_autoitemlist() {
|
||||
// We are only available via an ajax call.
|
||||
if (! Request::current()->is_ajax() OR ! isset($_REQUEST['key']) OR ! trim($_REQUEST['key']))
|
||||
die();
|
||||
|
||||
$output = View::factory($this->viewpath().'/head');
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
$i = 0;
|
||||
$list = array();
|
||||
if (isset($_REQUEST['pid']))
|
||||
foreach (ORM::factory('Payment',$_REQUEST['pid'])->items() as $pio) {
|
||||
$output .= View::factory($this->viewpath().'/body')
|
||||
->set('trc',$i++%2 ? 'odd' : 'even')
|
||||
->set('pio',$pio)
|
||||
->set('io',$pio->invoice);
|
||||
|
||||
// Remember the invoices we have listed
|
||||
array_push($list,$pio->invoice_id);
|
||||
}
|
||||
|
||||
foreach (ORM::factory('Account',$_REQUEST['key'])->invoices_due() as $io)
|
||||
// Only list invoices not yet listed
|
||||
if (! in_array($io->id,$list))
|
||||
$output .= View::factory($this->viewpath().'/body')
|
||||
->set('trc',$i++%2 ? 'odd' : 'even')
|
||||
->set('pio',ORM::factory('Payment_Item'))
|
||||
->set('io',$io);
|
||||
|
||||
// @todo Need the JS to add up the payment allocation before submission
|
||||
$output .= View::factory($this->viewpath().'/foot')
|
||||
->set('trc',$i++%2 ? 'odd' : 'even');
|
||||
|
||||
$this->response->body($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a list of invoices
|
||||
*/
|
||||
public function action_list() {
|
||||
Block::add(array(
|
||||
'title'=>_('Customer Payments'),
|
||||
'body'=>Table::display(
|
||||
ORM::factory('Payment')->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>URL::link('admin','payment/view/')),
|
||||
'date_payment'=>array('label'=>'Date'),
|
||||
'account->accnum()'=>array('class'=>'right'),
|
||||
'account->name()'=>array('label'=>'Account'),
|
||||
'checkout->display("name")'=>array('label'=>'Method'),
|
||||
'total_amt'=>array('label'=>'Total','class'=>'right'),
|
||||
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
|
||||
'invoicelist()'=>array('label'=>'Invoices'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>URL::link('admin','payment/view'),
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
private function add_view($id=NULL,$output='') {
|
||||
private function add_edit($id=NULL,$output='') {
|
||||
$po = ORM::factory('Payment',$id);
|
||||
|
||||
if ($_POST) {
|
||||
// Update our invoice payment items
|
||||
if (isset($_POST['payment_item']) AND count($_POST['payment_item']))
|
||||
foreach ($_POST['payment_item'] as $k=>$v)
|
||||
$po->add_item($k)->alloc_amt = is_numeric($v) ? $v : 0;
|
||||
foreach ($_POST['payment_item'] as $k=>$v) {
|
||||
$pio = $po->payment_item;
|
||||
$pio->invoice_id = $k;
|
||||
$pio->alloc_amt = is_numeric($v) ? $v : 0;
|
||||
|
||||
$po->add_item($pio);
|
||||
}
|
||||
|
||||
// Entry updated
|
||||
if ($po->values($_POST)->check() AND $po->save())
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Payment Recorded',
|
||||
'type'=>'info',
|
||||
'body'=>'Payment successfully recorded.',
|
||||
));
|
||||
SystemMessage::factory()
|
||||
->title('Record updated')
|
||||
->type('success')
|
||||
->body(_('Your Payment record has been recorded/updated.'));
|
||||
}
|
||||
|
||||
$output .= Form::open();
|
||||
$output .= View::factory('payment/admin/add_view')
|
||||
->set('po',$po);;
|
||||
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
|
||||
$output .= Form::close();
|
||||
Script::factory()
|
||||
->type('file')
|
||||
->data('media/theme/bootstrap/vendor/datepicker/js/bootstrap-datepicker.js');
|
||||
|
||||
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::factory()
|
||||
->type('file')
|
||||
->data('media/theme/bootstrap/vendor/datepicker/css/datepicker.css');
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'media/js/jquery.ui/css/smoothness/jquery-ui-1.8.16.custom.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);
|
||||
|
||||
Script::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'media/js/jquery-ui-1.8.16.custom.min.js',
|
||||
));
|
||||
$("#date_payment_label").datepicker({
|
||||
autoclose : true,
|
||||
endDate : now,
|
||||
format : "dd-mm-yyyy",
|
||||
todayBtn : true,
|
||||
}).on("hide",function(ev) {
|
||||
$("input[name=date_payment]").val(ev.date.valueOf());
|
||||
});
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("input[name=date_payment]").datepicker({
|
||||
dateFormat: "@",
|
||||
showOtherMonths: true,
|
||||
selectOtherMonths: true,
|
||||
showButtonPanel: true,
|
||||
beforeShow: function(data) {
|
||||
if (data.value)
|
||||
data.value = data.value*1000;
|
||||
},
|
||||
onClose: function(data) {
|
||||
$("input[name=date_payment]").val(data/1000);
|
||||
}
|
||||
});
|
||||
$("input[name=account_id]").autocomplete({
|
||||
source: "'.URL::link('admin','payment/ajaxlist',TRUE).'",
|
||||
minLength: 2,
|
||||
change: function(event,ui) {
|
||||
// Send the request and update sub category dropdown
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
data: "key="+$(this).val(),
|
||||
dataType: "html",
|
||||
cache: false,
|
||||
url: "'.URL::link('admin','payment/autoitemlist',TRUE).'",
|
||||
timeout: 2000,
|
||||
error: function(x) {
|
||||
alert("Failed to submit");
|
||||
},
|
||||
success: function(data) {
|
||||
$("div[id=items]").replaceWith(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});'
|
||||
));
|
||||
$("input[name=account_id_label]").typeahead({
|
||||
minLength: 2,
|
||||
source: function (query,process) {
|
||||
search("a/payment/ajaxlist",query,process);
|
||||
},
|
||||
|
||||
if ($po->loaded()) {
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("div[id=items]").load("'.URL::link('admin','payment/autoitemlist',TRUE).'", {key: "'.$po->account_id.'", pid: "'.$po->id.'" });
|
||||
});'
|
||||
));
|
||||
}
|
||||
matcher: function () { return true; },
|
||||
|
||||
return $output;
|
||||
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: "html",
|
||||
cache: false,
|
||||
url: "'.URL::link('admin','payment/ajaxitemlist',TRUE).'",
|
||||
timeout: 2000,
|
||||
error: function(x) {
|
||||
alert("Failed to submit");
|
||||
},
|
||||
success: function(data) {
|
||||
$("div[id=items]").replaceWith(data);
|
||||
}
|
||||
});
|
||||
|
||||
return item;
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
');
|
||||
|
||||
if ($po->loaded())
|
||||
Script::factory()
|
||||
->type('stdin')
|
||||
->data('
|
||||
$(document).ready(function() {
|
||||
$("div[id=items]").load("'.URL::link('admin','payment/ajaxitemlist',TRUE).'", {key: "'.$po->account_id.'", pid: "'.$po->id.'" });
|
||||
});
|
||||
');
|
||||
|
||||
return View::factory('payment/admin/add_edit')
|
||||
->set('o',$po);
|
||||
}
|
||||
|
||||
public function action_add() {
|
||||
Block::add(array(
|
||||
'title'=>_('Add Payments Received'),
|
||||
'body'=>$this->add_view(),
|
||||
));
|
||||
}
|
||||
|
||||
public function action_view() {
|
||||
public function action_edit() {
|
||||
list($id,$output) = Table::page(__METHOD__);
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',_('View Payments Received'),$id),
|
||||
'body'=>$this->add_view($id,$output),
|
||||
));
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title(sprintf('%s: %s',_('View Payments Received'),$id))
|
||||
->title_icon('icon-wrench')
|
||||
->body($this->add_edit($id,$output));
|
||||
}
|
||||
|
||||
public function action_addbulk() {
|
||||
// @todo This needs to come from the DB.
|
||||
$supported = array(
|
||||
'ezypay'=>'Ezypay',
|
||||
);
|
||||
/**
|
||||
* List our availale Buik Payment Methods
|
||||
*/
|
||||
private function templates() {
|
||||
$template_path = 'classes/Payment/Bulk';
|
||||
$result = array();
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($_POST AND isset($_POST['payer'])) {
|
||||
$c = sprintf('Payment_Bulk_%s',ucfirst($_POST['payer']));
|
||||
$o = new $c();
|
||||
|
||||
if (! $_FILES) {
|
||||
$output .= $o->form();
|
||||
|
||||
} else {
|
||||
|
||||
$output .= $o->process();
|
||||
}
|
||||
|
||||
// We dont know what sort of payment type yet
|
||||
} else {
|
||||
$output .= Form::open();
|
||||
$output .= Form::select('payer',$supported);
|
||||
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
|
||||
$output .= Form::close();
|
||||
foreach (Kohana::list_files($template_path) as $file => $path) {
|
||||
$file = strtoupper(preg_replace('/.php$/','',str_replace($template_path.'/','',$file)));
|
||||
$result[$file] = $file;
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Bulk Payments Received'),
|
||||
'body'=>$output,
|
||||
));
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user