Added ability to get a customer's running balance. It's quite flaky, doesn't tolerate having a grid with sub-pages, is actually incorrect for at least some customers (not sure why), but it helps answer a fundamental question for most customers. If I had a better solution, I would surely go for it.
git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@1036 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -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 <AP>: 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 <AP>: 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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 '</div>' . "\n";
|
||||
|
||||
|
||||
@@ -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'))));
|
||||
|
||||
Reference in New Issue
Block a user