2011-12-20 05:46:10 +00:00
|
|
|
<?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,
|
2012-01-11 08:59:20 +00:00
|
|
|
'addbulk'=>TRUE,
|
2011-12-20 05:46:10 +00:00
|
|
|
'list'=>TRUE,
|
2011-12-21 01:39:21 +00:00
|
|
|
'view'=>TRUE,
|
2012-10-07 04:15:34 +00:00
|
|
|
'ajaxlist'=>FALSE,
|
2011-12-20 05:46:10 +00:00
|
|
|
'autoitemlist'=>FALSE,
|
|
|
|
);
|
|
|
|
|
2012-10-07 04:15:34 +00:00
|
|
|
public function action_ajaxlist() {
|
2011-12-20 05:46:10 +00:00
|
|
|
$return = array();
|
|
|
|
|
|
|
|
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
|
2012-11-09 23:13:57 +00:00
|
|
|
$return += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
|
|
|
|
$return += ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'account_id');
|
2011-12-20 05:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
$output = View::factory($this->viewpath().'/head');
|
2011-12-20 05:46:10 +00:00
|
|
|
$this->auto_render = FALSE;
|
|
|
|
|
|
|
|
$i = 0;
|
2011-12-29 02:52:24 +00:00
|
|
|
$list = array();
|
2011-12-20 05:46:10 +00:00
|
|
|
if (isset($_REQUEST['pid']))
|
2012-11-09 23:13:57 +00:00
|
|
|
foreach (ORM::factory('Payment',$_REQUEST['pid'])->items() as $pio) {
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath().'/body')
|
2011-12-20 05:46:10 +00:00
|
|
|
->set('trc',$i++%2 ? 'odd' : 'even')
|
|
|
|
->set('pio',$pio)
|
|
|
|
->set('io',$pio->invoice);
|
|
|
|
|
2011-12-29 02:52:24 +00:00
|
|
|
// Remember the invoices we have listed
|
|
|
|
array_push($list,$pio->invoice_id);
|
|
|
|
}
|
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
foreach (ORM::factory('Account',$_REQUEST['key'])->invoices_due() as $io)
|
2011-12-29 02:52:24 +00:00
|
|
|
// Only list invoices not yet listed
|
|
|
|
if (! in_array($io->id,$list))
|
|
|
|
$output .= View::factory($this->viewpath().'/body')
|
|
|
|
->set('trc',$i++%2 ? 'odd' : 'even')
|
2012-11-09 23:13:57 +00:00
|
|
|
->set('pio',ORM::factory('Payment_Item'))
|
2011-12-29 02:52:24 +00:00
|
|
|
->set('io',$io);
|
2011-12-20 05:46:10 +00:00
|
|
|
|
|
|
|
// @todo Need the JS to add up the payment allocation before submission
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath().'/foot')
|
2011-12-20 05:46:10 +00:00
|
|
|
->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(
|
2012-11-09 23:13:57 +00:00
|
|
|
ORM::factory('Payment')->find_all(),
|
2011-12-20 05:46:10 +00:00
|
|
|
25,
|
|
|
|
array(
|
2011-12-21 01:39:21 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>'admin/payment/view/'),
|
2011-12-20 05:46:10 +00:00
|
|
|
'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',
|
2011-12-21 01:39:21 +00:00
|
|
|
'form'=>'admin/payment/view',
|
2011-12-20 05:46:10 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
private function add_view($id=NULL,$output='') {
|
2012-11-09 23:13:57 +00:00
|
|
|
$po = ORM::factory('Payment',$id);
|
2011-12-20 05:46:10 +00:00
|
|
|
|
|
|
|
if ($_POST) {
|
2011-12-29 02:52:24 +00:00
|
|
|
// 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;
|
2011-12-20 05:46:10 +00:00
|
|
|
|
2011-12-22 10:20:19 +00:00
|
|
|
// Entry updated
|
2011-12-29 02:52:24 +00:00
|
|
|
if ($po->values($_POST)->check() AND $po->save())
|
2011-12-22 10:20:19 +00:00
|
|
|
SystemMessage::add(array(
|
|
|
|
'title'=>'Payment Recorded',
|
|
|
|
'type'=>'info',
|
|
|
|
'body'=>'Payment successfully recorded.',
|
|
|
|
));
|
2011-12-20 05:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$output .= Form::open();
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory('payment/admin/add_view')
|
2011-12-20 05:46:10 +00:00
|
|
|
->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({
|
2012-10-07 04:15:34 +00:00
|
|
|
source: "'.URL::site('admin/payment/ajaxlist').'",
|
2011-12-20 05:46:10 +00:00
|
|
|
minLength: 2,
|
|
|
|
change: function(event,ui) {
|
2011-12-21 01:39:21 +00:00
|
|
|
// 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");
|
|
|
|
},
|
2011-12-20 05:46:10 +00:00
|
|
|
success: function(data) {
|
|
|
|
$("div[id=items]").replaceWith(data);
|
2011-12-21 01:39:21 +00:00
|
|
|
}
|
|
|
|
});
|
2011-12-20 05:46:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});'
|
|
|
|
));
|
|
|
|
|
|
|
|
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.'" });
|
|
|
|
});'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_add() {
|
2011-12-20 05:46:10 +00:00
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Add Payments Received'),
|
2011-12-21 01:39:21 +00:00
|
|
|
'body'=>$this->add_view(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_view() {
|
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s: %s',_('View Payments Received'),$id),
|
|
|
|
'body'=>$this->add_view($id,$output),
|
2011-12-20 05:46:10 +00:00
|
|
|
));
|
|
|
|
}
|
2012-01-11 08:59:20 +00:00
|
|
|
|
|
|
|
public function action_addbulk() {
|
2012-03-30 04:13:01 +00:00
|
|
|
// @todo This needs to come from the DB.
|
2012-01-11 08:59:20 +00:00
|
|
|
$supported = array(
|
|
|
|
'ezypay'=>'Ezypay',
|
|
|
|
);
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
if ($_POST AND isset($_POST['payer'])) {
|
2012-11-09 23:13:57 +00:00
|
|
|
$c = sprintf('Payment_Bulk_%s',ucfirst($_POST['payer']));
|
2012-01-11 08:59:20 +00:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Bulk Payments Received'),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
2011-12-20 05:46:10 +00:00
|
|
|
}
|
|
|
|
?>
|