Removed remnants of the Containable behavior (which we've already put into the application model. Modified the account model to look for all unreconciled transactions, not just those from the current ledger. Added a mechanism to find unreconciled transactions up the chain, including lease and customer.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@159 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-17 09:00:38 +00:00
parent 16126b7b6e
commit 45ae013e99
5 changed files with 53 additions and 15 deletions

View File

@@ -100,13 +100,11 @@ class Account extends AppModel {
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id'))); $contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
} }
$this->Behaviors->attach('Containable');
$account = $this->find('first', array $account = $this->find('first', array
('contain' => $contain, ('contain' => $contain,
'fields' => array(), 'fields' => array(),
'conditions' => array(array('Account.id' => $id)), 'conditions' => array(array('Account.id' => $id)),
)); ));
$this->Behaviors->detach('Containable');
if ($all) { if ($all) {
$ledger_ids = array(); $ledger_ids = array();
@@ -199,7 +197,8 @@ class Account extends AppModel {
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* function: findUnreconciledLedgerEntries * function: findUnreconciledLedgerEntries
* - Returns summary data from the requested account. * - Returns ledger entries that are not yet reconciled
* (such as charges not paid).
*/ */
function findUnreconciledLedgerEntries($id = null) { function findUnreconciledLedgerEntries($id = null) {
@@ -207,7 +206,7 @@ class Account extends AppModel {
$unreconciled['debits'] = $this->find $unreconciled['debits'] = $this->find
('all', array ('all', array
('link' => array ('link' => array
('CurrentLedger' => array ('Ledger' => array
('fields' => array(), ('fields' => array(),
'DebitLedgerEntry' => array 'DebitLedgerEntry' => array
('fields' => array('id', 'amount'), ('fields' => array('id', 'amount'),
@@ -229,7 +228,7 @@ class Account extends AppModel {
$unreconciled['credits'] = $this->find $unreconciled['credits'] = $this->find
('all', array ('all', array
('link' => array ('link' => array
('CurrentLedger' => array ('Ledger' => array
('fields' => array(), ('fields' => array(),
'CreditLedgerEntry' => array 'CreditLedgerEntry' => array
('fields' => array('id', 'amount'), ('fields' => array('id', 'amount'),
@@ -268,7 +267,6 @@ class Account extends AppModel {
// (not just the balance), so we may have to query all // (not just the balance), so we may have to query all
// ledgers, as dictated by the $all parameter. // ledgers, as dictated by the $all parameter.
$this->Behaviors->attach('Containable');
$account = $this->find('first', $account = $this->find('first',
array('contain' => array('contain' =>
($all ($all
@@ -280,7 +278,6 @@ class Account extends AppModel {
'conditions' => array 'conditions' => array
(array('Account.id' => $id)) (array('Account.id' => $id))
)); ));
$this->Behaviors->detach('Containable');
$stats = array(); $stats = array();
if ($all) { if ($all) {

View File

@@ -39,13 +39,11 @@ class Customer extends AppModel {
/* 'args' => compact('id', 'link'), */ /* 'args' => compact('id', 'link'), */
/* )); */ /* )); */
$this->Behaviors->attach('Containable');
$customer = $this->find('first', $customer = $this->find('first',
array('contain' => array('contain' =>
array('Lease' => array('fields' => array('id'))), array('Lease' => array('fields' => array('id'))),
'fields' => array('account_id'), 'fields' => array('account_id'),
'conditions' => array(array('Customer.id' => $id)))); 'conditions' => array(array('Customer.id' => $id))));
$this->Behaviors->detach('Containable');
$entries = $this->Account->findLedgerEntriesRelatedToAccount $entries = $this->Account->findLedgerEntriesRelatedToAccount
($customer['Customer']['account_id'], ($customer['Customer']['account_id'],
@@ -69,6 +67,36 @@ class Customer extends AppModel {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* function: findUnreconciledLedgerEntries
* - Returns ledger entries that are not yet reconciled
* (such as charges not paid).
*/
function findUnreconciledLedgerEntries($id = null) {
$customer = $this->find('first',
array('contain' =>
array('Lease' => array('fields' => array('id'))),
'fields' => array('account_id'),
'conditions' => array(array('Customer.id' => $id))));
$unreconciled = $this->Account->findUnreconciledLedgerEntries
($customer['Customer']['account_id']);
foreach ($customer['Lease'] AS $lease) {
$lease_unrec = $this->Lease->findUnreconciledLedgerEntries($lease['id']);
$unreconciled['debits'] = array_merge($unreconciled['debits'],
$lease_unrec['debits']);
$unreconciled['credits'] = array_merge($unreconciled['credits'],
$lease_unrec['credits']);
}
return $unreconciled;
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
@@ -132,7 +160,6 @@ class Customer extends AppModel {
return null; return null;
// Get the basic information necessary // Get the basic information necessary
$this->Behaviors->attach('Containable');
$customer = $this->find('first', $customer = $this->find('first',
array('contain' => array('contain' =>
array('Account' => array array('Account' => array
@@ -143,7 +170,6 @@ class Customer extends AppModel {
), ),
'conditions' => array 'conditions' => array
(array('Customer.id' => $id)))); (array('Customer.id' => $id))));
$this->Behaviors->detach('Containable');
// Get stats from the customer account, and each lease // Get stats from the customer account, and each lease
$stats['Account'] = $this->Account->stats($customer['Account']['id']); $stats['Account'] = $this->Account->stats($customer['Account']['id']);

View File

@@ -91,6 +91,25 @@ class Lease extends AppModel {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* function: findUnreconciledLedgerEntries
* - Returns ledger entries that are not yet reconciled
* (such as charges not paid).
*/
function findUnreconciledLedgerEntries($id = null) {
$lease = $this->find('first', array
('recursive' => -1,
'fields' => array('account_id'),
'conditions' => array(array('id' => $id)),
));
return $this->Account->findUnreconciledLedgerEntries($lease['Lease']['account_id']);
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************

View File

@@ -57,7 +57,6 @@ class Ledger extends AppModel {
/* )); */ /* )); */
if (!isset($account_type)) { if (!isset($account_type)) {
$this->Behaviors->attach('Containable');
$ledger = $this->find('first', array $ledger = $this->find('first', array
('contain' => array ('contain' => array
('Account' => array ('Account' => array
@@ -67,7 +66,6 @@ class Ledger extends AppModel {
'fields' => array(), 'fields' => array(),
'conditions' => array(array('Ledger.id' => $id)), 'conditions' => array(array('Ledger.id' => $id)),
)); ));
$this->Behaviors->detach('Containable');
$account_type = $ledger['Account']['type']; $account_type = $ledger['Account']['type'];
} }

View File

@@ -70,7 +70,6 @@ class Unit extends AppModel {
return null; return null;
// Get the basic information necessary // Get the basic information necessary
$this->Behaviors->attach('Containable');
$unit = $this->find('first', $unit = $this->find('first',
array('contain' => array array('contain' => array
('Lease' => array ('Lease' => array
@@ -82,7 +81,6 @@ class Unit extends AppModel {
'conditions' => array 'conditions' => array
(array('Unit.id' => $id)), (array('Unit.id' => $id)),
)); ));
$this->Behaviors->detach('Containable');
// Get the stats for the current lease // Get the stats for the current lease
$stats['CurrentLease'] = $this->Lease->stats($unit['CurrentLease']['id']); $stats['CurrentLease'] = $this->Lease->stats($unit['CurrentLease']['id']);