205 lines
5.6 KiB
PHP
205 lines
5.6 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class provides payment capabilities.
|
|
*
|
|
* @package OSB
|
|
* @subpackage Payment
|
|
* @category Controllers/Admin
|
|
* @author Deon George
|
|
* @copyright (c) 2010 Open Source Billing
|
|
* @license http://dev.osbill.net/license.html
|
|
*/
|
|
class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
|
|
protected $secure_actions = array(
|
|
'add'=>TRUE,
|
|
'list'=>TRUE,
|
|
'autocomplete'=>FALSE,
|
|
'autoitemlist'=>FALSE,
|
|
);
|
|
|
|
public function action_autocomplete() {
|
|
// We are only available via an ajax call.
|
|
if (! Request::current()->is_ajax())
|
|
die();
|
|
|
|
$return = array();
|
|
|
|
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
|
|
$return += ORM::factory('account')->list_autocomplete($_REQUEST['term']);
|
|
$return += ORM::factory('invoice')->list_autocomplete($_REQUEST['term'],'account_id');
|
|
}
|
|
|
|
$this->auto_render = FALSE;
|
|
$this->response->headers('Content-Type','application/json');
|
|
$this->response->body(json_encode(array_values($return)));
|
|
}
|
|
|
|
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('payment/admin/item/list_head');
|
|
$this->auto_render = FALSE;
|
|
|
|
$i = 0;
|
|
if (isset($_REQUEST['pid']))
|
|
foreach (ORM::factory('payment_item')->where('payment_id','=',$_REQUEST['pid'])->find_all() as $pio)
|
|
$output .= View::factory('payment/admin/item/list_body')
|
|
->set('trc',$i++%2 ? 'odd' : 'even')
|
|
->set('pio',$pio)
|
|
->set('io',$pio->invoice);
|
|
|
|
foreach (ORM::factory('account',$_REQUEST['key'])->invoices_due() as $io)
|
|
$output .= View::factory('payment/admin/item/list_body')
|
|
->set('trc',$i++%2 ? 'odd' : 'even')
|
|
->set('io',$io);
|
|
|
|
// @todo Need the JS to add up the payment allocation before submission
|
|
$output .= View::factory('payment/admin/item/list_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'=>'admin/payment/add/'),
|
|
'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'=>'admin/payment/add',
|
|
)),
|
|
));
|
|
}
|
|
|
|
public function action_add() {
|
|
$output = '';
|
|
|
|
if (! $id = $this->request->param('id')) {
|
|
if (isset($_POST['id']) AND is_array($_POST['id']))
|
|
Table::post('payment_view','id');
|
|
|
|
list($id,$output) = Table::page('payment_view');
|
|
|
|
} else {
|
|
$id = $this->request->param('id');
|
|
}
|
|
|
|
$po = ORM::factory('payment',$id);
|
|
|
|
if ($_POST) {
|
|
if (isset($_POST['payment_item']) AND count($_POST['payment_item'])) {
|
|
foreach ($_POST['payment_item'] as $k=>$v) {
|
|
$pio = $po->add_item();
|
|
$pio->invoice_id = $k;
|
|
$pio->alloc_amt = $v;
|
|
}
|
|
}
|
|
|
|
if ($po->changed()) {
|
|
// Entry updated
|
|
if (! $po->values($_POST)->check() OR ! $po->save())
|
|
throw new Kohana_Exception('Unable to save payment');
|
|
else
|
|
SystemMessage::add(array(
|
|
'title'=>'Payment Recorded',
|
|
'type'=>'info',
|
|
'body'=>'Payment successfully recorded.',
|
|
));
|
|
}
|
|
}
|
|
|
|
$output .= Form::open();
|
|
$output .= View::factory('payment/admin/add')
|
|
->set('po',$po);;
|
|
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
|
|
$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=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::site('admin/payment/autocomplete').'",
|
|
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::site('admin/payment/autoitemlist').'",
|
|
timeout: 2000,
|
|
error: function(x) {
|
|
alert("Failed to submit");
|
|
},
|
|
success: function(data) {
|
|
$("div[id=items]").replaceWith(data);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});'
|
|
));
|
|
|
|
if ($po->loaded()) {
|
|
Script::add(array('type'=>'stdin','data'=>'
|
|
$(document).ready(function() {
|
|
$("div[id=items]").load("'.URL::site('admin/payment/autoitemlist').'", {key: "'.$po->account_id.'", pid: "'.$po->id.'" });
|
|
});'
|
|
));
|
|
}
|
|
|
|
Block::add(array(
|
|
'title'=>_('Add Payments Received'),
|
|
'body'=>$output,
|
|
));
|
|
}
|
|
}
|
|
?>
|