Experiment to group ledger entries by their transaction ID instead of their entry ID.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@177 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-22 19:03:08 +00:00
parent e00e10bbb5
commit de93c7545b
5 changed files with 46 additions and 5 deletions

View File

@@ -96,7 +96,7 @@ class LedgerEntriesController extends AppController {
? $params['custom']['account_type'] ? $params['custom']['account_type']
: null); : null);
return $model->ledgerContextFields($ledger_id, $account_type); return $model->ledgerContextFields2($ledger_id, $account_type);
} }
function jqGridDataConditions(&$params, &$model) { function jqGridDataConditions(&$params, &$model) {
@@ -135,6 +135,20 @@ class LedgerEntriesController extends AppController {
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::jqGridRecordLinks($params, $model, $records, $links);
} }
function jqGridDataGroup(&$params, &$model) {
if (isset($params['custom']['notxgroup']))
return parent::jqGridDataGroup($params, $model);
return $model->alias.'.transaction_id';
}
function jqGridDataOrder(&$params, &$model, $index, $direction) {
/* if ($index === 'balance') */
/* return ($index .' '. $direction); */
return parent::jqGridDataOrder($params, $model, $index, $direction);
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************

View File

@@ -237,7 +237,7 @@ class TransactionsController extends AppController {
'amount' => 100, 'amount' => 100,
'debit_ledger_id' => 1, 'debit_ledger_id' => 1,
'credit_ledger_id' => 2, 'credit_ledger_id' => 2,
'transaction_id' => 1, 'transaction_id' => 66,
'DebitReconciliationLedgerEntry' => 'DebitReconciliationLedgerEntry' =>
array('amount' => 44, array('amount' => 44,
//'debit_ledger_entry_id' //'debit_ledger_entry_id'

View File

@@ -84,6 +84,29 @@ class LedgerEntry extends AppModel {
return $fields; return $fields;
} }
function ledgerContextFields2($ledger_id = null, $account_type = null) {
$fields = array('id', 'name', 'comment', 'amount');
if (isset($ledger_id)) {
$fields[] = ("IF(LedgerEntry.debit_ledger_id = $ledger_id," .
" SUM(LedgerEntry.amount), NULL) AS debit");
$fields[] = ("IF(LedgerEntry.credit_ledger_id = $ledger_id," .
" SUM(LedgerEntry.amount), NULL) AS credit");
if (isset($account_type)) {
if (in_array($account_type, array('ASSET', 'EXPENSE')))
$ledger_type = 'debit';
else
$ledger_type = 'credit';
$fields[] = ("(IF(LedgerEntry.{$ledger_type}_ledger_id = $ledger_id," .
" 1, -1) * SUM(LedgerEntry.amount)) AS balance");
}
}
return $fields;
}
function ledgerContextConditions($ledger_id, $account_type) { function ledgerContextConditions($ledger_id, $account_type) {
if (isset($ledger_id)) { if (isset($ledger_id)) {
return array return array

View File

@@ -2,8 +2,11 @@
// Define the table columns // Define the table columns
$cols = array(); $cols = array();
$cols['Transaction'] = array('index' => 'Transaction.id', 'formatter' => 'id'); if (isset($notxgroup))
$cols['Entry'] = array('index' => 'LedgerEntry.id', 'formatter' => 'id'); $cols['Entry'] = array('index' => 'LedgerEntry.id', 'formatter' => 'id');
else
$cols['Transaction'] = array('index' => 'Transaction.id', 'formatter' => 'id');
$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); $cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date');
if (isset($account_ftype) || isset($ledger_id)) { if (isset($account_ftype) || isset($ledger_id)) {
$cols['Account'] = array('index' => 'Account.name', 'formatter' => 'longname'); $cols['Account'] = array('index' => 'Account.name', 'formatter' => 'longname');
@@ -25,7 +28,7 @@ if (isset($reconcile_id)) {
$cols['Applied'] = array('index' => "Reconciliation.amount", 'formatter' => 'currency'); $cols['Applied'] = array('index' => "Reconciliation.amount", 'formatter' => 'currency');
} }
$custom_post_data = compact('ledger_id', 'account_type', 'account_ftype'); $custom_post_data = compact('ledger_id', 'account_type', 'account_ftype', 'notxgroup');
$jqGrid_options = array('jqGridColumns' => $cols, $jqGrid_options = array('jqGridColumns' => $cols,
'controller' => 'ledger_entries', 'controller' => 'ledger_entries',

View File

@@ -55,6 +55,7 @@ echo '<div CLASS="detail supporting">' . "\n";
echo $this->element('ledger_entries', echo $this->element('ledger_entries',
array('caption' => 'Entries in Transaction', array('caption' => 'Entries in Transaction',
'ledger_entries' => $transaction['LedgerEntry'], 'ledger_entries' => $transaction['LedgerEntry'],
'notxgroup' => true,
)); ));