Added Payment, other minor fixes

This commit is contained in:
Deon George 2011-12-20 16:46:10 +11:00
parent c8fd44f844
commit a40ce27a16
31 changed files with 452 additions and 1280 deletions

View File

@ -98,7 +98,7 @@ abstract class lnApp_Config extends Kohana_Config {
* Show a date using a site configured format * Show a date using a site configured format
*/ */
public static function date($date) { public static function date($date) {
return $date ? date(Kohana::config('config.date_format'),$date) : '&gtNot Set&lt'; return $date ? date(Kohana::config('config.date_format'),$date) : '>Not Set<';
} }
/** /**

View File

@ -39,7 +39,7 @@ class Model_Account extends Model_Auth_UserDefault {
*/ */
public function name($withcompany=FALSE) { public function name($withcompany=FALSE) {
if ($withcompany) if ($withcompany)
return sprintf('%s %s (%s)',$this->first_name,$this->last_name,$this->company); return sprintf('%s %s%s',$this->first_name,$this->last_name,$this->company ? sprintf(' (%s)',$this->company) : '');
else else
return sprintf('%s %s',$this->first_name,$this->last_name); return sprintf('%s %s',$this->first_name,$this->last_name);
} }
@ -121,11 +121,55 @@ class Model_Account extends Model_Auth_UserDefault {
// Log the logout // Log the logout
$alo = ORM::factory('account_log'); $alo = ORM::factory('account_log');
$alo->account_id = $this->id; $alo->account_id = $this->id;
$alo->ip = $_SERVER['REMOTE_ADDR']; $alo->ip = Request::$client_ip;
$alo->details = $message; $alo->details = $message;
$alo->save(); $alo->save();
return $alo->saved(); return $alo->saved();
} }
/**
* Search for accounts matching a term
*/
public function list_autocomplete($term,$index='id') {
$return = array();
$this->clear();
$value = 'name(TRUE)';
// Build our where clause
// First Name, Last name
if (preg_match('/\ /',$term)) {
list($fn,$ln) = explode(' ',$term,2);
$this->where_open()
->where('first_name','like','%'.$fn.'%')
->and_where('last_name','like','%'.$ln.'%')
->where_close()
->or_where('company','like','%'.$term.'%');
} elseif (is_numeric($term)) {
$this->where('id','like','%'.$term.'%');
} elseif (preg_match('/\@/',$term)) {
$this->where('email','like','%'.$term.'%');
$value = 'email';
} else {
$this->where('company','like','%'.$term.'%')
->or_where('first_name','like','%'.$term.'%')
->or_where('last_name','like','%'.$term.'%')
->or_where('email','like','%'.$term.'%');
}
// @todo This should limit the results so that users dont see other users services.
foreach ($this->find_all() as $o)
$return[$o->$index] = array(
'value'=>$o->$index,
'label'=>sprintf('ACC %s: %s',$o->id,Table::resolve($o,$value)),
);
return $return;
}
} }
?> ?>

View File

@ -118,5 +118,9 @@ abstract class ORMOSB extends ORM {
return $plugin ? sprintf('%s/%s/%s/%s',$request->controller(),$request->directory(),$plugin,$request->action()) : sprintf('%s/%s/%s',$request->controller(),$request->directory(),$request->action()); return $plugin ? sprintf('%s/%s/%s/%s',$request->controller(),$request->directory(),$plugin,$request->action()) : sprintf('%s/%s/%s',$request->controller(),$request->directory(),$request->action());
} }
public function changed() {
return $this->_changed;
}
} }
?> ?>

View File

@ -47,7 +47,7 @@ abstract class StaticListModule extends StaticList {
*/ */
public static function form($name,$default='',$addblank=FALSE) { public static function form($name,$default='',$addblank=FALSE) {
// Override our argument list as defined in parent // Override our argument list as defined in parent
list($name,$table,$default,$key,$value,$where) = func_get_args(); list($name,$table,$default,$key,$value,$where,$addblank,$attributes) = func_get_args();
// @todo - our query type should come from our configuration? // @todo - our query type should come from our configuration?
$db = DB::select()->from($table); $db = DB::select()->from($table);
@ -69,6 +69,9 @@ abstract class StaticListModule extends StaticList {
// Else we return a select list // Else we return a select list
$x = array(); $x = array();
if ($addblank)
$x[] = '';
foreach ($db as $record) { foreach ($db as $record) {
$x[$record[$key]] = $record[$value]; $x[$record[$key]] = $record[$value];
@ -77,7 +80,7 @@ abstract class StaticListModule extends StaticList {
static::$record[$table] = $record; static::$record[$table] = $record;
} }
return Form::select($name,$x,$default); return Form::select($name,$x,$default,$attributes);
} }
} }
?> ?>

View File

@ -56,7 +56,7 @@
/* Component containers /* Component containers
----------------------------------*/ ----------------------------------*/
.ui-widget { font-family: Verdana,Arial,sans-serif; font-size: 1.1em; } .ui-widget { font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 60%; }
.ui-widget .ui-widget { font-size: 1em; } .ui-widget .ui-widget { font-size: 1em; }
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Verdana,Arial,sans-serif; font-size: 1em; } .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Verdana,Arial,sans-serif; font-size: 1em; }
.ui-widget-content { border: 1px solid #aaaaaa; background: #ffffff url(images/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x; color: #222222; } .ui-widget-content { border: 1px solid #aaaaaa; background: #ffffff url(images/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x; color: #222222; }
@ -565,4 +565,4 @@ button.ui-button::-moz-focus-inner { border: 0; padding: 0; } /* reset extra pad
* http://docs.jquery.com/UI/Progressbar#theming * http://docs.jquery.com/UI/Progressbar#theming
*/ */
.ui-progressbar { height:2em; text-align: left; } .ui-progressbar { height:2em; text-align: left; }
.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; } .ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; }

View File

