Re-implemented the deposit functionality. This is mostly working, although I'd like to get customer added to the tenders table, and probably change to a single deposit ledger entry for each tender type. A single entry would require that all tender types have been recorded to the same account, something that isn't mandated at the present, but is likely to be true most of the time. Perhaps they could just be grouped by account id, which should work in all cases and yet align with tender type 99% of the time. I'll have to think about it.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@412 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-29 08:55:09 +00:00
parent cdba179d79
commit 2ffe04e3e4
10 changed files with 318 additions and 174 deletions

View File

@@ -148,80 +148,6 @@ class AccountsController extends AppController {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit
* - Prepares the books for a bank deposit
*/
function deposit() {
if ($this->data) {
// Action the close based on provided data
//pr($this->data);
// Get data about each closed ledger.
$deposit = array('total' => 0, 'ledgers' => array());
foreach ($this->data['Tillable']['Ledger'] AS $ledger_id => $ledger) {
if (!$ledger['checked'])
continue;
$ledger_entries =
$this->Account->Ledger->find
('all',
array('link' => array
('Account' =>
array('fields' => array('name')),
'LedgerEntry' =>
array('fields' => array('id', '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'),
),
));
$deposit['total'] += $ledger['amount'];
$deposit['ledgers'][] = array('id' => $ledger_id,
'name' => $ledger['account_name'],
'total' => $ledger['amount'],
'entries' => $ledger_entries);
}
// Perform the accounting work necessary to close the
// monetary ledgers and deposit into the bank account.
$this->Account->closeAndDeposit($deposit['ledgers'], $this->data['Deposit']['Account']['id']);
$title = 'Account: Deposit Slip';
$this->set(compact('title', 'deposit'));
$this->render('deposit_slip');
return;
}
// Prepare a close page...
$payment_accounts = $this->Account->paymentAccounts();
$deposit_accounts = $this->Account->depositAccounts();
foreach ($payment_accounts AS $acct_id => &$acct)
$acct = array('id' => $acct_id,
'name' => $acct,
'stats' => $this->Account->stats($acct_id));
$title = 'Account: Prepare Deposit';
$this->set(compact('title', 'payment_accounts', 'deposit_accounts'));
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************

View File

@@ -39,19 +39,138 @@ class TendersController extends AppController {
function gridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
return array return array
('link' => ('link' =>
array('LedgerEntry' => array('TenderType',
'LedgerEntry' =>
array('Transaction', array('Transaction',
), ),
), ),
); );
} }
function gridDataRecordsExecute(&$params, &$model, $query) {
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
$tquery['fields'] = array("SUM(COALESCE(LedgerEntry.amount,0)) AS 'total'");
$total = $model->find('first', $tquery);
$params['userdata']['total'] = $total[0]['total'];
return parent::gridDataRecordsExecute($params, $model, $query);
}
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Tender'] = array('name', 'id'); $links['Tender'] = array('name', 'id');
$links['TenderType'] = array('name');
return parent::gridDataPostProcessLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit
* - Prepares the books for a bank deposit
*/
function deposit() {
// Prepare a close page...
$deposit_types = $this->Tender->TenderType->depositTypes(
// Testing... limit to only one type
//array('limit' => 1)
);
$deposit_accounts = $this->Tender->TenderType->Account->depositAccounts();
foreach ($deposit_types AS $type_id => &$type)
$type = array('id' => $type_id,
'name' => $type,
'stats' => $this->Tender->TenderType->stats($type_id));
//pr(compact('deposit_types', 'deposit_accounts'));
$title = 'Prepare Deposit';
$this->set(compact('title', 'deposit_types', 'deposit_accounts'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: deposit_slip
* - The followup to the action 'deposit'.
* Processes the user input and updates the database
*/
function deposit_slip() {
if (!$this->data) {
$this->Session->setFlash(__('Invalid Action', true));
$this->redirect(array('action'=>'deposit'));
}
pr($this->data);
// Start building data for our deposit
$deposit = array('close_id' => null,
'total' => 0,
'types' => array(),
'Transaction' => array(),
'Entry' => array());
// Go through each type of tender presented to the user
foreach ($this->data['TenderType'] AS $type_id => $type) {
if (!$type['checked'])
continue;
$tenders = $this->Tender->find
('all',
array('contain' => array
('LedgerEntry',
),
'conditions' => array(array('Tender.deposit_transaction_id' => null),
array('Tender.tender_type_id' => $type_id)),
));
// Prepare for both the actual deposit, as well as the deposit slip
$deposit['types'][$type_id]['name'] = $type['name'];
$deposit['types'][$type_id]['entries'] = array();
$deposit['types'][$type_id]['total'] = 0;
foreach ($tenders AS $tender) {
$deposit['Entry'][] =
array('tender_id' => $tender['Tender']['id'],
//'ledger_entry_id' => $tender['LedgerEntry']['id'],
'account_id' => $tender['LedgerEntry']['account_id'],
'amount' => $tender['LedgerEntry']['amount'],
);
$deposit['types'][$type_id]['entries'][] =
array('name' => $tender['Tender']['name'],
//'customer' => $tender['Customer']['name'],
'customer' => 'Not Yet',
'amount' => $tender['LedgerEntry']['amount']);
$deposit['types'][$type_id]['total'] += $tender['LedgerEntry']['amount'];
}
// Add into the grand total
$deposit['total'] += $deposit['types'][$type_id]['total'];
if (!empty($type['close'])) {
// Close the associated ledger
$result = $this->Tender->LedgerEntry->Account->closeCurrentLedger
($type['account_id'], $deposit['close_id']);
if (!$result['error'] && empty($deposit['close_id']))
$deposit['close_id'] = $result['close_id'];
}
}
$result = $this->Tender->DepositTransaction->addDeposit
($deposit, $this->data['Deposit']['Account']['id']);
//pr(compact('deposit', 'result'));
$title = 'Deposit Slip';
$this->set(compact('title', 'deposit'));
$this->render('deposit_slip');
return;
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************

View File

@@ -290,16 +290,20 @@ class Account extends AppModel {
* with the old balance carried forward. * with the old balance carried forward.
*/ */
function closeCurrentLedger($id = null, $close_id = null) { function closeCurrentLedger($id = null, $close_id = null) {
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id'))); $ret = array();
if (!$close_id) { if (!$close_id) {
$close = new Close(); $close = new Close();
$close->create(); $close->create();
if (!$close->save(array('stamp' => null), false)) { if (!$close->save(array('stamp' => null), false))
return false; return array('error' => true) + $ret;
} $ret['close_id'] = $close->id;
$close_id = $close->id;
} }
else {
$ret['close_id'] = $close_id;
}
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
$this->cacheQueries = true; $this->cacheQueries = true;
$account = $this->find('all', array $account = $this->find('all', array
@@ -312,10 +316,12 @@ class Account extends AppModel {
//pr(compact('id', 'account')); //pr(compact('id', 'account'));
foreach ($account AS $acct) { foreach ($account AS $acct) {
if (!$this->Ledger->closeLedger($acct['CurrentLedger']['id'], $close_id)) if (!$this->Ledger->closeLedger($acct['CurrentLedger']['id'], $ret['close_id']))
return false; return array('error' => true) + $ret;
$ret['ledgers'][] = $acct['CurrentLedger']['id'];
} }
return true;
return $ret + array('error' => false);
} }

View File

@@ -63,7 +63,12 @@ class TenderType extends AppModel {
$types = $this->find('all', $query); $types = $this->find('all', $query);
$this->cacheQueries = false; $this->cacheQueries = false;
return $types; // Rearrange to be of the form (id => name)
$result = array();
foreach ($types AS $type)
$result[$type['TenderType']['id']] = $type['TenderType']['name'];
return $result;
} }
@@ -78,4 +83,33 @@ class TenderType extends AppModel {
return $this->nameToID('Check'); return $this->nameToID('Check');
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* function: stats
* - Returns the stats for the given tender type
*/
function stats($id = null, $query = null) {
if (!$id)
return null;
$this->queryInit($query);
if (!isset($query['link']['Tender']))
$query['link']['Tender'] = array('fields' => array());
if (!isset($query['link']['Tender']['LedgerEntry']))
$query['link']['Tender']['LedgerEntry'] = array('fields' => array());
$query['fields'][] = "SUM(COALESCE(LedgerEntry.amount,0)) AS 'total'";
$query['fields'][] = "SUM(IF(deposit_transaction_id IS NULL, COALESCE(LedgerEntry.amount,0), 0)) AS 'undeposited'";
$query['fields'][] = "SUM(IF(deposit_transaction_id IS NULL, 0, COALESCE(LedgerEntry.amount,0))) AS 'deposited'";
$query['fields'][] = "SUM(IF(nsf_transaction_id IS NULL, 0, COALESCE(LedgerEntry.amount,0))) AS 'nsf'";
$this->id = $id;
$stats = $this->find('first', $query);
return $stats[0];
}
} }

View File

@@ -45,7 +45,9 @@ class Transaction extends AppModel {
$invoice =& $data['Transaction']; $invoice =& $data['Transaction'];
$invoice['type'] = 'INVOICE'; $invoice['type'] = 'INVOICE';
$invoice['crdr'] = 'DEBIT'; $invoice['crdr'] = 'DEBIT';
$invoice['account_id'] = $this->Account->accountReceivableAccountID(); $invoice['account_id'] = $this->Account->accountReceivableAccountID();
$invoice['customer_id'] = $customer_id;
$invoice['lease_id'] = $lease_id;
// Go through the statement entries and flag as charges // Go through the statement entries and flag as charges
foreach ($data['Entry'] AS &$entry) { foreach ($data['Entry'] AS &$entry) {
@@ -53,7 +55,7 @@ class Transaction extends AppModel {
$entry['crdr'] = 'CREDIT'; $entry['crdr'] = 'CREDIT';
} }
$ids = $this->addTransaction($data, $customer_id, $lease_id); $ids = $this->addTransaction($data);
if (isset($ids['transaction_id'])) if (isset($ids['transaction_id']))
$ids['invoice_id'] = $ids['transaction_id']; $ids['invoice_id'] = $ids['transaction_id'];
@@ -69,15 +71,16 @@ class Transaction extends AppModel {
*/ */
function addReceipt($data, $customer_id, $lease_id = null) { function addReceipt($data, $customer_id, $lease_id = null) {
// Establish the transaction as an receipt // Establish the transaction as a receipt
$receipt =& $data['Transaction']; $receipt =& $data['Transaction'];
$receipt['type'] = 'RECEIPT'; $receipt['type'] = 'RECEIPT';
$receipt['crdr'] = 'CREDIT'; $receipt['crdr'] = 'CREDIT';
$receipt['account_id'] = $this->Account->accountReceivableAccountID(); $receipt['account_id'] = $this->Account->accountReceivableAccountID();
$receipt['customer_id'] = $customer_id;
$receipt['lease_id'] = $lease_id;
// Go through the statement entries and flag as payments // Go through the statement entries and flag as payments
foreach ($data['Entry'] AS &$entry) { foreach ($data['Entry'] AS &$entry) {
$entry['type'] = 'PAYMENT';
$entry['crdr'] = 'DEBIT'; $entry['crdr'] = 'DEBIT';
if (isset($entry['Tender']['tender_type_id'])) { if (isset($entry['Tender']['tender_type_id'])) {
$entry['account_id'] = $this->LedgerEntry->Tender->TenderType-> $entry['account_id'] = $this->LedgerEntry->Tender->TenderType->
@@ -85,7 +88,7 @@ class Transaction extends AppModel {
} }
} }
$ids = $this->addTransaction($data, $customer_id, $lease_id); $ids = $this->addTransaction($data);
if (isset($ids['transaction_id'])) if (isset($ids['transaction_id']))
$ids['receipt_id'] = $ids['transaction_id']; $ids['receipt_id'] = $ids['transaction_id'];
@@ -93,6 +96,56 @@ class Transaction extends AppModel {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addDeposit
* - Adds a new bank deposit
*/
function addDeposit($data, $account_id) {
// Establish the transaction as a deposit
$deposit =& $data['Transaction'];
$deposit['type'] = 'DEPOSIT';
$deposit['crdr'] = 'DEBIT';
$deposit['account_id'] = $account_id;
$deposit['customer_id'] = null;
$deposit['lease_id'] = null;
// Go through the statement entries and flag as credits
foreach ($data['Entry'] AS &$entry) {
$entry['crdr'] = 'CREDIT';
}
// For some reason, $data is being modified by the
// addTransaction call, even though we're not passing by
// reference. Not all items in $data['Entry'] are being
// stomped on... only the last one in the list :-/
// Save off all the tender ids now, before calling
// addTransaction, to make sure we don't lose any.
$tender_ids = array_map(create_function('$item',
/* 'if (!isset($item))' . */
/* ' pr("NO ITEM");' . */
/* 'if (!isset($item["tender_id"]))' . */
/* ' pr(array("BAD ITEM" => compact("item")));' . */
'return $item["tender_id"];'),
$data['Entry']);
$ids = $this->addTransaction($data);
if (isset($ids['transaction_id']))
$ids['deposit_id'] = $ids['transaction_id'];
if (!empty($ids['deposit_id'])) {
$this->LedgerEntry->Tender->updateAll
(array('Tender.deposit_transaction_id' => $ids['deposit_id']),
array('Tender.id' => $tender_ids)
);
}
return $ids;
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
@@ -126,7 +179,8 @@ class Transaction extends AppModel {
/* => "Double Entry verification failed")); */ /* => "Double Entry verification failed")); */
return false; return false;
} }
if (!$this->StatementEntry->verifyStatementEntry($se)) { if ($transaction['type'] == 'INVOICE' &&
!$this->StatementEntry->verifyStatementEntry($se)) {
/* pr(array("Transaction::verifyTransaction()" */ /* pr(array("Transaction::verifyTransaction()" */
/* => "Statement Entry verification failed")); */ /* => "Statement Entry verification failed")); */
return false; return false;
@@ -195,29 +249,28 @@ class Transaction extends AppModel {
* *
*/ */
function addTransaction($data, $customer_id, $lease_id = null) { function addTransaction($data) {
/* pr(array("Transaction::addTransaction()" */ /* pr(array("Transaction::addTransaction()" */
/* => compact('data', 'customer_id', 'lease_id'))); */ /* => compact('data', 'customer_id', 'lease_id'))); */
if (!isset($data['Transaction']) || !isset($data['Entry'])) // Verify that we have a transaction and entries
if (empty($data['Transaction']) || empty($data['Entry']))
return array('error' => true); return array('error' => true);
// Automatically figure out the customer if we have the lease // Extract the transaction to a local variable
if (!empty($lease_id) && empty($customer_id)) {
$L = new Lease();
$L->recursive = -1;
$lease = $L->read(null, $lease_id);
$customer_id = $lease['Lease']['customer_id'];
}
// Set the customer based on caller request, and set
// ledger ID as the current ledger of the specified account
$transaction = $data['Transaction']; $transaction = $data['Transaction'];
$transaction['customer_id'] = $customer_id;
$transaction['lease_id'] = $lease_id; // set ledger ID as the current ledger of the specified account
$transaction['ledger_id'] = $transaction['ledger_id'] =
$this->Account->currentLedgerID($transaction['account_id']); $this->Account->currentLedgerID($transaction['account_id']);
// Automatically figure out the customer if we have the lease
if (!empty($transaction['lease_id']) && empty($transaction['customer_id'])) {
$L = new Lease();
$L->recursive = -1;
$lease = $L->read(null, $transaction['lease_id']);
$transaction['customer_id'] = $lease['Lease']['customer_id'];
}
// Break each entry out of the combined statement/ledger entry // Break each entry out of the combined statement/ledger entry
// and into individual entries appropriate for saving. While // and into individual entries appropriate for saving. While
@@ -234,13 +287,13 @@ class Transaction extends AppModel {
// Set up our comments, possibly using the default 'comment' field // Set up our comments, possibly using the default 'comment' field
if (empty($entry['ledger_entry_comment'])) { if (empty($entry['ledger_entry_comment'])) {
if (!empty($entry['comment']) && $entry['type'] === 'PAYMENT') if ($transaction['type'] != 'INVOICE' && !empty($entry['comment']))
$entry['ledger_entry_comment'] = $entry['comment']; $entry['ledger_entry_comment'] = $entry['comment'];
else else
$entry['ledger_entry_comment'] = null; $entry['ledger_entry_comment'] = null;
} }
if (empty($entry['statement_entry_comment'])) { if (empty($entry['statement_entry_comment'])) {
if (!empty($entry['comment']) && $entry['type'] === 'CHARGE') if ($transaction['type'] == 'INVOICE' && !empty($entry['comment']))
$entry['statement_entry_comment'] = $entry['comment']; $entry['statement_entry_comment'] = $entry['comment'];
else else
$entry['statement_entry_comment'] = null; $entry['statement_entry_comment'] = null;
@@ -260,14 +313,18 @@ class Transaction extends AppModel {
array_intersect_key($entry, array_intersect_key($entry,
array_flip(array('amount'))); array_flip(array('amount')));
// Create a statement entry if ($transaction['type'] == 'INVOICE') {
$se = // Create a statement entry
array_intersect_key($transaction, // (PAYMENTS will have statement entries created below, when
array_flip(array('customer_id', 'lease_id'))) + // assigning credits, and DEPOSITS don't have statement entries)
array_intersect_key($entry, $se =
array_flip(array('type', 'account_id', 'amount', array_intersect_key($transaction,
array_flip(array('customer_id', 'lease_id'))) +
array_intersect_key($entry,
array_flip(array('type', 'account_id', 'amount',
'effective_date', 'through_date', 'due_date'))); 'effective_date', 'through_date', 'due_date')));
$se['comment'] = $entry['statement_entry_comment']; $se['comment'] = $entry['statement_entry_comment'];
}
// Replace combined entry with our new individual entries // Replace combined entry with our new individual entries
$entry = compact('le1', 'le1_tender', 'le2', 'se'); $entry = compact('le1', 'le1_tender', 'le2', 'se');
@@ -275,7 +332,7 @@ class Transaction extends AppModel {
// Move forward, verifying and saving everything. // Move forward, verifying and saving everything.
$ret = array(); $ret = array();
if (!$this->verifyTransaction($transaction, $data['Entry'], $customer_id, $lease_id)) if (!$this->verifyTransaction($transaction, $data['Entry']))
return array('error' => true) + $ret; return array('error' => true) + $ret;
/* pr(array('Transaction::addTransaction' => */ /* pr(array('Transaction::addTransaction' => */
@@ -295,10 +352,7 @@ class Transaction extends AppModel {
// Go through the entered charges // Go through the entered charges
foreach ($data['Entry'] AS $e_index => &$entry) { foreach ($data['Entry'] AS $e_index => &$entry) {
extract($entry); extract($entry);
$le1['transaction_id'] = $ret['transaction_id']; $le1['transaction_id'] = $le2['transaction_id'] = $ret['transaction_id'];
$le2['transaction_id'] = $ret['transaction_id'];
$se['transaction_id'] = $ret['transaction_id'];
$result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender); $result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender);
$ret['entries'][$e_index]['DoubleEntry'] = $result; $ret['entries'][$e_index]['DoubleEntry'] = $result;
if ($result['error']) { if ($result['error']) {
@@ -306,9 +360,8 @@ class Transaction extends AppModel {
continue; continue;
} }
if ($se['type'] === 'CHARGE') { if (isset($se)) {
// CHARGES need to be added as statement entries. $se['transaction_id'] = $ret['transaction_id'];
// PAYMENTS will be added later after reconciliation
$result = $this->StatementEntry->addStatementEntry($se); $result = $this->StatementEntry->addStatementEntry($se);
$ret['entries'][$e_index]['StatementEntry'] = $result; $ret['entries'][$e_index]['StatementEntry'] = $result;
if ($result['error']) { if ($result['error']) {
@@ -318,18 +371,13 @@ class Transaction extends AppModel {
} }
} }
// REVISIT <AP>: 20090723 if (($transaction['type'] == 'INVOICE' ||
// Now that we have new entries, WE MUST RECONCILE $transaction['type'] == 'RECEIPT') &&
// THE CHARGES TO CUSTOMER ACCOUNT BALANCE! This !$ret['error']) {
// is the only way "payments" are generated, and
// the only way to make use of a positive customer
// balance if new charges have been entered.
if (!$ret['error']) {
$result = $this->StatementEntry->assignCredits $result = $this->StatementEntry->assignCredits
(array('link' => array('Customer'), (array('link' => array('Customer'),
'conditions' => array('Customer.id' => $customer_id)), 'conditions' => array('Customer.id' => $customer_id)),
($transaction['type'] === 'RECEIPT' ($transaction['type'] == 'RECEIPT'
? $ret['transaction_id'] ? $ret['transaction_id']
: null)); : null));

View File

@@ -5,14 +5,16 @@ $cols = array();
//$cols['ID'] = array('index' => 'Tender.id', 'formatter' => 'id'); //$cols['ID'] = array('index' => 'Tender.id', 'formatter' => 'id');
$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); $cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date');
$cols['Name'] = array('index' => 'Tender.name', 'formatter' => 'longname'); $cols['Name'] = array('index' => 'Tender.name', 'formatter' => 'longname');
$cols['Type'] = array('index' => 'TenderType.name', 'formatter' => 'name');
$cols['Comment'] = array('index' => 'Tender.comment', 'formatter' => 'comment'); $cols['Comment'] = array('index' => 'Tender.comment', 'formatter' => 'comment');
$cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency'); $cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency');
$cols['Sub-Total'] = array('index' => 'subtotal-LedgerEntry.amount', 'formatter' => 'currency');
// Render the grid // Render the grid
$grid $grid
->columns($cols) ->columns($cols)
->sortField('Date') ->sortField('Date')
->defaultFields(array('Date', 'Name', 'Amount')) ->defaultFields(array('Date', 'Name', 'Amount'))
->searchFields(array('Name')) ->searchFields(array('Name', 'Type'))
->render($this, isset($config) ? $config : null, ->render($this, isset($config) ? $config : null,
array_diff(array_keys($cols), array())); array_diff(array_keys($cols), array('Sub-Total')));

View File

@@ -1,48 +1,48 @@
<?php /* -*- mode:PHP -*- */ <?php /* -*- mode:PHP -*- */
echo '<div class="account deposit">' . "\n"; echo '<div class="tender deposit">' . "\n";
echo '<H2>Perform Bank Deposit</H2>' . "\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>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"; echo '<P><BR>' . "\n";
pr(compact('paymentAccounts', 'depositAccounts')); //pr(compact('depositTypes', 'depositAccounts'));
echo $form->create(null, array('id' => 'deposit-form', echo $form->create(null, array('id' => 'deposit-form',
'url' => array('controller' => 'accounts', 'url' => array(//'controller' => 'accounts',
'action' => 'deposit'))); 'action' => 'deposit_slip')));
foreach ($paymentAccounts AS $acct) { foreach ($depositTypes AS $type) {
//$acct = $acct['Account']; //$acct = $acct['Account'];
echo "\n"; echo "\n";
echo $form->input("Tillable.Ledger.{$acct['id']}.checked", echo $form->input("TenderType.{$type['id']}.checked",
array(//'label' => $acct['name'], array(//'label' => $type['name'],
'type' => 'checkbox', 'type' => 'checkbox',
'checked' => true, 'checked' => true,
'value' => true, 'value' => true,
'label' => (" I have exactly " . 'label' => (" I have exactly " .
FormatHelper::currency($acct['stats']['Ledger']['balance']) . FormatHelper::currency($type['stats']['undeposited']) .
" in " . Inflector::pluralize($acct['name']) . " in " . Inflector::pluralize($type['name']) .
" and will be depositing it all.") " and will be depositing it all.")
)); ));
echo "\n"; echo "\n";
echo $form->input("Tillable.Ledger.{$acct['id']}.amount", echo $form->input("TenderType.{$type['id']}.amount",
array('type' => 'hidden', array('type' => 'hidden',
'value' => $acct['stats']['Ledger']['balance'], 'value' => $type['stats']['undeposited'],
)); ));
echo "\n"; echo "\n";
echo $form->input("Tillable.Ledger.{$acct['id']}.account_id", echo $form->input("TenderType.{$type['id']}.id",
array('type' => 'hidden', array('type' => 'hidden',
'value' => $acct['id'], 'value' => $type['id'],
)); ));
echo "\n"; echo "\n";
echo $form->input("Tillable.Ledger.{$acct['id']}.account_name", echo $form->input("TenderType.{$type['id']}.name",
array('type' => 'hidden', array('type' => 'hidden',
'value' => $acct['name'], 'value' => $type['name'],
)); ));
echo "\n"; echo "\n";
$grid_div_id = "tenders-{$acct['id']}-list"; $grid_div_id = "tenders-{$type['id']}-list";
echo $this->element('tenders', array echo $this->element('tenders', array
(// Grid configuration (// Grid configuration
'config' => array 'config' => array
@@ -50,10 +50,10 @@ foreach ($paymentAccounts AS $acct) {
'grid_div_id' => $grid_div_id, 'grid_div_id' => $grid_div_id,
'grid_setup' => array('hiddengrid' => true), 'grid_setup' => array('hiddengrid' => true),
'caption' => ('<A HREF="#" ONCLICK="$(\'#'.$grid_div_id.' .HeaderButton\').click();'. 'caption' => ('<A HREF="#" ONCLICK="$(\'#'.$grid_div_id.' .HeaderButton\').click();'.
' return false;">Items in '.$acct['name'].' Ledger</A>'), ' return false;">Items in '.$type['name'].' Ledger</A>'),
'filter' => array('Tender.deposit_transaction_id' => null, 'filter' => array('Tender.deposit_transaction_id' => null,
'LedgerEntry.account_id' => $acct['id']), 'Tender.tender_type_id' => $type['id']),
'exclude' => array(/*'Account'*/), 'exclude' => array('Type'),
), ),
)); ));
} }

View File

@@ -7,11 +7,11 @@ echo '<H2>Deposit Slip: ' . date('l, F jS, Y, g:ia') . '</H2>' . "\n";
// Handle account summaries // Handle account summaries
$rows = array(); $rows = array();
$row_class = array(); $row_class = array();
foreach ($deposit['ledgers'] AS $ledger) { foreach ($deposit['types'] AS $type) {
$row_class[] = array(); $row_class[] = array();
$rows[] = array($ledger['name'].':', $rows[] = array($type['name'].':',
FormatHelper::_n(count($ledger['entries']), 'Item'), FormatHelper::_n(count($type['entries']), 'Item'),
FormatHelper::currency($ledger['total'], true)); FormatHelper::currency($type['total'], true));
} }
$row_class[] = 'grand'; $row_class[] = 'grand';
$rows[] = array('Deposit Total:', $rows[] = array('Deposit Total:',
@@ -27,22 +27,20 @@ echo $this->element('table',
// Print out the items of each ledger // Print out the items of each ledger
foreach ($deposit['ledgers'] AS $ledger) { foreach ($deposit['types'] AS $type) {
//echo ('Count: ' . count($ledger['entries']) . '<BR>'); if (count($type['entries']) == 0)
//pr($ledger['entries']);
if (count($ledger['entries']) == 0)
continue; continue;
$rows = array(); $rows = array();
foreach ($ledger['entries'] AS $entry) { foreach ($type['entries'] AS $entry) {
$rows[] = array($entry['Customer']['name'], $rows[] = array($entry['customer'],
$entry['MonetarySource']['name'], $entry['name'],
$entry['LedgerEntry']['amount']); $entry['amount']);
} }
echo $this->element('table', echo $this->element('table',
array('class' => 'item deposit-slip list', array('class' => 'item deposit-slip list',
'caption' => $ledger['name'] . ' Items', 'caption' => $type['name'] . ' Items',
'rows' => $rows, 'rows' => $rows,
'headers' => array('Customer', 'Item', 'Amount'), 'headers' => array('Customer', 'Item', 'Amount'),
'column_class' => array('customer', 'item', 'amount'), 'column_class' => array('customer', 'item', 'amount'),

View File

@@ -25,6 +25,15 @@ for ($i=1; $i<=4; ++$i)
if (!empty($ttype["data{$i}_name"])) if (!empty($ttype["data{$i}_name"]))
$rows[] = array($ttype["data{$i}_name"], $tender["data{$i}"]); $rows[] = array($ttype["data{$i}_name"], $tender["data{$i}"]);
$rows[] = array('Deposit', $html->link('#'.$tender['deposit_transaction_id'],
array('controller' => 'transactions',
'action' => 'view',
$tender['deposit_transaction_id'])));
if (!empty($tender['nsf_transaction_id']))
$rows[] = array('NSF', $html->link('#'.$tender['nsf_transaction_id'],
array('controller' => 'transactions',
'action' => 'view',
$tender['nsf_transaction_id'])));
$rows[] = array('Comment', $tender['comment']); $rows[] = array('Comment', $tender['comment']);
echo $this->element('table', echo $this->element('table',

View File

@@ -67,14 +67,16 @@ echo '<div CLASS="detail supporting">' . "\n";
* Statement Entries * Statement Entries
*/ */
echo $this->element('statement_entries', array if ($transaction['type'] === 'INVOICE' || $transaction['type'] === 'RECEIPT') {
(// Grid configuration echo $this->element('statement_entries', array
'config' => array (// Grid configuration
( 'config' => array
'caption' => 'Statement Entries', (
'filter' => array('transaction_id' => $transaction['id']), 'caption' => 'Statement Entries',
'exclude' => array('Transaction'), 'filter' => array('transaction_id' => $transaction['id']),
))); 'exclude' => array('Transaction'),
)));
}
/********************************************************************** /**********************************************************************