Got the bank deposit working well.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@198 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-02 07:41:18 +00:00
parent 3ad0cc1d20
commit 63b2e7360b
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'));
}
}

View File

@@ -2,6 +2,8 @@
echo '<div class="account deposit">' . "\n";
echo '<H2>Perform Bank Deposit</H2>' . "\n";
echo '<P>Make sure to select the checkboxes below for only those types of currency (Cash, Check, etc) which you intend to actually deposit (you can see all the individual items by dropping down the list below the checkbox). Then, select the Deposit Account where you will make the deposit, and click "Perform Deposit" to close the books on the selected currency types and reset them to a zero balance. On the next page, you will be provided with a deposit slip to prepare the actual deposit.' . "\n";
echo '<P><BR>' . "\n";
//pr(compact('tillableAccount', 'depositableAccount'));
@@ -15,21 +17,35 @@ $grid_setup['hiddengrid'] = true;
foreach ($tillableAccount AS $acct) {
//$acct = $acct['Account'];
echo ('<INPUT type="checkbox"' .
' name="data[Tillable][Ledger][id][]"' .
' value="'.$acct['CurrentLedger']['id'].'"' .
' CHECKED> ');
echo ("I have exactly " .
FormatHelper::currency($acct['Account']['stats']['Ledger']['balance']) .
" in " . ($acct['Account']['name'] === 'Cash'
? 'Cash'
: Inflector::pluralize($acct['Account']['name'])) .
" and will be depositing it all." .
"" . "\n");
echo ('<INPUT type="hidden"' .
' name="data[Tillable][Ledger]['.$acct['CurrentLedger']['id'].'][amount]"' .
' value="'.$acct['Account']['stats']['Ledger']['balance'].'"' .
'> ');
echo "\n";
echo $form->input('Tillable.Ledger.'.$acct['CurrentLedger']['id'].'.checked',
array(//'label' => $acct['Account']['name'],
'type' => 'checkbox',
'checked' => true,
'value' => true,
'label' => (" I have exactly " .
FormatHelper::currency($acct['Account']['stats']['Ledger']['balance']) .
" in " . ($acct['Account']['name'] === 'Cash'
? 'Cash'
: Inflector::pluralize($acct['Account']['name'])) .
" and will be depositing it all.")
));
echo "\n";
echo $form->input('Tillable.Ledger.'.$acct['CurrentLedger']['id'].'.amount',
array('type' => 'hidden',
'value' => $acct['Account']['stats']['Ledger']['balance'],
));
echo "\n";
echo $form->input('Tillable.Ledger.'.$acct['CurrentLedger']['id'].'.account_id',
array('type' => 'hidden',
'value' => $acct['Account']['id'],
));
echo "\n";
echo $form->input('Tillable.Ledger.'.$acct['CurrentLedger']['id'].'.account_name',
array('type' => 'hidden',
'value' => $acct['Account']['name'],
));
echo "\n";
$grid_div_id = 'ledger_entries'.$acct['CurrentLedger']['id'].'-list';
echo $this->element('ledger_entries',
@@ -39,9 +55,6 @@ foreach ($tillableAccount AS $acct) {
'ledger_id' => $acct['CurrentLedger']['id'],
'no_account' => true,
'grid_setup' => $grid_setup,
//'account_id' => $acct['Account']['id'],
//'account_type' => $acct['Account']['type'],
//'account_ftype' => 'debit',
));
}

View File

@@ -0,0 +1,53 @@
<?php /* -*- mode:PHP -*- */
echo '<H2>Deposit Slip: ' . date('l, F jS, Y, g:ia') . '</H2>' . "\n";
pr(compact('deposit'));
// Handle account summaries
$rows = array();
$row_class = array();
foreach ($deposit['ledgers'] AS $ledger) {
$row_class[] = array();
$rows[] = array($ledger['name'].':',
FormatHelper::_n(count($ledger['entries']), 'Item'),
FormatHelper::currency($ledger['total'], true));
}
$row_class[] = 'grand';
$rows[] = array('Deposit Total:',
null,
FormatHelper::currency($deposit['total'], true));
echo $this->element('table',
array('class' => 'deposit-summary',
'rows' => $rows,
'row_class' => $row_class,
'column_class' => array('account', 'quantity', 'total'),
'suppress_alternate_rows' => true,
));
// Print out the items of each ledger
foreach ($deposit['ledgers'] AS $ledger) {
//echo ('Count: ' . count($ledger['entries']) . '<BR>');
//pr($ledger['entries']);
if (count($ledger['entries']) == 0)
continue;
$rows = array();
foreach ($ledger['entries'] AS $entry) {
$rows[] = array($entry['Customer']['name'],
$entry['MonetarySource']['name'],
$entry['LedgerEntry']['amount']);
}
echo $this->element('table',
array('class' => 'item deposit-slip list',
'caption' => $ledger['name'] . ' Items',
'rows' => $rows,
'headers' => array('Customer', 'Item', 'Amount'),
'column_class' => array('customer', 'item', 'amount'),
));
}
/* End page div */
//echo '</div>' . "\n";

View File

@@ -19,14 +19,20 @@ class FormatHelper extends AppHelper {
true));
}
function currency($amount) {
function currency($amount, $spans = false) {
if (!isset($amount))
return '-';
//return null;
return (isset($amount)
? self::$number->currency($amount)
: null);
$currency = self::$number->currency($amount,
'USD',
$spans ? array('before'=>'', 'after'=>'') : array());
if ($spans)
return ('<SPAN CLASS="dollar-sign">$</SPAN>' .
'<SPAN CLASS="dollar-amount">' . $currency . '</SPAN>');
return $currency;
}
function date($date, $age = false) {

View File

@@ -27,9 +27,8 @@ table caption { text-align: left;
padding-bottom: 0.5em;
}
div.item.list { margin-bottom: 1.5em; }
/* table.item caption { margin-top: 1em; } */
/* table.detail caption { margin-top: 0; } */
div.item.list { margin-bottom: 1.5em; }
table.item.list { margin-bottom: 1.5em; }
/************************************************************
@@ -57,6 +56,11 @@ table.item td { border-right: 1px solid #ccc; }
tr.evnrow { background: #f4f4f4; }
/* Generic classes to help with table alignment */
td.right { text-align: right; }
td.left { text-align: left; }
td.center { text-align: center; }
/************************************************************
************************************************************
@@ -147,6 +151,29 @@ table.list.ledger td.date.receipt { padding-left: 1em; }
table.list.ledger td.evnrow { background: #f4f4f4; }
/************************************************************
************************************************************
* Special cases
*/
/* Deposit Slips */
table.list.deposit-slip { width : 60%;
/* REVISIT <AP>: 20090701
* 100% if printing
*/
}
table.list.deposit-slip td.item { width : 30%; }
table.list.deposit-slip td.amount { width : 15%; }
table.deposit-summary { margin-bottom: 1em; }
table.deposit-summary td { vertical-align: bottom; }
table.deposit-summary td { font-size: 125%; }
table.deposit-summary td.grand.total { border-top : 4px double #000; }
table.deposit-summary td span.dollar-sign { float: left; }
table.deposit-summary td span.dollar-amount { float: right; }
table.deposit-summary td.account { padding-right: 0.8em; }
table.deposit-summary td.quantity { padding-right: 0.8em; }
/************************************************************
************************************************************
* jqGrid