git-svn-id: file:///svn-source/pmgr/branches/statements_20090623@184 97e9348a-65ac-dc4b-aefc-98561f571b83
157 lines
5.4 KiB
PHP
157 lines
5.4 KiB
PHP
<?php
|
|
|
|
class UnitsController extends AppController {
|
|
|
|
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 / unavailable / vacant / occupied / all
|
|
* - Generate a listing of units
|
|
*/
|
|
|
|
function index() { $this->all(); }
|
|
function unavailable() { $this->jqGridView('Unavailable Units'); }
|
|
function vacant() { $this->jqGridView('Vacant Units'); }
|
|
function occupied() { $this->jqGridView('Occupied Units'); }
|
|
function all() { $this->jqGridView('All Units', 'all'); }
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* virtuals: jqGridData
|
|
* - With the application controller handling the jqGridData action,
|
|
* these virtual functions ensure that the correct data is passed
|
|
* to jqGrid.
|
|
*/
|
|
|
|
function jqGridDataSetup(&$params) {
|
|
parent::jqGridDataSetup($params);
|
|
if (!isset($params['action']))
|
|
$params['action'] = 'all';
|
|
}
|
|
|
|
function jqGridDataTables(&$params, &$model) {
|
|
$link = array
|
|
('link' =>
|
|
array(// Models
|
|
'UnitSize' => array('fields' => array('id', 'name')),
|
|
),
|
|
);
|
|
|
|
if ($params['action'] === 'occupied')
|
|
$link['Lease'] = array('fields' => array(),
|
|
// Models
|
|
'Contact' => array('fields' => array('display_name'),
|
|
//'type' => 'LEFT',
|
|
),
|
|
);
|
|
|
|
return $link;
|
|
}
|
|
|
|
function jqGridDataConditions(&$params, &$model) {
|
|
$conditions = parent::jqGridDataConditions($params, $model);
|
|
|
|
if ($params['action'] === 'unavailable') {
|
|
$conditions[] = $this->Unit->conditionUnavailable();
|
|
}
|
|
elseif ($params['action'] === 'vacant') {
|
|
$conditions[] = $this->Unit->conditionVacant();
|
|
}
|
|
elseif ($params['action'] === 'occupied') {
|
|
$conditions[] = $this->Unit->conditionOccupied();
|
|
}
|
|
|
|
return $conditions;
|
|
}
|
|
|
|
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
|
if ($index === 'Unit.name') {
|
|
$index = 'Unit.sort_order';
|
|
}
|
|
return parent::jqGridDataOrder($params, $model, $index, $direction);
|
|
}
|
|
|
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
|
//$links['UnitSize'] = array('name');
|
|
$links['Unit'] = array('name', 'id');
|
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* 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['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']['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'));
|
|
}
|
|
}
|