Primarly a cleanup checkin, although a couple minor bugfixes were included as well.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@82 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-10 05:14:08 +00:00
parent ffd1b64580
commit e0d9edc4a8
15 changed files with 151 additions and 519 deletions

View File

@@ -25,77 +25,6 @@ class Customer extends AppModel {
);
/**************************************************************************
**************************************************************************
**************************************************************************
* function: findAccountEntries
* - Returns an array of ledger entries that belong to the current
* ledger of the account for the given customer. There is extra work
* done... see the LedgerEntry model.
*/
/* function findAccountEntries($id, $date = null, $link = null) { */
/* $result = $this->find('first', array */
/* ('recursive' => -1, */
/* 'fields' => array('account_id'), */
/* 'conditions' => array(array('id' => $id)), */
/* )); */
/* return $this->Account->findCurrentLedgerEntries($result['account_id'], */
/* $date, $link); */
/* } */
/**************************************************************************
**************************************************************************
**************************************************************************
* function: findSecurityDeposits
* - Returns an array of security deposit entries
*/
function zfindSecurityDeposits($id, $link = null) {
pr(array('function' => 'Customer::findSecurityDeposits',
'args' => compact('id', 'link'),
));
$this->Behaviors->attach('Containable');
$customer = $this->find('first',
array('contain' =>
array('Lease' => array
('fields' => array('Lease.account_id')),
),
'fields' => array('Customer.account_id'),
'conditions' => array(array('Customer.id' => $id))));
$this->Behaviors->detach('Containable');
$account_ids = array($customer['Customer']['account_id']);
foreach ($customer['Lease'] AS $lease)
array_push($account_ids, $lease['account_id']);
$acct = new Account();
$entries = $acct->findLedgerEntriesRelatedToAccount
($acct->securityDepositAccountID(),
$account_ids,
//$acct->rentAccountID(),
//6,
//array_merge(array(1), $account_ids),
true, null, $link);
// OK, we cheated by finding the entries of the security deposit account,
// and not by finding the security deposit entries of the customer
// account(s). Therefore, we have to invert the credit/debit business.
$entries['summary']['debits'] = $entries['summary']['credit'];
$entries['summary']['credits'] = $entries['summary']['debit'];
unset($entries['summary']['credit']);
unset($entries['summary']['debit']);
pr(array('function' => 'Customer::findSecurityDeposits',
'args' => compact('id', 'link'),
'vars' => compact('customer', 'account_ids'),
'return' => compact('entries'),
));
return $entries;
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -103,9 +32,9 @@ class Customer extends AppModel {
* - Returns an array of security deposit entries
*/
function findSecurityDeposits($id, $link = null) {
/* pr(array_merge(array('function' => 'Customer::findSecurityDeposits', */
/* 'checkpoint' => 'begin'), */
/* compact('id', 'link'))); */
/* pr(array('function' => 'Customer::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */
/* )); */
$this->Behaviors->attach('Containable');
$customer = $this->find('first',
@@ -122,16 +51,16 @@ class Customer extends AppModel {
foreach ($customer['Lease'] AS $lease) {
$ledger_entries = $this->Lease->findSecurityDeposits($lease['id'], $link);
//$this->statsMerge($ledger_entries['summary'], $entries['summary']);
//unset($entries['summary']);
$this->statsMerge($entries['summary'], $ledger_entries['summary']);
$entries['Entries'] = array_merge($entries['Entries'], $ledger_entries['Entries']);
$entries['Entries'] = array_merge($entries['Entries'],
$ledger_entries['Entries']);
}
/* pr(array('function' => 'Customer::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */
/* 'vars' => compact('customer'), */
/* 'return' => compact('entries'))); */
/* 'return' => compact('entries'), */
/* )); */
return $entries;
}
@@ -148,48 +77,28 @@ class Customer extends AppModel {
if (!$id)
return null;
// Get the basic information necessary
$this->Behaviors->attach('Containable');
$customer = $this->find('first',
array('contain' =>
array('Account' => array('fields' => array('Account.id')),
'Lease' => array('fields' => array('Lease.id'))
array('Account' => array
('fields' => array('Account.id')),
'Lease' => array
('fields' => array('Lease.id'))
),
/* array('Account' => array */
/* ('fields' => array('id'), */
/* /\* 'CurrentLedger' => array *\/ */
/* /\* ('fields => *\/ */
/* /\* 'Lease' => array('fields' => array('id') *\/ */
/* ), */
/* ), */
'conditions' => array(array('Customer.id' => $id))));
'conditions' => array
(array('Customer.id' => $id))));
$this->Behaviors->detach('Containable');
// Get stats from the customer account, and each lease
$stats['Account'] = $this->Account->stats($customer['Account']['id']);
foreach ($customer['Lease'] AS $lease) {
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
}
/* foreach($lease['Customer']['Transaction'] AS $transaction) { */
/* foreach($transaction['LedgerEntry'] AS $entry) { */
/* if ($entry['DebitLedger']['Account']['name'] === 'A/R') */
/* $outstanding_balance += $entry['amount']; */
/* if ($entry['CreditLedger']['Account']['name'] === 'A/R') */
/* $outstanding_balance -= $entry['amount']; */
/* if ($entry['DebitLedger']['Account']['name'] === 'Security Deposit') */
/* $outstanding_deposit -= $entry['amount']; */
/* if ($entry['CreditLedger']['Account']['name'] === 'Security Deposit') */
/* $outstanding_deposit += $entry['amount']; */
/* } */
/* } */
/* } */
/* if ($entry['DebitLedger']['Account']['name'] === 'Security Deposit') */
/* $outstanding_deposit -= $entry['amount']; */
/* if ($entry['CreditLedger']['Account']['name'] === 'Security Deposit') */
/* $outstanding_deposit += $entry['amount']; */
// Merge the stats from both the customer specific account, as
// well as the lease. This will provide current customer standing.
// well as the leases. This will provide current customer standing.
$this->statsMerge($stats, $stats['Account']['Ledger']);
$this->statsMerge($stats, $stats['Lease']['Account']['Ledger']);