2013-10-10 02:44:53 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides payment capabilities.
|
|
|
|
*
|
|
|
|
* @package Payment
|
|
|
|
* @category Controllers/Admin
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-06-19 09:26:07 +00:00
|
|
|
class Controller_Admin_Payment extends Controller_Payment {
|
2013-10-10 02:44:53 +00:00
|
|
|
protected $secure_actions = array(
|
|
|
|
'add'=>TRUE,
|
|
|
|
'addbulk'=>TRUE,
|
2013-06-19 09:26:07 +00:00
|
|
|
'ajaxitemlist'=>TRUE,
|
|
|
|
'ajaxlist'=>TRUE,
|
|
|
|
'edit'=>TRUE,
|
2013-10-10 02:44:53 +00:00
|
|
|
);
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2013-10-10 02:44:53 +00:00
|
|
|
public function action_ajaxlist() {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
|
2013-06-19 09:26:07 +00:00
|
|
|
$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)'))));
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
|
|
$this->response->body(json_encode(array_values($result)));
|
|
|
|
}
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
private function add_edit($id=NULL,$output='') {
|
2013-10-10 02:44:53 +00:00
|
|
|
$po = ORM::factory('Payment',$id);
|
|
|
|
|
|
|
|
if ($_POST) {
|
|
|
|
// Update our invoice payment items
|
|
|
|
if (isset($_POST['payment_item']) AND count($_POST['payment_item']))
|
2013-06-19 09:26:07 +00:00
|
|
|
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);
|
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
// Entry updated
|
|
|
|
if ($po->values($_POST)->check() AND $po->save())
|
2013-06-19 09:26:07 +00:00
|
|
|
SystemMessage::factory()
|
|
|
|
->title('Record updated')
|
|
|
|
->type('success')
|
|
|
|
->body(_('Your Payment record has been recorded/updated.'));
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
Script::factory()
|
|
|
|
->type('file')
|
|
|
|
->data('media/theme/bootstrap/vendor/datepicker/js/bootstrap-datepicker.js');
|
|
|
|
|
|
|
|
Style::factory()
|
|
|
|
->type('file')
|
|
|
|
->data('media/theme/bootstrap/vendor/datepicker/css/datepicker.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);
|
|
|
|
|
|
|
|
$("#date_payment_label").datepicker({
|
|
|
|
autoclose : true,
|
|
|
|
endDate : now,
|
|
|
|
format : "dd-mm-yyyy",
|
|
|
|
todayBtn : true,
|
|
|
|
}).on("hide",function(ev) {
|
2013-07-05 06:11:37 +00:00
|
|
|
$("input[name=date_payment]").val(ev.date.valueOf()/1000);
|
2013-06-19 09:26:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$("input[name=account_id_label]").typeahead({
|
|
|
|
minLength: 2,
|
|
|
|
source: function (query,process) {
|
|
|
|
search("a/payment/ajaxlist",query,process);
|
|
|
|
},
|
|
|
|
|
|
|
|
matcher: function () { return true; },
|
|
|
|
|
|
|
|
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);
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
public function action_edit() {
|
2013-10-10 02:44:53 +00:00
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
Block::factory()
|
|
|
|
->type('form-horizontal')
|
|
|
|
->title(sprintf('%s: %s',_('View Payments Received'),$id))
|
|
|
|
->title_icon('icon-wrench')
|
|
|
|
->body($this->add_edit($id,$output));
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
/**
|
|
|
|
* List our availale Buik Payment Methods
|
|
|
|
*/
|
|
|
|
private function templates() {
|
|
|
|
$template_path = 'classes/Payment/Bulk';
|
|
|
|
$result = array();
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
foreach (Kohana::list_files($template_path) as $file => $path) {
|
|
|
|
$file = strtoupper(preg_replace('/.php$/','',str_replace($template_path.'/','',$file)));
|
|
|
|
$result[$file] = $file;
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
return $result;
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|