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/site@181 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-23 19:04:41 +00:00
parent 7ea002850a
commit 009ea6b44d
16 changed files with 200 additions and 193 deletions

View File

@@ -25,11 +25,18 @@ class Lease extends AppModel {
var $belongsTo = array(
'LeaseType',
'Unit',
'Account',
'Customer',
'LateSchedule',
);
var $hasMany = array(
'LedgerEntry',
// Cheat to get Account set as part of this class
'Account',
);
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -37,15 +44,7 @@ class Lease extends AppModel {
* - Returns the accountId of the given lease
*/
function accountId($id) {
$this->cacheQueries = true;
$lease = $this->find('first', array
('recursive' => -1,
'fields' => array('account_id'),
'conditions' => array(array('id' => $id)),
));
$this->cacheQueries = false;
return $lease['Lease']['account_id'];
return $this->Account->invoiceAccountID();
}
@@ -61,6 +60,10 @@ class Lease extends AppModel {
/* 'args' => compact('id', 'all', 'cond', 'link'), */
/* )); */
if (!isset($cond))
$cond = array();
$cond[] = array('LedgerEntry.lease_id' => $id);
$entries = $this->Account->findLedgerEntries($this->accountId($id),
$all, $cond, $link);
@@ -87,7 +90,7 @@ class Lease extends AppModel {
$entries = $this->Account->findLedgerEntriesRelatedToAccount
($this->accountId($id),
$this->Account->securityDepositAccountID(),
true, null, $link);
true, array('LedgerEntry.lease_id' => $id), $link);
/* pr(array('function' => 'Lease::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */
@@ -108,7 +111,7 @@ class Lease extends AppModel {
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
return $this->Account->findUnreconciledLedgerEntries
($this->accountId($id), $fundamental_type);
($this->accountId($id), $fundamental_type, array('LedgerEntry.lease_id' => $id));
}
@@ -128,7 +131,7 @@ class Lease extends AppModel {
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
return $this->Account->reconcileNewLedgerEntry
($this->accountId($id), $fundamental_type, $amount);
($this->accountId($id), $fundamental_type, $amount, array('LedgerEntry.lease_id' => $id));
}
@@ -143,18 +146,11 @@ class Lease extends AppModel {
if (!$id)
return null;
// Find the associated account.
$lease = $this->find('first',
array('recursive' => -1,
'conditions' => array(array('Lease.id' => $id))));
// Pull the stats from the account.
$stats['Account'] = $this->Account->stats($lease['Lease']['account_id']);
// Place a summary of the stats (one lease account in this case)
// at the top level for easy summarized access.
$this->statsMerge($stats, $stats['Account']['Ledger']);
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
array('LedgerEntry.lease_id' => $id));
// Pull to the top level and return
$stats = $stats['Ledger'];
return $stats;
}