Got the bank deposit working well.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@198 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-02 07:41:18 +00:00
parent 5fa166e881
commit b5d7ecc269
5 changed files with 203 additions and 69 deletions

View File

@@ -139,6 +139,85 @@ class AccountsController extends AppController {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit
* - Prepares the books for a bank deposit
*/
function deposit() {
if ($this->data) {
pr($this->data);
$deposit = array('total' => 0, 'ledgers' => array());
$transaction = array();
foreach ($this->data['Tillable']['Ledger'] AS $ledger_id => $ledger) {
if (!$ledger['checked'])
continue;
/* pr(array('checkpoint' => 'save data', */
/* compact('ledger'))); */
$ledger_entries =
$this->Account->Ledger->find
('all',
array('link' => array
('Account' =>
array('fields' => array('name')),
'LedgerEntry' =>
array('fields' => array('amount'),
'MonetarySource' =>
array('fields' => array('name')),
'Customer' =>
array('fields' => array('name')),
//'Transaction' =>
//array('fields' => array('stamp')),
),
),
'fields' => false,
'conditions' => array(array('Ledger.id' => $ledger_id),
array('LedgerEntry.id IS NOT NULL'),
),
));
//pr($ledger_entries);
$deposit['total'] += $ledger['amount'];
$deposit['ledgers'][] = array('name' => $ledger['account_name'],
'total' => $ledger['amount'],
'entries' => $ledger_entries);
if ($ledger['amount'] != 0) {
$ids = $this->Account->postLedgerEntry
($transaction,
null,
array('debit_account_id' => $this->data['Deposit']['Account']['id'],
'credit_ledger_id' => $ledger_id,
'amount' => $ledger['amount']));
$transaction = array_intersect_key($ids, array('transaction_id'=>1));
$this->Account->closeCurrentLedger($ledger['account_id']);
}
}
$this->set(compact('deposit'));
$this->render('deposit_slip');
return;
}
$tillable_account = $this->Account->relatedAccounts('tillable');
$depositable_account = $this->Account->relatedAccounts('depositable');
foreach ($tillable_account AS &$acct) {
$acct['Account']['stats'] = $this->Account->stats($acct['Account']['id']);
}
$this->set(compact('tillable_account', 'depositable_account'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -189,49 +268,5 @@ class AccountsController extends AppController {
$title = 'Account: ' . $account['Account']['name'];
$this->set(compact('account', 'title', 'stats'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit
* - Prepares the books for a bank deposit
*/
function deposit() {
if ($this->data) {
pr($this->data);
/* $this->autoRender = false; */
/* return; */
$transaction = array();
foreach ($this->data['Tillable']['Ledger']['id'] AS $acct_id) {
if ($this->data['Tillable']['Ledger'][$acct_id]['amount'] == 0)
continue;
$ids = $this->Account->postLedgerEntry
($transaction,
null,
array('debit_account_id' => $this->data['Deposit']['Account']['id'],
'credit_account_id' => $acct_id,
'amount' => $this->data['Tillable']['Ledger'][$acct_id]['amount']));
$transaction = array_intersect_key($ids, array('transaction_id'=>1));
$this->Account->closeCurrentLedger($acct_id);
}
$this->autoRender = false;
return;
}
$tillable_account = $this->Account->relatedAccounts('tillable');
$depositable_account = $this->Account->relatedAccounts('depositable');
foreach ($tillable_account AS &$acct) {
$acct['Account']['stats'] = $this->Account->stats($acct['Account']['id']);
}
$this->set(compact('tillable_account', 'depositable_account'));
}
}