Improvements to payment and other misc items
This commit is contained in:
parent
1caeed6606
commit
3499776ddc
@ -65,7 +65,7 @@ class Config extends Kohana_Config {
|
||||
}
|
||||
|
||||
public static function date($date) {
|
||||
return is_null($date) ? ' ' : date(Company::instance()->date_format(),$date);
|
||||
return is_null($date) ? '' : date(Company::instance()->date_format(),$date);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,8 +89,8 @@ class Controller_Admin_Welcome extends Controller_Welcome {
|
||||
'account->accnum()'=>array('label'=>'Num'),
|
||||
'account->name()'=>array('label'=>'Account'),
|
||||
'account->display("status")'=>array('label'=>'Active'),
|
||||
'id'=>array('label'=>'ID','url'=>URL::link('admin','payment/view/')),
|
||||
'total_amt'=>array('label'=>'Total','class'=>'right'),
|
||||
'id'=>array('label'=>'ID','url'=>URL::link('admin','payment/edit/')),
|
||||
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
|
||||
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
|
||||
),
|
||||
array('show_other'=>'balance()')),
|
||||
|
@ -29,7 +29,6 @@ class Controller_User_Search extends Controller_Search {
|
||||
$result = Arr::merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'url','service_id',array('SVC %s: %s'=>array('service_id','service_name()')),array(),array('urlprefix'=>'u/service/view/')));
|
||||
}
|
||||
|
||||
$this->auto_render = FALSE;
|
||||
$this->response->headers('Content-Type','application/json');
|
||||
$this->response->body(json_encode(array_values($result)));
|
||||
}
|
||||
|
@ -34,13 +34,14 @@ abstract class Kohana extends Kohana_Core {
|
||||
if (! in_array($dir,$dirs) OR PHP_SAPI === 'cli')
|
||||
return parent::find_file($dir,$file,$ext,$array);
|
||||
|
||||
$prefixes = array('');
|
||||
|
||||
// Our search order.
|
||||
$prefixes = array(
|
||||
sprintf('site/%s/%s/',Config::siteid(),Config::theme()),
|
||||
sprintf('site/%s/',Config::siteid()),
|
||||
Config::theme().'/',
|
||||
'',
|
||||
);
|
||||
if (! preg_match('/^theme\//',$file)) {
|
||||
array_unshift($prefixes,Config::theme().'/');
|
||||
array_unshift($prefixes,sprintf('site/%s/',Config::siteid()));
|
||||
array_unshift($prefixes,sprintf('site/%s/%s/',Config::siteid(),Config::theme()));
|
||||
}
|
||||
|
||||
foreach ($prefixes as $p)
|
||||
if ($x = parent::find_file($dir,$p.$file,$ext,$array))
|
||||
|
@ -13,6 +13,7 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'user_tokens' => array('model' => 'user_token'),
|
||||
'service_billing' => array('far_key'=>'id'),
|
||||
'email_log' => array('far_key'=>'id'),
|
||||
'group' => array('through' => 'account_group'),
|
||||
'invoice' => array('far_key'=>'id'),
|
||||
@ -132,10 +133,7 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
* Return an account name
|
||||
*/
|
||||
public function name($withcompany=FALSE) {
|
||||
if ($withcompany)
|
||||
return sprintf('%s %s%s',$this->first_name,$this->last_name,$this->company ? sprintf(' (%s)',$this->company) : '');
|
||||
else
|
||||
return sprintf('%s %s',$this->first_name,$this->last_name);
|
||||
return trim(sprintf('%s %s',$this->first_name,$this->last_name).(($withcompany AND $this->company) ? sprintf(' (%s)',$this->company) : ''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,17 @@ abstract class ORM extends Kohana_ORM {
|
||||
if (! in_array($this->_table_name,ORM::$no_site_id_tables))
|
||||
$this->where($this->_object_name.'.site_id','=',Company::instance()->site());
|
||||
|
||||
// Ensure we Cache our queries
|
||||
$caching = FALSE;
|
||||
foreach ($this->_db_pending as $method)
|
||||
if ($method['name'] == 'cached') {
|
||||
$caching = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (! $caching)
|
||||
$this->cached(Kohana::$config->load('cache.orm.'.$this->_table_name));
|
||||
|
||||
return parent::_build($type);
|
||||
}
|
||||
|
||||
|
34
application/config/cache.php
Normal file
34
application/config/cache.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* OSB Caching
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage System
|
||||
* @category Configuration
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
|
||||
return array(
|
||||
'orm'=>array(
|
||||
'account'=>10,
|
||||
'account_log'=>86400,
|
||||
'account_group'=>60,
|
||||
'country'=>86400,
|
||||
'currency'=>86400,
|
||||
'invoice'=>60,
|
||||
'invoice_item'=>60,
|
||||
'invoice_item_tax'=>60,
|
||||
'service'=>60,
|
||||
'group'=>86400,
|
||||
'language'=>86400,
|
||||
'payment'=>60,
|
||||
'payment_item'=>60,
|
||||
'module'=>86400,
|
||||
'module_method'=>86400,
|
||||
'setup'=>86400,
|
||||
),
|
||||
);
|
||||
?>
|
@ -0,0 +1,16 @@
|
||||
var search = _.debounce(function(url,query,process){
|
||||
$.get(site_url+url,{term: query},function(data) {
|
||||
users = {};
|
||||
userLabels = [];
|
||||
|
||||
_.each(data,function(item,ix,list) {
|
||||
if (_.contains(users,item.label))
|
||||
item.label = item.label + ' #' + item.value;
|
||||
|
||||
userLabels.push(item.label);
|
||||
users[item.label] = item.value;
|
||||
});
|
||||
|
||||
process(userLabels);
|
||||
})
|
||||
}, 300);
|
@ -2,7 +2,7 @@ $(document).ready(function() {
|
||||
$("input[name=search-query]").typeahead({
|
||||
minLength: 2,
|
||||
source: function (query,process) {
|
||||
search (query,process);
|
||||
search('u/search/ajaxlist',query,process);
|
||||
},
|
||||
|
||||
matcher: function () { return true; },
|
||||
@ -12,21 +12,3 @@ $(document).ready(function() {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
var search = _.debounce(function( query, process ){
|
||||
$.get(site_url+"/u/search/ajaxlist", {term: query}, function (data) {
|
||||
users = {};
|
||||
userLabels = [];
|
||||
|
||||
_.each( data, function( item, ix, list ){
|
||||
if ( _.contains( users, item.label ) ){
|
||||
item.label = item.label + ' #' + item.value;
|
||||
}
|
||||
|
||||
userLabels.push( item.label );
|
||||
users[ item.label ] = item.value;
|
||||
});
|
||||
|
||||
process( userLabels );
|
||||
})
|
||||
}, 300);
|
||||
|
@ -135,7 +135,7 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
|
||||
|
||||
}
|
||||
|
||||
$po->add_item($cio->module_item)->alloc_amt = $cno->data['mc_gross_'.$c];
|
||||
$po->old_add_item($cio->module_item)->alloc_amt = $cno->data['mc_gross_'.$c];
|
||||
|
||||
break;
|
||||
|
||||
|
@ -215,7 +215,7 @@ class Export_Plugin_Quicken extends Export_Plugin {
|
||||
|
||||
$payment['NAME'] = $po->account->company ? $po->account->company : sprintf('%s %s',$po->account->last_name,$po->account->first_name);
|
||||
|
||||
$payment['MEMO'] = sprintf('Payment for invoice(s) %s (%s)',implode(':',$po->invoices()),$po->checkout->name);
|
||||
$payment['MEMO'] = sprintf('Payment for invoice(s) %s (%s)',$po->invoicelist(),$po->checkout->name);
|
||||
|
||||
// @todo Accounts/Payment should be configurable
|
||||
switch ($po->checkout->plugin) {
|
||||
|
@ -17,8 +17,6 @@ class Controller_Admin_Host extends Controller_TemplateDefault_Admin {
|
||||
);
|
||||
|
||||
public function action_ajaxmanage() {
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
$hso = ORM::factory('Host_Server',$this->request->param('id'));
|
||||
$k = Session::instance()->get_once('manage_button');
|
||||
|
||||
|
@ -39,6 +39,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
|
||||
// Items belonging to an invoice
|
||||
private $invoice_items = array();
|
||||
private $invoice_items_unsorted = TRUE;
|
||||
|
||||
/** INTERFACE REQUIREMENTS **/
|
||||
public function cart_item() {
|
||||
@ -52,34 +53,22 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
return count(Cart::instance()->get($this->mid(),$this->id));
|
||||
}
|
||||
|
||||
public function __construct($id = NULL) {
|
||||
// Load our Model
|
||||
parent::__construct($id);
|
||||
/**
|
||||
* Intercept our object load, so that we can load our subitems
|
||||
*/
|
||||
protected function _load_values(array $values) {
|
||||
parent::_load_values($values);
|
||||
|
||||
// Autoload our Sub Items
|
||||
if ($this->loaded())
|
||||
$this->_load_sub_items();
|
||||
if ($this->_loaded)
|
||||
$this->invoice_items = $this->invoice_item->find_all()->as_array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load our invoice items
|
||||
* We need these so that we can calculate totals, etc
|
||||
*/
|
||||
private function _load_sub_items() {
|
||||
// Load our sub items
|
||||
$this->invoice_items = $this->invoice_item->find_all()->as_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to an invoice
|
||||
*/
|
||||
public function add_item(Model_Invoice_Item $iio=NULL) {
|
||||
// Just to check if an invoice is called from the DB, that it should have items with it.
|
||||
if ($this->loaded() and ! $this->invoice_items)
|
||||
throw HTTP_Exception::factory(501,'Need dto load invoice_items?');
|
||||
|
||||
// @todo This is the old calling of this function, which should be removed
|
||||
if (is_null($iio)) {
|
||||
$c = count($this->invoice_items);
|
||||
@ -566,10 +555,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
public function total($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
// @todo - This should be required, but during checkout payment processing $pio->invoice->total() showed no invoice items?
|
||||
if ($this->loaded() AND ! count($this->items()))
|
||||
$this->_load_sub_items();
|
||||
|
||||
// This will include charges and credits
|
||||
foreach ($this->items() as $ito)
|
||||
$result += $ito->total();
|
||||
|
@ -1,8 +1,8 @@
|
||||
<table class="table table-striped table-condensed table-hover" id="list-table">
|
||||
<tbody>
|
||||
<?php foreach ($o->items_periods() as $rs) : ?>
|
||||
<tr><th colspan="5"><?php echo StaticList_RecurSchedule::get($rs); ?></th></tr>
|
||||
<?php foreach ($o->items_periods() as $rs) : ?>
|
||||
<thead><tr><th colspan="5"><?php echo StaticList_RecurSchedule::get($rs); ?></th></tr></thead>
|
||||
|
||||
<tbody>
|
||||
<?php foreach ($o->items_periods($rs) as $iio) : ?>
|
||||
<?php if ($iio->service_id) : ?>
|
||||
<tr>
|
||||
@ -31,6 +31,7 @@
|
||||
<?php endif ?>
|
||||
|
||||
<?php endforeach ?>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</tbody>
|
||||
|
||||
<?php endforeach ?>
|
||||
</table>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
42
modules/payment/classes/Controller/Reseller/Payment.php
Normal file
42
modules/payment/classes/Controller/Reseller/Payment.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides Reseller Payment functions
|
||||
*
|
||||
* @package Payment
|
||||
* @category Controllers/Reseller
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Reseller_Payment extends Controller_Payment {
|
||||
protected $secure_actions = array(
|
||||
'list'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Show a list of payments
|
||||
*/
|
||||
public function action_list() {
|
||||
Block::factory()
|
||||
->title('Customer Payments')
|
||||
->title_icon('icon-th-list')
|
||||
->body(Table::factory()
|
||||
->page_items(50)
|
||||
->data(ORM::factory('Payment')->where('account_id','IN',$this->ao->RTM->customers($this->ao->RTM))->find_all())
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'date_payment'=>'Date',
|
||||
'checkout->display("name")'=>'Method',
|
||||
'balance(TRUE)'=>'Balance',
|
||||
'invoicelist()'=>'Invoices',
|
||||
'account->accnum()'=>'Cust ID',
|
||||
'account->name()'=>'Customer',
|
||||
))
|
||||
->prepend(array(
|
||||
//'id'=>array('url'=>URL::link('reseller','payment/view/')), //@todo To Implement
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
@ -9,33 +9,30 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_User_Payment extends Controller_TemplateDefault_User {
|
||||
class Controller_User_Payment extends Controller_Payment {
|
||||
protected $secure_actions = array(
|
||||
'list'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Show a payments received
|
||||
* Show payments received
|
||||
*/
|
||||
public function action_list() {
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s - %s',_('Payments Received For'),$this->ao->accnum(),$this->ao->name(TRUE)),
|
||||
'body'=>Table::display(
|
||||
$this->ao->payment->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID'),
|
||||
'date_payment'=>array('label'=>'Date'),
|
||||
'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'=>'list',
|
||||
)),
|
||||
));
|
||||
Block::factory()
|
||||
->title(sprintf('%s: %s - %s',_('Payments Received For'),$this->ao->accnum(),$this->ao->name(TRUE)))
|
||||
->title_icon('icon-th-list')
|
||||
->body(Table::factory()
|
||||
->page_items(50)
|
||||
->data($this->ao->payment->find_all())
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'date_payment'=>'Date',
|
||||
'checkout->display("name")'=>'Method',
|
||||
'total(TRUE)'=>'Total',
|
||||
'balance(TRUE)'=>'Balance',
|
||||
'invoicelist()'=>'Invoices',
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -11,14 +11,14 @@
|
||||
*/
|
||||
class Model_Payment extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array(),
|
||||
'checkout'=>array('foreign_key'=>'checkout_id'),
|
||||
);
|
||||
protected $_has_many = array(
|
||||
'payment_item'=>array('far_key'=>'id'),
|
||||
'invoice'=>array('through'=>'payment_item'),
|
||||
);
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array(),
|
||||
'checkout'=>array('foreign_key'=>'checkout_plugin_id'),
|
||||
);
|
||||
|
||||
protected $_sorting = array(
|
||||
'date_payment'=>'DESC'
|
||||
@ -31,6 +31,9 @@ class Model_Payment extends ORM_OSB {
|
||||
'date_payment'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'fees_amt'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'total_amt'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
@ -38,33 +41,34 @@ class Model_Payment extends ORM_OSB {
|
||||
|
||||
// Items belonging to an invoice
|
||||
private $payment_items = array();
|
||||
private $payment_items_unsorted = TRUE;
|
||||
|
||||
public function __construct($id = NULL) {
|
||||
// Load our model.
|
||||
parent::__construct($id);
|
||||
/**
|
||||
* Intercept our object load, so that we can load our subitems
|
||||
*/
|
||||
protected function _load_values(array $values) {
|
||||
parent::_load_values($values);
|
||||
|
||||
// Load our sub items
|
||||
if ($this->loaded())
|
||||
if ($this->_loaded)
|
||||
$this->payment_items = $this->payment_item->find_all()->as_array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to this payment
|
||||
*
|
||||
* @param $inv number, to allocate payment to an invoice
|
||||
* Add an item to an payment
|
||||
*/
|
||||
public function add_item($invnum) {
|
||||
// Find our id, if it exists
|
||||
public function add_item(Model_Payment_Item $p=NULL) {
|
||||
$this->payment_items_unsorted = TRUE;
|
||||
|
||||
// Make sure this payment item for an invoice is not already in the list
|
||||
foreach ($this->payment_items as $pio)
|
||||
if ($pio->invoice_id == $invnum)
|
||||
if ($pio->invoice_id == $p->invoice_id)
|
||||
return $pio;
|
||||
|
||||
// New Item
|
||||
$c = count($this->payment_items);
|
||||
$this->payment_items[$c] = ORM::factory('Payment_Item');
|
||||
$this->payment_items[$c]->invoice_id = $invnum;
|
||||
array_push($this->payment_items,$p);
|
||||
|
||||
return $this->payment_items[$c];
|
||||
return $p;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,14 +84,15 @@ class Model_Payment extends ORM_OSB {
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all items that are exportable.
|
||||
*
|
||||
* @param int $start List payments that were modified this many days ago
|
||||
* Calculate there refund amount
|
||||
*/
|
||||
public function export($start) {
|
||||
return ORM::factory('Payment')
|
||||
->where('date_payment','>=',time()-$start*86400)
|
||||
->find_all();
|
||||
public function credit($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->items('CREDIT') as $pio)
|
||||
$result += $pio->alloc_amt*-1;
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,6 +117,11 @@ class Model_Payment extends ORM_OSB {
|
||||
* @see payment_items
|
||||
*/
|
||||
public function items($type='ALL') {
|
||||
if ($this->payment_items_unsorted) {
|
||||
Sort::MAsort($this->payment_items,'invoice_id');
|
||||
$this->payment_items_unsorted = FALSE;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($this->payment_items as $pio) {
|
||||
@ -119,7 +129,7 @@ class Model_Payment extends ORM_OSB {
|
||||
|
||||
switch ($type) {
|
||||
case 'ALLOC':
|
||||
if ($pio->alloc_amt > 0)
|
||||
if ($pio->alloc_amt >= 0)
|
||||
$return = TRUE;
|
||||
break;
|
||||
|
||||
@ -142,13 +152,73 @@ class Model_Payment extends ORM_OSB {
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the total amount of a payment.
|
||||
* Save a record and payment_items
|
||||
*/
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Our items will be clobbered once we save the object, so we need to save it here.
|
||||
$items = $this->items();
|
||||
|
||||
// If a user modified this payment, we'll update the source to their ID.
|
||||
if ($ao = Auth::instance()->get_user())
|
||||
$this->source_id = $ao->id;
|
||||
|
||||
$this->ip = Request::$client_ip;
|
||||
|
||||
// Make sure we dont over allocate
|
||||
$msg = '';
|
||||
foreach ($items as $pio)
|
||||
// Only need to check items that ave actually changed.
|
||||
if ($pio->changed() AND ($x=$pio->original_values()))
|
||||
if (($x = $pio->alloc_amt-$pio->invoice->due()-$x['alloc_amt']) > 0)
|
||||
$msg .= ($msg ? ' ' : '').sprintf('Invoice %s over allocated by %3.2f.',$pio->invoice_id,$x);
|
||||
|
||||
if (($x=$this->balance()) < 0)
|
||||
$msg .= ($msg ? ' ' : '').sprintf('Payment over allocated by %3.2f.',-$x);
|
||||
|
||||
if ($msg) {
|
||||
SystemMessage::factory()
|
||||
->title('Record NOT updated')
|
||||
->type('warning')
|
||||
->body($msg);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Save the payment
|
||||
parent::save($validation);
|
||||
|
||||
// Need to save the associated items and their taxes
|
||||
if (! $this->changed() OR $this->saved()) {
|
||||
foreach ($items as $pio) {
|
||||
// Skip applying 0 payments to invoices.
|
||||
if (! $pio->changed() OR (Currency::round($pio->alloc_amt) == 0 AND ! $pio->loaded()))
|
||||
continue;
|
||||
|
||||
$pio->payment_id = $this->id;
|
||||
|
||||
// @todo Mark payment as cancelled and write a memo, then...
|
||||
if (! $pio->check())
|
||||
throw HTTP_Exception::factory(501,'Problem saving payment_item for invoice :invoice - Failed check()',array(':invoice'=>$pio->invoice_id));
|
||||
|
||||
$pio->save();
|
||||
|
||||
// @todo Mark payment as cancelled and write a memo, then...
|
||||
if (! $pio->saved())
|
||||
throw HTTP_Exception::factory(501,'Problem saving payment_item for invoice :invoice - Failed save()',array(':invoice'=>$pio->invoice_id));
|
||||
}
|
||||
|
||||
} else {
|
||||
throw HTTP_Exception::factory(501,'Problem saving payment :id - Failed save()',array(':id'=>$this->id));
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce the total by the amount of credits returned.
|
||||
*/
|
||||
public function total($format=FALSE) {
|
||||
$result = $this->total_amt;
|
||||
|
||||
foreach ($this->items('CREDIT') as $pio)
|
||||
$result += $pio->alloc_amt;
|
||||
$result = $this->total_amt - $this->credit();
|
||||
|
||||
return $format ? Currency::display($result) : Currency::round($result);
|
||||
}
|
||||
@ -156,18 +226,22 @@ class Model_Payment extends ORM_OSB {
|
||||
/** LIST FUNCTIONS **/
|
||||
|
||||
public function list_unapplied() {
|
||||
return array();
|
||||
$pi = array();
|
||||
$pid = array();
|
||||
|
||||
// @todo database suffix needs to be dynamically calculated
|
||||
foreach (DB::Query(Database::SELECT,
|
||||
sprintf('SELECT A.id AS id,A.total_amt as total_amt FROM ab_%s A LEFT JOIN ab_%s B ON (A.site_id=B.site_id AND A.id=B.payment_id) WHERE (A.refund_status=0 OR A.refund_status IS NULL) GROUP BY A.id HAVING ROUND(SUM(IFNULL(B.alloc_amt,0)),2)!=A.total_amt ORDER BY account_id,payment_id','payment','payment_item'))
|
||||
->execute() as $values) {
|
||||
// We cant use ORM for this complex SQL
|
||||
$db = Database::instance();
|
||||
|
||||
array_push($pi,$values['id']);
|
||||
}
|
||||
$sql = 'SELECT A.id as id, A.total_amt, ROUND(SUM(IF(IFNULL(B.alloc_amt,0)<0,IFNULL(B.alloc_amt,0)*-1,IFNULL(B.alloc_amt,0))),2) as ALLOC';
|
||||
$sql .= ' FROM :prefix_payment A ';
|
||||
$sql .= ' RIGHT JOIN :prefix_payment_item B ON (A.site_id=B.site_id AND A.id=B.payment_id)';
|
||||
$sql .= ' WHERE A.site_id=:site_id';
|
||||
$sql .= ' GROUP BY A.id';
|
||||
$sql .= ' HAVING round(A.total_amt-ALLOC,2) <> 0';
|
||||
|
||||
return $this->where('id','IN',$pi)->order_by('account_id')->find_all();
|
||||
foreach ($db->query(Database::SELECT,__($sql,array(':prefix_'=>$db->table_prefix(),':site_id'=>Config::siteid()))) as $values)
|
||||
array_push($pid,$values['id']);
|
||||
|
||||
return $this->where('id','IN',$pid)->order_by('account_id')->find_all();
|
||||
}
|
||||
|
||||
public function list_recent_table() {
|
||||
@ -196,73 +270,5 @@ class Model_Payment extends ORM_OSB {
|
||||
'type'=>'list',
|
||||
));
|
||||
}
|
||||
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Our items will be clobbered once we save the object, so we need to save it here.
|
||||
$items = $this->items();
|
||||
|
||||
// @todo This should not be mandatory - or there should be a source for non-users (automatic postings)
|
||||
$this->source_id = Auth::instance()->get_user() ? Auth::instance()->get_user()->id : 1;
|
||||
$this->ip = Request::$client_ip;
|
||||
|
||||
// Make sure we dont over allocate
|
||||
$t = 0;
|
||||
$msg = '';
|
||||
foreach ($items as $pio) {
|
||||
// Only need to check items that ave actually changed.
|
||||
if ($pio->changed()) {
|
||||
$old_pio = ORM::factory('Payment_Item',$pio->id);
|
||||
|
||||
if (($it = $pio->invoice->due()+ORM::factory('Payment_Item',$pio->id)->alloc_amt-$pio->alloc_amt) < 0)
|
||||
$msg .= ($msg ? ' ' : '').sprintf('Invoice %s over allocated by %3.2f.',$pio->invoice_id,$it);
|
||||
}
|
||||
|
||||
$t += $pio->alloc_amt;
|
||||
}
|
||||
|
||||
if ($t > (float)$this->total_amt)
|
||||
$msg .= ($msg ? ' ' : '').sprintf('Payment over allocated by %3.2f.',$t-$this->total_amt);
|
||||
|
||||
if ($msg) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Payment NOT Recorded',
|
||||
'type'=>'warning',
|
||||
'body'=>$msg,
|
||||
));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Save the payment
|
||||
parent::save($validation);
|
||||
|
||||
// Need to save the associated items and their taxes
|
||||
if (! $this->changed() OR $this->saved()) {
|
||||
foreach ($items as $pio) {
|
||||
// Skip applying 0 payments to invoices.
|
||||
if (Currency::round($pio->alloc_amt) == 0 AND ! $pio->loaded())
|
||||
continue;
|
||||
|
||||
$pio->payment_id = $this->id;
|
||||
|
||||
if (! $pio->check()) {
|
||||
// @todo Mark payment as cancelled and write a memo, then...
|
||||
throw new Kohana_Exception('Problem saving payment_item for invoice :invoice - Failed check()',array(':invoice'=>$invoice->id));
|
||||
}
|
||||
|
||||
$pio->save();
|
||||
|
||||
if (! $pio->saved()) {
|
||||
// @todo Mark payment as cancelled and write a memo, then...
|
||||
throw new Kohana_Exception('Problem saving payment_item for invoice :invoice - Failed save()',array(':invoice'=>$invoice->id));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Kohana_Exception('Couldnt save payment for some reason?');
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -11,12 +11,17 @@
|
||||
*/
|
||||
class Model_Payment_Item extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'payment'=>array(),
|
||||
);
|
||||
protected $_has_one = array(
|
||||
'invoice'=>array('far_key'=>'invoice_id','foreign_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_belongs_to = array(
|
||||
'payment'=>array(),
|
||||
protected $_display_filters = array(
|
||||
'alloc_amt'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
@ -10,24 +10,11 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Payment_Bulk_Ezypay {
|
||||
public function form() {
|
||||
$result = '';
|
||||
private function file($name) {
|
||||
$result = array();
|
||||
|
||||
$result .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
|
||||
$result .= Form::hidden('payer',$_POST['payer']);
|
||||
$result .= View::factory('payment/admin/addbulk/ezypay');
|
||||
$result .= Form::submit('submit','submit',array('class'=>'form_button'));
|
||||
$result .= Form::close();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function process() {
|
||||
$payments = array();
|
||||
|
||||
// Process payment
|
||||
$file = file_get_contents($_FILES['payment']['tmp_name']);
|
||||
$file = preg_split("/[\r]?[\n]+/",$file);
|
||||
// Process file
|
||||
$file = preg_split("/[\r]?[\n]+/",file_get_contents($_FILES[$name]['tmp_name']));
|
||||
|
||||
$i = 0;
|
||||
foreach ($file as $line) {
|
||||
@ -37,8 +24,33 @@ class Payment_Bulk_Ezypay {
|
||||
|
||||
// Trim our whitespace on the end of the line.
|
||||
$line = preg_replace("/\s+$/",'',$line);
|
||||
$array = explode("\t",$line);
|
||||
array_push($result,explode("\t",$line));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The input form to capture the required files
|
||||
*/
|
||||
public function form() {
|
||||
$result = '';
|
||||
|
||||
$result .= Form::open(NULL,array('enctype'=>'multipart/form-data','class'=>'form-horizontal'));
|
||||
$result .= View::factory('payment/admin/addbulk/ezypay');
|
||||
$result .= Form::close();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the uploaded files
|
||||
*/
|
||||
public function process() {
|
||||
// Process payment
|
||||
$payments = array();
|
||||
|
||||
foreach ($this->file('payment') as $line => $array) {
|
||||
// Field 4 has our account reference
|
||||
if (preg_match('/^'.Company::instance()->site(TRUE).'-/',$array[4]) AND $array[10] == 'Cleared') {
|
||||
$aid = preg_replace('/^'.Company::instance()->site(TRUE).'-/','',$array[4]);
|
||||
@ -46,62 +58,59 @@ class Payment_Bulk_Ezypay {
|
||||
$po = ORM::factory('Payment');
|
||||
$po->account_id = $aid;
|
||||
$po->total_amt = $array[7];
|
||||
$po->notes = $array[2].':'.$array[3];
|
||||
$po->checkout_data = array('transid'=>$array[2].':'.$array[3]);
|
||||
$po->date_payment = strtotime(str_replace('/','-',$array[8]));
|
||||
|
||||
$sbo = $po->account->service_billing->where('plugin_data','=',$array[3])->find();
|
||||
if (! $sbo->loaded())
|
||||
throw HTTP_Exception::factory(501,'No Service Billing Data for :aid (:pd)?',array(':aid'=>$aid,':pd'=>$array[3]));
|
||||
|
||||
$po->checkout_id = $sbo->checkout_id;
|
||||
|
||||
$payments[$array[3]] = $po;
|
||||
}
|
||||
}
|
||||
|
||||
$file = file_get_contents($_FILES['transaction']['tmp_name']);
|
||||
$file = preg_split("/[\r]?[\n]+/",$file);
|
||||
|
||||
$i = 0;
|
||||
foreach ($file as $line) {
|
||||
// Line 0 is our header
|
||||
if ($i++ == 0 OR ! trim($line))
|
||||
continue;
|
||||
|
||||
// Trim our whitespace on the end of the line.
|
||||
$line = preg_replace("/\s+$/",'',$line);
|
||||
$array = explode("\t",$line);
|
||||
|
||||
foreach ($this->file('transaction') as $line => $array) {
|
||||
// If we dont have a payment item for this fee, we'll continue.
|
||||
if (! isset($payments[$array[3]]))
|
||||
continue;
|
||||
|
||||
// Our commission fees
|
||||
// @todo This should be in a config file
|
||||
// Our commission fees, which appear has Type 1 or 15
|
||||
if (in_array($array[9],array(1,15)))
|
||||
$payments[$array[3]]->fees_amt = (float)$array[7];
|
||||
|
||||
// @todo Hack - since the reports dont show how the payment was made.
|
||||
// @todo Put this in a config file, in the mean time.
|
||||
if ($array[7] == 1.05)
|
||||
$payments[$array[3]]->checkout_id = 2;
|
||||
else
|
||||
$payments[$array[3]]->checkout_id = 4;
|
||||
}
|
||||
|
||||
$result = '';
|
||||
$result .= View::Factory('payment/admin/addbulk/ezypay/head');
|
||||
|
||||
$total = $fees = 0;
|
||||
foreach ($payments as $po) {
|
||||
$po->save();
|
||||
|
||||
if (! $po->saved())
|
||||
throw HTTP_Exception::factory(501,'Failed to Save Payment for :aid (:pd)?',array(':aid'=>$po->account_id,':pd'=>$po->checkout_data['transid']));
|
||||
|
||||
$total += $po->total_amt;
|
||||
$fees += $po->fees_amt;
|
||||
|
||||
$result .= View::Factory('payment/admin/addbulk/ezypay/body')
|
||||
->set('o',$po);
|
||||
}
|
||||
|
||||
$result .= View::Factory('payment/admin/addbulk/ezypay/foot')
|
||||
->set('total',$total)
|
||||
->set('fees',$fees);;
|
||||
$output = Table::factory()
|
||||
->data($payments)
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'date_payment'=>'Date',
|
||||
'checkout->display("name")'=>'Method',
|
||||
'total_amt'=>'Amount',
|
||||
'fees_amt'=>'Fees',
|
||||
'account->accnum()'=>'Cust ID',
|
||||
'account->name()'=>'Customer',
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('admin','payment/view/')),
|
||||
));
|
||||
|
||||
return $result;
|
||||
return View::factory('payment/admin/addbulk/ezypay_processed')
|
||||
->set('table',$output)
|
||||
->set('fee',$fees)
|
||||
->set('total',$total);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
23
modules/payment/views/payment/admin/add_edit.php
Normal file
23
modules/payment/views/payment/admin/add_edit.php
Normal file
@ -0,0 +1,23 @@
|
||||
<div class="row">
|
||||
<div class="span9 offset1">
|
||||
|
||||
<fieldset>
|
||||
<legend>Payment Details</legend>
|
||||
|
||||
<div class="input-append date" id="date_payment_label">
|
||||
<?php echo Form::input('date_payment_label',$o->display('date_payment'),array('class'=>'span2','label'=>'Date Paid','add-on'=>'<i class="icon-calendar"></i>','disabled')); ?>
|
||||
</div>
|
||||
|
||||
<?php echo Form::hidden('date_payment',$o->date_payment); ?>
|
||||
<?php echo Form::select('checkout_id',ORM::factory('Checkout')->list_select(),$o->checkout_id,array('label'=>'Payment Method','required')); ?>
|
||||
<?php echo Form::input('total_amt',$o->total_amt,array('class'=>'span2','label'=>'Amount','placeholder'=>'Total','help-block'=>sprintf('Credits: %s, Balance: %s',$o->credit(),$o->total()))); ?>
|
||||
<?php echo Form::input('fees_amt',$o->fees_amt,array('class'=>'span2','label'=>'Fees','placeholder'=>'Fees')); ?>
|
||||
<?php echo Form::input('account_id_label',$o->account->name(),array('class'=>'span5','label'=>'Account','placeholder'=>'Account','data-provide'=>'typeahead')); ?>
|
||||
<?php echo Form::hidden('account_id',$o->account_id); ?>
|
||||
<?php echo Form::input('notes',$o->notes,array('class'=>'span5','label'=>'Notes','placeholder'=>'Any notes about this payment?')); ?>
|
||||
</fieldset>
|
||||
|
||||
<td><div id='items'></div></td>
|
||||
<?php echo Form::button('submit','Submit',array('class'=>'btn btn-primary')); ?>
|
||||
</div> <!-- /span -->
|
||||
</div> <!-- /row -->
|
@ -1,35 +0,0 @@
|
||||
<table width="100%" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td style="width: 25%;">Payment Date</td>
|
||||
<td style="width: 75%;"><?php echo Form::input('date_payment',$po->date_payment); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Account</td>
|
||||
<td><?php echo Form::input('account_id',$po->account_id); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Method</td>
|
||||
<td><?php echo Form::select('checkout_id',ORM::factory('Checkout')->list_select(),$po->checkout_id,array('label'=>'Payment Method','required')); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Amount</td>
|
||||
<td><?php echo Form::input('total_amt',$po->total()); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Fees</td>
|
||||
<td><?php echo Form::input('fees_amt',$po->fees_amt); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Notes</td>
|
||||
<td><?php echo Form::input('notes',$po->notes); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><div id='items'></div></td>
|
||||
</tr>
|
||||
</table>
|
@ -1,13 +1,13 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan="2">Ezypay Payment</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Payment File (BillDetails)</td>
|
||||
<td><?php echo Form::file('payment'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Transaction File (AddItems)</td>
|
||||
<td><?php echo Form::file('transaction'); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="span9 offset1">
|
||||
<fieldset>
|
||||
<legend>Ezypay Payment</legend>
|
||||
|
||||
<?php echo Form::hidden('payer',$_POST['payer']); ?>
|
||||
<?php echo Form::file('transaction',array('label'=>'Transaction File','required','help-block'=>'AddItems')); ?>
|
||||
<?php echo Form::file('payment',array('label'=>'Payment File','required','help-block'=>'BillDetails')); ?>
|
||||
</fieldset>
|
||||
|
||||
<?php echo Form::button('submit','Submit',array('class'=>'btn btn-primary')); ?>
|
||||
</div> <!-- /span -->
|
||||
</div> <!-- /row -->
|
||||
|
@ -1,7 +0,0 @@
|
||||
<tr>
|
||||
<td><?php echo HTML::anchor(URL::link('admin','payment/view/'.$o->id),$o->display('id')); ?></td>
|
||||
<td><?php echo $o->display('date_payment'); ?></td>
|
||||
<td><?php echo $o->display('total_amt'); ?></td>
|
||||
<td><?php echo $o->display('fees_amt'); ?></td>
|
||||
<td><?php echo $o->display('notes'); ?></td>
|
||||
</tr>
|
@ -1,6 +0,0 @@
|
||||
<tr class="head">
|
||||
<td colspan="2"> </td>
|
||||
<td><?php echo $total; ?></td>
|
||||
<td><?php echo $fees; ?></td>
|
||||
</tr>
|
||||
</table>
|
@ -1,8 +0,0 @@
|
||||
<table>
|
||||
<tr class="head">
|
||||
<td>Payment ID</td>
|
||||
<td>Date Payment</td>
|
||||
<td>Amount</td>
|
||||
<td>Fees</td>
|
||||
<td>Transaction ID</td>
|
||||
</tr>
|
@ -0,0 +1,18 @@
|
||||
<div class="row">
|
||||
<div class="span9 offset1">
|
||||
<fieldset>
|
||||
<legend>Bulk Payment Details</legend>
|
||||
</fieldset>
|
||||
|
||||
<div class="dl-horizontal">
|
||||
<dt>Total</dt>
|
||||
<dd><?php echo $total; ?></dd>
|
||||
|
||||
<dt>Fees</dt>
|
||||
<dd><?php echo $fee; ?></dd>
|
||||
|
||||
<dt>Payments</dt>
|
||||
<dd><?php echo $table; ?></dd>
|
||||
</div> <!-- /dl-horizontal -->
|
||||
</div> <!-- /span -->
|
||||
</div> <!-- /row -->
|
33
modules/payment/views/payment/admin/ajaxitemlist.php
Normal file
33
modules/payment/views/payment/admin/ajaxitemlist.php
Normal file
@ -0,0 +1,33 @@
|
||||
<div id="items">
|
||||
<table class="table table-striped table-condensed table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Invoice</th>
|
||||
<th>Date Issue</th>
|
||||
<th>Date Due</th>
|
||||
<th class="text-right">Total</th>
|
||||
<th class="text-right">Payments</th>
|
||||
<th class="text-right">Due</th>
|
||||
<th class="text-right">Alloc</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<?php $c=0;foreach ($o->items('ALLOC') as $pio) : ?>
|
||||
<tr>
|
||||
<td><?php echo HTML::anchor(URL::link('user','invoice/view/'.$pio->invoice_id),$pio->invoice->id()); ?></td>
|
||||
<td><?php echo $pio->invoice->display('date_orig'); ?></td>
|
||||
<td><?php echo $pio->invoice->display('due_date'); ?></td>
|
||||
<td class="text-right"><?php echo $pio->invoice->total(TRUE); ?></td>
|
||||
<td class="text-right"><?php echo $pio->invoice->payments_total(TRUE); ?></td>
|
||||
<td class="text-right"><?php echo $pio->invoice->due(TRUE); ?></td>
|
||||
<td class="text-right"><?php echo Form::input('payment_item['.$pio->invoice_id.']',$pio->display('alloc_amt'),array('class'=>'span1','nocg'=>TRUE,'tabindex'=>++$c)); ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
|
||||
<tr>
|
||||
<td class="text-right" colspan="6">Unapplied</td>
|
||||
<td class="text-right"><?php echo Form::input('invoice_item[excess]',$o->balance(TRUE),array('class'=>'span1','nocg'=>TRUE,'disabled'=>'disabled')); ?></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div> <!-- /items -->
|
@ -1,9 +0,0 @@
|
||||
<tr class="<?php echo $trc; ?>">
|
||||
<td><?php echo HTML::anchor(URL::link('user','invoice/view/'.$io->id),$io->id()); ?></td>
|
||||
<td><?php echo $io->display('date_orig'); ?></td>
|
||||
<td><?php echo $io->display('due_date'); ?></td>
|
||||
<td><?php echo $io->total(TRUE); ?></td>
|
||||
<td><?php echo $io->payments_total(TRUE); ?></td>
|
||||
<td><?php echo $io->due(TRUE); ?></td>
|
||||
<td><?php echo Form::input('payment_item['.$io->id.']',$pio->alloc_amt); ?></td>
|
||||
</tr>
|
@ -1,7 +0,0 @@
|
||||
<tr class="<?php echo $trc; ?>">
|
||||
<td colspan="5"> </td>
|
||||
<td class="head">Unapplied</td>
|
||||
<td><?php echo Form::input('invoice_item[excess]','',array('disabled'=>'disabled')); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
@ -1,11 +0,0 @@
|
||||
<div id="items">
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td class="head">Invoice</td>
|
||||
<td class="head">Date Issue</td>
|
||||
<td class="head">Date Due</td>
|
||||
<td class="head">Total</td>
|
||||
<td class="head">Payments</td>
|
||||
<td class="head">Due</td>
|
||||
<td class="head">Alloc</td>
|
||||
</tr>
|
@ -20,8 +20,6 @@ class Controller_User_Service extends Controller_Service {
|
||||
* This ajax functions obtains the manage button login/password for this service
|
||||
*/
|
||||
public function action_ajaxmanage() {
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
$so = ORM::factory('Service',$this->request->param('id'));
|
||||
$k = Session::instance()->get_once('manage_button');
|
||||
$amo = $so->plugin(isset($_REQUEST['t']) ? $_REQUEST['t'] : '');
|
||||
|
@ -45,7 +45,7 @@ class Controller_User_Statement extends Controller_TemplateDefault_User {
|
||||
if (isset($v['invoice']))
|
||||
$t += $v['invoice']->total();
|
||||
elseif (isset($v['payment']))
|
||||
$t -= $v['payment']->total_amt;
|
||||
$t -= $v['payment']->total();
|
||||
|
||||
$ta[$k]['total'] = $t;
|
||||
$a = $v['time'];
|
||||
|
Reference in New Issue
Block a user