From 6e1c684a06d0e16cbba99b4e5ac40ed80f2a675c Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 12 Jul 2009 18:01:01 +0000 Subject: [PATCH] Implemented a list that checks for collected rents. There is AccountsController::collected, which I'm keeping at the moment, but I decided to move the logic into ledger_entries, since ultimately that's what we want a list of and it doesn't make sense to add a bunch of LedgerEntry logic into the jqGrid query of AccountsController. Of course, right now there is hardcoded calendar functions, and hardcoded exclusion of the Concession Account. I will probably offer up two calendars to provide a range, and a list of checkboxes of each payable account. git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@318 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 4 +- site/controllers/accounts_controller.php | 81 +++++++++++++++++++ .../controllers/ledger_entries_controller.php | 69 +++++++++++++++- site/views/elements/collected.ctp | 45 +++++++++++ 4 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 site/views/elements/collected.ctp diff --git a/site/app_controller.php b/site/app_controller.php index 1018b63..35a4729 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -88,12 +88,12 @@ class AppController extends Controller { * - called by function to create an index listing */ - function jqGridView($title, $action = null) { + function jqGridView($title, $action = null, $element = null) { $this->set('title', $title); // The resulting page will contain a jqGrid, which will // use ajax to obtain the actual data for this action $this->set('action', $action ? $action : $this->params['action']); - $this->render('/elements/' . $this->params['controller']); + $this->render('/elements/' . ($element ? $element : $this->params['controller'])); } /************************************************************************** diff --git a/site/controllers/accounts_controller.php b/site/controllers/accounts_controller.php index 49a4c44..8b17dfa 100644 --- a/site/controllers/accounts_controller.php +++ b/site/controllers/accounts_controller.php @@ -139,6 +139,84 @@ class AccountsController extends AppController { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: collected + * - 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); + //} + +/* $tillable_account = $this->Account->relatedAccounts('tillable'); */ +/* $depositable_account = $this->Account->relatedAccounts('depositable'); */ + + $ledger_entries = + $this->Account->Ledger->LedgerEntry->find + ('all', + array('link' => array + ('Ledger' => + array('fields' => array('sequence'), + + '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'); + } + /************************************************************************** ************************************************************************** ************************************************************************** @@ -258,6 +336,9 @@ class AccountsController extends AppController { array('name' => 'Operations', 'header' => true); $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)); // Prepare to render $title = 'Account: ' . $account['Account']['name']; diff --git a/site/controllers/ledger_entries_controller.php b/site/controllers/ledger_entries_controller.php index dfaa832..d6fbd0c 100644 --- a/site/controllers/ledger_entries_controller.php +++ b/site/controllers/ledger_entries_controller.php @@ -16,6 +16,16 @@ class LedgerEntriesController extends AppController { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: index / etc + * - Generate a listing of ledger_entries + */ + + function collected() { $this->jqGridView('Collected Entries', null, 'collected'); } + + /************************************************************************** ************************************************************************** ************************************************************************** @@ -56,6 +66,40 @@ class LedgerEntriesController extends AppController { ), ); + if ($params['action'] === 'collected') { + $link['DebitLedger']['fields'][] = 'sequence'; + $link['DebitLedger']['Account']['fields'][] = 'id'; + $link['DebitLedger']['Account']['fields'][] = 'name'; + + $link['MonetarySource']['fields'][] = 'name'; + $link['Customer']['fields'][] = 'name'; + $link['Transaction']['fields'][] = 'id'; + $link['Transaction']['fields'][] = '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). + $link['CreditReconciliationLedgerEntry']['alias'] = 'RLedgerEntry'; + $link['CreditReconciliationLedgerEntry']['Transaction']['alias'] = 'RTransaction'; + + // Debit should be A/R; Credit is Account of interest + $link['CreditReconciliationLedgerEntry']['CreditLedger']['alias'] = 'RLedger'; + $link['CreditReconciliationLedgerEntry']['CreditLedger']['Account']['alias'] = 'RAccount'; + + $link['DebitReconciliationLedgerEntry']['alias'] = 'DRLE'; + $link['DebitReconciliationLedgerEntry']['linkalias'] = 'DRLE_R'; + $link['DebitReconciliationLedgerEntry']['DebitLedger']['alias'] = 'DL'; + $link['DebitReconciliationLedgerEntry']['DebitLedger']['Account']['alias'] = 'DA'; + + //$link['DebitReconciliationLedgerEntry']['conditions'] = + + } + if (isset($params['custom']['account_ftype'])) { $ftype = $params['custom']['account_ftype']; $ftype = ucfirst($ftype); @@ -130,7 +174,13 @@ class LedgerEntriesController extends AppController { ? $params['custom']['account_type'] : null); - return $model->ledgerContextFields2($ledger_id, $account_id, $account_type); + $fields = $model->ledgerContextFields2($ledger_id, $account_id, $account_type); + + if ($params['action'] === 'collected') { + $fields[] = 'Reconciliation.amount'; + } + + return $fields; } function jqGridDataConditions(&$params, &$model) { @@ -143,6 +193,23 @@ class LedgerEntriesController extends AppController { $conditions = parent::jqGridDataConditions($params, $model); + if ($params['action'] === 'collected') { + $conditions[] = array('RAccount.id' => $params['custom']['collected_account_id']); + //$conditions[] = array('DebitAccount.tillable' => 1); + //$conditions[] = array('RLedgerEntry.amount != LedgerEntry.amount'); + //$conditions[] = array('Reconciliation.amount < RLedgerEntry.amount'); + $conditions[] = array('DA.payable' => 1); + $conditions[] = array('NOT' => array('DA.name' => 'Concession')); + //$conditions[] = array('DA.name' => 'Check'); + //$conditions[] = array('DA.name' => 'Cash'); + //$conditions[] = array('Transaction.stamp >=' => '2009-03-26'); + //$conditions[] = array('Transaction.stamp <' => '2009-04-11'); + //$conditions[] = array('Transaction.stamp >=' => '2009-04-11'); + //$conditions[] = array('Transaction.stamp <' => '2009-05-09'); + $conditions[] = array('Transaction.stamp >=' => '2009-05-09'); + $conditions[] = array('Transaction.stamp <' => '2009-06-11'); + } + if ($params['action'] === 'ledger') { $conditions[] = $model->ledgerContextConditions($ledger_id, $account_type); } diff --git a/site/views/elements/collected.ctp b/site/views/elements/collected.ctp new file mode 100644 index 0000000..9ea52d1 --- /dev/null +++ b/site/views/elements/collected.ctp @@ -0,0 +1,45 @@ + 'RLedgerEntry.id', 'formatter' => 'id'); +$cols['RDate'] = array('index' => 'RTransaction.stamp', 'formatter' => 'date'); +$cols['REffective'] = array('index' => 'RLedgerEntry.effective_date', 'formatter' => 'date'); +$cols['RThrough'] = array('index' => 'RLedgerEntry.through_date', 'formatter' => 'date'); +$cols['RAccount'] = array('index' => 'RAccount.name', 'formatter' => 'name'); + +//$cols['Transaction'] = array('index' => 'Transaction.id', 'formatter' => 'id'); +$cols['Entry'] = array('index' => 'LedgerEntry.id', 'formatter' => 'id'); + +$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); + +$cols['Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'name'); + +$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname'); +//$cols['Lease'] = array('index' => 'Lease.number', 'formatter' => 'id'); +$cols['Unit'] = array('index' => 'Unit.name', 'formatter' => 'name'); + +//$cols['Source'] = array('index' => 'MonetarySource.name', 'formatter' => 'name'); +//$cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150); + +$cols['RAmount'] = array('index' => 'RLedgerEntry.amount', 'formatter' => 'currency'); +$cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency'); +$cols['Applied'] = array('index' => 'Reconciliation.amount', 'formatter' => 'currency'); + +$cols['Sub-Total'] = array('index' => 'subtotal', 'formatter' => 'currency', 'sortable' => false); + +// This element is non-standard. +// Let grid know who the controller is +$grid->controller = 'ledger_entries'; + +$collected_account_id = $this->passedArgs[0]; +$collected_not = (isset($this->passedArgs[1]) ? $this->passedArgs[1] : 0); +$grid->customData(compact('collected_account_id', 'collected_not')); + +// Render the grid +$grid +->limit(500) +->columns($cols) +->sortField('Date') +->render($this, isset($config) ? $config : null);