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) {
|
||||
|
||||
Reference in New Issue
Block a user