gridView('All Ledger Entries'); } /************************************************************************** ************************************************************************** ************************************************************************** * 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', 'nsf_transaction_id'), ), /* 'DebitEntry', */ /* 'CreditEntry', */ ); return array('link' => $link); } function gridDataFields(&$params, &$model) { $fields = parent::gridDataFields($params, $model); return array_merge($fields, $this->LedgerEntry->debitCreditFields()); } function gridDataFilterTablesTable(&$params, &$model, $table) { $table = $this->gridDataFilterTableName($params, $model, $table); // Account is already part of our standard table set. // Ensure we don't add it in again as part of filtering. if ($table == 'Account') return null; // Customer needs to be added beneath Transaction if ($table == 'Customer') return 'Transaction'; return $table; } function gridDataFilterTablesConfig(&$params, &$model, $table) { $config = parent::gridDataFilterTablesConfig($params, $model, $table); // Customer is special in that its linked in by Transaction // Therefore, the actual table used for the join is 'Transaction', // not 'Customer', and so we need to specify Customer here. if ($table == 'Customer') $config = array('Customer' => $config); return $config; } function gridDataFilterConditionsStatement(&$params, &$model, $table, $key, $value) { //pr(compact('table', 'key', 'value')); if ($table == 'Account' && $value['value_present'] && $value['value'] === '-AR-') $value = $this->LedgerEntry->Ledger->Account->accountReceivableAccountID(); return parent::gridDataFilterConditionsStatement($params, $model, $table, $key, $value); } 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 gridDataPostProcessCalculatedFields(&$params, &$model, &$records) { parent::gridDataPostProcessCalculatedFields($params, $model, $records); foreach ($records AS &$record) { // REVISIT : 20090730 // We really need the grid to handle this. We probably need to // either create a hidden column with the nsf id, or pass back // a list of nsf items as user data. We can then add an onload // function to sweep through the nsf items and format them. // For now... this works. if (!empty($record['Tender']['nsf_transaction_id'])) $record['Tender']['name'] = '' . $record['Tender']['name'] . ''; } } function gridDataPostProcessLinks(&$params, &$model, &$records, $links) { $links['LedgerEntry'] = array('id'); $links['Transaction'] = array('id'); // REVISIT : 20090827 // Need to take 'level' into account if ($this->Permission->allow('controller.accounts')) { $links['Ledger'] = array('id'); $links['Account'] = array('name'); } $links['Tender'] = array('name'); return parent::gridDataPostProcessLinks($params, $model, $records, $links); } /************************************************************************** ************************************************************************** ************************************************************************** * action: view * - Displays information about a specific entry */ function view($id = null) { $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'), ), ), 'Tender' => array('fields' => array('id', 'name'), ), 'DebitDoubleEntry' => array('id'), 'CreditDoubleEntry' => array('id'), 'DebitEntry' => array('fields' => array('id', 'crdr')), 'CreditEntry' => array('fields' => array('id', 'crdr')), ), 'conditions' => array('LedgerEntry.id' => $id), )); if (empty($entry) || empty($entry['Ledger']['Account'])) { $this->Session->setFlash(__('Invalid Item.', true)); $this->redirect(array('controller' => 'accounts', 'action'=>'index')); } 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]; if (empty($entry['DebitDoubleEntry']['id'])) $entry['DoubleEntry'] = $entry['CreditDoubleEntry']; else $entry['DoubleEntry'] = $entry['DebitDoubleEntry']; // REVISIT : 20090816 // This page doesn't seem very useful, let's just keep it // all to the double entry view. $this->redirect(array('controller' => 'double_entries', 'action' => 'view', $entry['DoubleEntry']['id'])); // Prepare to render. $title = "Ledger Entry #{$entry['LedgerEntry']['id']}"; $this->set(compact('entry', 'title')); } }