Moved ledgers over the jqGrid. Working reasonably well at the moment.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@131 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -11,9 +11,6 @@ $cols['Credits'] = array('index' => 'Account.credits', 'formatter' => 'currenc
|
||||
$cols['Balance'] = array('index' => 'Account.balance', 'formatter' => 'currency');
|
||||
$cols['Comment'] = array('index' => 'Account.comment', 'formatter' => 'comment');
|
||||
|
||||
|
||||
$cols['Name']['formatoptions'] = array('showAction' => 'view', 'idName' => 'myid');
|
||||
|
||||
$jqGrid_options = array('jqGridColumns' => $cols,
|
||||
'controller' => 'accounts',
|
||||
'caption' => isset($caption) ? $caption : null);
|
||||
|
||||
@@ -7,16 +7,18 @@ if (!isset($limit))
|
||||
$limit = 20;
|
||||
|
||||
if (!isset($limitOptions)) {
|
||||
$limitOptions = array();
|
||||
$limitOptions = array($limit);
|
||||
if ($limit < 10)
|
||||
array_push($limitOptions, 2, 5);
|
||||
if ($limit < 30)
|
||||
array_push($limitOptions, 10, 25);
|
||||
if ($limit > 10)
|
||||
array_push($limitOptions, 50, 200);
|
||||
array_push($limitOptions, 25, 50, 200);
|
||||
if ($limit > 20)
|
||||
array_push($limitOptions, 500);
|
||||
}
|
||||
sort($limitOptions, SORT_NUMERIC);
|
||||
$limitOptions = array_unique($limitOptions, SORT_NUMERIC);
|
||||
|
||||
if (!isset($height))
|
||||
$height = 'auto';
|
||||
@@ -130,6 +132,10 @@ foreach ($jqGridColumns AS &$col) {
|
||||
$col = array_merge($default, $col);
|
||||
}
|
||||
|
||||
reset($jqGridColumns);
|
||||
$sortname = current($jqGridColumns);
|
||||
$sortname = $sortname['index'];
|
||||
|
||||
|
||||
// OK, now that everything is in place, get out of PHP mode,
|
||||
// and add the javascript code (along with a touch of HTML)
|
||||
@@ -163,12 +169,14 @@ jQuery(document).ready(function(){
|
||||
'height' => $height,
|
||||
'rowNum' => $limit,
|
||||
'rowList' => $limitOptions,
|
||||
'sortname' => $sortname,
|
||||
'caption' => $caption,
|
||||
'imgpath' => $imgpath,
|
||||
'viewrecords' => true,
|
||||
'pager' => $grid_id.'-pager',
|
||||
|
||||
'loadComplete' => array('--special' => "function() {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Query</A><BR>'+url);}"),
|
||||
'loadError' => array('--special' => "function(xhr,st,err) {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Error Query</A><BR>'+url);}"),
|
||||
//'toolbar' => array(true,"bottom"),
|
||||
)); ?>
|
||||
);
|
||||
|
||||
@@ -1,88 +1,29 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Ledgers',true).'</h2>';
|
||||
// Define the table columns
|
||||
$cols = array();
|
||||
$cols['ID'] = array('index' => 'id_sequence', 'formatter' => 'id');
|
||||
$cols['Account'] = array('index' => 'Account.name', 'formatter' => 'name', 'width' => '250');
|
||||
$cols['Entries'] = array('index' => 'entries', 'width' => '60', 'align' => 'right');
|
||||
$cols['Debits'] = array('index' => 'debits', 'formatter' => 'currency');
|
||||
$cols['Credits'] = array('index' => 'credits', 'formatter' => 'currency');
|
||||
$cols['Balance'] = array('index' => 'balance', 'formatter' => 'currency');
|
||||
$cols['Close Date'] = array('index' => 'Ledger.close_stamp', 'formatter' => 'date');
|
||||
$cols['Comment'] = array('index' => 'Ledger.comment', 'formatter' => 'comment');
|
||||
|
||||
$headers = array_merge(array('Sequence'), //array('Name'),
|
||||
(isset($ledgers[0]['Account'])
|
||||
? array('Account')
|
||||
: array()),
|
||||
array('Entries', 'Debits', 'Credits', 'Balance', 'Close Date', 'Comment'));
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('ID', 'Sequence')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
$jqGrid_options = array('jqGridColumns' => $cols,
|
||||
'controller' => 'ledgers',
|
||||
'caption' => isset($caption) ? $caption : null);
|
||||
|
||||
if (isset($ledgers)) {
|
||||
$jqGrid_options += array('custom_ids' =>
|
||||
array_map(create_function('$data',
|
||||
'return $data["id"];'),
|
||||
$ledgers),
|
||||
'limit' => 5);
|
||||
}
|
||||
foreach (array_intersect($headers, array('Debits', 'Credits', 'Balance')) AS $k => $v) {
|
||||
$column_class[$k] = 'currency';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'slack';
|
||||
else {
|
||||
$jqGrid_options += array('search_fields' => array('Account'));
|
||||
}
|
||||
|
||||
if (isset($paginator)) {
|
||||
echo $paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||
|
||||
$headers = array_merge(array($paginator->sort('sequence')), //array($paginator->sort('name')),
|
||||
(isset($ledgers[0]['Account'])
|
||||
? array($paginator->sort('Account', 'Account.name'))
|
||||
: array()),
|
||||
array($paginator->sort('entries'),
|
||||
$paginator->sort('debits'),
|
||||
$paginator->sort('credits'),
|
||||
$paginator->sort('balance'),
|
||||
$paginator->sort('Close Date', 'close_stamp'),
|
||||
$paginator->sort('comment')));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($ledgers as $ledger) {
|
||||
$account = null;
|
||||
$stats = null;
|
||||
|
||||
if (isset($ledger[0]))
|
||||
$stats = $ledger[0];
|
||||
else
|
||||
$stats = $ledger;
|
||||
|
||||
if (isset($ledger['Account']))
|
||||
$account = $ledger['Account'];
|
||||
if (isset($ledger['Ledger']))
|
||||
$ledger = $ledger['Ledger'];
|
||||
|
||||
$rows[] = array_merge(array($html->link('#'.$ledger['account_id'].'-'.$ledger['sequence'],
|
||||
array('controller' => 'ledgers',
|
||||
'action' => 'view',
|
||||
$ledger['id']))),
|
||||
(isset($account)
|
||||
? array($html->link($account['name'],
|
||||
array('controller' => 'accounts',
|
||||
'action' => 'view',
|
||||
$account['id'])))
|
||||
: array()),
|
||||
array($stats['entries'],
|
||||
FormatHelper::currency($stats['debits']),
|
||||
FormatHelper::currency($stats['credits']),
|
||||
FormatHelper::currency($stats['balance']),
|
||||
FormatHelper::datetime($ledger['close_stamp']),
|
||||
$ledger['comment']));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
if (isset($paginator)) {
|
||||
echo('<div class="paging">' . "\n");
|
||||
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
|
||||
echo(' | ');
|
||||
echo $paginator->numbers();
|
||||
echo(' | ');
|
||||
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
|
||||
echo('</div>' . "\n");
|
||||
}
|
||||
echo $this->element('jqGrid', $jqGrid_options);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<div class="ledgers index">
|
||||
<?php
|
||||
function currency($number) {
|
||||
if (!isset($number))
|
||||
return null;
|
||||
|
||||
if ($number < 0)
|
||||
return "($ " . number_format(-1*$number, 2) . ")";
|
||||
else
|
||||
return "$ " . number_format($number, 2);
|
||||
}
|
||||
?>
|
||||
<?php echo $this->element('ledgers', array('heading' => '<h2>'.$heading.'</h2>')) ?>
|
||||
</div>
|
||||
Reference in New Issue
Block a user