Updated accounts to use jqGrid.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@130 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -1,34 +1,6 @@
|
||||
<?php
|
||||
|
||||
class AccountsController extends AppController {
|
||||
var $paginate = array
|
||||
('limit' => 100,
|
||||
'link' =>
|
||||
array(// Models
|
||||
'CurrentLedger' => array
|
||||
(// Models
|
||||
'LedgerEntry' =>
|
||||
array('fields' =>
|
||||
array('SUM(IF(LedgerEntry.debit_ledger_id = CurrentLedger.id,
|
||||
LedgerEntry.amount, NULL)) AS debits',
|
||||
'SUM(IF(LedgerEntry.credit_ledger_id = CurrentLedger.id,
|
||||
LedgerEntry.amount, NULL)) AS credits',
|
||||
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
||||
IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, 1, -1),
|
||||
IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, 1, -1)
|
||||
) * IF(LedgerEntry.amount, LedgerEntry.amount, 0)
|
||||
) AS balance",
|
||||
'COUNT(LedgerEntry.id) AS entries'),
|
||||
'conditions' =>
|
||||
array('OR' =>
|
||||
array('LedgerEntry.debit_ledger_id = CurrentLedger.id',
|
||||
'LedgerEntry.credit_ledger_id = CurrentLedger.id'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'group' => 'Account.id',
|
||||
'order' => array('Account.name' => 'ASC'));
|
||||
|
||||
var $uses = array('Account', 'LedgerEntry');
|
||||
|
||||
@@ -57,102 +29,80 @@ class AccountsController extends AppController {
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: index
|
||||
* - Lists all accounts
|
||||
* action: index / asset / liability / equity / income / expense / all
|
||||
* - Generate a chart of accounts
|
||||
*/
|
||||
|
||||
function index() {
|
||||
$this->all();
|
||||
}
|
||||
function index() { $this->all(); }
|
||||
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'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: asset
|
||||
* - Lists all asset accounts
|
||||
* virtuals: jqGridData
|
||||
* - With the application controller handling the jqGridData action,
|
||||
* these virtual functions ensure that the correct data is passed
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function asset() {
|
||||
$title = 'Asset Accounts';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('accounts', $this->paginate(array('Account.type' => 'ASSET')));
|
||||
$this->render('index');
|
||||
function jqGridDataSetup(&$params) {
|
||||
parent::jqGridDataSetup($params);
|
||||
if (!isset($params['action']))
|
||||
$params['action'] = 'all';
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: liability
|
||||
* - Lists all liability accounts
|
||||
*/
|
||||
|
||||
function liability() {
|
||||
$title = 'Liability Accounts';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('accounts', $this->paginate(array('Account.type' => 'LIABILITY')));
|
||||
$this->render('index');
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return array
|
||||
('link' =>
|
||||
array(// Models
|
||||
'CurrentLedger' => array
|
||||
(// Models
|
||||
'LedgerEntry' => array
|
||||
('conditions' =>
|
||||
array('OR' =>
|
||||
array('LedgerEntry.debit_ledger_id = CurrentLedger.id',
|
||||
'LedgerEntry.credit_ledger_id = CurrentLedger.id'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: equity
|
||||
* - Lists all equity accounts
|
||||
*/
|
||||
|
||||
function equity() {
|
||||
$title = 'Equity Accounts';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('accounts', $this->paginate(array('Account.type' => 'EQUITY')));
|
||||
$this->render('index');
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
return array
|
||||
('Account.*',
|
||||
'SUM(IF(LedgerEntry.debit_ledger_id = CurrentLedger.id,
|
||||
LedgerEntry.amount, NULL)) AS debits',
|
||||
'SUM(IF(LedgerEntry.credit_ledger_id = CurrentLedger.id,
|
||||
LedgerEntry.amount, NULL)) AS credits',
|
||||
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
||||
IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, 1, -1),
|
||||
IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, 1, -1)
|
||||
) * IF(LedgerEntry.amount, LedgerEntry.amount, 0)
|
||||
) AS balance",
|
||||
'COUNT(LedgerEntry.id) AS entries');
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
$conditions = parent::jqGridDataConditions($params, $model);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: income
|
||||
* - Lists all income accounts
|
||||
*/
|
||||
if (in_array($params['action'], array('asset', 'liability', 'equity', 'income', 'expense'))) {
|
||||
$conditions[] = array('Account.type' => strtoupper($params['action']));
|
||||
}
|
||||
|
||||
function income() {
|
||||
$title = 'Income Accounts';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('accounts', $this->paginate(array('Account.type' => 'INCOME')));
|
||||
$this->render('index');
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: expense
|
||||
* - Lists all expense accounts
|
||||
*/
|
||||
|
||||
function expense() {
|
||||
$title = 'Expense Accounts';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('accounts', $this->paginate(array('Account.type' => 'EXPENSE')));
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: all
|
||||
* - Lists all accounts
|
||||
*/
|
||||
|
||||
function all() {
|
||||
$title = 'All Accounts';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('accounts', $this->paginate());
|
||||
$this->render('index');
|
||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||
$links['Account'] = array('name');
|
||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<div class="accounts index">
|
||||
<?php echo $this->element('accounts', array('heading' => '<h2>'.$heading.'</h2>')) ?>
|
||||
</div>
|
||||
@@ -1,74 +1,32 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Accounts',true).'</h2>';
|
||||
// Define the table columns
|
||||
$cols = array();
|
||||
$cols['ID'] = array('index' => 'Account.id', 'formatter' => 'id');
|
||||
$cols['Name'] = array('index' => 'Account.name', 'formatter' => 'name', 'width' => '250');
|
||||
$cols['Type'] = array('index' => 'Account.type', 'width' => '60');
|
||||
$cols['Entries'] = array('index' => 'Account.entries', 'width' => '60', 'align' => 'right');
|
||||
$cols['Debits'] = array('index' => 'Account.debits', 'formatter' => 'currency');
|
||||
$cols['Credits'] = array('index' => 'Account.credits', 'formatter' => 'currency');
|
||||
$cols['Balance'] = array('index' => 'Account.balance', 'formatter' => 'currency');
|
||||
$cols['Comment'] = array('index' => 'Account.comment', 'formatter' => 'comment');
|
||||
|
||||
$headers = array('Name', 'Type', /*'Ext. Name', 'Ext. Account',*/ 'Entries', 'Debits', 'Credits', 'Balance', 'Comment');
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('Debits', 'Credits', 'Balance')) AS $k => $v) {
|
||||
$column_class[$k] = 'currency';
|
||||
|
||||
$cols['Name']['formatoptions'] = array('showAction' => 'view', 'idName' => 'myid');
|
||||
|
||||
$jqGrid_options = array('jqGridColumns' => $cols,
|
||||
'controller' => 'accounts',
|
||||
'caption' => isset($caption) ? $caption : null);
|
||||
|
||||
if (isset($accounts)) {
|
||||
$jqGrid_options += array('custom_ids' =>
|
||||
array_map(create_function('$data',
|
||||
'return $data["id"];'),
|
||||
$accounts),
|
||||
'limit' => 5);
|
||||
}
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'slack';
|
||||
else {
|
||||
$jqGrid_options += array('search_fields' => array('Name'));
|
||||
}
|
||||
|
||||
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('name'),
|
||||
$paginator->sort('type'),
|
||||
/* $paginator->sort('Ext. Name', 'external_name'), */
|
||||
/* $paginator->sort('Ext. Account', 'external_account'), */
|
||||
$paginator->sort('entries'),
|
||||
$paginator->sort('debits'),
|
||||
$paginator->sort('credits'),
|
||||
$paginator->sort('balance'),
|
||||
$paginator->sort('comment'));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($accounts as $account) {
|
||||
//pr($account);
|
||||
if (isset($account[0]))
|
||||
$stats = $account[0];
|
||||
else
|
||||
$stats = $account;
|
||||
|
||||
// Move our pointer to the meat
|
||||
if (isset($account['Account']))
|
||||
$account = $account['Account'];
|
||||
|
||||
$rows[] = array($html->link($account['name'],
|
||||
array('controller' => 'accounts',
|
||||
'action' => 'view',
|
||||
$account['id'])),
|
||||
$account['type'],
|
||||
/* $account['external_name'], */
|
||||
/* $account['external_account'], */
|
||||
$stats['entries'],
|
||||
FormatHelper::currency($stats['debits']),
|
||||
FormatHelper::currency($stats['credits']),
|
||||
FormatHelper::currency($stats['balance']),
|
||||
$account['comment'],
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item account 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);
|
||||
|
||||
Reference in New Issue
Block a user