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:
@@ -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']));
|
||||
|
||||
Reference in New Issue
Block a user