Primarly a cleanup checkin, although a couple minor bugfixes were included as well.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@82 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -11,7 +11,6 @@ class Account extends AppModel {
|
||||
var $hasOne = array(
|
||||
'CurrentLedger' => array(
|
||||
'className' => 'Ledger',
|
||||
//'foreignKey' => 'account_id',
|
||||
'conditions' => array('NOT' => array('CurrentLedger.closed'))
|
||||
),
|
||||
);
|
||||
@@ -21,19 +20,6 @@ class Account extends AppModel {
|
||||
);
|
||||
|
||||
var $cache;
|
||||
/* var $instantiated; */
|
||||
|
||||
|
||||
/* /\************************************************************************** */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************** */
|
||||
/* * function: constructor */
|
||||
/* *\/ */
|
||||
/* function __constructor($id = null) { */
|
||||
/* parent::__contstructor(); */
|
||||
/* $this->id = $id; */
|
||||
/* $this->instantiated = true; */
|
||||
/* } */
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
@@ -45,7 +31,8 @@ class Account extends AppModel {
|
||||
function securityDepositAccountID() {
|
||||
$account = $this->find('first', array
|
||||
('recursive' => -1,
|
||||
'conditions' => array(array('name' => 'Security Deposit')),
|
||||
'conditions' => array
|
||||
(array('name' => 'Security Deposit')),
|
||||
));
|
||||
return $account['Account']['id'];
|
||||
}
|
||||
@@ -60,7 +47,8 @@ class Account extends AppModel {
|
||||
function rentAccountID() {
|
||||
$account = $this->find('first', array
|
||||
('recursive' => -1,
|
||||
'conditions' => array(array('name' => 'Rent')),
|
||||
'conditions' => array
|
||||
(array('name' => 'Rent')),
|
||||
));
|
||||
return $account['Account']['id'];
|
||||
}
|
||||
@@ -74,10 +62,6 @@ class Account extends AppModel {
|
||||
*/
|
||||
function type($id) {
|
||||
if (isset($this->cache[$id]['type'])) {
|
||||
/* pr(array('function' => 'Account::type', */
|
||||
/* 'args' => compact('id'), */
|
||||
/* 'cache_hit' => true, */
|
||||
/* 'return' => $this->cache[$id]['type'])); */
|
||||
return $this->cache[$id]['type'];
|
||||
}
|
||||
|
||||
@@ -87,7 +71,9 @@ class Account extends AppModel {
|
||||
'conditions' => array(array('Account.id' => $id)),
|
||||
));
|
||||
|
||||
// Save the account type in our cache for future reference
|
||||
$this->cache[$id]['type'] = $account['Account']['type'];
|
||||
|
||||
/* pr(array('function' => 'Account::type', */
|
||||
/* 'args' => compact('id'), */
|
||||
/* 'return' => $this->cache[$id]['type'])); */
|
||||
@@ -105,10 +91,6 @@ class Account extends AppModel {
|
||||
function ledgers($id, $all = false) {
|
||||
$cachekey = $all ? 'all' : 'current';
|
||||
if (isset($this->cache[$id]['ledgers'][$cachekey])) {
|
||||
/* pr(array('function' => 'Account::ledgers', */
|
||||
/* 'args' => compact('id', 'all'), */
|
||||
/* 'cache_hit' => true, */
|
||||
/* 'return' => $this->cache[$id]['ledgers'][$cachekey])); */
|
||||
return $this->cache[$id]['ledgers'][$cachekey];
|
||||
}
|
||||
|
||||
@@ -135,6 +117,7 @@ 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', */
|
||||
@@ -159,19 +142,22 @@ class Account extends AppModel {
|
||||
|
||||
$entries = array();
|
||||
foreach ($this->ledgers($id, $all) AS $ledger_id) {
|
||||
$ledger_entries = $this->Ledger->findLedgerEntries($ledger_id, $this->type($id), $cond, $link);
|
||||
$ledger_entries = $this->Ledger->findLedgerEntries
|
||||
($ledger_id, $this->type($id), $cond, $link);
|
||||
$entries = array_merge($entries, $ledger_entries);
|
||||
//$entries = array_merge($entries, array_diff_key($ledger_entries, array('summary'=>1)));
|
||||
//$this->statsMerge($entries['summary'], $ledger_entries['summary']);
|
||||
}
|
||||
|
||||
$stats = $this->stats($id, $all, $cond);
|
||||
$entries = array('Entries' => $entries,
|
||||
'summary' => $stats['Ledger']);
|
||||
|
||||
/* pr(array('function' => 'Account::findLedgerEntries', */
|
||||
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||
/* 'vars' => compact('stats'), */
|
||||
/* 'return' => compact('entries'), */
|
||||
/* )); */
|
||||
|
||||
$stats = $this->stats($id, $all, $cond);
|
||||
return array('Entries' => $entries, 'summary' => $stats['Ledger']);
|
||||
return $entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -187,9 +173,9 @@ class Account extends AppModel {
|
||||
/* pr(array('function' => 'Account::findLedgerEntriesRelatedToAccount', */
|
||||
/* 'args' => compact('id', 'rel_ids', 'all', 'cond', 'link'), */
|
||||
/* )); */
|
||||
|
||||
if (!isset($cond))
|
||||
$cond = array();
|
||||
|
||||
if (!is_array($rel_ids))
|
||||
$rel_ids = array($rel_ids);
|
||||
|
||||
@@ -209,196 +195,6 @@ class Account extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findCurrentLedgerEntries
|
||||
* - Returns an array of ledger entries that belong to the current
|
||||
* ledger of the given account. There is extra work done... see the
|
||||
* LedgerEntry model.
|
||||
*/
|
||||
function findCurrentLedgerEntries($id, $cond = null, $link = null) {
|
||||
$this->Behaviors->attach('Containable');
|
||||
$account = $this->find('first', array
|
||||
('contain' => array('CurrentLedger'),
|
||||
'fields' => array('Account.type', 'CurrentLedger.id'),
|
||||
'conditions' => array(array('Account.id' => $id)),
|
||||
));
|
||||
$this->Behaviors->detach('Containable');
|
||||
|
||||
$ledger_id = $account['CurrentLedger']['id'];
|
||||
$account_type = $account['Account']['type'];
|
||||
|
||||
return $this->Ledger->findLedgerEntries($ledger_id, $account_type, $cond, $link);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findLedgerRelatedEntries
|
||||
* - Returns an array of ledger entries from this account that are
|
||||
* related to one of the given ledgers.
|
||||
*/
|
||||
function findLedgerRelatedEntries($id, $ledgers, $link = null) {
|
||||
pr(array_merge(array('function' => 'Account::findLedgerRelatedEntries',
|
||||
'checkpoint' => 'begin'),
|
||||
compact('id', 'ledgers', 'link')));
|
||||
$this->Behaviors->attach('Containable');
|
||||
$account = $this->find('first', array
|
||||
('contain' => array
|
||||
('Ledger' => array('fields' => array('Ledger.id')),
|
||||
),
|
||||
'fields' => array('Account.type'),
|
||||
'conditions' => array(array('Account.id' => $id)),
|
||||
));
|
||||
$this->Behaviors->detach('Containable');
|
||||
|
||||
$cond = array('OR' =>
|
||||
array(array('debit_ledger_id' => $ledgers),
|
||||
array('credit_ledger_id' => $ledgers)));
|
||||
|
||||
pr(array_merge(array('function' => 'Account::findLedgerRelatedEntries',
|
||||
'checkpoint' => 'get-account-ledgers'),
|
||||
compact('account', 'cond')));
|
||||
|
||||
$entries = array();
|
||||
foreach($account['Ledger'] AS $ledger) {
|
||||
//pr(array('find', $ledger, $account, $cond, $link));
|
||||
$entries = array_merge
|
||||
($entries,
|
||||
$this->Ledger->findLedgerEntries($ledger['id'],
|
||||
$account['Account']['type'],
|
||||
$cond, $link));
|
||||
}
|
||||
|
||||
foreach($entries AS $entry)
|
||||
$this->statsMerge($entries['summary'], $entry[0]);
|
||||
|
||||
//$entries['summary']
|
||||
|
||||
pr(array_merge(array('function' => 'Account::findLedgerRelatedEntries',
|
||||
'checkpoint' => 'return'),
|
||||
compact('entries')));
|
||||
return $entries;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findAccountRelatedEntries
|
||||
* - Returns an array of ledger entries from this account that are
|
||||
* related to the given account.
|
||||
*/
|
||||
function findAccountRelatedEntries($id, $relid, $link = null) {
|
||||
pr(array_merge(array('function' => 'Account::findAccountRelatedEntries',
|
||||
'checkpoint' => 'begin'),
|
||||
compact('id', 'relid', 'link')));
|
||||
$this->Behaviors->attach('Containable');
|
||||
$related = $this->find('first', array
|
||||
('contain' => array
|
||||
('Ledger' => array('fields' => array('Ledger.id')),
|
||||
),
|
||||
'fields' => array(),
|
||||
'conditions' => array(array('Account.id' => $relid)),
|
||||
));
|
||||
$this->Behaviors->detach('Containable');
|
||||
|
||||
$ledger_ids = array();
|
||||
foreach ($related['Ledger'] AS $ledger)
|
||||
array_push($ledger_ids, $ledger['id']);
|
||||
|
||||
pr(array_merge(array('function' => 'Account::findAccountRelatedEntries',
|
||||
'checkpoint' => 'get-related'),
|
||||
compact('related', 'ledger_ids')));
|
||||
|
||||
$entries = $this->findLedgerRelatedEntries($id, $ledger_ids, $link);
|
||||
pr(array_merge(array('function' => 'Account::findAccountRelatedEntries',
|
||||
'checkpoint' => 'return'),
|
||||
compact('entries')));
|
||||
return $entries;
|
||||
//return $this->findLedgerRelatedEntries($id, $ledger_ids, $link);
|
||||
}
|
||||
|
||||
|
||||
/* /\************************************************************************** */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************** */
|
||||
/* * function: findSecurityDeposits */
|
||||
/* * - Returns an array of security deposit entries */
|
||||
/* *\/ */
|
||||
/* function findSecurityDeposits($id, $link = null) { */
|
||||
/* pr(array_merge(array('function' => 'Account::findSecurityDeposits', */
|
||||
/* 'checkpoint' => 'begin'), */
|
||||
/* compact('id', 'link'))); */
|
||||
/* $sd_account = $this->find('first', array */
|
||||
/* ('recursive' => -1, */
|
||||
/* 'conditions' => array(array('name' => 'Security Deposit')), */
|
||||
/* )); */
|
||||
/* pr(array_merge(array('function' => 'Account::findSecurityDeposits', */
|
||||
/* 'checkpoint' => 'get-security-deposit-account'), */
|
||||
/* compact('sd_account'))); */
|
||||
|
||||
/* $deposits = $this->findAccountRelatedEntries($id, $sd_account['Account']['id'], $link); */
|
||||
/* pr(array_merge(array('function' => 'Account::findSecurityDeposits', */
|
||||
/* 'checkpoint' => 'return'), */
|
||||
/* compact('deposits'))); */
|
||||
/* return $deposits; */
|
||||
/* //return $this->findAccountRelatedEntries($id, $sd_account['Account']['id'], $link); */
|
||||
/* } */
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findSecurityDeposits
|
||||
* - Returns an array of security deposit entries
|
||||
*/
|
||||
function zzfindSecurityDeposits($id, $cond = array(), $link = null) {
|
||||
$this->Behaviors->attach('Containable');
|
||||
$account = $this->find('first', array
|
||||
('contain' => array
|
||||
('Ledger' => array('fields' => array('Ledger.id')),
|
||||
),
|
||||
'fields' => array('Account.type'),
|
||||
'conditions' => array(array('Account.id' => $id)),
|
||||
));
|
||||
|
||||
$sd_account = $this->find('first', array
|
||||
('contain' => array
|
||||
('Ledger' => array('fields' => array('Ledger.id')),
|
||||
),
|
||||
'conditions' => array(array('name' => 'Security Deposit')),
|
||||
));
|
||||
$this->Behaviors->detach('Containable');
|
||||
|
||||
pr(array('sd_account', $sd_account));
|
||||
$sd_ledger_ids = array();
|
||||
foreach ($sd_account['Ledger'] AS $ledger)
|
||||
array_push($sd_ledger_ids, $ledger['id']);
|
||||
|
||||
pr(array('sd_ledger_ids', $sd_ledger_ids));
|
||||
array_push($cond,
|
||||
array('OR' =>
|
||||
array(array('debit_ledger_id' => $sd_ledger_ids),
|
||||
array('credit_ledger_id' => $sd_ledger_ids))));
|
||||
|
||||
$sd_entries = array();
|
||||
foreach($account['Ledger'] AS $ledger) {
|
||||
pr(array('find', $ledger, $account, $cond, $link));
|
||||
$add = $this->Ledger->findLedgerEntries($ledger['id'],
|
||||
$account['Account']['type'],
|
||||
$cond, $link);
|
||||
$sd_entries = array_merge($sd_entries, $add);
|
||||
}
|
||||
|
||||
pr(array('sd_entries', $sd_entries));
|
||||
|
||||
//return $this->Ledger->findLedgerEntries($ledger_id, $account_type, $cond, $link);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -411,24 +207,33 @@ class Account extends AppModel {
|
||||
return null;
|
||||
|
||||
// All old, closed ledgers MUST balance to 0.
|
||||
// However, the user may want the ENTIRE running totals.
|
||||
// However, the user may want the ENTIRE running totals,
|
||||
// (not just the balance), so we may have to query all
|
||||
// ledgers, as dictated by the $all parameter.
|
||||
|
||||
$this->Behaviors->attach('Containable');
|
||||
$account = $this->find('first',
|
||||
array('contain' =>
|
||||
($all
|
||||
? array('Ledger' => array('fields' => array('id')))
|
||||
: array('CurrentLedger' => array('fields' => array('id')))
|
||||
? array('Ledger' => array
|
||||
('fields' => array('id')))
|
||||
: array('CurrentLedger' => array
|
||||
('fields' => array('id')))
|
||||
),
|
||||
'conditions' => array(array('Account.id' => $id))));
|
||||
'conditions' => array
|
||||
(array('Account.id' => $id))
|
||||
));
|
||||
$this->Behaviors->detach('Containable');
|
||||
|
||||
if ($all)
|
||||
$ledgers = $account['Ledger'];
|
||||
else
|
||||
$ledgers = array($account['CurrentLedger']);
|
||||
|
||||
foreach ($ledgers AS $ledger) {
|
||||
$this->statsMerge($stats['Ledger'], $this->Ledger->stats($ledger['id'], $cond));
|
||||
$stats = array();
|
||||
if ($all) {
|
||||
foreach ($account['Ledger'] AS $ledger)
|
||||
$this->statsMerge($stats['Ledger'],
|
||||
$this->Ledger->stats($ledger['id'], $cond));
|
||||
}
|
||||
else {
|
||||
$stats['Ledger'] =
|
||||
$this->Ledger->stats($account['CurrentLedger']['id'], $cond);
|
||||
}
|
||||
|
||||
return $stats;
|
||||
|
||||
Reference in New Issue
Block a user