Moved transaction listings to jqGrid, and fixed a bug in the jqGrid element wrt. comment columns

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@136 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-15 21:24:42 +00:00
parent 23f4a29fc7
commit edca01f98c
4 changed files with 37 additions and 114 deletions

View File

@@ -1,14 +1,10 @@
<?php
class TransactionsController extends AppController {
var $paginate = array('limit' => 100,
'group' => 'Transaction.id',
'order' => array('Transaction.stamp' => 'ASC'));
var $sidemenu_links =
array(array('name' => 'Transactions', 'header' => true),
array('name' => 'Cleared', 'url' => array('controller' => 'transactions', 'action' => 'cleared')),
array('name' => 'Unresolved', 'url' => array('controller' => 'transactions', 'action' => 'unresolved')),
array(array('name' => 'Transactions', 'header' => true),
array('name' => 'All', 'url' => array('controller' => 'transactions', 'action' => 'all')),
);
@@ -26,61 +22,26 @@ class TransactionsController extends AppController {
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index
* - Lists all transactions
* action: index / active / closed / all
* - Generate a listing of leases
*/
function index() {
$this->all();
}
function index() { $this->all(); }
function all() { $this->jqGridView('All Transactions', 'all'); }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: cleared
* - Lists cleared transactions
* virtuals: jqGridData
* - With the application controller handling the jqGridData action,
* these virtual functions ensure that the correct data is passed
* to jqGrid.
*/
function cleared() {
$this->all();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: unresolved
* - Lists unresolved transactions
*/
function unresolved() {
$this->all();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all transactions
*/
function all() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
array(// Models
'Customer',
'LedgerEntry' => array('DebitLedger', 'CreditLedger')
),
));
$title = 'All Transactions';
$this->set('title', $title); $this->set('heading', $title);
$this->set('transactions', $this->paginate());
$this->render('index');
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
$links['Transaction'] = array('id');
return parent::jqGridRecordLinks($params, $model, $records, $links);
}

View File

@@ -130,6 +130,9 @@ foreach ($jqGridColumns AS &$col) {
elseif ($col['formatter'] === 'comment') {
$default['width'] = 300;
$default['sortable'] = false;
// No special formatting for comment
unset($col['formatter']);
}
}

View File

@@ -1,65 +1,27 @@
<?php /* -*- mode:PHP -*- */
if (isset($heading))
echo $heading;
elseif (!isset($caption))
echo '<h2>'.__('Transactions',true).'</h2>';
// Define the table columns
$cols = array();
$cols['ID'] = array('index' => 'Transaction.id', 'formatter' => 'id');
//$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname');
$cols['Timesamp'] = array('index' => 'Transaction.stamp', 'formatter' => 'date');
$cols['Through'] = array('index' => 'Transaction.through_date', 'formatter' => 'date');
$cols['Due'] = array('index' => 'Transaction.due_date', 'formatter' => 'date');
$cols['Comment'] = array('index' => 'Transaction.comment', 'formatter' => 'comment');
$headers = array('Id', 'Timestamp', 'Comment');
$column_class = array();
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
$column_class[$k] = 'slack';
$jqGrid_options = array('jqGridColumns' => $cols,
'controller' => 'transactions',
'caption' => isset($caption) ? $caption : null);
if (isset($transactions)) {
$jqGrid_options += array('custom_ids' =>
array_map(create_function('$data',
'return $data["id"];'),
$transactions),
'limit' => 5);
}
foreach (array_intersect($headers, array('Id')) AS $k => $v) {
$column_class[$k] = 'id';
else {
$jqGrid_options += array('search_fields' => array('Due', 'Comment'));
}
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
$headers = array($paginator->sort('id'),
$paginator->sort('customer_id'),
$paginator->sort('Timestamp', 'stamp'),
$paginator->sort('Through', 'through_date'),
$paginator->sort('Due', 'due_date'),
$paginator->sort('comment'));
}
$rows = array();
foreach ($transactions as $transaction) {
$customer = $transaction['Customer'];
if (isset($transaction['Transaction']))
$transaction = $transaction['Transaction'];
$rows[] = array($html->link('#'.$transaction['id'],
array('controller' => 'transactions',
'action' => 'view',
$transaction['id'])),
$html->link($customer['name'],
array('controller' => 'customers',
'action' => 'view',
$customer['id'])),
FormatHelper::date($transaction['stamp']),
FormatHelper::date($transaction['through_date']),
FormatHelper::date($transaction['due_date']),
$transaction['comment']);
}
echo $this->element('table',
array('class' => 'item transaction 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);

View File

@@ -1,3 +0,0 @@
<div class="transactions index">
<?php echo $this->element('transactions', array('heading' => '<h2>'.$heading.'</h2>')) ?>
</div>