git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@802 97e9348a-65ac-dc4b-aefc-98561f571b83
153 lines
5.1 KiB
PHP
153 lines
5.1 KiB
PHP
<?php
|
|
|
|
class LedgersController extends AppController {
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: addGridViewSideMenuLinks
|
|
* - Adds grid view navigation side menu links
|
|
*/
|
|
|
|
function addGridViewSideMenuLinks() {
|
|
parent::addGridViewSideMenuLinks();
|
|
|
|
$this->addSideMenuLink('Current',
|
|
array('controller' => 'ledgers', 'action' => 'current'), null,
|
|
'CONTROLLER');
|
|
$this->addSideMenuLink('Closed',
|
|
array('controller' => 'ledgers', 'action' => 'closed'), null,
|
|
'CONTROLLER');
|
|
$this->addSideMenuLink('All',
|
|
array('controller' => 'ledgers', 'action' => 'all'), null,
|
|
'CONTROLLER');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index / current / closed / all
|
|
* - Generate a list of ledgers
|
|
*/
|
|
|
|
function index() { $this->all(); }
|
|
function current() { $this->gridView('Current Ledgers'); }
|
|
function closed() { $this->gridView('Closed Ledgers'); }
|
|
function all() { $this->gridView('All Ledgers', 'all'); }
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* virtuals: gridData
|
|
* - With the application controller handling the gridData action,
|
|
* these virtual functions ensure that the correct data is passed
|
|
* to jqGrid.
|
|
*/
|
|
|
|
function gridDataSetup(&$params) {
|
|
parent::gridDataSetup($params);
|
|
if (!isset($params['action']))
|
|
$params['action'] = 'all';
|
|
}
|
|
|
|
function gridDataCountTables(&$params, &$model) {
|
|
return array
|
|
('link' =>
|
|
array(// Models
|
|
'Account',
|
|
),
|
|
);
|
|
}
|
|
|
|
function gridDataTables(&$params, &$model) {
|
|
$tables = $this->gridDataCountTables($params, $model);
|
|
$tables['link'][] = 'LedgerEntry';
|
|
$tables['link'][] = 'CloseTransaction';
|
|
return $tables;
|
|
}
|
|
|
|
function gridDataFields(&$params, &$model) {
|
|
$fields = parent::gridDataFields($params, $model);
|
|
$fields[] = 'CONCAT(Account.id, "-", Ledger.sequence) AS id_sequence';
|
|
return array_merge($fields,
|
|
$this->Ledger->LedgerEntry->debitCreditFields(true));
|
|
}
|
|
|
|
function gridDataConditions(&$params, &$model) {
|
|
$conditions = parent::gridDataConditions($params, $model);
|
|
|
|
if ($params['action'] === 'current') {
|
|
$conditions[] = array('Ledger.close_transaction_id' => null);
|
|
}
|
|
elseif ($params['action'] === 'closed') {
|
|
$conditions[] = array('Ledger.close_transaction_id !=' => null);
|
|
}
|
|
|
|
$conditions[] = array('Account.level >=' =>
|
|
$this->Permission->level('controller.accounts'));
|
|
|
|
return $conditions;
|
|
}
|
|
|
|
function gridDataOrder(&$params, &$model, $index, $direction) {
|
|
$order = parent::gridDataOrder($params, $model, $index, $direction);
|
|
|
|
// After sorting by whatever the user wants, add these
|
|
// defaults into the sort mechanism. If we're already
|
|
// sorting by one of them, it will only be redundant,
|
|
// and should cause no harm (possible a longer query?)
|
|
$order[] = 'Account.name ' . $direction;
|
|
$order[] = 'Ledger.sequence ' . $direction;
|
|
|
|
return $order;
|
|
}
|
|
|
|
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
|
// REVISIT <AP>: 20090827
|
|
// Need to take 'level' into account
|
|
if ($this->Permission->allow('controller.accounts')) {
|
|
$links['Ledger'] = array('sequence');
|
|
$links['Account'] = array('name');
|
|
}
|
|
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: view
|
|
* - Displays information about a specific ledger
|
|
*/
|
|
|
|
function view($id = null) {
|
|
$ledger = $this->Ledger->find
|
|
('first',
|
|
array('contain' =>
|
|
array(// Models
|
|
'Account',
|
|
),
|
|
'conditions' => array(array('Ledger.id' => $id),
|
|
array('Account.level >=' =>
|
|
$this->Permission->level('controller.accounts')),
|
|
),
|
|
)
|
|
);
|
|
|
|
if (empty($ledger)) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
// Get ledger stats for our summary box
|
|
$stats = $this->Ledger->stats($id);
|
|
|
|
// OK, set our view variables and render!
|
|
$title = 'Ledger: #' . $ledger['Account']['id'] .'-'. $ledger['Ledger']['sequence'];
|
|
$this->set(compact('ledger', 'title', 'stats'));
|
|
}
|
|
}
|