git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@499 97e9348a-65ac-dc4b-aefc-98561f571b83
200 lines
6.8 KiB
PHP
200 lines
6.8 KiB
PHP
<?php
|
|
|
|
class LedgerEntriesController extends AppController {
|
|
|
|
var $sidemenu_links = array();
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: sideMenuLinks
|
|
* - Generates controller specific links for the side menu
|
|
*/
|
|
function sideMenuLinks() {
|
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index / current / past / all
|
|
* - Creates a list of ledger entries
|
|
*/
|
|
|
|
function index() { $this->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 <AP>: 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'] =
|
|
'<SPAN class="nsf-tender">' . $record['Tender']['name'] . '</SPAN>';
|
|
}
|
|
}
|
|
|
|
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'),
|
|
),
|
|
),
|
|
|
|
'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'));
|
|
}
|
|
|
|
}
|