Another snapshot. I think I'll be taking the CREDIT/DEBIT reconcile functionality out.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@353 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -82,7 +82,7 @@ class Customer extends AppModel {
|
||||
/* )); */
|
||||
|
||||
$A = new Account();
|
||||
$entries = $A->findLedgerEntries
|
||||
$entries = $A->ledgerEntries
|
||||
($A->securityDepositAccountID(),
|
||||
true, array('DoubleEntry.customer_id' => $id), $link);
|
||||
|
||||
@@ -96,6 +96,80 @@ class Customer extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: unreconciledCharges
|
||||
* - Returns charges have not yet been fully paid
|
||||
*/
|
||||
|
||||
function unreconciledCharges($id, $cond = null, $link = null) {
|
||||
if (!isset($cond))
|
||||
$cond = array();
|
||||
if (!isset($link))
|
||||
$link = array();
|
||||
if (!isset($link['DoubleEntry']))
|
||||
$link['DoubleEntry'] = array();
|
||||
if (!isset($link['DoubleEntry']['Customer']))
|
||||
$link['DoubleEntry']['Customer'] = array();
|
||||
if (!isset($link['DoubleEntry']['Customer']['fields']))
|
||||
$link['DoubleEntry']['Customer']['fields'] = array();
|
||||
$cond[] = array('Customer.id' => $id);
|
||||
$set = $this->DoubleEntry->Entry->reconciledSet('CHARGE', $cond, $link, true);
|
||||
pr(compact('set'));
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: paymentWouldReconcile
|
||||
* - Returns which ledger entries a new credit/debit would
|
||||
* reconcile, and how much.
|
||||
*
|
||||
* - REVISIT <AP> 20090617
|
||||
* This should be subject to different algorithms, such
|
||||
* as apply to oldest charges first, newest first, to fees
|
||||
* before rent, etc. Until we get there, I'll hardcode
|
||||
* whatever algorithm is simplest.
|
||||
*/
|
||||
|
||||
function paymentWouldReconcile($id, $amount, $cond = null, $link = null) {
|
||||
$unreconciled = array($ofund => array('entry'=>array(), 'balance'=>0));
|
||||
$applied = 0;
|
||||
|
||||
if ($amount <= 0)
|
||||
return;
|
||||
|
||||
$unreconciled = $this->unreconciledEntries($id, 'CHARGE', $cond, $link);
|
||||
|
||||
foreach ($unreconciled AS $i => &$item) {
|
||||
$entry =& $item['DoubleEntry'];
|
||||
// Determine if amount is sufficient to cover the entry
|
||||
if ($amount > $entry['balance'])
|
||||
$apply = $entry['balance'];
|
||||
elseif ($amount > 0)
|
||||
$apply = $amount;
|
||||
else {
|
||||
unset($unreconciled[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$entry['applied'] = $apply;
|
||||
$entry['reconciled'] += $apply;
|
||||
$entry['balance'] -= $apply;
|
||||
$applied += $apply;
|
||||
$amount -= $apply;
|
||||
}
|
||||
|
||||
$unreconciled['unapplied'] = $amount;
|
||||
$unreconciled['applied'] = $applied;
|
||||
$unreconciled['balance'] -= $applied;
|
||||
return $unreconciled;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user