diff --git a/site/app_controller.php b/site/app_controller.php index 0be0d4a..cecdddf 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -539,6 +539,9 @@ class AppController extends Controller { // Retreive the appropriate subset of data $records = $this->gridDataRecords($params, $model, $pagination); + // If subtotaling, figure out the running total before pagination... + $this->gridDataRecordsRunningSubtotal($params, $model, $pagination); + // Post process the records $this->gridDataPostProcess($params, $model, $records); @@ -1035,6 +1038,53 @@ class AppController extends Controller { return $model->find($type, $query); } + function gridDataRecordsRunningSubtotal(&$params, $model, $pagination) { + + // REVISIT : 20090722 + // Horrible solution to something that should be done + // in SQL. Doesn't really work, but for a grid that contains + // ALL records, and is sorted on the correct field, it does + // actually work. + // + // If this function worked correctly, this mechanism would also + // work for grids that did not contain ALL records. + + $subtotals = array(); + foreach ($params['post']['fields'] AS $field) { + if (preg_match('/subtotal-(.*)$/', $field, $matches)) + $subtotals[] = array('field' => $matches[1], + 'name' => $field, + 'amount' => 0); + } + + // This part, if functioning, should do a sub-total off all records + // that are not part of the grid, instead of starting at zero, so that + // the totals come out correctly for the each record entry. + + /* $pagination['start'] = $pagination['start'] + $pagination['limit']; */ + /* $pagination['limit'] = 10000000; */ + + /* // Retreive the appropriate subset of data */ + /* $params_copy = $params; */ + /* $records = $this->gridDataRecords($params_copy, $model, $pagination); */ + + /* foreach ($records AS &$record) { */ + /* foreach ($subtotals AS &$subtotal) { */ + /* $field = $subtotal['field']; */ + /* if (preg_match("/\./", $field)) { */ + /* list($tbl, $col) = explode(".", $field); */ + /* $record['subtotal-'.$tbl][$col] = */ + /* ($subtotal['amount'] += $record[$tbl][$col]); */ + /* } */ + /* else { */ + /* $record[$model->alias]['subtotal-'.$field] = */ + /* ($subtotal['amount'] += $record[$model->alias][$field]); */ + /* } */ + /* } */ + /* } */ + + $params['subtotals'] = $subtotals; + } /************************************************************************** ************************************************************************** @@ -1085,15 +1135,11 @@ class AppController extends Controller { // REVISIT : 20090722 // Horrible solution to something that should be done - // in SQL. But, it works for now, so what the heck... + // in SQL. Doesn't really work, but for a grid that contains + // ALL records, and is sorted on the correct field, it does + // actually work. - $subtotals = array(); - foreach ($params['post']['fields'] AS $field) { - if (preg_match('/subtotal-(.*)$/', $field, $matches)) - $subtotals[] = array('field' => $matches[1], - 'name' => $field, - 'amount' => 0); - } + $subtotals = $params['subtotals']; foreach ($records AS &$record) { foreach ($subtotals AS &$subtotal) { diff --git a/site/controllers/transactions_controller.php b/site/controllers/transactions_controller.php index 8f908ea..b0e86ad 100644 --- a/site/controllers/transactions_controller.php +++ b/site/controllers/transactions_controller.php @@ -93,7 +93,8 @@ class TransactionsController extends AppController { $fields[] = ("IF(Transaction.type = 'DEPOSIT'," . " COUNT(DepositTender.id)," . " COUNT(StatementEntry.id)) AS entries"); - return $fields; + return array_merge($fields, + $this->Transaction->LedgerEntry->debitCreditFields(false, true, 'Transaction')); } function gridDataConditions(&$params, &$model) { diff --git a/site/views/customers/view.ctp b/site/views/customers/view.ctp index 0bd6200..b02f983 100644 --- a/site/views/customers/view.ctp +++ b/site/views/customers/view.ctp @@ -157,13 +157,14 @@ echo $this->element('contacts', array /********************************************************************** - * Customer Account History + * Customer Statement History */ echo $this->element('statement_entries', array (// Grid configuration 'config' => array ('caption' => 'Customer Statement', + 'grid_setup' => array('hiddengrid' => true), 'filter' => array('Customer.id' => $customer['Customer']['id'], 'type !=' => 'VOID'), //'include' => array('Sub-Total'), @@ -171,6 +172,28 @@ echo $this->element('statement_entries', array ))); +/********************************************************************** + * Customer Transaction History + */ + +echo $this->element('transactions', array + (// Grid configuration + 'config' => array + ('caption' => 'Balance History', + 'limit' => 10000, + 'limitOptions' => array('10000'), + 'sort_column' => 'Timestamp', + 'sort_order' => 'ASC', + 'grid_setup' => array('hiddengrid' => true), + 'filter' => array('Customer.id' => $customer['Customer']['id']), + 'include' => array('Comment', 'PosNeg', 'Balance'), + 'exclude' => array('Amount', 'Entries'), + 'remap' => array(//'ID' => 'Invoice', + 'PosNeg' => 'Amount', + //'Entries' => 'Charges', + ), + ))); + /* End "detail supporting" div */ echo '' . "\n"; diff --git a/site/views/elements/transactions.ctp b/site/views/elements/transactions.ctp index 6fad163..8366b84 100644 --- a/site/views/elements/transactions.ctp +++ b/site/views/elements/transactions.ctp @@ -11,9 +11,11 @@ $cols['ID'] = array('index' => 'Transaction.id', 'formatter' = $cols['Type'] = array('index' => 'Transaction.type', 'formatter' => 'enum'); $cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname'); $cols['Timestamp'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); +$cols['Comment'] = array('index' => 'Transaction.comment', 'formatter' => 'comment', 'sortable' => false); $cols['Entries'] = array('index' => 'entries', 'formatter' => 'number'); $cols['Amount'] = array('index' => 'Transaction.amount', 'formatter' => 'currency'); -$cols['Comment'] = array('index' => 'Transaction.comment', 'formatter' => 'comment'); +$cols['PosNeg'] = array('index' => 'balance', 'formatter' => 'currency'); +$cols['Balance'] = array('index' => 'subtotal-balance', 'formatter' => 'currency', 'sortable' => false); // Render the grid $grid @@ -22,4 +24,4 @@ $grid ->defaultFields(array('ID', 'Timestamp')) ->searchFields(array('Type', 'Comment')) ->render($this, isset($config) ? $config : null, - array_merge($include, array_diff(array_keys($cols), array('Customer', 'Comment')))); + array_merge($include, array_diff(array_keys($cols), array('Customer', 'PosNeg', 'Balance', 'Comment'))));