Nowhere near done yet, but checking in a snapshot of semi-working code. There is some simultaneous support for both with and without use of the Invoice/Receipt account. I want to do away with them completely, but will need to change how sitelink payments are mapped (right now, they split a payment into multiple parts to match the charge).
git-svn-id: file:///svn-source/pmgr/branches/single_AR_20090622@181 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -82,37 +82,26 @@ class Account extends AppModel {
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: securityDepositAccountID
|
||||
* - Returns the ID of the Security Deposit Account
|
||||
* function: accountNameToID
|
||||
* - Returns the ID of the named account
|
||||
*/
|
||||
function securityDepositAccountID() {
|
||||
function accountNameToID($name) {
|
||||
$this->cacheQueries = true;
|
||||
$account = $this->find('first', array
|
||||
('recursive' => -1,
|
||||
'conditions' => array
|
||||
(array('name' => 'Security Deposit')),
|
||||
'conditions' => compact('name'),
|
||||
));
|
||||
$this->cacheQueries = false;
|
||||
return $account['Account']['id'];
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function:rentAccountID
|
||||
* - Returns the ID of the Rent Account
|
||||
*/
|
||||
function rentAccountID() {
|
||||
$this->cacheQueries = true;
|
||||
$account = $this->find('first', array
|
||||
('recursive' => -1,
|
||||
'conditions' => array
|
||||
(array('name' => 'Rent')),
|
||||
));
|
||||
$this->cacheQueries = false;
|
||||
return $account['Account']['id'];
|
||||
}
|
||||
function securityDepositAccountID() { return $this->accountNameToID('Security Deposit'); }
|
||||
function rentAccountID() { return $this->accountNameToID('Rent'); }
|
||||
function accountReceivableAccountID() { return $this->accountNameToID('A/R'); }
|
||||
function invoiceAccountID() { return $this->accountReceivableAccountID(); }
|
||||
function receiptAccountID() { return $this->accountReceivableAccountID(); }
|
||||
//function invoiceAccountID() { return $this->accountNameToID('Invoice'); }
|
||||
//function receiptAccountID() { return $this->accountNameToID('Receipt'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
@@ -122,22 +111,19 @@ class Account extends AppModel {
|
||||
* - Returns an array of ledger ids from the given account
|
||||
*/
|
||||
function ledgers($id, $all = false) {
|
||||
$cachekey = $all ? 'all' : 'current';
|
||||
if (isset($this->cache[$id]['ledgers'][$cachekey])) {
|
||||
return $this->cache[$id]['ledgers'][$cachekey];
|
||||
}
|
||||
|
||||
if ($all) {
|
||||
$contain = array('Ledger' => array('fields' => array('Ledger.id')));
|
||||
} else {
|
||||
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
|
||||
}
|
||||
|
||||
$this->cacheQueries = true;
|
||||
$account = $this->find('first', array
|
||||
('contain' => $contain,
|
||||
'fields' => array(),
|
||||
'conditions' => array(array('Account.id' => $id)),
|
||||
));
|
||||
$this->cacheQueries = false;
|
||||
|
||||
if ($all) {
|
||||
$ledger_ids = array();
|
||||
@@ -148,14 +134,11 @@ class Account extends AppModel {
|
||||
$ledger_ids = array($account['CurrentLedger']['id']);
|
||||
}
|
||||
|
||||
// Save the ledgers in our cache for future reference
|
||||
$this->cache[$id]['ledgers'][$cachekey] = $ledger_ids;
|
||||
|
||||
/* pr(array('function' => 'Account::ledgers', */
|
||||
/* 'args' => compact('id', 'all'), */
|
||||
/* 'return' => $this->cache[$id]['ledgers'][$cachekey])); */
|
||||
/* 'return' => $ledger_ids)); */
|
||||
|
||||
return $this->cache[$id]['ledgers'][$cachekey];
|
||||
return $ledger_ids;
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +217,11 @@ class Account extends AppModel {
|
||||
* (such as charges not paid).
|
||||
*/
|
||||
|
||||
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
|
||||
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null, $cond = null) {
|
||||
if (!isset($cond))
|
||||
$cond = array();
|
||||
$cond[] = array('Account.id' => $id);
|
||||
|
||||
foreach (($fundamental_type
|
||||
? array($fundamental_type)
|
||||
: array('debit', 'credit')) AS $fund) {
|
||||
@@ -260,7 +247,7 @@ class Account extends AppModel {
|
||||
'group' => ("LedgerEntry.id" .
|
||||
" HAVING LedgerEntry.amount" .
|
||||
" <> COALESCE(SUM(Reconciliation.amount),0)"),
|
||||
'conditions' => array('Account.id' => $id),
|
||||
'conditions' => $cond,
|
||||
'fields' => array(),
|
||||
));
|
||||
$balance = 0;
|
||||
@@ -290,7 +277,7 @@ class Account extends AppModel {
|
||||
* whatever algorithm is simplest.
|
||||
*/
|
||||
|
||||
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
|
||||
function reconcileNewLedgerEntry($id, $fundamental_type, $amount, $cond = null) {
|
||||
$ofund = $this->fundamentalOpposite($fundamental_type);
|
||||
$unreconciled = array($ofund => array('entry'=>array(), 'balance'=>0));
|
||||
$applied = 0;
|
||||
@@ -298,7 +285,7 @@ class Account extends AppModel {
|
||||
// if there is no money in the entry, it can reconcile nothing
|
||||
// don't bother wasting time sifting ledger entries.
|
||||
if ($amount > 0) {
|
||||
$unreconciled = $this->findUnreconciledLedgerEntries($id, $ofund);
|
||||
$unreconciled = $this->findUnreconciledLedgerEntries($id, $ofund, $cond);
|
||||
|
||||
foreach ($unreconciled[$ofund]['entry'] AS $i => &$entry) {
|
||||
// Determine if amount is sufficient to cover the entry
|
||||
|
||||
Reference in New Issue
Block a user