@ -16,9 +16,6 @@ class Model_ADSL_Plan extends ORMOSB {
protected $_belongs_to = array( protected $_belongs_to = array(
'adsl_supplier_plan'=>array(), 'adsl_supplier_plan'=>array(),
); );
protected $_has_many = array(
'product'=>array('far_key'=>'id','foreign_key'=>'prod_plugin_data'),
);
protected $_display_filters = array( protected $_display_filters = array(
'extra_down_peak'=>array( 'extra_down_peak'=>array(

View File

@ -18,6 +18,31 @@ class Model_ADSL_Supplier extends ORMOSB {
protected $_updated_column = FALSE; protected $_updated_column = FALSE;
/**
* Return a list of plans that this supplier makes available
*/
public function plans($active=TRUE) {
$a = $this->adsl_supplier_plan;
if ($active)
$a->where('status','=',TRUE);
return $a;
}
/**
* Return a list of plans that we provide by this supplier
*/
public function adsl_plans($active=TRUE) {
$return = array();
foreach ($this->plans($active)->find_all() as $po)
foreach ($po->adsl_plan->find_all() as $apo)
$return[$apo->id] = $apo;
return $return;
}
/** /**
* Return a list of services for this supplier * Return a list of services for this supplier
* *
@ -27,16 +52,13 @@ class Model_ADSL_Supplier extends ORMOSB {
$services = array(); $services = array();
// Get a list of plans made for this supplier // Get a list of plans made for this supplier
// @todo This doesnt work if a product adsl plan is overriden. $plans = array_keys($this->adsl_plans(FALSE));
foreach ($this->adsl_supplier_plan->find_all() as $aspo)
// Find all the plan who use this supplier plan // Start with all our ADSL Plans
foreach ($aspo->adsl_plan->find_all() as $apo) foreach (ORM::factory('service')->list_bylistgroup('ADSL') as $so)
// Find all the products who use this plan if (! $active OR $so->active)
foreach ($apo->product->find_all() as $po) if (in_array($so->product->prod_plugin_data,$plans) OR in_array($so->plugin()->provided_adsl_plan_id,$plans))
// Find all the services who that use this product array_push($services,$so);
foreach ($po->service->find_all() as $so)
if (! $active OR $so->active)
array_push($services,$so);
return $services; return $services;
} }

View File

@ -46,9 +46,9 @@ $(document).ready(function() {
public static function NS(Model_Service_Plugin_Domain $o) { public static function NS(Model_Service_Plugin_Domain $o) {
if ($o->registrar_ns) if ($o->registrar_ns)
return is_array($o->registrar_ns) ? implode(',',$o->registrar_ns) : '&gtInvalid&lt'; return is_array($o->registrar_ns) ? implode(',',$o->registrar_ns) : '>Invalid<';
else else
return is_array($o->domain_registrar->whitelabel_ns) ? implode(',',$o->domain_registrar->whitelabel_ns) : '&gtUnknown&lt'; return is_array($o->domain_registrar->whitelabel_ns) ? implode(',',$o->domain_registrar->whitelabel_ns) : '>Unknown<';
} }
} }
?> ?>

View File

@ -71,7 +71,7 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
->set('io',$io); ->set('io',$io);
Block::add(array( Block::add(array(
'title'=>sprintf('%s: %s',_('Invoice'),$io->refnum()), 'title'=>sprintf('%s: %s - %s',_('Invoice'),$io->refnum(),$io->account->name()),
'body'=>$output, 'body'=>$output,
)); ));
} }

View File

@ -135,7 +135,7 @@ class Model_Invoice extends ORMOSB {
} }
public function payments() { public function payments() {
return ($this->loaded() AND ! $this->_changed) ? $this->payment_item->find_all() : NULL; return ($this->loaded() AND ! $this->_changed) ? $this->payment_item->find_all() : array();
} }
public function payments_total($format=FALSE) { public function payments_total($format=FALSE) {
@ -406,6 +406,30 @@ class Model_Invoice extends ORMOSB {
/** LIST FUNCTIONS **/ /** LIST FUNCTIONS **/
/**
* Search for invoices matching a term
*/
public function list_autocomplete($term,$index='id') {
$return = array();
if (is_numeric($term)) {
$this->clear();
$value = 'account->name(TRUE)';
// Build our where clause
$this->where('id','like','%'.$term.'%');
// @todo This should limit the results so that users dont see other users services.
foreach ($this->find_all() as $o)
$return[$o->$index] = array(
'value'=>$o->$index,
'label'=>sprintf('INV %s: %s',$o->id,Table::resolve($o,$value)),
);
}
return $return;
}
private function _list_active() { private function _list_active() {
return ORM::factory('invoice')->where('status','=',1); return ORM::factory('invoice')->where('status','=',1);
} }

View File

@ -1,33 +0,0 @@
<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
*
* Originally authored by Tony Landis, AgileBill LLC
*
* Recent modifications by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @subpackage Modules:Invoice
*/
/**
* The main AgileBill Payment Class
*
* @package AgileBill
*/
$auth_methods = array (
);
?>

View File

@ -0,0 +1,204 @@
<?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,
));
}
}
?>

View File

@ -1,10 +1,10 @@
<?php defined('SYSPATH') or die('No direct access allowed.'); <?php defined('SYSPATH') or die('No direct access allowed.');
/** /**
* This class supports OSB exporting by rending the exportable items. * This class supports OSB payments.
* *
* @package OSB * @package OSB
* @subpackage Export * @subpackage Payment
* @category Models * @category Models
* @author Deon George * @author Deon George
* @copyright (c) 2010 Open Source Billing * @copyright (c) 2010 Open Source Billing
@ -34,6 +34,34 @@ class Model_Payment extends ORMOSB {
), ),
); );
// Items belonging to an invoice
private $payment_items = array();
/**
* Return a list of invoice items for this payment.
*/
public function items() {
// If we havent been changed, we'll load the records from the DB.
if ($this->loaded() AND ! $this->_changed)
return $this->payment_item->order_by('invoice_id')->find_all()->as_array();
else
return $this->payment_items;
}
/**
* Add an item to an invoice
*/
public function add_item() {
if ($this->loaded() and ! $this->payment_items)
throw new Kohana_Exception('Need to load payment_items?');
$c = count($this->payment_items);
$this->payment_items[$c] = ORM::factory('payment_item');
return $this->payment_items[$c];
}
/** /**
* Find all items that are exportable. * Find all items that are exportable.
* *
@ -103,7 +131,7 @@ class Model_Payment extends ORMOSB {
return $css.Table::display( return $css.Table::display(
$this->limit(10)->find_all(), $this->limit(10)->find_all(),
25, 25,
array( array(
'id'=>array('label'=>'ID'), 'id'=>array('label'=>'ID'),
'date_payment'=>array('label'=>'Date'), 'date_payment'=>array('label'=>'Date'),
'checkout->display("name")'=>array('label'=>'Method'), 'checkout->display("name")'=>array('label'=>'Method'),
@ -111,9 +139,45 @@ class Model_Payment extends ORMOSB {
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'), 'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
'invoicelist()'=>array('label'=>'Invoices'), 'invoicelist()'=>array('label'=>'Invoices'),
), ),
array( array(
'type'=>'list', '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();
$this->source_id = Auth::instance()->get_user()->id;
$this->ip = Request::$client_ip;
// @todo Need validation, if there is an overbalance in payment_items or if an invoice is overpaid.
// Save the payment
parent::save($validation);
// Need to save the associated items and their taxes
if ($this->saved()) {
foreach ($items as $pio) {
$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;
}
} }
?> ?>

View File

@ -1,241 +0,0 @@
<?php
/**
* osBilling - Open Billing Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Originally authored by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
* @license http://www.gnu.org/licenses/
* @package AgileBill
* @subpackage Modules:Payment
*/
/**
* The main AgileBill Payment Class
*
* @package AgileBill
* @subpackage Modules:Payment
*/
class payment extends OSB_module {
public function allocate($VAR) { return $this->tmAllocate($VAR); }
/**
* Template Method to support the allocation of payments to invoices
*
* @uses payment_item
* @uses invoice
*/
public function tmAllocate($VAR) {
$db = DB();
$invoices = array();
include_once(PATH_MODULES.'payment_item/payment_item.inc.php');
$pi = new payment_item;
include_once(PATH_MODULES.'invoice/invoice.inc.php');
$io = new Invoice;
# Get our payment information
$payment = $this->sPaymentsBal($VAR['payment_id']);
# If this payment has been allocated to some invoices, collect those details
$payment_items = $pi->sPaymentAllocation($VAR['payment_id']);
foreach ($io->sInvoicesBal($payment['account_id']) as $index => $details) {
$invoices[$index] = $details;
# Get additional information on the invoices to be displayed.
$invoices[$index]['id'] = $index;
$invoices[$index]['_C'] = sprintf('row%s',$i++%2 ? 1 : 2);
if (isset($payment_items[$index])) {
$invoices[$index]['alloc_amt'] = $payment_items[$index];
unset($payment_items[$index]);
}
}
# Left over payment_items are fully paid invoices
if (count($payment_items)) {
foreach ($io->sInvoicesAcc($payment['account_id'],array_keys($payment_items)) as $index => $details) {
$invoices[$index] = $details;
# Get additional information on the invoices to be displayed.
$invoices[$index]['id'] = $index;
$invoices[$index]['_C'] = sprintf('row%s',$i++%2 ? 1 : 2);
$invoices[$index]['alloc_amt'] = $payment_items[$index];
}
}
# Sort the entries
ksort($invoices);
global $smarty;
$smarty->assign('invoices',$invoices);
$smarty->assign('results',count($invoices));
}
/**
* Compare the billed_amt with the payments, and auto fix when the allocation is not correct
*/
public function taskAuditPaymentItems() {
$db = DB();
$rs = $db->Execute(sprintf('SELECT A.id,A.account_id,A.billed_amt,A.total_amt,IFNULL(A.credit_amt,0) as credit_amt,ROUND(SUM(IFNULL(B.alloc_amt,0)),4) AS alloc_amt FROM %sinvoice A LEFT OUTER JOIN %spayment_item B ON (A.id=B.invoice_id) WHERE A.site_id=%s GROUP BY A.id HAVING A.billed_amt != alloc_amt',AGILE_DB_PREFIX,AGILE_DB_PREFIX,DEFAULT_SITE));
if ($rs && $rs->RecordCount()) {
while (! $rs->EOF) {
$db->Execute(sqlUpdate('invoice',array('billed_amt'=>$rs->fields['alloc_amt']),array('where'=>array('id'=>$rs->fields['id']))));
# Add a memo
$db->Execute(sqlInsert($db,'invoice_memo',array('date_orig'=>time(),'invoice_id'=>$rs->fields['id'],'account_id'=>$rs->fields['account_id'],'type'=>'audit','memo'=>sprintf('Payments applied to this invoice have been changed, due to over allocation, was: %3.2f, payments applied: %3.2f, credits applied: %3.2f',$rs->fields['billed_amt'],$rs->fields['alloc_amt'],$rs->fields['credit_amt']))));
$rs->MoveNext();
}
}
}
public function ListUnbalanced($VAR) { return $this->tmListUnbalanced($VAR); }
/**
* List all invoices that are out of balance with the payment tables.
*
* @return void
*/
public function tmListUnbalanced() {
global $smarty;
$db = DB();
$smart = array();
$counter = 0;
$rs = $db->Execute(sprintf('SELECT B.payment_id AS id,A.account_id,B.invoice_id,A.billed_amt,A.total_amt,IFNULL(A.credit_amt,0) as credit_amt,B.payment_id,ROUND(SUM(IFNULL(B.alloc_amt,0)),4) AS alloc_amt,A.date_orig FROM %sinvoice A LEFT OUTER JOIN %spayment_item B ON (A.id=B.invoice_id) WHERE A.site_id=%s GROUP BY A.id HAVING A.billed_amt != alloc_amt OR A.total_amt < A.billed_amt ORDER BY A.account_id,A.id',AGILE_DB_PREFIX,AGILE_DB_PREFIX,DEFAULT_SITE));
if ($rs && $rs->RecordCount()) {
while (! $rs->EOF) {
$rs->fields['_C'] = ++$counter%s ? 'row1' : 'row2';
array_push($smart,$rs->fields);
$rs->MoveNext();
}
}
$smarty->assign('results',count($smart));
$smarty->assign('limit',count($smart));
$smarty->assign('search_show',$smart);
}
public function ListUnallocated($VAR) { return $this->tmListUnallocated($VAR); }
/**
* Return payments that still have unallocated balances
*
* @return void
* @uses invoice
*/
public function tmListUnallocated($VAR) {
global $smarty;
require_once(PATH_MODULES.'invoice/invoice.inc.php');
$io = new invoice;
$accounts = $io->sAccountsBal();
$smart = array();
$counter = 0;
foreach ($this->sPaymentsBal() as $payment) {
$payment['_C'] = ++$counter%s ? 'row1' : 'row2';
$payment['balance'] = $payment['total_amt']-$payment['alloc_amt'];
$payment['acct_bal'] = isset($accounts[$payment['account_id']]) ? $accounts[$payment['account_id']] : 0;
array_push($smart,$payment);
}
$smarty->assign('results',count($smart));
$smarty->assign('limit',count($smart));
$smarty->assign('search_show',$smart);
}
public function ListInvoicesBalance($VAR) { return $this->tmListInvoicesBalance($VAR); }
public function tmListInvoicesBalance($VAR) {
global $smarty;
$smart = array();
$counter = 0;
foreach ($this->sAccountsBal() as $account_id => $invoices) {
foreach ($invoices as $index => $values) {
$smart[$index] = $values;
$smart[$index]['_C'] = ++$counter%s ? 'row1' : 'row2';
}
}
$smarty->assign('results',count($smart));
$smarty->assign('limit',count($smart));
$smarty->assign('search_show',$smart);
}
/**
* Return a list of payments with an unallocated balance
*
* @param $payment_id Return only this payment ID, otherwise return all payment IDs.
* @return array Payments with a unallocated balance
*/
public function sPaymentsBal($payment_id=null) {
static $sPaymentsBal = array();
if (! count($sPaymentsBal) || (! is_null($payment_id) && ! isset($sPaymentsBal[$payment_id]))) {
$db = &DB();
$rs = $db->Execute(sprintf('SELECT A.id,A.account_id,A.total_amt,ROUND(SUM(IFNULL(B.alloc_amt,0)),4) AS alloc_amt,A.date_orig FROM %spayment A LEFT OUTER JOIN %spayment_item B ON (B.payment_id=A.id) WHERE A.site_id=%s GROUP BY (A.id) HAVING %s alloc_amt != A.total_amt ORDER BY A.account_id',
AGILE_DB_PREFIX,AGILE_DB_PREFIX,DEFAULT_SITE,is_null($payment_id) ? '' : sprintf('A.id=%s OR',$payment_id)));
if ($rs && $rs->RecordCount()) {
while (! $rs->EOF) {
$sPaymentsBal[$rs->fields['id']]['id'] = $rs->fields['id'];
$sPaymentsBal[$rs->fields['id']]['account_id'] = $rs->fields['account_id'];
$sPaymentsBal[$rs->fields['id']]['total_amt'] = $rs->fields['total_amt'];
$sPaymentsBal[$rs->fields['id']]['alloc_amt'] = $rs->fields['alloc_amt'];
$sPaymentsBal[$rs->fields['id']]['date_orig'] = $rs->fields['date_orig'];
$rs->MoveNext();
}
}
}
return (is_null($payment_id) ? $sPaymentsBal : (isset($sPaymentsBal[$payment_id]) ? $sPaymentsBal[$payment_id] : array()));
}
/**
* Return a list of invoices with unbalanced payments
*
* @param $account_id Return invoices with unbalanced payments for an account, otherwise return all accounts
* @return array Invoices with unbalanced payments
*/
public function sAccountsBal($account_id) {
static $sAccountsBal = array();
if (! count($sAccountsBal) || (! is_null($account_id) && ! isset($sAccountsBal[$account_id]))) {
$db = &DB();
$rs = $db->Execute(sprintf('SELECT A.id,A.account_id,A.total_amt,A.billed_amt,IFNULL(A.credit_amt,0) as credit_amt,ROUND(SUM(IFNULL(B.alloc_amt,0)),4) AS alloc_amt,A.date_orig,B.payment_id FROM %sinvoice A INNER JOIN %spayment_item B ON (B.invoice_id=A.id) WHERE A.site_id=%s GROUP BY (A.id) HAVING %s A.total_amt!=alloc_amt+credit_amt ORDER BY A.account_id,A.id',
AGILE_DB_PREFIX,AGILE_DB_PREFIX,DEFAULT_SITE,is_null($account_id) ? '' : sprintf('A.account_id=%s AND',$account_id)));
if ($rs && $rs->RecordCount()) {
while (! $rs->EOF) {
$sAccountsBal[$rs->fields['account_id']][$rs->fields['id']]['id'] = $rs->fields['payment_id'];
$sAccountsBal[$rs->fields['account_id']][$rs->fields['id']]['invoice_id'] = $rs->fields['id'];
$sAccountsBal[$rs->fields['account_id']][$rs->fields['id']]['account_id'] = $rs->fields['account_id'];
$sAccountsBal[$rs->fields['account_id']][$rs->fields['id']]['total_amt'] = $rs->fields['total_amt'];
$sAccountsBal[$rs->fields['account_id']][$rs->fields['id']]['alloc_amt'] = $rs->fields['alloc_amt'];
$sAccountsBal[$rs->fields['account_id']][$rs->fields['id']]['date_orig'] = $rs->fields['date_orig'];
$rs->MoveNext();
}
}
}
return (is_null($account_id) ? $sAccountsBal : (isset($sAccountsBal[$account_id]) ? $sAccountsBal[$account_id] : array()));
}
}
?>

View File

@ -1,248 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<!-- Module name -->
<module>payment</module>
<!-- Module supporting database table -->
<table>payment</table>
<!-- Module dependancy(s) (module wont install if these modules are not yet installed) -->
<dependancy>invoice</dependancy>
<!-- DB cache in seconds -->
<cache>0</cache>
<!-- Default order_by field for SQL queries -->
<order_by>date_orig</order_by>
<!-- Default SQL limit for SQL queries -->
<limit>25</limit>
<!-- Schema version (used to determine if the schema has change during upgrades) -->
<version>1</version>
<!-- Database indexes -->
<index>
</index>
<!-- Database fields -->
<field>
<!-- Record ID -->
<id>
<display>Payment</display>
<index>1</index>
<type>I4</type>
<unique>1</unique>
</id>
<!-- Site ID -->
<site_id>
<index>1</index>
<type>I4</type>
</site_id>
<!-- Date record created -->
<date_orig>
<convert>date-now</convert>
<display>Date Created</display>
<type>I8</type>
</date_orig>
<!-- Date record updated -->
<date_last>
<convert>date-now</convert>
<display>Date Updated</display>
<type>I8</type>
</date_last>
<!-- The account this payment belongs to -->
<account_id>
<asso_table>account</asso_table>
<asso_field>first_name,last_name</asso_field>
<type>I8</type>
<validate>any</validate>
</account_id>
<!-- Date Payment -->
<date_payment>
<convert>date-time</convert>
<display>Payment Date</display>
<type>I8</type>
</date_payment>
<!-- Checkout plugin for this payment -->
<checkout_plugin_id>
<asso_table>checkout</asso_table>
<asso_field>name</asso_field>
<display>Checkout Plugin</display>
<type>I4</type>
<validate>any</validate>
</checkout_plugin_id>
<!-- Checkout plugin data -->
<checkout_plugin_data>
<type>C(255)</type>
<convert>array</convert>
</checkout_plugin_data>
<!-- Gross payment amount (local currency) -->
<total_amt>
<type>F</type>
<validate>float</validate>
</total_amt>
<!-- Payment Fees (local currency) -->
<fees_amt>
<type>F</type>
</fees_amt>
<!-- The local currency for this payment -->
<billed_currency_id>
<type>I4</type>
</billed_currency_id>
<!-- The amount in billed_currency that was made -->
<actual_total_amt>
<type>F</type>
</actual_total_amt>
<!-- The currency this payment was paid -->
<actual_billed_currency_id>
<type>I4</type>
</actual_billed_currency_id>
<!-- Payment has been refunded when STATUS = 1 -->
<refund_status>
<display>Refund Status</display>
<type>L</type>
</refund_status>
<!-- Account who made payment -->
<source_id>
<asso_table>account</asso_table>
<asso_field>username</asso_field>
<display>Source</display>
<type>I8</type>
<validate>any</validate>
</source_id>
<!-- Whether payment has been cleared -->
<pending_status>
<display>Pending</display>
<type>L</type>
</pending_status>
<!-- IP Address of Client -->
<notes>
<type>X</type>
</notes>
<!-- IP Address of Client -->
<ip>
<type>C(32)</type>
</ip>
</field>
<!-- Methods for this class, and the fields they have access to, if applicable -->
<method>
<add>account_id,date_payment,checkout_plugin_id,total_amt,fees_amt,notes,source_id</add>
<update>account_id,date_payment,checkout_plugin_id,total_amt,fees_amt,notes,pending_status</update>
<search>id,account_id,date_payment,checkout_plugin_id,total_amt,source_id</search>
<view>id,date_orig,account_id,date_payment,checkout_plugin_id,total_amt,fees_amt,notes,source_id</view>
</method>
<!-- Method triggers -->
<trigger></trigger>
<!-- Template page display titles -->
<title>
<view>Payment</view>
</title>
<!-- Template helpers -->
<tpl>
<search_show>
<checkbox>
<field>id</field>
<type>checkbox</type>
<width>25px</width>
</checkbox>
<account_id>
<field>account_id</field>
</account_id>
<source_id>
<field>source_id</field>
</source_id>
<checkout_plugin_id>
<field>checkout_plugin_id</field>
</checkout_plugin_id>
<date_payment>
<field>date_payment</field>
<type>date</type>
</date_payment>
<total_amt>
<field>total_amt</field>
<type>currency</type>
</total_amt>
</search_show>
<user_search_show>
<checkbox>
<field>id</field>
<type>checkbox</type>
<width>25px</width>
</checkbox>
<id>
<field>id</field>
</id>
<date_payment>
<field>date_orig</field>
<type>date</type>
</date_payment>
<total_amt>
<field>total_amt</field>
<type>currency</type>
</total_amt>
</user_search_show>
<ListUnallocated>
<checkbox>
<field>id</field>
<type>checkbox</type>
<width>25px</width>
</checkbox>
<id>
<field>id</field>
</id>
<account_id>
<field>account_id</field>
</account_id>
<date_payment>
<field>date_orig</field>
<type>date</type>
</date_payment>
<total_amt>
<field>total_amt</field>
<type>currency</type>
</total_amt>
<alloc_amt>
<field>alloc_amt</field>
<type>currency</type>
</alloc_amt>
<balance>
<field>balance</field>
<type>currency</type>
</balance>
<acct_bal>
<field>acct_bal</field>
</acct_bal>
</ListUnallocated>
<ListUnbalanced>
<checkbox>
<field>id</field>
<type>checkbox</type>
<width>25px</width>
</checkbox>
<id>
<field>id</field>
</id>
<account_id>
<field>account_id</field>
</account_id>
<invoice_id>
<field>invoice_id</field>
</invoice_id>
<date_payment>
<field>date_orig</field>
<type>date</type>
</date_payment>
<total_amt>
<field>total_amt</field>
<type>currency</type>
</total_amt>
<billed_amt>
<field>billed_amt</field>
<type>currency</type>
</billed_amt>
<alloc_amt>
<field>alloc_amt</field>
<type>currency</type>
</alloc_amt>
</ListUnbalanced>
</tpl>
</construct>

View File

@ -1,61 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<!-- Tree Menu Module Properties -->
<module_properties>
<!-- MODULE Dependancy, this module wont be installed if the dependant modules dont exist -->
<dependancy></dependancy>
<!-- Translated display to use on the tree -->
<display>Payment</display>
<!-- Display a module in the menu tree -->
<menu_display>1</menu_display>
<!-- MODULE Name -->
<name>payment</name>
<!-- MODULE Notes, these notes show up in the modules table, as a description of the module -->
<notes><![CDATA[This module records payments to invoices]]></notes>
<!-- MODULE Parent, the parent node in the tree -->
<parent>invoice</parent>
<!-- SUB Modules to install with this one -->
<sub_modules></sub_modules>
<!-- MODULE Type (core|base), core modules cannot be deleted, unrecognised types are ignored. -->
<type></type>
</module_properties>
<!-- Tree Menu & Module Methods to load, they will be assigned the group permissions on install time, as selected by the user. -->
<module_method>
<add>
<display>Add</display>
<menu_display>1</menu_display>
<name>add</name>
<notes><![CDATA[Add records]]></notes>
</add>
<delete>
<name>delete</name>
<notes><![CDATA[Delete records]]></notes>
</delete>
<search>
<display>List</display>
<menu_display>1</menu_display>
<name>search</name>
<notes><![CDATA[List records]]></notes>
<page><![CDATA[core:search&module=%%&_next_page_one=view]]></page>
</search>
<search_form>
<display>Search</display>
<menu_display>1</menu_display>
<name>search_form</name>
<notes><![CDATA[Search for records]]></notes>
</search_form>
<search_show>
<name>search_show</name>
<notes><![CDATA[Show the results of a search]]></notes>
</search_show>
<update>
<name>update</name>
<notes><![CDATA[Update a record]]></notes>
</update>
<view>
<name>view</name>
<notes><![CDATA[View a record]]></notes>
</view>
</module_method>
</install>

View File

@ -0,0 +1,35 @@
<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 StaticList_Module::form('checkout_plugin_id','checkout',$po->checkout_plugin_id,'id','name',array('active'=>'=:1'),TRUE,array('class'=>'form_button'));?></td>
</tr>
<tr>
<td>Amount</td>
<td><?php echo Form::input('total_amt',$po->total_amt); ?></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>

View File

@ -0,0 +1,9 @@
<tr class="<?php echo $trc; ?>">
<td><?php echo $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>

View File

@ -0,0 +1,7 @@
<tr class="<?php echo $trc; ?>">
<td colspan="5">&nbsp;</td>
<td class="head">Unapplied</td>
<td><?php echo Form::input('invoice_item[excess]','',array('disabled'=>'disabled')); ?></td>
</tr>
</table>
</div>

View File

@ -0,0 +1,11 @@
<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>

View File

@ -1,159 +0,0 @@
<?php
/**
* osBilling - Open Billing Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Originally authored by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
* @license http://www.gnu.org/licenses/
* @package AgileBill
* @subpackage Modules:Payment
*/
/**
* The main AgileBill Payment Class
*
* @package AgileBill
* @subpackage Modules:Payment
*/
class payment_item extends OSB_module {
public function allocate($VAR) { return $this->doAllocate($VAR); }
/**
* Allocate a payment to invoices
*
* @uses invoice
* @uses payment
*/
public function doAllocate($VAR) {
$db = DB();
# Get the payment invoices for this account.
include_once(PATH_MODULES.'payment/payment.inc.php');
$po = new payment;
# Get our payment information
if (! $payment = $po->sPaymentsBal($VAR['payment_id']))
return false;
# Check that our allocation is correct.
$total = round(array_sum($VAR['payment_item_allocate']),2);
if ($total > $payment['total_amt']) {
global $C_debug;
$C_debug->alert(sprintf('%s: (%3.2f/%3.2f) ?',_('Payment over allocated'),$total,$payment['total_amt']));
return false;
}
# If this payment has been allocated to some invoices, collect those details
$payment_items = $this->sPaymentAllocation($VAR['payment_id']);
# Get the unpaid invoices for this account.
include_once(PATH_MODULES.'invoice/invoice.inc.php');
$io = new invoice;
$invoices = $io->sInvoicesAcc($payment['account_id'],array_keys($VAR['payment_item_allocate']));
# Apply the new allocation
foreach ($VAR['payment_item_allocate'] as $invoice => $alloc) {
if (! trim($alloc))
continue;
# Sanity check
if (! isset($invoices[$invoice])) {
global $C_debug;
$C_debug->alert(sprintf('Payment for invoice doesnt exist? (%s)?',$invoices['invoice']));
# This payment has been processed
if (isset($payment_items[$invoice]))
unset($payment_items[$invoice]);
continue;
} elseif ((isset($payment_items[$invoice]) && $invoices[$invoice]['balance']+$payment_items[$invoice] < $alloc)
|| (! isset($payment_items[$invoice]) && $invoices[$invoice]['balance'] < $alloc)) {
global $C_debug;
$C_debug->alert(sprintf('Over allocation for invoice %s - remaining balance is %s?',$invoice,$invoices[$invoice]['balance']));
# This payment has been processed
if (isset($payment_items[$invoice]))
unset($payment_items[$invoice]);
continue;
}
# Have we already applied payments to this invoice in the past
if (isset($payment_items[$invoice])) {
if ($alloc != $payment_items[$invoice]) {
# Record the adjusted payment details
$db->Execute(sqlUpdate('payment_item',array('date_last'=>time(),'alloc_amt'=>$alloc),array('where'=>array('payment_id'=>$VAR['payment_id'],'invoice_id'=>$invoice,'alloc_amt'=>$payment_items[$invoice]))));
# Adjust the invoice balance
$db->Execute(sqlUpdate('invoice',array('billed_amt'=>$invoices[$invoice]['billed_amt']+$alloc-$payment_items[$invoice]),array('where'=>array('id'=>$invoice,'billed_amt'=>$invoices[$invoice]['billed_amt']))));
}
# This payment has been processed
unset($payment_items[$invoice]);
# New payment allocation
} else {
# Reduce the invoice balance
$db->Execute(sqlUpdate('invoice',array('billed_amt'=>$invoices[$invoice]['billed_amt']+$alloc),array('where'=>array('id'=>$invoice))));
# Record the payment
$db->Execute(sqlInsert($db,'payment_item',array('date_orig'=>time(),'date_last'=>time(),'payment_id'=>$VAR['payment_id'],'invoice_id'=>$invoice,'alloc_amt'=>$alloc)));
}
}
# Any left over payments need to be reversed
foreach ($payment_items as $invoice => $alloc) {
if (! $alloc)
continue;
$db->Execute(sqlUpdate('payment_item',array('date_last'=>time(),'alloc_amt'=>0),array('where'=>array('payment_id'=>$VAR['payment_id'],'invoice_id'=>$invoice,'alloc_amt'=>$payment_items[$invoice]))));
$db->Execute(sqlUpdate('invoice',array('billed_amt'=>$invoices[$invoice]['billed_amt']-$alloc),array('where'=>array('id'=>$invoice,'billed_amt'=>$invoices[$invoice]['billed_amt']))));
}
# Force the refresh of the account balances
$io->sInvoicesBal(null,true);
}
/**
* Get the payment allocation for a payment ID
*
* @param $payment_id Payment ID to retrieve
* @return array Invoices and the payment location
*/
public function sPaymentAllocation($payment_id) {
static $sPaymentAllocation = array();
if (! isset($sPaymentsBalance[$payment_id])) {
$db = DB();
$rs = $db->Execute(sqlSelect('payment_item','invoice_id,alloc_amt',array('where'=>array('payment_id'=>$payment_id))));
if ($rs && $rs->RecordCount()) {
while (! $rs->EOF) {
$sPaymentsBalance[$payment_id][$rs->fields['invoice_id']] = $rs->fields['alloc_amt'];
$rs->MoveNext();
}
}
}
return $sPaymentsBalance[$payment_id];
}
}
?>

View File

@ -1,82 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<!-- Module name -->
<module>payment_item</module>
<!-- Module supporting database table -->
<table>payment_item</table>
<!-- Module dependancy(s) (module wont install if these modules are not yet installed) -->
<dependancy>payment</dependancy>
<!-- DB cache in seconds -->
<cache>0</cache>
<!-- Default order_by field for SQL queries -->
<order_by>date_orig</order_by>
<!-- Default SQL limit for SQL queries -->
<limit>25</limit>
<!-- Schema version (used to determine if the schema has change during upgrades) -->
<version>1</version>
<!-- Database indexes -->
<index>
<!--
id,site_id,payment_id,invoice_id
-->
</index>
<!-- Database fields -->
<field>
<!-- Record ID -->
<id>
<index>1</index>
<type>I4</type>
<unique>1</unique>
</id>
<!-- Site ID -->
<site_id>
<index>1</index>
<type>I4</type>
</site_id>
<!-- Date record created -->
<date_orig>
<convert>date-now</convert>
<display>Date Created</display>
<type>I8</type>
</date_orig>
<!-- Date record updated -->
<date_last>
<convert>date-now</convert>
<display>Date Updated</display>
<type>I8</type>
</date_last>
<!-- Payment ID -->
<payment_id>
<asso_table>account</asso_table>
<type>I8</type>
</payment_id>
<!-- Invoice ID -->
<invoice_id>
<asso_table>invoice</asso_table>
<type>I8</type>
</invoice_id>
<!-- Gross amount allocated -->
<alloc_amt>
<type>F</type>
<validate>float</validate>
</alloc_amt>
</field>
<!-- Methods for this class, and the fields they have access to, if applicable -->
<method>
<add>payment_id,invoice_id,alloc_amt</add>
</method>
<!-- Method triggers -->
<trigger></trigger>
<!-- Template page display titles -->
<title>
</title>
<!-- Template helpers -->
<tpl>
</tpl>
</construct>

View File

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<!-- Tree Menu Module Properties -->
<module_properties>
<!-- MODULE Dependancy, this module wont be installed if the dependant modules dont exist -->
<dependancy>payment</dependancy>
<!-- Translated display to use on the tree -->
<display></display>
<!-- Display a module in the menu tree -->
<menu_display>0</menu_display>
<!-- MODULE Name -->
<name>payment_item</name>
<!-- MODULE Notes, these notes show up in the modules table, as a description of the module -->
<notes><![CDATA[This module records payments allocated to invoices]]></notes>
<!-- MODULE Parent, the parent node in the tree -->
<parent>payment</parent>
<!-- SUB Modules to install with this one -->
<sub_modules></sub_modules>
<!-- MODULE Type (core|base), core modules cannot be deleted, unrecognised types are ignored. -->
<type></type>
</module_properties>
<!-- Tree Menu & Module Methods to load, they will be assigned the group permissions on install time, as selected by the user. -->
<module_method>
<add>
<name>add</name>
<notes><![CDATA[Add records]]></notes>
</add>
<delete>
<name>delete</name>
<notes><![CDATA[Delete records]]></notes>
</delete>
<search>
<name>search</name>
<notes><![CDATA[List records]]></notes>
<page><![CDATA[core:search&module=%%&_next_page_one=view]]></page>
</search>
<search_form>
<name>search_form</name>
<notes><![CDATA[Search for records]]></notes>
</search_form>
<search_show>
<name>search_show</name>
<notes><![CDATA[Show the results of a search]]></notes>
</search_show>
<update>
<name>update</name>
<notes><![CDATA[Update a record]]></notes>
</update>
<view>
<name>view</name>
<notes><![CDATA[View a record]]></notes>
</view>
<allocate>
<notes><![CDATA[Allocate payments to an invoice]]></notes>
</allocate>
</module_method>
</install>

View File

@ -1,34 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
{$method->exe($meth.0,$meth.1)}
{if ($method->result == FALSE)}
{$block->display('core:method_error')}
{else}
{include file='file:../core/search_show_pre.tpl'}
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
{$method->exe_noauth($meth.0,'tpl_search_show')}
{foreach from=$search_show item=record}
{include file='file:../core/search_show_tr_record.tpl'}
<td>{$record.id}</td>
<td>{$record.account_id}</td>
<td>{$list->date($record.date_orig)}</td>
<td>{$list->format_currency_num($record.total_amt,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.alloc_amt,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.balance,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.acct_bal,$record.billed_currency_id)}</td>
</tr>
{/foreach}
</table>
</td>
</tr>
</table>
{include file='file:../core/search_show_post-1.tpl'}
{include file='file:../core/search_show_post-2.tpl'}
{/if}

View File

@ -1,34 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
{$method->exe($meth.0,$meth.1)}
{if ($method->result == FALSE)}
{$block->display('core:method_error')}
{else}
{include file='file:../core/search_show_pre.tpl'}
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
{$method->exe_noauth($meth.0,'tpl_search_show')}
{foreach from=$search_show item=record}
{include file='file:../core/search_show_tr_record.tpl'}
<td>{$record.id}</td>
<td>{$record.account_id}</td>
<td>{$list->date($record.date_orig)}</td>
<td>{$list->format_currency_num($record.total_amt,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.alloc_amt,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.balance,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.acct_bal,$record.billed_currency_id)}</td>
</tr>
{/foreach}
</table>
</td>
</tr>
</table>
{include file='file:../core/search_show_post-1.tpl'}
{include file='file:../core/search_show_post-2.tpl'}
{/if}

View File

@ -1,34 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
{$method->exe($meth.0,$meth.1)}
{if ($method->result == FALSE)}
{$block->display('core:method_error')}
{else}
{include file='file:../core/search_show_pre.tpl'}
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
{$method->exe_noauth($meth.0,'tpl_search_show')}
{foreach from=$search_show item=record}
{include file='file:../core/search_show_tr_record.tpl'}
<td>{$record.id}</td>
<td>{$record.account_id}</td>
<td>{$record.invoice_id}</td>
<td>{$list->date($record.date_orig)}</td>
<td>{$list->format_currency_num($record.total_amt,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.billed_amt,$record.billed_currency_id)}</td>
<td>{$list->format_currency_num($record.alloc_amt,$record.billed_currency_id)}</td>
</tr>
{/foreach}
</table>
</td>
</tr>
</table>
{include file='file:../core/search_show_post-1.tpl'}
{include file='file:../core/search_show_post-2.tpl'}
{/if}

View File

@ -1,66 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
<!-- Display the form validation -->
{if $form_validation}
{$block->display('core:alert_fields')}
{/if}
<!-- Display the form to collect the input values -->
<form id="add" method="post" action="" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr valign="top">
<td class="table_heading">{osb f=tt}</td>
</tr>
<tr valign="top">
<td class="row1">
<table width="100%" border="0" cellspacing="3" cellpadding="1" class="row1">
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=account_id}</td>
<td style="width: 65%;">{osb f=autoselect module=account return=id field=payment_account_id default=$VAR.payment_account_id}</td>
</tr>
{if $VAR.payment_account_id}
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=date_payment}</td>
<td style="width: 65%;">{$list->calender_add('payment_date_payment','now','form_field','')}</td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=checkout_plugin_id}</td>
<td style="width: 65%;">{$list->mmenu('no','payment_checkout_plugin_id','checkout','name',$VAR.payment_checkout_plugin_id,'active=1','',true)}</td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=total_amt}</td>
<td style="width: 65%;"><input type="text" name="payment_total_amt" value="{$VAR.payment_total_amt}" {if $payment_total_amt == true}class="form_field_error"{/if}/></td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=fees_amt}</td>
<td style="width: 65%;"><input type="text" name="payment_fees_amt" value="{$VAR.payment_fees_amt}" {if $payment_fees_amt == true}class="form_field_error"{/if}/></td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=notes}</td>
<td style="width: 65%;"><textarea name="payment_notes" cols="25" rows="2" {if $payment_notes == true}class="form_field_error"{/if}>{$VAR.payment_notes}</textarea></td>
</tr>
{include file='file:../core/add_tr_submit.tpl'}
{else}
<tr valign="top">
<td style="width: 35%;"><input type="hidden" name="_page" value="payment:add"/></td>
{include file='file:../core/view_td_submit.tpl'}
</tr>
{/if}
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div>
<input type="hidden" name="payment_source_id" value="{$smarty.const.SESS_ACCOUNT}">
</div>
</form>

