Moved the ledger_entries controller/view to jqGrid.
Changed the app controller jqGrid virtual functions for getting the tables for both count and the full query. The ExtraTables bit was too confusing, and was only intended to allow the user to specify a subset for count and augment it for full query. This is easily accomplished by having DataTables just call DataCountTables first... one line solution ends the confusion.
Modified linkable behavior to support a %{MODEL_ALIAS} tag, which is replaced in the relationship conditions at runtime with the actual model alias. This is experimental at best, and certainly will create a problem for any model that ends up using the conditions in 'contain' instead of 'link'.
Broke the LedgerEntry->findInLedgerContext function out into multiple pieces, so those same pieces could be used in the LedgerEntries controller to populate jqGrid.
Changed the ledger_entries element, as a special case, to also allow listing control from ledger_id and account_type, instead of idlist as a mechanism for populating the grid.
Changed the infobox summary css, which will break several pages until I rework them.
Some next steps include fixing the broken infoboxes, and changing the transactions view to use the ledger_entries element. This also means the ledger_entries element will need to add support for idlist, or if we have any credit/debit issues, perhaps another custom transaction_id instead.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@134 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -98,8 +98,11 @@ class AppController extends Controller {
|
||||
// Get the number of records prior to pagination
|
||||
$count = $this->jqGridDataRecordCount($params, $model, $query);
|
||||
|
||||
// Get the rest of the tables.
|
||||
$this->jqGridDataExtraTables($params, $model, $query);
|
||||
// Start the query over, this time getting the actual set
|
||||
// of tables needed, not just those needed for counting.
|
||||
$query = array_intersect_key($this->jqGridDataTables($params, $model),
|
||||
array('link'=>1, 'contain'=>1));
|
||||
$query['conditions'] = $this->jqGridDataConditions($params, $model);
|
||||
|
||||
// Verify a few parameters and determine our starting row
|
||||
$limit = $params['rows'];
|
||||
@@ -122,7 +125,7 @@ class AppController extends Controller {
|
||||
// Add in any needed hyperlinks
|
||||
$this->jqGridRecordLinks($params, $model, $results, array());
|
||||
|
||||
// DEBUG PURPOSES ONLY
|
||||
// DEBUG PURPOSES ONLY!
|
||||
$params['query'] = $query;
|
||||
|
||||
// Finally, dump out the data
|
||||
@@ -163,36 +166,44 @@ class AppController extends Controller {
|
||||
Configure::write('debug', '0');
|
||||
}
|
||||
|
||||
// Unserialize our complex structure of fields
|
||||
// This SHOULD be always set, except when debugging
|
||||
if (isset($params['fields']))
|
||||
$fields = unserialize($params['fields']);
|
||||
else
|
||||
$fields = array($this->modelClass . '.id');
|
||||
|
||||
$params['fields_str'] = $params['fields'];
|
||||
$params['fields'] = $fields;
|
||||
|
||||
// Establish some defaults before extracting params
|
||||
// Establish some defaults (except for serialized items)
|
||||
$params = array_merge(array('page' => 1,
|
||||
'rows' => 20),
|
||||
$params);
|
||||
|
||||
// Unserialize our complex structure of fields
|
||||
// This SHOULD always be set, except when debugging
|
||||
if (isset($params['fields']))
|
||||
$params['fields'] = unserialize($params['fields']);
|
||||
else
|
||||
$params['fields'] = array($this->{$this->modelClass}->alias
|
||||
.'.'.
|
||||
$this->{$this->modelClass}->primarKey);
|
||||
|
||||
// Unserialize the list of ids, if present.
|
||||
if (isset($params['custom']))
|
||||
$params['custom'] = unserialize($params['custom']);
|
||||
else
|
||||
$params['custom'] = null;
|
||||
|
||||
// Unserialize the list of ids, if present.
|
||||
if (isset($params['idlist']))
|
||||
$params['idlist'] = unserialize($params['idlist']);
|
||||
|
||||
}
|
||||
|
||||
function jqGridDataModel(&$params) {
|
||||
return $this->{$this->modelClass};
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return array('contain' => false);
|
||||
}
|
||||
|
||||
function jqGridDataCountTables(&$params, &$model) {
|
||||
// For backwards compatibility
|
||||
// If not overridden, we use the same tables to
|
||||
// perform our count as we do to for the actual query
|
||||
return $this->jqGridDataTables($params, $model);
|
||||
}
|
||||
|
||||
function jqGridDataExtraTables(&$params, &$model, &$query) {
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return array('contain' => false);
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
@@ -237,7 +248,7 @@ class AppController extends Controller {
|
||||
}
|
||||
|
||||
if (isset($params['action']) && $params['action'] === 'idlist') {
|
||||
$conditions[] = array($model->alias.'.'.$model->primaryKey => unserialize($params['idlist']));
|
||||
$conditions[] = array($model->alias.'.'.$model->primaryKey => $params['idlist']);
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
@@ -265,23 +276,31 @@ class AppController extends Controller {
|
||||
|
||||
function jqGridRecordsPostProcess(&$params, &$model, &$records) {
|
||||
$model_alias = $model->alias;
|
||||
$id = $model->primaryKey;
|
||||
|
||||
foreach ($records AS &$record) {
|
||||
$record['jqGrid_id'] = $record[$model_alias][$id];
|
||||
// Add the calculated fields (if any), to the model fields
|
||||
if (isset($record[0]))
|
||||
if (isset($record[0])) {
|
||||
$record[$model_alias] += $record[0];
|
||||
unset($record[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// DEBUG PURPOSES ONLY!
|
||||
//$params['records'] = $records;
|
||||
}
|
||||
|
||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||
foreach ($links AS $table => $fields) {
|
||||
$controller = Inflector::pluralize(strtolower($table));
|
||||
$controller = Inflector::pluralize(Inflector::underscore($table));
|
||||
$id = 'id';
|
||||
if (isset($fields['id']))
|
||||
$id = $fields['id'];
|
||||
foreach ($records AS &$record) {
|
||||
foreach (array_diff_key($fields, array('id'=>1)) AS $field) {
|
||||
$params['linkrecord'][] = compact('table', 'field', 'id', 'controller', 'record');
|
||||
// DEBUG PURPOSES ONLY!
|
||||
//$params['linkrecord'][] = compact('table', 'field', 'id', 'controller', 'record');
|
||||
$record[$table][$field] =
|
||||
'<A HREF="' .
|
||||
Router::url(array('controller' => $controller,
|
||||
@@ -313,9 +332,10 @@ class AppController extends Controller {
|
||||
|
||||
function jqGridDataOutputRecords(&$params, &$model, &$records) {
|
||||
$model_alias = $model->alias;
|
||||
$id = 'jqGrid_id';
|
||||
|
||||
foreach ($records AS $record) {
|
||||
echo " <row id='{$record[$model_alias]['id']}'>\n";
|
||||
echo " <row id='{$record[$id]}'>\n";
|
||||
foreach ($params['fields'] AS $field) {
|
||||
if (preg_match("/\./", $field)) {
|
||||
list($tbl, $col) = explode(".", $field);
|
||||
|
||||
@@ -34,12 +34,12 @@ class AccountsController extends AppController {
|
||||
*/
|
||||
|
||||
function index() { $this->all(); }
|
||||
function asset() { $this->jqGridView('Asset Accounts'); }
|
||||
function liability() { $this->jqGridView('Liability Accounts'); }
|
||||
function equity() { $this->jqGridView('Equity Accounts'); }
|
||||
function income() { $this->jqGridView('Income Accounts'); }
|
||||
function expense() { $this->jqGridView('Expense Accounts'); }
|
||||
function all() { $this->jqGridView('All Accounts', 'all'); }
|
||||
function asset() { $this->jqGridView('Asset Accounts', 'asset'); }
|
||||
function liability() { $this->jqGridView('Liability Accounts', 'liability'); }
|
||||
function equity() { $this->jqGridView('Equity Accounts', 'equity'); }
|
||||
function income() { $this->jqGridView('Income Accounts', 'income'); }
|
||||
function expense() { $this->jqGridView('Expense Accounts', 'expense'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
@@ -57,21 +57,35 @@ class AccountsController extends AppController {
|
||||
$params['action'] = 'all';
|
||||
}
|
||||
|
||||
function jqGridDataExtraTables(&$params, &$model, &$query) {
|
||||
unset($query['contain']);
|
||||
$query['link'] =
|
||||
array(// Models
|
||||
'CurrentLedger' => array
|
||||
(// Models
|
||||
'LedgerEntry' => array
|
||||
('conditions' =>
|
||||
array('OR' =>
|
||||
array('LedgerEntry.debit_ledger_id = CurrentLedger.id',
|
||||
'LedgerEntry.credit_ledger_id = CurrentLedger.id'),
|
||||
),
|
||||
function jqGridDataCountTables(&$params, &$model) {
|
||||
return parent::jqGridDataTables($params, $model);
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return array
|
||||
('link' =>
|
||||
array(// Models
|
||||
'CurrentLedger' => array
|
||||
(// Models
|
||||
'LedgerEntry'
|
||||
/* REVISIT <AP> 20090615:
|
||||
* I'll remove this 'conditions' section on a future checkin,
|
||||
* after I've proven out the %{MODEL_ALIAS} feature will be
|
||||
* sticking around.
|
||||
|
||||
=> array
|
||||
('conditions' =>
|
||||
array('OR' =>
|
||||
array('LedgerEntry.debit_ledger_id = CurrentLedger.id',
|
||||
'LedgerEntry.credit_ledger_id = CurrentLedger.id'),
|
||||
),
|
||||
),
|
||||
|
||||
* END REVISIT
|
||||
*/
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
@@ -142,14 +156,12 @@ class AccountsController extends AppController {
|
||||
$ledger = array_merge($ledger,
|
||||
$this->Account->Ledger->stats($ledger['id']));
|
||||
|
||||
// Obtain the overall account balance
|
||||
$account['Account'] =
|
||||
array_merge($account['Account'],
|
||||
array('stats' => $this->Account->stats($id)));
|
||||
$balance = $account['Account']['stats']['Ledger']['balance'];
|
||||
// Obtain stats across ALL ledgers for the summary infobox
|
||||
$stats = $this->Account->stats($id, true);
|
||||
$stats = $stats['Ledger'];
|
||||
|
||||
// Prepare to render
|
||||
$title = 'Account: ' . $account['Account']['name'];
|
||||
$this->set(compact('account', 'title', 'balance'));
|
||||
$this->set(compact('account', 'title', 'stats'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class LeasesController extends AppController {
|
||||
function index() { $this->all(); }
|
||||
function active() { $this->jqGridView('Active Leases'); }
|
||||
function closed() { $this->jqGridView('Closed Leases'); }
|
||||
function all() { $this->jqGridView('All Leases'); }
|
||||
function all() { $this->jqGridView('All Leases', 'all'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
@@ -16,6 +16,44 @@ class LedgerEntriesController extends AppController {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* virtuals: jqGridData
|
||||
* - With the application controller handling the jqGridData action,
|
||||
* these virtual functions ensure that the correct data is passed
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return array
|
||||
('link' =>
|
||||
array(// Models
|
||||
'Transaction' => array('fields' =>
|
||||
array('Transaction.id', 'Transaction.stamp')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
return $model->ledgerContextFields($params['custom']['ledger_id'],
|
||||
$params['custom']['account_type']);
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
$conditions = parent::jqGridDataConditions($params, $model);
|
||||
$conditions[] = $model->ledgerContextConditions($params['custom']['ledger_id'],
|
||||
$params['custom']['account_type']);
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||
$links['Transaction'] = array('id');
|
||||
$links['LedgerEntry'] = array('id');
|
||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -49,19 +49,18 @@ class LedgersController extends AppController {
|
||||
$params['action'] = 'all';
|
||||
}
|
||||
|
||||
function jqGridDataExtraTables(&$params, &$model, &$query) {
|
||||
unset($query['contain']);
|
||||
$query['link'] =
|
||||
array(// Models
|
||||
'Account',
|
||||
'LedgerEntry' =>
|
||||
array('conditions' =>
|
||||
array('OR' =>
|
||||
array('LedgerEntry.debit_ledger_id = Ledger.id',
|
||||
'LedgerEntry.credit_ledger_id = Ledger.id'),
|
||||
),
|
||||
),
|
||||
);
|
||||
function jqGridDataCountTables(&$params, &$model) {
|
||||
return array('contain' => false);
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return array
|
||||
('link' =>
|
||||
array(// Models
|
||||
'Account',
|
||||
'LedgerEntry',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
@@ -140,18 +139,11 @@ class LedgersController extends AppController {
|
||||
)
|
||||
);
|
||||
|
||||
// Get all ledger entries of this ledger
|
||||
$ledger['LedgerEntry'] = $this->Ledger->findLedgerEntries
|
||||
($id, $ledger['Account']['type']);
|
||||
|
||||
// Summarize the entries, and obtain the ledger balance
|
||||
$ledger['Ledger'] =
|
||||
array_merge($ledger['Ledger'],
|
||||
array('stats' => $this->Ledger->stats($id)));
|
||||
$balance = $ledger['Ledger']['stats']['balance'];
|
||||
// Get ledger stats for our summary box
|
||||
$stats = $this->Ledger->stats($id);
|
||||
|
||||
// OK, set our view variables and render!
|
||||
$title = 'Ledger: ' . $ledger['Ledger']['name'];
|
||||
$this->set(compact('ledger', 'title', 'balance'));
|
||||
$this->set(compact('ledger', 'title', 'stats'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,28 @@ class LinkableBehavior extends ModelBehavior {
|
||||
|
||||
protected $_defaults = array('type' => 'LEFT');
|
||||
|
||||
/*
|
||||
* This is a function for made recursive str_replaces in an array
|
||||
* NOTE: The palacement of this function is terrible, but I don't
|
||||
* know if I really want to go down this path or not.
|
||||
*/
|
||||
function recursive_array_replace($find, $replace, &$data) {
|
||||
if (!isset($data))
|
||||
return;
|
||||
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$this->recursive_array_replace($find, $replace, $data[$key]);
|
||||
} else {
|
||||
$data[$key] = str_replace($find, $replace, $value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data = str_replace($find, $replace, $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function beforeFind(&$Model, $query) {
|
||||
/* pr("Linkable::beforeFind() begin"); pr($query); */
|
||||
if (isset($query[$this->_key])) {
|
||||
@@ -111,6 +133,15 @@ class LinkableBehavior extends ModelBehavior {
|
||||
$_Model->unbindModel(array('belongsTo' => array($Reference->alias)));
|
||||
}
|
||||
|
||||
if ($associatedThroughReference)
|
||||
$this->recursive_array_replace("%{MODEL_ALIAS}",
|
||||
$Reference->alias,
|
||||
$association['conditions']);
|
||||
else
|
||||
$this->recursive_array_replace("%{MODEL_ALIAS}",
|
||||
$_Model->alias,
|
||||
$association['conditions']);
|
||||
|
||||
// Determine which model holds the foreign key
|
||||
if (($type === 'hasMany' || $type === 'hasOne') ^ $associatedThroughReference) {
|
||||
$primaryModel = $Reference;
|
||||
|
||||
@@ -19,8 +19,8 @@ class Ledger extends AppModel {
|
||||
// conditions will be used when JOINing tables
|
||||
// (such as find with LinkableBehavior)
|
||||
'conditions' => array('OR' =>
|
||||
array('LedgerEntry.debit_ledger_id = Ledger.id',
|
||||
'LedgerEntry.credit_ledger_id = Ledger.id')),
|
||||
array('LedgerEntry.debit_ledger_id = %{MODEL_ALIAS}.id',
|
||||
'LedgerEntry.credit_ledger_id = %{MODEL_ALIAS}.id')),
|
||||
|
||||
// finderQuery will be used when tables are put
|
||||
// together across several querys, not with JOIN.
|
||||
|
||||
@@ -37,6 +37,41 @@ class LedgerEntry extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: ledgerContext query helpers
|
||||
* - Returns parameters necessary to generate a query which
|
||||
* puts ledger entries into the context of a ledger. Since
|
||||
* debit/credit depends on the account type, it is required
|
||||
* as an argument for each function to avoid having to
|
||||
* query the ledger/account to find it out.
|
||||
*/
|
||||
function ledgerContextFields($ledger_id, $account_type) {
|
||||
if (in_array($account_type, array('ASSET', 'EXPENSE')))
|
||||
$ledger_type = 'debit';
|
||||
else
|
||||
$ledger_type = 'credit';
|
||||
|
||||
return array
|
||||
('id', 'name', 'comment',
|
||||
"IF(LedgerEntry.debit_ledger_id = $ledger_id," .
|
||||
" LedgerEntry.amount, NULL) AS debit",
|
||||
"IF(LedgerEntry.credit_ledger_id = $ledger_id," .
|
||||
" LedgerEntry.amount, NULL) AS credit",
|
||||
"(IF(LedgerEntry.{$ledger_type}_ledger_id = $ledger_id, 1, -1)" .
|
||||
" * LedgerEntry.amount) AS balance",
|
||||
);
|
||||
}
|
||||
|
||||
function ledgerContextConditions($ledger_id, $account_type) {
|
||||
return array
|
||||
('OR' =>
|
||||
array(array('LedgerEntry.debit_ledger_id' => $ledger_id),
|
||||
array('LedgerEntry.credit_ledger_id' => $ledger_id)),
|
||||
);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -52,32 +87,19 @@ class LedgerEntry extends AppModel {
|
||||
if (!isset($link))
|
||||
$link = array('Transaction');
|
||||
|
||||
if (in_array($account_type, array('ASSET', 'EXPENSE')))
|
||||
$ledger_type = 'debit';
|
||||
else
|
||||
$ledger_type = 'credit';
|
||||
if (!isset($cond))
|
||||
$cond = array();
|
||||
|
||||
$fields = $this->ledgerContextFields($ledger_id, $account_type);
|
||||
$cond[] = $this->ledgerContextConditions($ledger_id, $account_type);
|
||||
$order = array('Transaction.stamp');
|
||||
|
||||
$entries = $this->find
|
||||
('all',
|
||||
array('link' => $link,
|
||||
|
||||
'fields' =>
|
||||
array('id', 'name', 'comment',
|
||||
"IF(LedgerEntry.debit_ledger_id = $ledger_id," .
|
||||
" LedgerEntry.amount, NULL) AS debit",
|
||||
"IF(LedgerEntry.credit_ledger_id = $ledger_id," .
|
||||
" LedgerEntry.amount, NULL) AS credit",
|
||||
"(IF(LedgerEntry.{$ledger_type}_ledger_id = $ledger_id, 1, -1)" .
|
||||
" * LedgerEntry.amount) AS balance"),
|
||||
|
||||
'conditions' =>
|
||||
array(isset($cond) ? $cond : array(),
|
||||
'OR' =>
|
||||
array(array('LedgerEntry.debit_ledger_id' => $ledger_id),
|
||||
array('LedgerEntry.credit_ledger_id' => $ledger_id))),
|
||||
|
||||
'order' =>
|
||||
array('Transaction.stamp'),
|
||||
array('link' => $link,
|
||||
'fields' => $fields,
|
||||
'conditions' => $cond,
|
||||
'order' => $order,
|
||||
));
|
||||
|
||||
return $entries;
|
||||
|
||||
@@ -33,9 +33,22 @@ echo $this->element('table',
|
||||
?>
|
||||
|
||||
<DIV CLASS="infobox">
|
||||
<DIV CLASS="summary balance">
|
||||
Account Balance: <?php echo FormatHelper::currency($balance); ?>
|
||||
</DIV>
|
||||
<TABLE CLASS="summary">
|
||||
<TR>
|
||||
<TD>Debits:</TD>
|
||||
<TD><?php echo FormatHelper::currency($stats['debits']); ?></TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>Credits:</TD>
|
||||
<TD><?php echo FormatHelper::currency($stats['credits']); ?></TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>Accout Balance:</TD>
|
||||
<TD><?php echo FormatHelper::currency($stats['balance']); ?></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</DIV>
|
||||
|
||||
<DIV CLASS="detail supporting">
|
||||
@@ -65,7 +78,9 @@ echo $this->element('ledgers',
|
||||
|
||||
echo $this->element('ledger_entries',
|
||||
array('caption' => "Current Ledger: (#{$account['CurrentLedger']['sequence']})",
|
||||
'ledger_entries' => $account['CurrentLedger']['LedgerEntry']));
|
||||
'ledger_id' => $account['CurrentLedger']['id'],
|
||||
'account_type' => $account['Account']['type'],
|
||||
));
|
||||
|
||||
/* End "detail supporting" DIV */ ?>
|
||||
</DIV>
|
||||
|
||||
@@ -82,6 +82,10 @@ elseif (!isset($action)) {
|
||||
$action = null;
|
||||
}
|
||||
|
||||
if (isset($custom_post_data)) {
|
||||
$postData['custom'] = serialize($custom_post_data);
|
||||
}
|
||||
|
||||
// 'action' will ensure that the controller provides the
|
||||
// correct subset of data
|
||||
$postData['action'] = $action;
|
||||
|
||||
@@ -1,69 +1,24 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Ledger Entries',true).'</h2>';
|
||||
// Define the table columns
|
||||
$cols = array();
|
||||
$cols['Transaction'] = array('index' => 'Transaction.id', 'formatter' => 'id');
|
||||
$cols['Entry'] = array('index' => 'LedgerEntry.id', 'formatter' => 'id');
|
||||
$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date');
|
||||
$cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment');
|
||||
$cols['Debit'] = array('index' => 'debit', 'formatter' => 'currency');
|
||||
$cols['Credit'] = array('index' => 'credit', 'formatter' => 'currency');
|
||||
//$cols['Total'] = array('index' => 'balance', 'formatter' => 'currency');
|
||||
|
||||
$headers = array('Transaction', 'Entry', 'Date', 'Comment', 'Debit', 'Credit', 'Total');
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('Transaction', 'Entry')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Debit', 'Credit', 'Total')) AS $k => $v) {
|
||||
$column_class[$k] = 'currency';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'slack';
|
||||
$jqGrid_options = array('jqGridColumns' => $cols,
|
||||
'controller' => 'ledger_entries',
|
||||
'caption' => isset($caption) ? $caption : null);
|
||||
|
||||
if (isset($ledger_id)) {
|
||||
$jqGrid_options += array('custom_post_data' => array('ledger_id' => $ledger_id,
|
||||
'account_type' => $account_type),
|
||||
'limit' => 50);
|
||||
}
|
||||
|
||||
echo $this->element('jqGrid', $jqGrid_options);
|
||||
|
||||
$rows = array();
|
||||
$running_total = 0;
|
||||
foreach($ledger_entries AS $entry) {
|
||||
$credit = $debit = null;
|
||||
$running_total += $entry[0]['balance'];
|
||||
|
||||
if (isset($entry[0]['debit']))
|
||||
$debit = $entry[0]['debit'];
|
||||
if (isset($entry[0]['credit']))
|
||||
$credit = $entry[0]['credit'];
|
||||
|
||||
// local references to linked tables
|
||||
$transaction = $entry['Transaction'];
|
||||
|
||||
// Now that we've extracted top level 'LedgerEntry' data
|
||||
// move our variable to the meat of 'LedgerEntry' for clarity
|
||||
if (isset($entry['LedgerEntry']))
|
||||
$entry = $entry['LedgerEntry'];
|
||||
|
||||
$rows[] = array(isset($transaction['id'])
|
||||
? $html->link('#'.$transaction['id'],
|
||||
array('controller' => 'transactions',
|
||||
'action' => 'view',
|
||||
$transaction['id']))
|
||||
: null,
|
||||
|
||||
isset($entry['id'])
|
||||
? $html->link('#'.$entry['id'],
|
||||
array('controller' => 'ledger_entries',
|
||||
'action' => 'view',
|
||||
$entry['id']))
|
||||
: null,
|
||||
|
||||
FormatHelper::date($transaction['stamp']),
|
||||
FormatHelper::comment(array($transaction['comment'], $entry['comment'])),
|
||||
FormatHelper::currency($debit),
|
||||
FormatHelper::currency($credit),
|
||||
FormatHelper::currency($running_total)
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger-entries list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
?>
|
||||
|
||||
@@ -35,9 +35,22 @@ echo $this->element('table',
|
||||
?>
|
||||
|
||||
<DIV CLASS="infobox">
|
||||
<DIV CLASS="summary balance">
|
||||
Ledger Balance: <?php echo FormatHelper::currency($balance); ?>
|
||||
</DIV>
|
||||
<TABLE CLASS="summary">
|
||||
<TR>
|
||||
<TD>Debits:</TD>
|
||||
<TD><?php echo FormatHelper::currency($stats['debits']); ?></TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>Credits:</TD>
|
||||
<TD><?php echo FormatHelper::currency($stats['credits']); ?></TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>Ledger Balance:</TD>
|
||||
<TD><?php echo FormatHelper::currency($stats['balance']); ?></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</DIV>
|
||||
|
||||
<DIV CLASS="detail supporting">
|
||||
@@ -58,7 +71,9 @@ echo $this->element('table',
|
||||
|
||||
echo $this->element('ledger_entries',
|
||||
array('caption' => $ledger['Ledger']['name'],
|
||||
'ledger_entries' => $ledger['LedgerEntry']));
|
||||
'ledger_id' => $ledger['Ledger']['id'],
|
||||
'account_type' => $ledger['Account']['type'],
|
||||
));
|
||||
|
||||
/* End "detail supporting" DIV */ ?>
|
||||
</DIV>
|
||||
|
||||
@@ -87,13 +87,21 @@ div.infobox { float: right;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
div.summary { color: #993;
|
||||
table.summary {
|
||||
margin-left:auto;
|
||||
margin-right:0.5em;
|
||||
color: #993;
|
||||
font-family:'Gill Sans','lucida grande',helvetica, arial, sans-serif;
|
||||
font-size: 125%;
|
||||
text-align: right;
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.2em;
|
||||
}
|
||||
|
||||
table.summary td {
|
||||
padding-left:0.5em;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
************************************************************
|
||||
|
||||
Reference in New Issue
Block a user