Files
pmgr/site/controllers/units_controller.php
abijah 18b928411b Added the Containable behavior back into the AppModel, since it's obviously getting used in every controller.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@91 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-10 21:09:23 +00:00

197 lines
6.3 KiB
PHP

<?php
class UnitsController extends AppController {
var $paginate = array('limit' => 100,
'group' => 'Unit.id',
'order' => array('Unit.sort_order' => 'ASC'));
var $sidemenu_links =
array(array('name' => 'Units', 'header' => true),
array('name' => 'Occupied', 'url' => array('controller' => 'units', 'action' => 'occupied')),
array('name' => 'Vacant', 'url' => array('controller' => 'units', 'action' => 'vacant')),
array('name' => 'Unavailable', 'url' => array('controller' => 'units', 'action' => 'unavailable')),
array('name' => 'All', 'url' => array('controller' => 'units', 'action' => 'all')),
);
/**************************************************************************
**************************************************************************
**************************************************************************
* override: sideMenuLinks
* - Generates controller specific links for the side menu
*/
function sideMenuLinks() {
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index
* - Lists all units
*/
function index() {
$this->all();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: unavailable
* - Lists unavailable units
*/
function unavailable() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
array(// Models
'UnitSize' => array('fields' => array('name')),
),
'conditions' => $this->Unit->conditionUnavailable()
));
$title = 'Unavailable Units';
$this->set('title', $title); $this->set('heading', $title);
$this->set('units', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: vacant
* - Lists vacant units
*/
function vacant() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
array(// Models
'UnitSize' => array('fields' => array('name')),
),
'conditions' => $this->Unit->conditionVacant()
));
$title = 'Vacant Units';
$this->set('title', $title); $this->set('heading', $title);
$this->set('units', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: occupied
* - Lists occupied units
*/
function occupied() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
array(// Models
'UnitSize' => array('fields' => array('name')),
'Lease' => array('fields' => array(),
// Models
'Contact' => array('fields' => array('display_name'),
//'type' => 'LEFT',
),
),
),
'conditions' => $this->Unit->conditionOccupied()
));
$title = 'Occupied Units';
$this->set('title', $title); $this->set('heading', $title);
$this->set('units', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all units
*/
function all() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
array(// Models
'UnitSize' => array('fields' => array('name')),
),
));
$title = 'All Units';
$this->set('title', $title); $this->set('heading', $title);
$this->set('units', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Displays information about a specific unit
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>''));
}
$unit = $this->Unit->find
('first',
array('contain' =>
array(// Models
'UnitSize',
'Lease' => array('Customer'),
'CurrentLease' => array('Customer')
),
'conditions' => array('Unit.id' => $id),
));
// Get the balance on each lease.
foreach ($unit['Lease'] AS &$lease) {
$stats = $this->Unit->Lease->stats($lease['id']);
$lease['balance'] = $stats['Account']['Ledger']['balance'];
}
$outstanding_balance = 0;
$outstanding_deposit = 0;
if (isset($unit['CurrentLease']['id'])) {
// Figure out the outstanding balance of the current lease.
$stats = $this->Unit->stats($id);
$outstanding_balance =
$stats['CurrentLease']['Account']['Ledger']['balance'];
// Figure out the total security deposit for the current lease.
$deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']);
$outstanding_deposit = $deposits['summary']['balance'];
}
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
// Prepare to render.
$title = 'Unit ' . $unit['Unit']['name'];
$this->set(compact('unit', 'title',
'outstanding_balance',
'outstanding_deposit'));
}
}