Got the ledger closings to work again. This seems to work ok, although I notice closing the ledger after deposit results in a balance forward entry of $0.00 . I'll work on it next

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@421 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-30 01:59:10 +00:00
parent 42677ae2f4
commit 55c5c9e9e6
11 changed files with 186 additions and 192 deletions

View File

@@ -9,8 +9,8 @@ class Account extends AppModel {
// engine specific code. However, it doesn't
// work with the Linkable behavior. I need to
// look into that, just not right now.
//'conditions' => array('CurrentLedger.close_id' => null),
'conditions' => array('CurrentLedger.close_id IS NULL'),
//'conditions' => array(array('CurrentLedger.close_transaction_id' => null)),
'conditions' => array('CurrentLedger.close_transaction_id IS NULL'),
),
);
@@ -72,7 +72,7 @@ class Account extends AppModel {
else
$fund = $this->fundamentalType($id_or_type);
if ($fund == 'debit')
if (strtolower($fund) == 'debit')
return 'credit';
return 'debit';
@@ -289,39 +289,24 @@ class Account extends AppModel {
* - Closes the current account ledger, and opens a new one
* with the old balance carried forward.
*/
function closeCurrentLedger($id = null, $close_id = null) {
$ret = array();
if (!$close_id) {
$close = new Close();
$close->create();
if (!$close->save(array('stamp' => null), false))
return array('error' => true) + $ret;
$ret['close_id'] = $close->id;
}
else {
$ret['close_id'] = $close_id;
}
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
function closeCurrentLedgers($ids = null) {
$this->cacheQueries = true;
$account = $this->find('all', array
('contain' => $contain,
('contain' => array('CurrentLedger.id'),
'fields' => array(),
'conditions' =>
$id ? array(array('Account.id' => $id)) : array()
'conditions' => (empty($ids)
? array()
: array(array('Account.id' => $ids)))
));
$this->cacheQueries = false;
//pr(compact('id', 'account'));
foreach ($account AS $acct) {
if (!$this->Ledger->closeLedger($acct['CurrentLedger']['id'], $ret['close_id']))
return array('error' => true) + $ret;
$ret['ledgers'][] = $acct['CurrentLedger']['id'];
}
$ledger_ids = array();
foreach ($account AS $acct)
$ledger_ids[] = $acct['CurrentLedger']['id'];
return $ret + array('error' => false);
return $this->Ledger->closeLedgers($ledger_ids);
}
@@ -744,50 +729,6 @@ class Account extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: closeAndDeposit
* - Closes the current set of ledgers, transferring
* their balances to specified ledger.
*/
function closeAndDeposit($set, $deposit_account_id) {
$close = new Close();
$close->create();
if (!$close->save(array('stamp' => null, 'comment' => 'Deposit'), false)) {
return false;
}
$transaction = array();
foreach ($set AS $ledger) {
// REVISIT <AP>: 20090710
// If the user said to include a ledger in the
// set, should we really be excluding it?
if ($ledger['total'] == 0)
continue;
$ids = $this->postLedgerEntry
($transaction,
null,
array('debit_account_id' => $deposit_account_id,
'credit_ledger_id' => $ledger['id'],
'amount' => $ledger['total']),
// Reconcile the account for cash/check/etc,
// which is the credit side of this entry.
array('credit' => $ledger['entries']));
//pr(compact('ids'));
if ($ids['error'])
die("closeAndDeposit : postLedgerEntry returned error!");
$transaction = array_intersect_key($ids, array('transaction_id'=>1));
$this->Ledger->closeLedger($ledger['id'], $close->id);
}
}
/**************************************************************************
**************************************************************************
**************************************************************************