sidemenu_links); } /************************************************************************** ************************************************************************** ************************************************************************** * virtuals: gridData * - With the application controller handling the gridData action, * these virtual functions ensure that the correct data is passed * to jqGrid. */ function gridDataTables(&$params, &$model) { $link = array(// Models 'Transaction' => array('fields' => array('id', 'stamp'), ), 'Ledger' => array('fields' => array('id', 'sequence'), 'Account' => array('fields' => array('id', 'name', 'type'), ), ), 'Tender' => array('fields' => array('id', 'name'), ), /* 'DebitEntry', */ /* 'CreditEntry', */ ); return array('link' => $link); } function gridDataFields(&$params, &$model) { $fields = parent::gridDataFields($params, $model); return array_merge($fields, $this->LedgerEntry->debitCreditFields()); } function gridDataOrder(&$params, &$model, $index, $direction) { /* if ($index === 'balance') */ /* return ($index .' '. $direction); */ $order = parent::gridDataOrder($params, $model, $index, $direction); if ($index === 'Transaction.stamp') { $order[] = 'LedgerEntry.id ' . $direction; } return $order; } function gridDataPostProcessLinks(&$params, &$model, &$records, $links) { $links['LedgerEntry'] = array('id'); $links['Transaction'] = array('id'); $links['Ledger'] = array('id'); $links['Account'] = array('controller' => 'accounts', 'name'); $links['Tender'] = array('name'); return parent::gridDataPostProcessLinks($params, $model, $records, $links); } /************************************************************************** ************************************************************************** ************************************************************************** * action: view * - Displays information about a specific entry */ function view($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid Item.', true)); $this->redirect(array('controller' => 'accounts', 'action'=>'index')); } // Get the Entry and related fields $entry = $this->LedgerEntry->find ('first', array('contain' => array ( 'Transaction' => array('fields' => array('id', 'stamp'), ), 'Ledger' => array('fields' => array('id', 'sequence', 'name'), 'Account' => array('fields' => array('id', 'name', 'type', 'trackable'), ), ), 'Tender' => array('fields' => array('id', 'name'), ), 'DebitEntry' => array('fields' => array('id', 'crdr')), 'CreditEntry' => array('fields' => array('id', 'crdr')), ), 'conditions' => array('LedgerEntry.id' => $id), )); if (!empty($entry['DebitEntry']) && !empty($entry['CreditEntry'])) die("LedgerEntry has both a matching DebitEntry and CreditEntry"); if (empty($entry['DebitEntry']) && empty($entry['CreditEntry'])) die("LedgerEntry has neither a matching DebitEntry nor a CreditEntry"); if (empty($entry['DebitEntry']) && count($entry['CreditEntry']) != 1) die("LedgerEntry has more than one CreditEntry"); if (empty($entry['CreditEntry']) && count($entry['DebitEntry']) != 1) die("LedgerEntry has more than one DebitEntry"); if (empty($entry['DebitEntry'])) $entry['MatchingEntry'] = $entry['CreditEntry'][0]; else $entry['MatchingEntry'] = $entry['DebitEntry'][0]; // Prepare to render. $title = "Ledger Entry #{$entry['LedgerEntry']['id']}"; $this->set(compact('entry', 'title')); } }