Files
pmgr/site/controllers/charges_controller.php
abijah e586268dee Added a couple helpers, including Html, to our app controller and removed Html from each individual controller
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@65 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-03 22:33:03 +00:00

128 lines
4.0 KiB
PHP

<?php
class ChargesController extends AppController {
var $paginate = array('limit' => 100,
'group' => 'Charge.id',
'order' => array('Charge.charge_date' => 'ASC'));
var $sidemenu_links =
array(array('name' => 'Charges', 'header' => true),
array('name' => 'Cleared', 'url' => array('controller' => 'charges', 'action' => 'cleared')),
array('name' => 'Unresolved', 'url' => array('controller' => 'charges', '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 charges
*/
function index() {
$this->all();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: cleared
* - Lists cleared charges
*/
function cleared() {
$this->all();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: unresolved
* - Lists unresolved charges
*/
function unresolved() {
$this->all();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all charges
*/
function all() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
array(// Models
'ChargeType',
'Receipt',
'Lease' => array('fields' => array('number'))
),
));
$title = 'All Charges';
$this->set('title', $title); $this->set('heading', $title);
$this->set('charges', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Displays information about a specific charge
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$this->Charge->Behaviors->attach('Containable');
$this->Charge->contain
(array(// Models
'ChargeType',
'Receipt',
'Lease' => array('fields' => array('number')),
)
);
$charge = $this->Charge->read(null, $id);
//pr($charge);
$payment_amount = 0;
foreach($charge['Receipt'] AS $receipt)
$payment_amount += $receipt['ChargesReceipt']['amount'];
$balance_amount = $charge['Charge']['total'] - $payment_amount;
/* $this->sidemenu_links[] = */
/* array('name' => 'Operations', 'header' => true); */
/* $this->sidemenu_links[] = */
/* array('name' => 'Move-Out', 'url' => array('controller' => 'charges', 'action' => 'move-out')); */
$title = 'Charge #' . $charge['Charge']['id'];
$this->set(compact('charge', 'title',
'payment_amount',
'balance_amount'));
}
}