New generic mechanism for subtotaling columns. This is NOT an ideal solution, as it only subtotals for the current grid page. Hopefully we can get something better into the app controller at some point

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@321 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-12 20:15:56 +00:00
parent 6a0a77c116
commit b97d071bb4
2 changed files with 22 additions and 1 deletions

View File

@@ -322,6 +322,14 @@ class AppController extends Controller {
$model_alias = $model->alias;
$id = $model->primaryKey;
$subtotals = array();
foreach ($params['fields'] AS $field) {
if (preg_match('/subtotal-(.*)$/', $field, $matches))
$subtotals[] = array('field' => $matches[1],
'name' => $field,
'amount' => 0);
}
foreach ($records AS &$record) {
$record['jqGrid_id'] = $record[$model_alias][$id];
// Add the calculated fields (if any), to the model fields
@@ -329,6 +337,19 @@ class AppController extends Controller {
$record[$model_alias] += $record[0];
unset($record[0]);
}
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]);
}
}
}
// DEBUG PURPOSES ONLY!

View File

@@ -25,7 +25,7 @@ $cols['Debit'] = array('index' => 'debit', 'formatter' =>
$cols['Credit'] = array('index' => 'credit', 'formatter' => 'currency');
$cols['Applied'] = array('index' => "Reconciliation.amount", 'formatter' => 'currency');
$cols['Sub-Total'] = array('index' => 'subtotal', 'formatter' => 'currency', 'sortable' => false);
$cols['Sub-Total'] = array('index' => 'subtotal-LedgerEntry.amount', 'formatter' => 'currency', 'sortable' => false);
// Since group_by_tx is a boolean, let's just get it