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:
abijah
2009-06-15 04:15:55 +00:00
parent 41636f5c75
commit 3dcdcb03eb
3 changed files with 81 additions and 176 deletions

View File

@@ -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);
}