diff --git a/controllers/accounts_controller.php b/controllers/accounts_controller.php index 738d9ad..bf650c6 100644 --- a/controllers/accounts_controller.php +++ b/controllers/accounts_controller.php @@ -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')); - } - - /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/controllers/tenders_controller.php b/controllers/tenders_controller.php index b54cc1a..ee5e738 100644 --- a/controllers/tenders_controller.php +++ b/controllers/tenders_controller.php @@ -39,19 +39,138 @@ class TendersController extends AppController { function gridDataTables(&$params, &$model) { return array ('link' => - array('LedgerEntry' => + array('TenderType', + 'LedgerEntry' => 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) { - $links['Tender'] = array('name', 'id'); + $links['Tender'] = array('name', 'id'); + $links['TenderType'] = array('name'); 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; + } + + /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/models/account.php b/models/account.php index 1de163d..844f536 100644 --- a/models/account.php +++ b/models/account.php @@ -290,16 +290,20 @@ class Account extends AppModel { * with the old balance carried forward. */ function closeCurrentLedger($id = null, $close_id = null) { - $contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id'))); + $ret = array(); if (!$close_id) { $close = new Close(); $close->create(); - if (!$close->save(array('stamp' => null), false)) { - return false; - } - $close_id = $close->id; + if (!$close->save(array('stamp' => null), false)) + return array('error' => true) + $ret; + $ret['close_id'] = $close->id; } + else { + $ret['close_id'] = $close_id; + } + + $contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id'))); $this->cacheQueries = true; $account = $this->find('all', array @@ -312,10 +316,12 @@ class Account extends AppModel { //pr(compact('id', 'account')); foreach ($account AS $acct) { - if (!$this->Ledger->closeLedger($acct['CurrentLedger']['id'], $close_id)) - return false; + if (!$this->Ledger->closeLedger($acct['CurrentLedger']['id'], $ret['close_id'])) + return array('error' => true) + $ret; + $ret['ledgers'][] = $acct['CurrentLedger']['id']; } - return true; + + return $ret + array('error' => false); } diff --git a/models/tender_type.php b/models/tender_type.php index 6ed39c4..885e372 100644 --- a/models/tender_type.php +++ b/models/tender_type.php @@ -63,7 +63,12 @@ class TenderType extends AppModel { $types = $this->find('all', $query); $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'); } + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * 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]; + } + } diff --git a/models/transaction.php b/models/transaction.php index 2ca8fa6..c32dad4 100644 --- a/models/transaction.php +++ b/models/transaction.php @@ -45,7 +45,9 @@ class Transaction extends AppModel { $invoice =& $data['Transaction']; $invoice['type'] = 'INVOICE'; $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 foreach ($data['Entry'] AS &$entry) { @@ -53,7 +55,7 @@ class Transaction extends AppModel { $entry['crdr'] = 'CREDIT'; } - $ids = $this->addTransaction($data, $customer_id, $lease_id); + $ids = $this->addTransaction($data); if (isset($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) { - // Establish the transaction as an receipt + // Establish the transaction as a receipt $receipt =& $data['Transaction']; $receipt['type'] = 'RECEIPT'; $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 foreach ($data['Entry'] AS &$entry) { - $entry['type'] = 'PAYMENT'; $entry['crdr'] = 'DEBIT'; if (isset($entry['Tender']['tender_type_id'])) { $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'])) $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")); */ return false; } - if (!$this->StatementEntry->verifyStatementEntry($se)) { + if ($transaction['type'] == 'INVOICE' && + !$this->StatementEntry->verifyStatementEntry($se)) { /* pr(array("Transaction::verifyTransaction()" */ /* => "Statement Entry verification failed")); */ 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()" */ /* => 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); - // Automatically figure out the customer if we have the lease - 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 + // Extract the transaction to a local variable $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'] = $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 // 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 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']; else $entry['ledger_entry_comment'] = null; } 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']; else $entry['statement_entry_comment'] = null; @@ -260,14 +313,18 @@ class Transaction extends AppModel { array_intersect_key($entry, array_flip(array('amount'))); - // Create a statement entry - $se = - array_intersect_key($transaction, - array_flip(array('customer_id', 'lease_id'))) + - array_intersect_key($entry, - array_flip(array('type', 'account_id', 'amount', + if ($transaction['type'] == 'INVOICE') { + // Create a statement entry + // (PAYMENTS will have statement entries created below, when + // assigning credits, and DEPOSITS don't have statement entries) + $se = + 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'))); - $se['comment'] = $entry['statement_entry_comment']; + $se['comment'] = $entry['statement_entry_comment']; + } // Replace combined entry with our new individual entries $entry = compact('le1', 'le1_tender', 'le2', 'se'); @@ -275,7 +332,7 @@ class Transaction extends AppModel { // Move forward, verifying and saving everything. $ret = array(); - if (!$this->verifyTransaction($transaction, $data['Entry'], $customer_id, $lease_id)) + if (!$this->verifyTransaction($transaction, $data['Entry'])) return array('error' => true) + $ret; /* pr(array('Transaction::addTransaction' => */ @@ -295,10 +352,7 @@ class Transaction extends AppModel { // Go through the entered charges foreach ($data['Entry'] AS $e_index => &$entry) { extract($entry); - $le1['transaction_id'] = $ret['transaction_id']; - $le2['transaction_id'] = $ret['transaction_id']; - $se['transaction_id'] = $ret['transaction_id']; - + $le1['transaction_id'] = $le2['transaction_id'] = $ret['transaction_id']; $result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender); $ret['entries'][$e_index]['DoubleEntry'] = $result; if ($result['error']) { @@ -306,9 +360,8 @@ class Transaction extends AppModel { continue; } - if ($se['type'] === 'CHARGE') { - // CHARGES need to be added as statement entries. - // PAYMENTS will be added later after reconciliation + if (isset($se)) { + $se['transaction_id'] = $ret['transaction_id']; $result = $this->StatementEntry->addStatementEntry($se); $ret['entries'][$e_index]['StatementEntry'] = $result; if ($result['error']) { @@ -318,18 +371,13 @@ class Transaction extends AppModel { } } - // REVISIT : 20090723 - // Now that we have new entries, WE MUST RECONCILE - // THE CHARGES TO CUSTOMER ACCOUNT BALANCE! This - // 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']) { + if (($transaction['type'] == 'INVOICE' || + $transaction['type'] == 'RECEIPT') && + !$ret['error']) { $result = $this->StatementEntry->assignCredits (array('link' => array('Customer'), 'conditions' => array('Customer.id' => $customer_id)), - ($transaction['type'] === 'RECEIPT' + ($transaction['type'] == 'RECEIPT' ? $ret['transaction_id'] : null)); diff --git a/views/elements/tenders.ctp b/views/elements/tenders.ctp index dedbe88..8b6a57c 100644 --- a/views/elements/tenders.ctp +++ b/views/elements/tenders.ctp @@ -5,14 +5,16 @@ $cols = array(); //$cols['ID'] = array('index' => 'Tender.id', 'formatter' => 'id'); $cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); $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['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency'); +$cols['Sub-Total'] = array('index' => 'subtotal-LedgerEntry.amount', 'formatter' => 'currency'); // Render the grid $grid ->columns($cols) ->sortField('Date') ->defaultFields(array('Date', 'Name', 'Amount')) -->searchFields(array('Name')) +->searchFields(array('Name', 'Type')) ->render($this, isset($config) ? $config : null, - array_diff(array_keys($cols), array())); + array_diff(array_keys($cols), array('Sub-Total'))); diff --git a/views/accounts/deposit.ctp b/views/tenders/deposit.ctp similarity index 61% rename from views/accounts/deposit.ctp rename to views/tenders/deposit.ctp index a6e7e61..dedfffd 100644 --- a/views/accounts/deposit.ctp +++ b/views/tenders/deposit.ctp @@ -1,48 +1,48 @@ ' . "\n"; +echo '
' . "\n"; echo '

Perform Bank Deposit

' . "\n"; echo '

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 '


' . "\n"; -pr(compact('paymentAccounts', 'depositAccounts')); +//pr(compact('depositTypes', 'depositAccounts')); echo $form->create(null, array('id' => 'deposit-form', - 'url' => array('controller' => 'accounts', - 'action' => 'deposit'))); + 'url' => array(//'controller' => 'accounts', + 'action' => 'deposit_slip'))); -foreach ($paymentAccounts AS $acct) { +foreach ($depositTypes AS $type) { //$acct = $acct['Account']; echo "\n"; - echo $form->input("Tillable.Ledger.{$acct['id']}.checked", - array(//'label' => $acct['name'], + echo $form->input("TenderType.{$type['id']}.checked", + array(//'label' => $type['name'], 'type' => 'checkbox', 'checked' => true, 'value' => true, 'label' => (" I have exactly " . - FormatHelper::currency($acct['stats']['Ledger']['balance']) . - " in " . Inflector::pluralize($acct['name']) . + FormatHelper::currency($type['stats']['undeposited']) . + " in " . Inflector::pluralize($type['name']) . " and will be depositing it all.") )); echo "\n"; - echo $form->input("Tillable.Ledger.{$acct['id']}.amount", + echo $form->input("TenderType.{$type['id']}.amount", array('type' => 'hidden', - 'value' => $acct['stats']['Ledger']['balance'], + 'value' => $type['stats']['undeposited'], )); echo "\n"; - echo $form->input("Tillable.Ledger.{$acct['id']}.account_id", + echo $form->input("TenderType.{$type['id']}.id", array('type' => 'hidden', - 'value' => $acct['id'], + 'value' => $type['id'], )); echo "\n"; - echo $form->input("Tillable.Ledger.{$acct['id']}.account_name", + echo $form->input("TenderType.{$type['id']}.name", array('type' => 'hidden', - 'value' => $acct['name'], + 'value' => $type['name'], )); echo "\n"; - $grid_div_id = "tenders-{$acct['id']}-list"; + $grid_div_id = "tenders-{$type['id']}-list"; echo $this->element('tenders', array (// Grid configuration 'config' => array @@ -50,10 +50,10 @@ foreach ($paymentAccounts AS $acct) { 'grid_div_id' => $grid_div_id, 'grid_setup' => array('hiddengrid' => true), 'caption' => ('Items in '.$acct['name'].' Ledger'), + ' return false;">Items in '.$type['name'].' Ledger'), 'filter' => array('Tender.deposit_transaction_id' => null, - 'LedgerEntry.account_id' => $acct['id']), - 'exclude' => array(/*'Account'*/), + 'Tender.tender_type_id' => $type['id']), + 'exclude' => array('Type'), ), )); } diff --git a/views/accounts/deposit_slip.ctp b/views/tenders/deposit_slip.ctp similarity index 60% rename from views/accounts/deposit_slip.ctp rename to views/tenders/deposit_slip.ctp index 36b18c7..1aa57f3 100644 --- a/views/accounts/deposit_slip.ctp +++ b/views/tenders/deposit_slip.ctp @@ -7,11 +7,11 @@ echo '

Deposit Slip: ' . date('l, F jS, Y, g:ia') . '

' . "\n"; // Handle account summaries $rows = array(); $row_class = array(); -foreach ($deposit['ledgers'] AS $ledger) { +foreach ($deposit['types'] AS $type) { $row_class[] = array(); - $rows[] = array($ledger['name'].':', - FormatHelper::_n(count($ledger['entries']), 'Item'), - FormatHelper::currency($ledger['total'], true)); + $rows[] = array($type['name'].':', + FormatHelper::_n(count($type['entries']), 'Item'), + FormatHelper::currency($type['total'], true)); } $row_class[] = 'grand'; $rows[] = array('Deposit Total:', @@ -27,22 +27,20 @@ echo $this->element('table', // Print out the items of each ledger -foreach ($deposit['ledgers'] AS $ledger) { - //echo ('Count: ' . count($ledger['entries']) . '
'); - //pr($ledger['entries']); - if (count($ledger['entries']) == 0) +foreach ($deposit['types'] AS $type) { + if (count($type['entries']) == 0) continue; $rows = array(); - foreach ($ledger['entries'] AS $entry) { - $rows[] = array($entry['Customer']['name'], - $entry['MonetarySource']['name'], - $entry['LedgerEntry']['amount']); + foreach ($type['entries'] AS $entry) { + $rows[] = array($entry['customer'], + $entry['name'], + $entry['amount']); } echo $this->element('table', array('class' => 'item deposit-slip list', - 'caption' => $ledger['name'] . ' Items', + 'caption' => $type['name'] . ' Items', 'rows' => $rows, 'headers' => array('Customer', 'Item', 'Amount'), 'column_class' => array('customer', 'item', 'amount'), diff --git a/views/tenders/view.ctp b/views/tenders/view.ctp index c99d097..aaa7357 100644 --- a/views/tenders/view.ctp +++ b/views/tenders/view.ctp @@ -25,6 +25,15 @@ for ($i=1; $i<=4; ++$i) if (!empty($ttype["data{$i}_name"])) $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']); echo $this->element('table', diff --git a/views/transactions/view.ctp b/views/transactions/view.ctp index 7c8d6a8..b6eb932 100644 --- a/views/transactions/view.ctp +++ b/views/transactions/view.ctp @@ -67,14 +67,16 @@ echo '
' . "\n"; * Statement Entries */ -echo $this->element('statement_entries', array - (// Grid configuration - 'config' => array - ( - 'caption' => 'Statement Entries', - 'filter' => array('transaction_id' => $transaction['id']), - 'exclude' => array('Transaction'), - ))); +if ($transaction['type'] === 'INVOICE' || $transaction['type'] === 'RECEIPT') { + echo $this->element('statement_entries', array + (// Grid configuration + 'config' => array + ( + 'caption' => 'Statement Entries', + 'filter' => array('transaction_id' => $transaction['id']), + 'exclude' => array('Transaction'), + ))); +} /**********************************************************************