diff --git a/app_controller.php b/app_controller.php index 0d962dd..050d8ae 100644 --- a/app_controller.php +++ b/app_controller.php @@ -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! diff --git a/views/elements/ledger_entries.ctp b/views/elements/ledger_entries.ctp index 2dca8c6..ededadc 100644 --- a/views/elements/ledger_entries.ctp +++ b/views/elements/ledger_entries.ctp @@ -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