View File

@ -1,51 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
<!-- @todo change to exe() -->
{$method->exe_noauth($meth.0,$meth.1)}
{if ($method->result == false)}
{$block->display('core:method_error')}
{else}
{include file='file:../core/search_show_pre.tpl'}
<!-- Display each record -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr valign="top">
<td class="table_heading">{t}Invoice Date{/t}</td>
<td class="table_heading">{t}Invoice Number{/t}</td>
<td class="table_heading">{t}Invoice Amount{/t}</td>
<td class="table_heading">{t}Invoice Balance{/t}</td>
<td class="table_heading">{t}Allocate{/t}</td>
</tr>
{foreach from=$invoices item=record}
<tr id="row{$record.id}" onclick="row_sel('{$record.id}',1);" ondblclick="window.location='?_page=invoice:view&amp;id={$record.id},';" onmouseover="row_mouseover('{$record.id}','row_mouse_over_select','row_mouse_over');" onmouseout="row_mouseout('{$record.id}','{$record._C}','row_select');" class="{$record._C}">
<td>{$list->date($record.date_orig)}</td>
<td id="record{$record.id}" style="width: 150px;">{$record.id}</td>
<td>{$list->format_currency_num($record.total_amt,$smarty.const.SESS_CURRENCY)} ({$list->format_currency_num($record.credit_amt,$smarty.const.SESS_CURRENCY)})</td>
<td>{$list->format_currency_num($record.balance,$smarty.const.SESS_CURRENCY)}</td>
<td><input type="text" name="payment_item_allocate[{$record.id}]" value="{$record.alloc_amt}"/></td>
</tr>
{/foreach}
</table>
</td>
</tr>
<tr class="row1">
<td>&nbsp;</td>
</tr>
<tr class="row2">
{include file='file:../core/view_td_submit.tpl'}
</tr>
</table>
<div>
<input type="hidden" name="do[]" value="payment_item:allocate"/>
</div>
</form>
</div>
{/if}

