'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) { return array('contain' => false); } function gridDataTables(&$params, &$model) { return array ('link' => array(// Models 'Account', 'LedgerEntry', 'Close', ), ); } function gridDataFields(&$params, &$model) { return array_merge(array('Ledger.*', 'CONCAT(Account.id, "-", Ledger.sequence) AS id_sequence'), $this->Ledger->LedgerEntry->debitCreditFields(true)); } function gridDataConditions(&$params, &$model) { $conditions = parent::gridDataConditions($params, $model); if ($params['action'] === 'current') { $conditions[] = array('NOT' => array('Ledger.closed')); } elseif ($params['action'] === 'closed') { $conditions[] = 'Ledger.closed'; } 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')); } }