Files
pmgr/site/controllers/transactions_controller.php
abijah f8eb45a0b9 Added lease and ledger_entry controllers/views. Minor bugfixes as well.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@85 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-10 08:53:22 +00:00

135 lines
4.3 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('fields' => array('LedgerEntry.id',
'LedgerEntry.amount',
'LedgerEntry.comment'),
//Models
'DebitLedger' => array
('fields' => array('DebitLedger.id', 'DebitLedger.sequence'),
'Account' => array
('fields' => array('Account.id', 'Account.name')),
),
'CreditLedger' => array
('fields' => array('CreditLedger.id', 'CreditLedger.sequence'),
'Account' => array
('fields' => array('Account.id', 'Account.name')),
),
),
)
);
$transaction = $this->Transaction->read(null, $id);
$this->Transaction->Behaviors->detach('Containable');
// Figure out the transaction total
$total = 0;
foreach($transaction['LedgerEntry'] AS $entry)
$total += $entry['amount'];
// OK, prepare to render.
$title = 'Transaction #' . $transaction['Transaction']['id'];
$this->set(compact('transaction', 'title', 'total'));
}
}