View File

@ -1,62 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
{$method->exe($meth.0,$meth.1)}
{if ($method->result == false)}
{$block->display('core:method_error')}
{else}
<form id="search_form" method="post" action="" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr valign="top">
<td class="table_heading">{osb f=tt}</td>
</tr>
<tr valign="top">
<td class="row1">
<table width="100%" border="0" cellspacing="3" cellpadding="1" class="row1">
<tr valign="top">
<td width="35%">{osb f=tf field=account_id}</td>
<td width="65%">{osb f=autoselect module=account return=id field=payment_account_id default=$record.account_id}</td>
</tr>
<tr valign="top">
<td width="35%">{osb f=tf field=source_id}</td>
<td width="65%">{osb f=autoselect module=account return=id field=payment_source_id default=$record.source_id}</td>
</tr>
<tr valign="top">
<td width="35%">{osb f=tf field=checkout_plugin_id}</td>
<td width="65%">{$list->menu('','payment_checkout_plugin_id','checkout','name','','form_menu',true)}</td>
</tr>
<tr valign="top">
<td width="35%">{osb f=tf field=billed_currency_id}</td>
<td width="65%">{$list->menu('','payment_billed_currency_id','currency','name','','form_menu',true)}</td>
</tr>
<tr valign="top">
<td width="35%">{osb f=tf field=date_orig}</td>
<td width="65%">{$list->calender_search('payment_date_orig',$VAR.payment_date_orig,'form_field','')}</td>
</tr>
<tr valign="top">
<td width="35%">{osb f=tf field=payment_date}</td>
<td width="65%">{$list->calender_search('payment_payment_date',$VAR.payment_payment_date,'form_field','')}</td>
</tr>
<tr valign="top">
<td width="35%">{osb f=tf field=refund_status}</td>
<td width="65%">{$list->bool('payment_refund_status','all')}</td>
</tr>
{include file='file:../core/search_post.tpl'}
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
{$block->display('core:saved_searches')}
{$block->display('core:recent_searches')}
{/if}

