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')
|
2016-08-10 06:07:00 +00:00
|
|
|
->title_icon($this->icon)
|
2013-06-19 09:26:07 +00:00
|
|
|
->body($this->add_edit());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_addbulk() {
|
|
|
|
$output = '';
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post() AND $this->request->post('payer')) {
|
|
|
|
$c = Kohana::classname('Payment_Bulk_'.$this->request->post('payer'));
|
2013-06-19 09:26:07 +00:00
|
|
|
$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
|
2016-08-10 06:07:00 +00:00
|
|
|
$po = ORM::factory('Payment',$this->request->post('pid'));
|
2013-06-19 09:26:07 +00:00
|
|
|
|
|
|
|
// Get all our other outstanding invoices
|
2016-08-10 06:07:00 +00:00
|
|
|
foreach (ORM::factory('Account',$this->request->post('key'))->invoices_due() as $io) {
|
2013-06-19 09:26:07 +00:00
|
|
|
$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();
|
|
|
|
|
2016-08-10 06:07:00 +00:00
|
|
|
if ($this->request->query('term')) {
|
2016-08-03 06:20:25 +00:00
|
|
|
$result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($this->request->query('term'),'id','id',array('ACC %s: %s'=>array('id','name()'))));
|
|
|
|
$result = Arr::merge($result,ORM::factory('Invoice')->list_autocomplete($this->request->query('term'),'id','account_id',array('INV %s: %s'=>array('id','account->name()'))));
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
|
|
$this->response->body(json_encode(array_values($result)));
|
|
|
|
}
|
|
|
|
|
2013-11-27 00:22:20 +00:00
|
|
|
public function action_edit() {
|
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->type('form-horizontal')
|
|
|
|
->title(sprintf('%s: %s',_('View Payments Received'),$id))
|
2016-08-10 06:07:00 +00:00
|
|
|
->title_icon($this->icon)
|
2013-11-27 00:22:20 +00:00
|
|
|
->body($this->add_edit($id,$output));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2016-08-25 03:14:08 +00:00
|
|
|
$this->meta->title = $po->loaded() ? 'Payment: '.$po->refnum(TRUE) : 'A|Payment Add';
|
2016-08-10 06:07:00 +00:00
|
|
|
|
2013-12-02 04:16:28 +00:00
|
|
|
if ($this->request->post()) {
|
|
|
|
$po->values($this->request->post());
|
|
|
|
|
2013-10-10 02:44:53 +00:00
|
|
|
// Update our invoice payment items
|
2016-08-03 06:20:25 +00:00
|
|
|
if (is_array($this->request->post('payment_item')) AND count($this->request->post('payment_item')))
|
|
|
|
foreach ($this->request->post('payment_item') as $k=>$v) {
|
2013-06-19 09:26:07 +00:00
|
|
|
$pio = $po->payment_item;
|
|
|
|
$pio->invoice_id = $k;
|
2013-06-05 03:42:55 +00:00
|
|
|
$pio = $po->add_item($pio);
|
2013-06-19 09:26:07 +00:00
|
|
|
|
2013-06-05 03:42:55 +00:00
|
|
|
$pio->alloc_amt = is_numeric($v) ? $v : 0;
|
2013-06-19 09:26:07 +00:00
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
$this->save($po);
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 09:26:07 +00:00
|
|
|
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
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|