Another snapshot
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@356 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -73,26 +73,27 @@ class Customer extends AppModel {
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findSecurityDeposits
|
||||
* function: securityDeposits
|
||||
* - Returns an array of security deposit entries
|
||||
*/
|
||||
function findSecurityDeposits($id, $link = null) {
|
||||
/* pr(array('function' => 'Customer::findSecurityDeposits', */
|
||||
/* 'args' => compact('id', 'link'), */
|
||||
/* )); */
|
||||
function securityDeposits($id, $query = null) {
|
||||
$this->queryInit($query);
|
||||
|
||||
$A = new Account();
|
||||
$entries = $A->ledgerEntries
|
||||
($A->securityDepositAccountID(),
|
||||
true, array('DoubleEntry.customer_id' => $id), $link);
|
||||
|
||||
/* pr(array('function' => 'Customer::findSecurityDeposits', */
|
||||
/* 'args' => compact('id', 'link'), */
|
||||
/* 'vars' => compact('customer'), */
|
||||
/* 'return' => compact('entries'), */
|
||||
/* )); */
|
||||
if (!isset($query['link']['DoubleEntry']))
|
||||
$query['link']['DoubleEntry'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Customer']))
|
||||
$query['link']['DoubleEntry']['Customer'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
|
||||
$query['link']['DoubleEntry']['Customer']['fields'] = array();
|
||||
|
||||
return $entries;
|
||||
$query['conditions'][] = array('Customer.id' => $id);
|
||||
$query['conditions'][] = array('Entry.account_id' => $A->securityDepositAccountID());
|
||||
|
||||
$set = $this->DoubleEntry->Entry->reconciledSet('CHARGE', $query);
|
||||
//pr(compact('set'));
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,20 +104,45 @@ class Customer extends AppModel {
|
||||
* - 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'));
|
||||
function unreconciledCharges($id, $query = null) {
|
||||
$this->queryInit($query);
|
||||
|
||||
if (!isset($query['link']['DoubleEntry']))
|
||||
$query['link']['DoubleEntry'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Customer']))
|
||||
$query['link']['DoubleEntry']['Customer'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
|
||||
$query['link']['DoubleEntry']['Customer']['fields'] = array();
|
||||
|
||||
$query['conditions'][] = array('Customer.id' => $id);
|
||||
|
||||
$set = $this->DoubleEntry->Entry->reconciledSet('CHARGE', $query, true);
|
||||
//pr(compact('set'));
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: excessPayments
|
||||
* - Returns payments which have not yet been fully utilized
|
||||
*/
|
||||
|
||||
function excessPayments($id, $query = null) {
|
||||
$this->queryInit($query);
|
||||
|
||||
if (!isset($query['link']['DoubleEntry']))
|
||||
$query['link']['DoubleEntry'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Customer']))
|
||||
$query['link']['DoubleEntry']['Customer'] = array();
|
||||
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
|
||||
$query['link']['DoubleEntry']['Customer']['fields'] = array();
|
||||
|
||||
$query['conditions'][] = array('Customer.id' => $id);
|
||||
|
||||
$set = $this->DoubleEntry->Entry->reconciledSet('PAYMENT', $query, true);
|
||||
//pr(compact('set'));
|
||||
return $set;
|
||||
}
|
||||
|
||||
@@ -125,8 +151,7 @@ class Customer extends AppModel {
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: paymentWouldReconcile
|
||||
* - Returns which ledger entries a new credit/debit would
|
||||
* reconcile, and how much.
|
||||
* - Returns which charges a new payment would reconcile
|
||||
*
|
||||
* - REVISIT <AP> 20090617
|
||||
* This should be subject to different algorithms, such
|
||||
@@ -135,16 +160,17 @@ class Customer extends AppModel {
|
||||
* whatever algorithm is simplest.
|
||||
*/
|
||||
|
||||
function paymentWouldReconcile($id, $amount, $cond = null, $link = null) {
|
||||
function paymentWouldReconcile($id, $amount, $query = null) {
|
||||
$unreconciled = array($ofund => array('entry'=>array(), 'balance'=>0));
|
||||
$applied = 0;
|
||||
|
||||
if ($amount <= 0)
|
||||
return;
|
||||
|
||||
$unreconciled = $this->unreconciledEntries($id, 'CHARGE', $cond, $link);
|
||||
$unreconciled = array();
|
||||
$unreconciled['entries'] = $this->unreconciledCharges($id, $query);
|
||||
|
||||
foreach ($unreconciled AS $i => &$item) {
|
||||
foreach ($unreconciled['entries'] AS $i => &$item) {
|
||||
$entry =& $item['DoubleEntry'];
|
||||
// Determine if amount is sufficient to cover the entry
|
||||
if ($amount > $entry['balance'])
|
||||
@@ -170,51 +196,6 @@ class Customer extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findUnreconciledLedgerEntries
|
||||
* - Returns ledger entries that are not yet reconciled
|
||||
* (such as charges not paid).
|
||||
*/
|
||||
|
||||
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
|
||||
$A = new Account();
|
||||
$unreconciled = $A->findUnreconciledLedgerEntries
|
||||
($A->accountReceivableAccountID(),
|
||||
$fundamental_type,
|
||||
array('DoubleEntry.customer_id' => $id));
|
||||
|
||||
return $unreconciled;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: amountWouldReconcile
|
||||
* - 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 amountWouldReconcile($id, $fundamental_type, $amount) {
|
||||
$A = new Account();
|
||||
$reconciled = $A->amountWouldReconcile
|
||||
($A->accountReceivableAccountID(),
|
||||
$fundamental_type,
|
||||
$amount,
|
||||
array('DoubleEntry.customer_id' => $id));
|
||||
|
||||
return $reconciled;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -273,7 +254,7 @@ class Customer extends AppModel {
|
||||
$customer['stats'] = $this->stats($id);
|
||||
|
||||
// Figure out the total security deposit for the current lease.
|
||||
$customer['deposits'] = $this->findSecurityDeposits($id);
|
||||
$customer['deposits'] = $this->securityDeposits($id);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user