diff --git a/controllers/accounts_controller.php b/controllers/accounts_controller.php index 8b17dfa..52e3a88 100644 --- a/controllers/accounts_controller.php +++ b/controllers/accounts_controller.php @@ -146,77 +146,26 @@ class AccountsController extends AppController { * - Displays the items actually collected for the period * e.g. How much was collected in rent from 4/1/09 - 5/1/09 */ - function collected($id) { - //if ($this->data) { - //pr($this->data); - //} + function collected($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Item.', true)); + $this->redirect(array('action'=>'index')); + } -/* $tillable_account = $this->Account->relatedAccounts('tillable'); */ -/* $depositable_account = $this->Account->relatedAccounts('depositable'); */ + $payment_accounts = $this->Account->paymentAccounts(); + $default_accounts = array_diff_key($payment_accounts, + array($this->Account->concessionAccountID() => 1)); + $this->set(compact('payment_accounts', 'default_accounts')); - $ledger_entries = - $this->Account->Ledger->LedgerEntry->find - ('all', - array('link' => array - ('Ledger' => - array('fields' => array('sequence'), + $this->Account->recursive = -1; + $account = $this->Account->read(null, $id); + $account = $account['Account']; - 'Account' => - array('fields' => array('id', 'name')), - ), - - 'MonetarySource' => - array('fields' => array('name')), - - 'Customer' => - array('fields' => array('name')), - - 'Transaction' => - array('fields' => array('stamp')), - - // Income / Receipt flow - // debit: Receipt credit: A/R <-- this entry - // debit: A/R credit: Income <-- CRLE, below - // - // We're searching for the Receipt<->A/R entries, - // which are credits on the A/R account. Find the - // reconciling A/R entries (except for unassigned - // pre-payments, all A/R credits should have one). - 'CreditReconciliationLedgerEntry' => - array('alias' => 'RLedgerEntry', - 'fields' => true, - - 'Transaction' => - array('alias' => 'RTransaction', - 'fields' => array('stamp')), - - // Debit should be A/R; Credit is Account of interest - 'CreditLedger' => - array('alias' => 'RLedger', - 'fields' => true, - - 'Account' => - array('alias' => 'RAccount', - 'fields' => true, - - ), - ), - ), - ), - - 'fields' => array('LedgerEntry.*', 'Reconciliation.amount'), - 'conditions' => array(array('RAccount.id' => $id), - //array('Account.tillable' => 1), - ), - )); - - pr(compact('ledger_entries')); - - $title = 'Collected Whatever'; - $this->set(compact('title', 'ledger_entries')); - //$this->render('/empty'); + $title = ($account['name'] . ': Collected Report'); + $this->set(compact('account', 'title')); } + /************************************************************************** ************************************************************************** ************************************************************************** @@ -337,8 +286,7 @@ class AccountsController extends AppController { $this->sidemenu_links[] = array('name' => 'New Ledger', 'url' => array('action' => 'newledger', $id)); $this->sidemenu_links[] = - array('name' => 'Collected', 'url' => array('controller' => 'ledger_entries', - 'action' => 'collected', $id)); + array('name' => 'Collected', 'url' => array('action' => 'collected', $id)); // Prepare to render $title = 'Account: ' . $account['Account']['name']; diff --git a/controllers/ledger_entries_controller.php b/controllers/ledger_entries_controller.php index ef8c603..9e6ee26 100644 --- a/controllers/ledger_entries_controller.php +++ b/controllers/ledger_entries_controller.php @@ -16,22 +16,6 @@ class LedgerEntriesController extends AppController { } - /************************************************************************** - ************************************************************************** - ************************************************************************** - * action: index / etc - * - Generate a listing of ledger_entries - */ - - function collected($account_id) { - $A = new Account(); - $this->set('collected_account_id', $account_id); - $this->jqGridView('Collected ' . - $this->LedgerEntry->Ledger->Account->name($account_id) . - ' Entries'); - } - - /************************************************************************** ************************************************************************** ************************************************************************** @@ -214,22 +198,27 @@ class LedgerEntriesController extends AppController { $conditions = parent::jqGridDataConditions($params, $model); if ($params['action'] === 'collected') { - $conditions[] = array('Account.id' => $params['custom']['collected_account_id']); - //$conditions[] = array('DebitAccount.tillable' => 1); - //$conditions[] = array('ReceiptLedgerEntry.amount != LedgerEntry.amount'); - //$conditions[] = array('Reconciliation.amount < ReceiptLedgerEntry.amount'); - $conditions[] = array('MoneyAccount.payable' => 1); - $conditions[] = array('NOT' => array('MoneyAccount.name' => 'Concession')); - //$conditions[] = array('DA.name' => 'Check'); - //$conditions[] = array('DA.name' => 'Cash'); - //$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-03-26'); - //$conditions[] = array('ReceiptTransaction.stamp <' => '2009-04-11'); - //$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-04-11'); - //$conditions[] = array('ReceiptTransaction.stamp <' => '2009-05-09'); - //$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-05-09'); - //$conditions[] = array('ReceiptTransaction.stamp <' => '2009-06-11'); - $conditions[] = array('ReceiptTransaction.stamp >=' => '2009-06-11'); - $conditions[] = array('ReceiptTransaction.stamp <' => '2009-07-11'); + extract($params['custom']); + + if (isset($collected_account_id)) + $conditions[] = array('Account.id' => $params['custom']['collected_account_id']); + else + die("INTERNAL ERROR: COLLECTED ACCOUNT ID NOT SET"); + + if (isset($collected_from_date)) + $conditions[] + = array('ReceiptTransaction.stamp >=' => + $this->LedgerEntry->Transaction->dateFormatBeforeSave($collected_from_date)); + + if (isset($collected_through_date)) + $conditions[] + = array('ReceiptTransaction.stamp <=' => + $this->LedgerEntry->Transaction->dateFormatBeforeSave($collected_through_date . ' 23:59:59')); + + if (isset($collected_payment_accounts)) + $conditions[] = array('MoneyAccount.id' => $collected_payment_accounts); + else + $conditions[] = array('MoneyAccount.payable' => 1); } if ($params['action'] === 'ledger') { diff --git a/models/account.php b/models/account.php index 56b90f2..f2fde75 100644 --- a/models/account.php +++ b/models/account.php @@ -119,6 +119,7 @@ class Account extends AppModel { function cashAccountID() { return $this->nameToID('Cash'); } function checkAccountID() { return $this->nameToID('Check'); } function moneyOrderAccountID() { return $this->nameToID('Money Order'); } + function concessionAccountID() { return $this->nameToID('Concession'); } function pettyCashAccountID() { return $this->nameToID('Petty Cash'); } function invoiceAccountID() { return $this->nameToID('Invoice'); } function receiptAccountID() { return $this->nameToID('Receipt'); } diff --git a/views/accounts/collected.ctp b/views/accounts/collected.ctp new file mode 100644 index 0000000..92b50e9 --- /dev/null +++ b/views/accounts/collected.ctp @@ -0,0 +1,145 @@ +' . "\n"; + +/********************************************************************** + ********************************************************************** + ********************************************************************** + ********************************************************************** + * Javascript + */ + +?> + + + +' . "\n"; + +echo $form->create(null, array('id' => 'receipt-form', + //'onsubmit' => 'updateEntriesGrid(); return false', + 'url' => array('controller' => 'transactions', + 'action' => 'postReceipt'))); + +echo $form->input("id", + array('id' => 'account-id', + 'type' => 'hidden', + 'value' => 0)); + +echo $this->element('form_table', + array('class' => "item account collected entry", + //'with_name_after' => ':', + 'field_prefix' => 'Tx.', + 'fields' => array + ("account_id" => array('name' => 'Account', + 'opts' => + array('type' => 'select', + 'multiple' => 'checkbox', + 'options' => $paymentAccounts, + 'selected' => array_keys($defaultAccounts), + ), + ), + "from_date" => array('opts' => + array('type' => 'text'), + 'between' => 'BOM', + ), + "through_date" => array('opts' => + array('type' => 'text'), + 'between' => 'EOM', + ), + ), + )); + +echo $form->button('Update', + array('onclick' => 'updateEntriesGrid(); return false', + )); + +echo $form->end(); + +echo $this->element('ledger_entries', array + (// Element configuration + 'collected_account_id' => $account['id'], + 'collected_payment_accounts' => array_keys($defaultAccounts), + + // Grid configuration + 'config' => array + ( + 'grid_div_id' => 'collected-entries', + 'grid_div_class' => 'text-below', + //'caption' => '', + 'caption' => 'Collected Charges', + ), + )); + +echo('
' . + '' . + '' . + '
Balance:
' . + '
' . + "\n"); + +?> + + + + + +Clear Debug Output diff --git a/views/elements/form_table.ctp b/views/elements/form_table.ctp index cecc4ad..8a9b5fa 100644 --- a/views/elements/form_table.ctp +++ b/views/elements/form_table.ctp @@ -64,8 +64,10 @@ foreach ($fields AS $field => $config) { elseif (isset($field_prefix) && !isset($config['no_prefix'])) $field = $field_prefix . '.' . $field; - $config['opts']['label'] = false; - $config['opts']['div'] = false; + if (!isset($config['opts']['label'])) + $config['opts']['label'] = false; + if (!isset($config['opts']['div'])) + $config['opts']['div'] = false; $cells = array(); if ($include_before) { diff --git a/views/elements/ledger_entries.ctp b/views/elements/ledger_entries.ctp index 0dd3b03..ab25b89 100644 --- a/views/elements/ledger_entries.ctp +++ b/views/elements/ledger_entries.ctp @@ -88,6 +88,12 @@ if (isset($account_ftype)) $grid->invalidFields('Sub-Total'); +// Now that columns are defined, establish basic grid parameters +$grid +->columns($cols) +->sortField('Date') +->defaultFields(array('Entry', 'Date', 'Amount', 'Credit', 'Debit')); + if (!isset($config['rows']) && !isset($collected_account_id)) { $config['action'] = 'ledger'; @@ -99,7 +105,9 @@ if (isset($reconcile_id)) { } if (isset($collected_account_id)) { + $config['action'] = 'collected'; $grid->customData(compact('collected_account_id'))->limit(500); + $grid->sortField('Paid'); } // Set up search fields if requested by caller @@ -113,9 +121,6 @@ $grid->customData(compact('ledger_id', 'account_id', 'ar_account', // Render the grid $grid -->columns($cols) -->sortField('Date') -->defaultFields(array('Entry', 'Date', 'Amount', 'Credit', 'Debit')) ->render($this, isset($config) ? $config : null, array('Transaction', 'Entry', 'Date', 'Effective', 'Paid', 'Account', 'Debit Account', 'Credit Account',