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

@@ -111,7 +111,11 @@ class AccountsController extends AppController {
*/
function newledger($id = null) {
if (!$this->Account->closeCurrentLedger($id)) {
$result = $this->Account->closeCurrentLedgers($id);
if ($result['error']) {
pr(compact('result'));
die("Unable to create new ledger.");
$this->Session->setFlash(__('Unable to create new Ledger.', true));
}
if ($id)
@@ -172,8 +176,8 @@ class AccountsController extends AppController {
array('fields' => array('id', 'sequence', 'name')),
'Ledger' =>
array('Close' => array
('order' => array('Close.stamp' => 'DESC'))),
array('CloseTransaction' => array
('order' => array('CloseTransaction.stamp' => 'DESC'))),
),
'conditions' => array(array('Account.id' => $id)),
)

View File

@@ -63,7 +63,7 @@ class LedgersController extends AppController {
array(// Models
'Account',
'LedgerEntry',
'Close',
'CloseTransaction',
),
);
}
@@ -79,10 +79,10 @@ class LedgersController extends AppController {
$conditions = parent::gridDataConditions($params, $model);
if ($params['action'] === 'current') {
$conditions[] = array('NOT' => array('Ledger.closed'));
$conditions[] = array('Ledger.close_transaction_id' => null);
}
elseif ($params['action'] === 'closed') {
$conditions[] = 'Ledger.closed';
$conditions[] = array('Ledger.close_transaction_id !=' => null);
}
return $conditions;

View File

@@ -162,53 +162,60 @@ class TransactionsController extends AppController {
//pr($this->data);
// Start building data for our deposit
$deposit = array('close_id' => null,
'Transaction' => array(),
'Entry' => array());
// Go through each type of tender presented to the user
// Determine which are to be deposited, and which are to
// have their corresponding account ledgers closed.
$type_ids = $close_type_ids = array();
foreach ($this->data['TenderType'] AS $type_id => $type) {
if (!$type['checked'])
continue;
$type_ids[] = $type_id;
$tenders = $this->Transaction->DepositTender->find
('all',
array('contain' => array
('TenderType', 'LedgerEntry'),
'conditions' => array(array('DepositTender.deposit_transaction_id' => null),
array('TenderType.id' => $type_id)),
));
// Prepare for the actual deposit
foreach ($tenders AS $tender) {
$deposit['Entry'][] =
array('tender_id' => $tender['DepositTender']['id'],
'account_id' => $tender['LedgerEntry']['account_id'],
'amount' => $tender['LedgerEntry']['amount'],
);
}
if (!empty($type['close']) && !empty($tenders)) {
// Close the associated ledger
$result = $this->Transaction->Account->closeCurrentLedger
($tenders[0]['TenderType']['account_id'], $deposit['close_id']);
if (!$result['error'] && empty($deposit['close_id']))
$deposit['close_id'] = $result['close_id'];
}
if (!empty($type['close']))
$close_type_ids[] = $type_id;
}
// Find all items which are actually to be deposited
$tenders = $this->Transaction->DepositTender->find
('all',
array('contain' => array('TenderType', 'LedgerEntry'),
'conditions' => array(array('DepositTender.deposit_transaction_id' => null),
array('TenderType.id' => $type_ids)),
));
// Prepare for the deposit by building a list of entries
$deposit = array('Transaction' => array(), 'Entry' => array());
foreach ($tenders AS $tender) {
$deposit['Entry'][] =
array('tender_id' => $tender['DepositTender']['id'],
'account_id' => $tender['LedgerEntry']['account_id'],
'amount' => $tender['LedgerEntry']['amount'],
);
}
// OK, perform the deposit and associated accounting
$result = $this->Transaction->addDeposit
($deposit, $this->data['Deposit']['Account']['id']);
//pr(compact('deposit', 'result'));
// Now find out which accounts are to be closed...
$accounts = $this->Transaction->DepositTender->find
('all',
array('contain' => array('TenderType.account_id'),
'conditions' => array(array('TenderType.id' => $close_type_ids)),
));
// ... and close them
$this->Transaction->Account->closeCurrentLedgers
(array_map(create_function('$item', 'return $item["TenderType"]["account_id"];'), $accounts));
// Look out for errors
if ($result['error']) {
$this->Session->setFlash(__('Unable to Create Deposit', true));
$this->redirect(array('controller' => 'tenders', 'action'=>'deposit'));
}
// Present the deposit slip to the user
$this->redirect(array('controller' => 'transactions',
'action' => 'deposit_slip',
$result['transaction_id']));