Files
pmgr/controllers/units_controller.php

213 lines
6.6 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'=>''));
}
$this->Unit->Behaviors->attach('Containable');
$this->Unit->contain
(array(// Models
'UnitSize',
'Lease' =>
array('order' => 'movein_date',
'conditions' => array('Lease.lease_date IS NOT NULL',
),
// Models
'Contact' =>
array(//'order' => array('sort_order'),
'fields' => array('id', 'display_name'),
),
'Charge' =>
array('order' => array('charge_date'),
// Models
'ChargeType',
'Receipt' => array(// Models
'Payment'
),
)
)
)
);
$unit = $this->Unit->read(null, $id);
//pr($unit);
$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'];
/* foreach($receipt['Payment'] AS $payment) */
/* $outstanding_balance -= $payment['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'));
$title = 'Unit ' . $unit['Unit']['name'];
$this->set(compact('unit', 'title',
'outstanding_balance',
'outstanding_deposit'));
}
}