Forgot the new files on the last checkin
git-svn-id: file:///svn-source/pmgr/branches/statements_20090623@185 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
116
site/controllers/statement_entries_controller.php
Normal file
116
site/controllers/statement_entries_controller.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
class StatementEntriesController 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) {
|
||||
$link =
|
||||
array(// Models
|
||||
'LedgerEntry' =>
|
||||
array('fields' => array('id'),
|
||||
// Models
|
||||
'Transaction' =>
|
||||
array('fields' => array('id', 'stamp'),
|
||||
),
|
||||
|
||||
'Ledger' =>
|
||||
array('fields' => array('id', 'sequence'),
|
||||
'conditions' => ("Ledger.id = IF(StatementEntry.type = 'CHARGE'," .
|
||||
" LedgerEntry.credit_ledger_id," .
|
||||
" LedgerEntry.debit_ledger_id)"),
|
||||
// Models
|
||||
'Account' => array('fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return array('link' => $link);
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
$fields = array('id', 'type', 'comment');
|
||||
$fields[] = "IF(StatementEntry.type = 'CHARGE', StatementEntry.amount, NULL) AS 'charge'";
|
||||
$fields[] = "IF(StatementEntry.type = 'PAYMENT', StatementEntry.amount, NULL) AS 'payment'";
|
||||
$fields[] = "IF(StatementEntry.type = 'CHARGE', 1, -1) * StatementEntry.amount AS 'amount'";
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
$conditions = parent::jqGridDataConditions($params, $model);
|
||||
|
||||
if (isset($params['custom']['statement_id'])) {
|
||||
$conditions[] =
|
||||
array('StatementEntry.statement_id' => $params['custom']['statement_id']);
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||
$links['Transaction'] = array('id');
|
||||
$links['StatementEntry'] = array('id');
|
||||
$links['Account'] = array('controller' => 'accounts', 'name');
|
||||
$links['LedgerEntry'] = array('id');
|
||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
function jqGridRecordsPostProcess(&$params, &$model, &$records) {
|
||||
parent::jqGridRecordsPostProcess($params, $model, $records);
|
||||
|
||||
$subtotal = 0;
|
||||
foreach ($records AS &$record) {
|
||||
$amount = $record['StatementEntry']['amount'];
|
||||
$record['StatementEntry']['amount'] = $amount;
|
||||
$record['StatementEntry']['subtotal'] = ($subtotal += $amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* 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 StatementEntry and related fields
|
||||
$entry = $this->StatementEntry->find
|
||||
('first',
|
||||
array('contain' => array(),
|
||||
'conditions' => array('StatementEntry.id' => $id),
|
||||
));
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Statement Entry #{$entry['StatementEntry']['id']}";
|
||||
$this->set(compact('entry', 'title'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user