git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@239 97e9348a-65ac-dc4b-aefc-98561f571b83
158 lines
5.1 KiB
PHP
158 lines
5.1 KiB
PHP
<?php
|
|
|
|
class TransactionsController extends AppController {
|
|
|
|
var $components = array('RequestHandler');
|
|
|
|
var $sidemenu_links =
|
|
array(array('name' => 'Transactions', 'header' => true),
|
|
array('name' => 'All', 'url' => array('controller' => 'transactions', 'action' => 'all')),
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: sideMenuLinks
|
|
* - Generates controller specific links for the side menu
|
|
*/
|
|
function sideMenuLinks() {
|
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index / all
|
|
* - Generate a listing of transactions
|
|
*/
|
|
|
|
function index() { $this->all(); }
|
|
function all() { $this->jqGridView('All Transactions', 'all'); }
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* virtuals: jqGridData
|
|
* - With the application controller handling the jqGridData action,
|
|
* these virtual functions ensure that the correct data is passed
|
|
* to jqGrid.
|
|
*/
|
|
|
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
|
$links['Transaction'] = array('id');
|
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* 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'));
|
|
}
|
|
|
|
$transaction = $this->Transaction->find
|
|
('first',
|
|
array('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')),
|
|
),
|
|
),
|
|
),
|
|
'conditions' => array('Transaction.id' => $id),
|
|
));
|
|
|
|
// 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'));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: postInvoice
|
|
* - handles the creation of a charge invoice
|
|
*/
|
|
|
|
function postInvoice() {
|
|
if (!$this->RequestHandler->isPost()) {
|
|
echo('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
|
|
return;
|
|
}
|
|
|
|
if (!$this->Transaction->addInvoice($this->data, null,
|
|
$this->data['Lease']['id'])) {
|
|
$this->Session->setFlash("INVOICE FAILED", true);
|
|
// REVISIT <AP> 20090706:
|
|
// Until we can work out the session problems,
|
|
// just die.
|
|
die("<H1>INVOICE FAILED</H1>");
|
|
}
|
|
|
|
// Comment this out to debug
|
|
$this->redirect($this->data['redirect']);
|
|
|
|
pr($this->data['redirect']);
|
|
$this->render('/empty');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: postReceipt
|
|
* - handles the creation of a payment receipt
|
|
*/
|
|
|
|
function postReceipt() {
|
|
if (!$this->RequestHandler->isPost()) {
|
|
echo('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
|
|
return;
|
|
}
|
|
|
|
if (!$this->Transaction->addReceipt($this->data,
|
|
$this->data['Customer']['id'])) {
|
|
$this->Session->setFlash("RECEIPT FAILED", true);
|
|
// REVISIT <AP> 20090706:
|
|
// Until we can work out the session problems,
|
|
// just die.
|
|
die("<H1>RECEIPT FAILED</H1>");
|
|
}
|
|
|
|
$this->layout = null;
|
|
$this->autoLayout = false;
|
|
$this->autoRender = false;
|
|
}
|
|
|
|
|
|
}
|