git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@139 97e9348a-65ac-dc4b-aefc-98561f571b83
124 lines
4.2 KiB
PHP
124 lines
4.2 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);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* virtuals: jqGridData
|
|
* - With the application controller handling the jqGridData action,
|
|
* these virtual functions ensure that the correct data is passed
|
|
* to jqGrid.
|
|
*/
|
|
|
|
function jqGridDataTables(&$params, &$model) {
|
|
return array
|
|
('link' =>
|
|
array(// Models
|
|
'Transaction' =>
|
|
array('fields' =>
|
|
array('Transaction.id', 'Transaction.stamp')),
|
|
|
|
'MonetarySource' =>
|
|
array('fields' =>
|
|
array('MonetarySource.id', 'MonetarySource.name')),
|
|
),
|
|
);
|
|
}
|
|
|
|
function jqGridDataFields(&$params, &$model) {
|
|
return $model->ledgerContextFields($params['custom']['ledger_id'],
|
|
$params['custom']['account_type']);
|
|
}
|
|
|
|
function jqGridDataConditions(&$params, &$model) {
|
|
$conditions = parent::jqGridDataConditions($params, $model);
|
|
$conditions[] = $model->ledgerContextConditions($params['custom']['ledger_id'],
|
|
$params['custom']['account_type']);
|
|
return $conditions;
|
|
}
|
|
|
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
|
$links['Transaction'] = array('id');
|
|
$links['LedgerEntry'] = array('id');
|
|
return parent::jqGridRecordLinks($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 LedgerEntry and related fields
|
|
$entry = $this->LedgerEntry->find
|
|
('first',
|
|
array('contain' => array('MonetarySource.id',
|
|
'MonetarySource.MonetaryType.id',
|
|
'Transaction.id',
|
|
'Transaction.stamp',
|
|
'DebitLedger.id',
|
|
'DebitLedger.sequence',
|
|
'DebitLedger.account_id',
|
|
'CreditLedger.id',
|
|
'CreditLedger.sequence',
|
|
'CreditLedger.account_id',
|
|
),
|
|
|
|
'fields' => array('LedgerEntry.id',
|
|
'LedgerEntry.amount',
|
|
'LedgerEntry.comment'),
|
|
|
|
'conditions' => array('LedgerEntry.id' => $id),
|
|
));
|
|
|
|
// Because 'DebitLedger' and 'CreditLedger' both relate to 'Account',
|
|
// CakePHP will not include them in the LedgerEntry->find (or so it
|
|
// seems). We'll have to break out each Account separately.
|
|
|
|
// Get the Account from DebitLedger
|
|
$account = $this->LedgerEntry->DebitLedger->Account->find
|
|
('first',
|
|
array('contain' => true,
|
|
'fields' => array('Account.id', 'Account.name', 'Account.type'),
|
|
'conditions' => array('Account.id' => $entry['DebitLedger']['account_id']),
|
|
));
|
|
$entry['DebitLedger'] = array_merge($entry['DebitLedger'], $account);
|
|
|
|
// Get the Account from CreditLedger
|
|
$account = $this->LedgerEntry->CreditLedger->Account->find
|
|
('first',
|
|
array('contain' => true,
|
|
'fields' => array('Account.id', 'Account.name', 'Account.type'),
|
|
'conditions' => array('Account.id' => $entry['CreditLedger']['account_id']),
|
|
));
|
|
$entry['CreditLedger'] = array_merge($entry['CreditLedger'], $account);
|
|
|
|
// Prepare to render.
|
|
$title = "Ledger Entry #{$entry['LedgerEntry']['id']}";
|
|
$this->set(compact('entry', 'title'));
|
|
}
|
|
}
|