Added a closes table to the schema, so that we can keep track of daily closes, deposits, etc. Moved into the model an operation to close a set of ledgers and make a deposit.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@200 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-02 09:19:33 +00:00
parent dfe61cbc2a
commit ed673de22f
6 changed files with 99 additions and 41 deletions

View File

@@ -147,17 +147,15 @@ class AccountsController extends AppController {
*/
function deposit() {
if ($this->data) {
pr($this->data);
// Action the close based on provided data
//pr($this->data);
// Get data about each closed ledger.
$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',
@@ -184,29 +182,29 @@ class AccountsController extends AppController {
),
));
//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']);
}
}
// Estabish a set of ledgers to close
$set = array();
foreach ($this->data['Tillable']['Ledger'] AS $ledger_id => $ledger) {
if (!$ledger['checked'])
continue;
$set[] = array('ledger_id' => $ledger_id, 'amount' => $ledger['amount']);
}
// Pull the trigger
$this->Account->closeAndDeposit($set, $this->data['Deposit']['Account']['id']);
$this->set(compact('deposit'));
$this->render('deposit_slip');
return;
}
// Prepare a close page...
$tillable_account = $this->Account->relatedAccounts('tillable');
$depositable_account = $this->Account->relatedAccounts('depositable');
@@ -240,7 +238,8 @@ class AccountsController extends AppController {
array('fields' => array('id', 'sequence')),
'Ledger' =>
array('order' => array('Ledger.open_stamp' => 'DESC')),
array('Close' => array
('order' => array('Close.stamp' => 'DESC'))),
),
'conditions' => array(array('Account.id' => $id)),
)