diff --git a/controllers/ledger_entries_controller.php b/controllers/ledger_entries_controller.php index d6fbd0c..e1467bf 100644 --- a/controllers/ledger_entries_controller.php +++ b/controllers/ledger_entries_controller.php @@ -66,40 +66,6 @@ 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); @@ -123,6 +89,55 @@ class LedgerEntriesController extends AppController { ), ); } + elseif ($params['action'] === 'collected') { + // Income / Receipt / Money + // debit: A/R credit: Income <-- this entry + // debit: Receipt credit: A/R <-- ReceiptLedgerEntry, below + // debit: Money credit: Receipt <-- MoneyLedgerEntry, below + + $link['CreditLedger'] = + array('fields' => 'sequence', + 'Account' => + array('fields' => array('id', 'name'), + ), + ); + + $link['MonetarySource'] = array('fields' => array('name')); + $link['Customer'] = array('fields' => array('name')); + $link['Transaction'] = array('fields' => array('id', 'stamp')); + + // We're searching for the Receipt<->A/R entries, + // which are debits on the A/R account. Find the + // reconciling entries to that A/R debit. + $link['DebitReconciliationLedgerEntry'] = + array('alias' => 'ReceiptLedgerEntry', + + 'Transaction' => + array('alias' => 'ReceiptTransaction'), + + // Credit Ledger should be A/R; + // Debit Ledger should be Receipt + 'DebitLedger' => + array('alias' => 'ReceiptLedger', + 'Account' => array('alias' => 'ReceiptAccount'), + ), + + // Finally, the Money (Cash/Check/etc) Entry is the one + // which reconciles our ReceiptLedgerEntry debit + 'DebitReconciliationLedgerEntry' => + array('alias' => 'MoneyLedgerEntry', + 'linkalias' => 'MoneyLedgerEntryR', + + // Credit Ledger should be Receipt; + // Debit Ledger should be our Money Account + 'DebitLedger' => + array('alias' => 'MoneyLedger', + 'Account' => + array('alias' => 'MoneyAccount'), + ), + ), + ); + } else { $link['DebitLedger'] = array('fields' => array('id', 'sequence'), @@ -177,7 +192,7 @@ class LedgerEntriesController extends AppController { $fields = $model->ledgerContextFields2($ledger_id, $account_id, $account_type); if ($params['action'] === 'collected') { - $fields[] = 'Reconciliation.amount'; + $fields[] = 'SUM(Reconciliation.amount) AS applied'; } return $fields; @@ -194,20 +209,22 @@ class LedgerEntriesController extends AppController { $conditions = parent::jqGridDataConditions($params, $model); if ($params['action'] === 'collected') { - $conditions[] = array('RAccount.id' => $params['custom']['collected_account_id']); + $conditions[] = array('Account.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('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('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'); + $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'); + //$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-06-11'); + //$conditions[] = array('ReceiptTransaction.stamp <' => '2009-07-11'); } if ($params['action'] === 'ledger') { @@ -306,24 +323,6 @@ class LedgerEntriesController extends AppController { return $order; } - function jqGridRecordsPostProcess(&$params, &$model, &$records) { - parent::jqGridRecordsPostProcess($params, $model, $records); - - $subtotal = 0; - foreach ($records AS &$record) { - $amount = (isset($record['LedgerEntry']['balance']) - ? $record['LedgerEntry']['balance'] - : $record['LedgerEntry']['amount']); - $record['LedgerEntry']['subtotal'] = ($subtotal += $amount); - - continue; - // Experiment to minimize columns by putting the monetary source - // as the Account, when available - if ($record['MonetarySource']['name']) - $record['Account']['name'] = $record['MonetarySource']['name']; - } - } - function jqGridDataOutputRecordCell(&$params, &$model, &$record, $field, $data) { /* if ($field === 'CreditAccount.name') { */ /* $data .= '-OK'; */ diff --git a/views/elements/collected.ctp b/views/elements/collected.ctp index 9ea52d1..d7350d1 100644 --- a/views/elements/collected.ctp +++ b/views/elements/collected.ctp @@ -3,18 +3,30 @@ // Define the table columns $cols = array(); -$cols['REntry'] = array('index' => '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['Transaction'] = array('index' => 'Transaction.id', 'formatter' => 'id'); $cols['Entry'] = array('index' => 'LedgerEntry.id', 'formatter' => 'id'); - $cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); +$cols['Effective'] = array('index' => 'LedgerEntry.effective_date', 'formatter' => 'date'); +$cols['Through'] = array('index' => 'LedgerEntry.through_date', 'formatter' => 'date'); +//$cols['Account'] = array('index' => 'Account.name', 'formatter' => 'name'); -$cols['Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'name'); +/* $cols['RTransaction'] = array('index' => 'ReceiptTransaction.id', 'formatter' => 'id'); */ +/* $cols['REntry'] = array('index' => 'ReceiptLedgerEntry.id', 'formatter' => 'id'); */ +/* $cols['RDate'] = array('index' => 'ReceiptTransaction.stamp', 'formatter' => 'date'); */ +/* $cols['REffective'] = array('index' => 'ReceiptLedgerEntry.effective_date', 'formatter' => 'date'); */ +/* $cols['RThrough'] = array('index' => 'ReceiptLedgerEntry.through_date', 'formatter' => 'date'); */ +/* $cols['RAccount'] = array('index' => 'ReceiptAccount.name', 'formatter' => 'name'); */ +/* $cols['RAmount'] = array('index' => 'ReceiptLedgerEntry.amount', 'formatter' => 'currency'); */ + +/* $cols['MTransaction'] = array('index' => 'MoneyTransaction.id', 'formatter' => 'id'); */ +/* $cols['MEntry'] = array('index' => 'MoneyLedgerEntry.id', 'formatter' => 'id'); */ +/* $cols['MDate'] = array('index' => 'MoneyTransaction.stamp', 'formatter' => 'date'); */ +/* $cols['MEffective'] = array('index' => 'MoneyLedgerEntry.effective_date', 'formatter' => 'date'); */ +/* $cols['MThrough'] = array('index' => 'MoneyLedgerEntry.through_date', 'formatter' => 'date'); */ +/* $cols['MAccount'] = array('index' => 'MoneyAccount.name', 'formatter' => 'name'); */ +/* $cols['MAmount'] = array('index' => 'MoneyLedgerEntry.amount', 'formatter' => 'currency'); */ + +$cols['Paid'] = array('index' => 'ReceiptTransaction.stamp', 'formatter' => 'date'); $cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname'); //$cols['Lease'] = array('index' => 'Lease.number', 'formatter' => 'id'); @@ -23,11 +35,12 @@ $cols['Unit'] = array('index' => 'Unit.name', 'formatter' => //$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['RAmount'] = array('index' => 'ReceiptLedgerEntry.amount', 'formatter' => 'currency'); */ +/* $cols['MAmount'] = array('index' => 'MoneyLedgerEntry.amount', 'formatter' => 'currency'); */ +$cols['Applied'] = array('index' => 'applied', 'formatter' => 'currency'); -$cols['Sub-Total'] = array('index' => 'subtotal', 'formatter' => 'currency', 'sortable' => false); +$cols['Sub-Total'] = array('index' => 'subtotal-applied', 'formatter' => 'currency', 'sortable' => false); // This element is non-standard. // Let grid know who the controller is @@ -41,5 +54,5 @@ $grid->customData(compact('collected_account_id', 'collected_not')); $grid ->limit(500) ->columns($cols) -->sortField('Date') +//->sortField('Date') ->render($this, isset($config) ? $config : null);