git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@802 97e9348a-65ac-dc4b-aefc-98561f571b83
211 lines
7.3 KiB
PHP
211 lines
7.3 KiB
PHP
<?php
|
|
|
|
class AccountsController extends AppController {
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: addGridViewSideMenuLinks
|
|
* - Adds grid view navigation side menu links
|
|
*/
|
|
|
|
function addGridViewSideMenuLinks() {
|
|
parent::addGridViewSideMenuLinks();
|
|
|
|
$this->addSideMenuLink('Asset',
|
|
array('controller' => 'accounts', 'action' => 'asset'), null,
|
|
'CONTROLLER', $this->admin_area);
|
|
$this->addSideMenuLink('Liability',
|
|
array('controller' => 'accounts', 'action' => 'liability'), null,
|
|
'CONTROLLER', $this->admin_area);
|
|
$this->addSideMenuLink('Equity',
|
|
array('controller' => 'accounts', 'action' => 'equity'), null,
|
|
'CONTROLLER', $this->admin_area);
|
|
$this->addSideMenuLink('Income',
|
|
array('controller' => 'accounts', 'action' => 'income'), null,
|
|
'CONTROLLER', $this->admin_area);
|
|
$this->addSideMenuLink('Expense',
|
|
array('controller' => 'accounts', 'action' => 'expense'), null,
|
|
'CONTROLLER', $this->admin_area);
|
|
$this->addSideMenuLink('All',
|
|
array('controller' => 'accounts', 'action' => 'all'), null,
|
|
'CONTROLLER', $this->admin_area);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index / asset / liability / equity / income / expense / all
|
|
* - Generate a chart of accounts
|
|
*/
|
|
|
|
function index() { $this->all(); }
|
|
function asset() { $this->gridView('Asset Accounts'); }
|
|
function liability() { $this->gridView('Liability Accounts'); }
|
|
function equity() { $this->gridView('Equity Accounts'); }
|
|
function income() { $this->gridView('Income Accounts'); }
|
|
function expense() { $this->gridView('Expense Accounts'); }
|
|
function all() { $this->gridView('All Accounts', '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
|
|
'CurrentLedger' => array
|
|
(// Models
|
|
'LedgerEntry'
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
function gridDataFields(&$params, &$model) {
|
|
$fields = parent::gridDataFields($params, $model);
|
|
return array_merge($fields,
|
|
$this->Account->Ledger->LedgerEntry->debitCreditFields(true));
|
|
}
|
|
|
|
function gridDataConditions(&$params, &$model) {
|
|
$conditions = parent::gridDataConditions($params, $model);
|
|
|
|
if (in_array($params['action'], array('asset', 'liability', 'equity', 'income', 'expense'))) {
|
|
$conditions[] = array('Account.type' => strtoupper($params['action']));
|
|
}
|
|
|
|
$conditions[] = array('Account.level >=' =>
|
|
$this->Permission->level('controller.accounts'));
|
|
|
|
return $conditions;
|
|
}
|
|
|
|
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
|
$links['Account'] = array('name');
|
|
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: newledger
|
|
* - Close the current account ledger and create a new one,
|
|
* carrying forward any balance if necessary.
|
|
*/
|
|
|
|
function newledger($id = null) {
|
|
$result = $this->Account->closeCurrentLedgers($id);
|
|
|
|
if ($result['error']) {
|
|
pr(compact('result'));
|
|
die("Unable to create new ledger.");
|
|
$this->Session->setFlash(__('Unable to create new Ledger.', true));
|
|
}
|
|
if ($id)
|
|
$this->redirect(array('action'=>'view', $id));
|
|
else
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: collected
|
|
* - Displays the items actually collected for the period
|
|
* e.g. How much was collected in rent from 4/1/09 - 5/1/09
|
|
*/
|
|
function collected($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
$this->Account->recursive = -1;
|
|
$account = $this->Account->read(null, $id);
|
|
$account = $account['Account'];
|
|
|
|
$accounts = $this->Account->collectableAccounts();
|
|
$payment_accounts = $accounts['all'];
|
|
$default_accounts = $accounts['default'];
|
|
$this->set(compact('payment_accounts', 'default_accounts'));
|
|
|
|
$title = ($account['name'] . ': Collected Report');
|
|
$this->set(compact('account', 'title'));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: view
|
|
* - Displays information about a specific account
|
|
*/
|
|
|
|
function view($id = null) {
|
|
$account = $this->Account->find
|
|
('first',
|
|
array('contain' =>
|
|
array(// Models
|
|
'CurrentLedger' =>
|
|
array('fields' => array('id', 'sequence', 'name')),
|
|
|
|
'Ledger' =>
|
|
array('CloseTransaction' => array
|
|
('order' => array('CloseTransaction.stamp' => 'DESC'))),
|
|
),
|
|
'conditions' => array(array('Account.id' => $id),
|
|
array('Account.level >=' =>
|
|
$this->Permission->level('controller.accounts')),
|
|
),
|
|
)
|
|
);
|
|
|
|
if (empty($account)) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
// Obtain stats across ALL ledgers for the summary infobox
|
|
$stats = $this->Account->stats($id, true);
|
|
$stats = $stats['Ledger'];
|
|
|
|
$this->addSideMenuLink('New Ledger',
|
|
array('action' => 'newledger', $id), null,
|
|
'ACTION', $this->admin_area);
|
|
$this->addSideMenuLink('Collected',
|
|
array('action' => 'collected', $id), null,
|
|
'ACTION', $this->admin_area);
|
|
|
|
// Prepare to render
|
|
$title = 'Account: ' . $account['Account']['name'];
|
|
$this->set(compact('account', 'title', 'stats'));
|
|
}
|
|
|
|
}
|