Fixed bug when marking NSF of a tender that has only been used as a surplus and never applied to any charges. Modified the applyCredits algorithm to try and distinguish between surplus credits of a lease and general customer surplus. I don't know if it works completely, but I do know it creates an issue since a lease surplus can now never be utilized without additional lease charges, a refund (no yet implemented), or moving the surplus to the customer level (not intended to be implemented).

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@483 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-04 21:19:20 +00:00
parent 1afed6a6e0
commit 67280c89e7
5 changed files with 152 additions and 77 deletions

View File

@@ -22,7 +22,7 @@ class StatementEntry extends AppModel {
);
//var $default_log_level = array('log' => 30, 'show' => 15);
var $default_log_level = array('log' => 30, 'show' => 15);
/**************************************************************************
**************************************************************************
@@ -380,12 +380,15 @@ OPTION 2
$charge_ids = null, $payment_type = null,
$customer_id = null, $lease_id = null)
{
//$this->prFunctionLevel(25);
$this->prFunctionLevel(25);
$this->prEnter(compact('query', 'receipt_id',
'charge_ids', 'payment_type',
'customer_id', 'lease_id'));
$this->queryInit($query);
if (!empty($customer_id))
$query['conditions'][] = array('StatementEntry.customer_id' => $customer_id);
if (empty($payment_type))
$payment_type = 'PAYMENT';
@@ -394,6 +397,22 @@ OPTION 2
// First, find all known credits
$lquery = $query;
$lquery['conditions'][] = array('StatementEntry.type' => 'SURPLUS');
// REVISIT <AP>: 20090804
// We need to ensure that we're using surplus credits ONLY from either
// the given lease, or those that do not apply to any specific lease.
// However, by doing this, it forces any lease surplus amounts to
// remain frozen with that lease until either there is a lease charge,
// we refund the money, or we "promote" that surplus to the customer
// level and out of the leases direct control.
// That seems like a pain. Perhaps we should allow any customer
// surplus to be used on any customer charge.
$lquery['conditions'][] =
array('OR' =>
array(array('StatementEntry.lease_id' => null),
(!empty($lease_id)
? array('StatementEntry.lease_id' => $lease_id)
: array()),
));
$lquery['order'][] = 'StatementEntry.effective_date ASC';
$credits = $this->find('all', $lquery);
$this->pr(18, compact('credits'),
@@ -403,6 +422,7 @@ OPTION 2
$receipt_credit = null;
if (!empty($receipt_id)) {
$lquery = $query;
$lquery['link'] = array('StatementEntry' => $lquery['link']);
$lquery['link'] += array('LedgerEntry' =>
array('conditions' =>
//array(LedgerEntry.'crdr'=>'DEBIT'),
@@ -429,6 +449,9 @@ OPTION 2
'conditions' => array('StatementEntry.id' => $charge_ids));
} else {
$lquery = $query;
// If we're working with a specific lease, then limit charges to it
if (!empty($lease_id))
$lquery['conditions'][] = array('StatementEntry.lease_id' => $lease_id);
}
$lquery['order'] = 'StatementEntry.effective_date ASC';
$charges = $this->reconciledSet('CHARGE', $lquery, true);