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/site@136 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-15 21:24:42 +00:00
parent c9c06a9fb4
commit af32d88605
4 changed files with 37 additions and 114 deletions

View File

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

View File

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

View File

@@ -1,65 +1,27 @@
<?php /* -*- mode:PHP -*- */ <?php /* -*- mode:PHP -*- */
if (isset($heading)) // Define the table columns
echo $heading; $cols = array();
elseif (!isset($caption)) $cols['ID'] = array('index' => 'Transaction.id', 'formatter' => 'id');
echo '<h2>'.__('Transactions',true).'</h2>'; //$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'); $jqGrid_options = array('jqGridColumns' => $cols,
$column_class = array(); 'controller' => 'transactions',
foreach (array_intersect($headers, array('Comment')) AS $k => $v) { 'caption' => isset($caption) ? $caption : null);
$column_class[$k] = 'slack';
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) { else {
$column_class[$k] = 'id'; $jqGrid_options += array('search_fields' => array('Due', 'Comment'));
} }
if (isset($paginator)) { echo $this->element('jqGrid', $jqGrid_options);
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");
}

View File

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