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:
abijah
2009-06-15 06:22:38 +00:00
parent 5fd7483ac1
commit e3b838d62a
6 changed files with 132 additions and 168 deletions

View File

@@ -1,33 +1,6 @@
<?php
class LedgersController extends AppController {
var $paginate = array
('limit' => 100,
'link' =>
array(// Models
'Account',
'LedgerEntry' =>
array('fields' =>
array('SUM(IF(LedgerEntry.debit_ledger_id = Ledger.id,
LedgerEntry.amount, NULL)) AS debits',
'SUM(IF(LedgerEntry.credit_ledger_id = Ledger.id,
LedgerEntry.amount, NULL)) AS credits',
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
IF(LedgerEntry.debit_ledger_id = Ledger.id, 1, -1),
IF(LedgerEntry.credit_ledger_id = Ledger.id, 1, -1)
) * IF(LedgerEntry.amount, LedgerEntry.amount, 0)
) AS balance",
'COUNT(LedgerEntry.id) AS entries'),
'conditions' =>
array('OR' =>
array('LedgerEntry.debit_ledger_id = Ledger.id',
'LedgerEntry.credit_ledger_id = Ledger.id'),
),
),
),
'group' => 'Ledger.id',
'order' => array('Ledger.account_id', 'Ledger.sequence'));
var $sidemenu_links =
array(array('name' => 'Ledgers', 'header' => true),
@@ -51,56 +24,95 @@ class LedgersController extends AppController {
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index
* action: index / current / closed / all
* - Generate a list of ledgers
*/
function index() {
$this->current();
}
function index() { $this->all(); }
function current() { $this->jqGridView('Current Ledgers'); }
function closed() { $this->jqGridView('Closed Ledgers'); }
function all() { $this->jqGridView('All Ledgers', 'all'); }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: current
* - Lists all current ledgers
* virtuals: jqGridData
* - With the application controller handling the jqGridData action,
* these virtual functions ensure that the correct data is passed
* to jqGrid.
*/
function current() {
$title = 'Current Ledgers';
$this->set('title', $title); $this->set('heading', $title);
$this->set('ledgers', $this->paginate(null, array('NOT' => array('Ledger.closed'))));
$this->render('index');
function jqGridDataSetup(&$params) {
parent::jqGridDataSetup($params);
if (!isset($params['action']))
$params['action'] = 'all';
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: closed
* - Lists all closed ledgers
*/
function closed() {
$title = 'Closed Ledgers';
$this->set('title', $title); $this->set('heading', $title);
$this->set('ledgers', $this->paginate(null, array('Ledger.closed')));
$this->render('index');
function jqGridDataExtraTables(&$params, &$model, &$query) {
unset($query['contain']);
$query['link'] =
array(// Models
'Account',
'LedgerEntry' =>
array('conditions' =>
array('OR' =>
array('LedgerEntry.debit_ledger_id = Ledger.id',
'LedgerEntry.credit_ledger_id = Ledger.id'),
),
),
);
}
function jqGridDataFields(&$params, &$model) {
return array
('Ledger.*',
'CONCAT(Account.id, "-", Ledger.sequence) AS id_sequence',
'SUM(IF(LedgerEntry.debit_ledger_id = Ledger.id,
LedgerEntry.amount, NULL)) AS debits',
'SUM(IF(LedgerEntry.credit_ledger_id = Ledger.id,
LedgerEntry.amount, NULL)) AS credits',
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
IF(LedgerEntry.debit_ledger_id = Ledger.id, 1, -1),
IF(LedgerEntry.credit_ledger_id = Ledger.id, 1, -1)
) * IF(LedgerEntry.amount, LedgerEntry.amount, 0)
) AS balance",
'COUNT(LedgerEntry.id) AS entries');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all ledgers
*/
function jqGridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model);
function all() {
$title = 'All Ledgers';
$this->set('title', $title); $this->set('heading', $title);
$this->set('ledgers', $this->paginate());
$this->render('index');
if ($params['action'] === 'current') {
$conditions[] = array('NOT' => array('Ledger.closed'));
}
elseif ($params['action'] === 'closed') {
$conditions[] = 'Ledger.closed';
}
return $conditions;
}
function jqGridDataOrder(&$params, &$model, $index, $direction) {
$id_sequence = false;
if ($index === 'id_sequence') {
$id_sequence = true;
$index = 'Ledger.account_id';
}
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
if ($id_sequence) {
$order[] = 'Ledger.sequence ' . $direction;
}
return $order;
}
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
$links['Ledger'] = array('id_sequence');
$links['Account'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links);
}