View File

@ -1,12 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
{$method->exe($meth.0,$meth.1)}
{if ($method->result == false)}
{$block->display('core:method_error')}
{else}
{include file='file:../core/search_show_pre.tpl'}
{$method->exe_noauth($meth.0,'tpl_search_show',$search_show)}
{include file='file:../core/search_show_post-1.tpl'}
{include file='file:../core/search_show_post-2.tpl'}
{/if}

View File

@ -1,77 +0,0 @@
{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->
{$method->exe($meth.0,$meth.1)}
{if ($method->result == false)}
{$block->display('core:method_error')}
{else}
{include file='file:../core/view_pre.tpl'}
<!-- Display the field validation -->
{if $form_validation}
{$block->display('core:alert_fields')}
{/if}
<!-- Display each record -->
<form id="view" method="post" action="" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr valign="top">
<td class="table_heading">{osb f=tt} {$record.id}</td>
</tr>
<tr valign="top">
<td class="row1">
<table width="100%" border="0" cellspacing="3" cellpadding="1" class="row1">
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=account_id}</td>
<td style="width: 65%;">{osb f=autoselect module=account return=id field=payment_account_id default=$record.account_id}</td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=date_payment}</td>
<td style="width: 65%;">{$list->calender_view('payment_date_payment',$record.date_payment,'form_field')}</td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=checkout_plugin_id}</td>
<td style="width: 65%;">{$list->mmenu('no','payment_checkout_plugin_id','checkout','name',$record.checkout_plugin_id,'active=1','',true)}</td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=total_amt}</td>
<td style="width: 65%;"><input type="text" name="payment_total_amt" value="{$record.total_amt}" {if $payment_total_amt == true}class="form_field_error"{/if}/></td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=fees_amt}</td>
<td style="width: 65%;"><input type="text" name="payment_fees_amt" value="{$record.fees_amt}" {if $payment_fees_amt == true}class="form_field_error"{/if}/></td>
</tr>
<tr valign="top">
<td style="width: 35%;">{osb f=tf field=notes}</td>
<td style="width: 65%;"><textarea name="payment_notes" cols="25" rows="2" {if $payment_notes == true}class="form_field_error"{/if}>{$record.notes}</textarea></td>
</tr>
</table>
</td>
</tr>
{include file='file:../core/view_tr_submit_delete.tpl'}
</table>
</td>
</tr>
</table>
{include file='file:../core/view_post.tpl'}
</form>
<iframe name="iframe" id="iframe" style="border:0px; width:0px; height:0px;" scrolling="auto" allowtransparency="true" frameborder="0" src="themes/{$THEME_NAME}/IEFrameWarningBypass.htm"></iframe>
<script type="text/javascript">
<!--
{literal}
function showUnpaidInvoices(payment,account) {
showIFrame('iframe',getPageWidth(650),350,'?_page=payment:allocate&payment_id='+payment);
}
showUnpaidInvoices({/literal}{$record.id}{literal});
{/literal}
//-->
</script>
{/if}