'Accounts', 'header' => true), array('name' => 'All', 'url' => array('controller' => 'accounts', 'action' => 'all')), array('name' => 'Asset', 'url' => array('controller' => 'accounts', 'action' => 'asset')), array('name' => 'Liability', 'url' => array('controller' => 'accounts', 'action' => 'liability')), array('name' => 'Equity', 'url' => array('controller' => 'accounts', 'action' => 'equity')), array('name' => 'Income', 'url' => array('controller' => 'accounts', 'action' => 'income')), array('name' => 'Expense', 'url' => array('controller' => 'accounts', 'action' => 'expense')), ); /************************************************************************** ************************************************************************** ************************************************************************** * override: sideMenuLinks * - Generates controller specific links for the side menu */ function sideMenuLinks() { return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); } /************************************************************************** ************************************************************************** ************************************************************************** * 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'])); } // REVISIT : 20090811 // No security issues have been worked out yet $conditions[] = array('Account.level >=' => 10); 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']; $payment_accounts = $this->Account->collectableAccounts(); //$payment_accounts[$this->Account->nameToID('Closing')] = 'Closing'; //$payment_accounts[$this->Account->nameToID('Equity')] = 'Equity'; //$payment_accounts[$id] = 'Reversals'; $default_accounts = array_diff_key($this->Account->receiptAccounts(), array($this->Account->concessionAccountID() => 1)); $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), // REVISIT : 20090811 // No security issues have been worked out yet array('Account.level >=' => 10), ), ) ); 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->sidemenu_links[] = array('name' => 'Operations', 'header' => true); $this->sidemenu_links[] = array('name' => 'New Ledger', 'url' => array('action' => 'newledger', $id)); $this->sidemenu_links[] = array('name' => 'Collected', 'url' => array('action' => 'collected', $id)); // Prepare to render $title = 'Account: ' . $account['Account']['name']; $this->set(compact('account', 'title', 'stats')); } }