git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@421 97e9348a-65ac-dc4b-aefc-98561f571b83
146 lines
4.8 KiB
PHP
146 lines
4.8 KiB
PHP
<?php
|
|
|
|
class LedgersController extends AppController {
|
|
|
|
var $sidemenu_links =
|
|
array(array('name' => 'Ledgers', 'header' => true),
|
|
array('name' => 'Current', 'url' => array('controller' => 'ledgers', 'action' => 'current')),
|
|
array('name' => 'Closed', 'url' => array('controller' => 'ledgers', 'action' => 'closed')),
|
|
array('name' => 'All', 'url' => array('controller' => 'ledgers', 'action' => 'all')),
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: sideMenuLinks
|
|
* - Generates controller specific links for the side menu
|
|
*/
|
|
function sideMenuLinks() {
|
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* 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) {
|
|
// Our count should NOT include anything extra,
|
|
// so we need the virtual function to prevent
|
|
// the base class from just calling our
|
|
// gridDataTables function.
|
|
return parent::gridDataTables($params, $model);
|
|
}
|
|
|
|
function gridDataTables(&$params, &$model) {
|
|
return array
|
|
('link' =>
|
|
array(// Models
|
|
'Account',
|
|
'LedgerEntry',
|
|
'CloseTransaction',
|
|
),
|
|
);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
return $conditions;
|
|
}
|
|
|
|
function gridDataOrder(&$params, &$model, $index, $direction) {
|
|
$id_sequence = false;
|
|
if ($index === 'id_sequence') {
|
|
$id_sequence = true;
|
|
$index = 'Ledger.account_id';
|
|
}
|
|
|
|
$order = parent::gridDataOrder($params, $model, $index, $direction);
|
|
|
|
if ($id_sequence) {
|
|
$order[] = 'Ledger.sequence ' . $direction;
|
|
}
|
|
|
|
return $order;
|
|
}
|
|
|
|
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
|
$links['Ledger'] = array('id_sequence');
|
|
$links['Account'] = array('name');
|
|
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: view
|
|
* - Displays information about a specific ledger
|
|
*/
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
// Get details about the ledger itself (no entries yet)
|
|
$ledger = $this->Ledger->find
|
|
('first',
|
|
array('contain' =>
|
|
array(// Models
|
|
'Account',
|
|
),
|
|
'conditions' => array(array('Ledger.id' => $id)),
|
|
)
|
|
);
|
|
|
|
// 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'));
|
|
}
|
|
}
|