git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@71 97e9348a-65ac-dc4b-aefc-98561f571b83
130 lines
4.1 KiB
PHP
130 lines
4.1 KiB
PHP
<?php
|
|
|
|
class TransactionsController extends AppController {
|
|
var $paginate = array('limit' => 100,
|
|
'group' => 'Transaction.id',
|
|
'order' => array('Transaction.stamp' => 'ASC'));
|
|
|
|
var $sidemenu_links =
|
|
array(array('name' => 'Transactions', 'header' => true),
|
|
array('name' => 'Cleared', 'url' => array('controller' => 'transactions', 'action' => 'cleared')),
|
|
array('name' => 'Unresolved', 'url' => array('controller' => 'transactions', 'action' => 'unresolved')),
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: sideMenuLinks
|
|
* - Generates controller specific links for the side menu
|
|
*/
|
|
function sideMenuLinks() {
|
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index
|
|
* - Lists all transactions
|
|
*/
|
|
|
|
function index() {
|
|
$this->all();
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: cleared
|
|
* - Lists cleared transactions
|
|
*/
|
|
|
|
function cleared() {
|
|
$this->all();
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: unresolved
|
|
* - Lists unresolved transactions
|
|
*/
|
|
|
|
function unresolved() {
|
|
$this->all();
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: all
|
|
* - Lists all transactions
|
|
*/
|
|
|
|
function all() {
|
|
$this->paginate = array_merge
|
|
($this->paginate,
|
|
array('link' =>
|
|
array(// Models
|
|
'Customer',
|
|
'LedgerEntry' => array('DebitLedger', 'CreditLedger')
|
|
),
|
|
));
|
|
|
|
$title = 'All Transactions';
|
|
$this->set('title', $title); $this->set('heading', $title);
|
|
$this->set('transactions', $this->paginate());
|
|
$this->render('index');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: view
|
|
* - Displays information about a specific transaction
|
|
*/
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
$this->Transaction->Behaviors->attach('Containable');
|
|
$this->Transaction->contain
|
|
(array(// Models
|
|
'LedgerEntry' => array(//Models
|
|
'DebitLedger',
|
|
'CreditLedger',
|
|
),
|
|
)
|
|
);
|
|
$transaction = $this->Transaction->read(null, $id);
|
|
pr($transaction);
|
|
|
|
$debit_amount = 0;
|
|
$credit_amount = 0;
|
|
foreach($transaction['LedgerEntry'] AS $entry) {
|
|
$debit_amount += $entry['amount'];
|
|
$credit_amount += $entry['amount'];
|
|
}
|
|
|
|
/* $this->sidemenu_links[] = */
|
|
/* array('name' => 'Operations', 'header' => true); */
|
|
/* $this->sidemenu_links[] = */
|
|
/* array('name' => 'Move-Out', 'url' => array('controller' => 'transactions', 'action' => 'move-out')); */
|
|
|
|
$title = 'Transaction #' . $transaction['Transaction']['id'];
|
|
$this->set(compact('transaction', 'title',
|
|
'debit_amount',
|
|
'credit_amount'));
|
|
}
|
|
}
|