git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@49 97e9348a-65ac-dc4b-aefc-98561f571b83
242 lines
7.8 KiB
PHP
242 lines
7.8 KiB
PHP
<?php
|
|
|
|
class UnitsController extends AppController {
|
|
var $helpers = array('Html');
|
|
|
|
var $paginate = array('limit' => 100,
|
|
'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->Unit->recursive = 0;
|
|
|
|
// $units = $this->Unit->find
|
|
// ('all',
|
|
$this->paginate =
|
|
array(
|
|
'link' => array
|
|
('UnitSize' //=> array('fields' => array('name')),
|
|
//=> array('fields' => true),
|
|
=> array('fields' => array('name')),
|
|
//=> array('fields' => array()),
|
|
//=> array(),
|
|
|
|
//'Lease',
|
|
),
|
|
'conditions' => array('UnitSize.name =' => "10x30",
|
|
'UnitSize.id IS NOT NULL'),
|
|
//'fields' => true
|
|
'fields' => array('id', 'name', 'status', 'comment')
|
|
// )
|
|
);
|
|
|
|
$units = $this->paginate();
|
|
|
|
|
|
/* Array */
|
|
/* ( */
|
|
/* [joins] => Array */
|
|
/* ( */
|
|
/* [0] => Array */
|
|
/* ( */
|
|
/* [type] => LEFT */
|
|
/* [alias] => UnitSize */
|
|
/* [conditions] => `UnitSize`.`id` = `Unit`.`unit_size_id` */
|
|
/* [table] => `pmgr_unit_sizes` */
|
|
/* ) */
|
|
|
|
/* ) */
|
|
|
|
/* [conditions] => Array */
|
|
/* ( */
|
|
/* [UnitSize.name =] => 10x30 */
|
|
/* [0] => UnitSize.id IS NOT NULL */
|
|
/* ) */
|
|
|
|
/* [fields] => Array */
|
|
/* ( */
|
|
/* [0] => id */
|
|
/* [1] => name */
|
|
/* [2] => status */
|
|
/* [3] => comment */
|
|
/* [4] => `UnitSize`.`name` */
|
|
/* ) */
|
|
|
|
/* [limit] => */
|
|
/* [offset] => */
|
|
/* [order] => Array */
|
|
/* ( */
|
|
/* [0] => */
|
|
/* ) */
|
|
|
|
/* [page] => 1 */
|
|
/* [group] => */
|
|
/* [callbacks] => 1 */
|
|
/* [link] => Array */
|
|
/* ( */
|
|
/* [UnitSize] => Array */
|
|
/* ( */
|
|
/* [fields] => Array */
|
|
/* ( */
|
|
/* [0] => name */
|
|
/* ) */
|
|
|
|
/* ) */
|
|
|
|
/* ) */
|
|
|
|
/* [recursive] => -1 */
|
|
/* ) */
|
|
|
|
|
|
pr($units);
|
|
$title = 'Index Units';
|
|
$this->set('title', $title); $this->set('heading', $title);
|
|
$this->set('units', $units);
|
|
|
|
//$this->all();
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: unavailable
|
|
* - Lists unavailable units
|
|
*/
|
|
|
|
function unavailable() {
|
|
$this->Unit->recursive = 0;
|
|
$title = 'Unavailable Units';
|
|
$this->set('title', $title); $this->set('heading', $title);
|
|
$this->set('units', $this->paginate(array($this->Unit->conditionUnavailable())));
|
|
$this->render('index');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: vacant
|
|
* - Lists vacant units
|
|
*/
|
|
|
|
function vacant() {
|
|
$this->Unit->recursive = 0;
|
|
$title = 'Vacant Units';
|
|
$this->set('title', $title); $this->set('heading', $title);
|
|
$this->set('units', $this->paginate(array($this->Unit->conditionVacant())));
|
|
$this->render('index');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: occupied
|
|
* - Lists occupied units
|
|
*/
|
|
|
|
function occupied() {
|
|
$this->Unit->recursive = 0;
|
|
$title = 'Occupied Units';
|
|
$this->set('title', $title); $this->set('heading', $title);
|
|
$this->set('units', $this->paginate(array($this->Unit->conditionOccupied())));
|
|
$this->render('index');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: all
|
|
* - Lists all units
|
|
*/
|
|
|
|
function all() {
|
|
$this->Unit->recursive = 0;
|
|
$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'=>''));
|
|
}
|
|
$this->Unit->recursive = 4;
|
|
$this->Unit->UnitSize->unbindModel(array('hasMany' => array('Unit')));
|
|
$this->Unit->UnitSize->UnitType->unbindModel(array('hasMany' => array('UnitSize')));
|
|
$this->Unit->Lease->unbindModel(array('belongsTo' => array('Unit')));
|
|
$this->Unit->Lease->LeaseType->unbindModel(array('hasMany' => array('Lease')));
|
|
$this->Unit->Lease->Charge->unbindModel(array('belongsTo' => array('Lease')));
|
|
$this->Unit->Lease->Charge->ChargeType->unbindModel(array('hasMany' => array('Charge')));
|
|
$this->Unit->Lease->Charge->Receipt->unbindModel(array('hasMany' => array('ChargesReceipt')));
|
|
|
|
$unit = $this->Unit->read(null, $id);
|
|
$title = 'Unit ' . $unit['Unit']['name'];
|
|
|
|
$outstanding_deposit = 0;
|
|
$outstanding_balance = 0;
|
|
foreach($unit['Lease'] AS $lease) {
|
|
foreach($lease['Charge'] AS $charge) {
|
|
$outstanding_balance += $charge['total'];
|
|
foreach ($charge['Receipt'] AS $receipt) {
|
|
$outstanding_balance -= $receipt['ChargesReceipt']['amount'];
|
|
// REVISIT <AP> 20090530:
|
|
// Using hardcoded value for security deposit...
|
|
// That can't be good!
|
|
if ($charge['charge_type_id'] == 1)
|
|
$outstanding_deposit += $receipt['ChargesReceipt']['amount'];
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->sidemenu_links[] =
|
|
array('name' => 'Operations', 'header' => true);
|
|
$this->sidemenu_links[] =
|
|
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
|
|
|
$this->set(compact('unit', 'title',
|
|
'outstanding_balance',
|
|
'outstanding_deposit'));
|
|
}
|
|
}
|
|
|
|
?>
|