Files
pmgr/site/models/unit.php
abijah 504f1e7cc0 Finished basic functionality for Move-Out. This still needs some work to handle the security deposit.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@202 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-07-02 20:00:50 +00:00

116 lines
3.1 KiB
PHP

<?php
class Unit extends AppModel {
var $name = 'Unit';
var $validate = array(
'id' => array('numeric'),
'unit_size_id' => array('numeric'),
'name' => array('notempty'),
'sort_order' => array('numeric'),
'walk_order' => array('numeric'),
'deposit' => array('money'),
'amount' => array('money')
);
var $belongsTo = array(
'UnitSize',
);
var $hasOne = array(
'CurrentLease' => array(
'className' => 'Lease',
'conditions' => 'CurrentLease.moveout_date IS NULL',
),
);
var $hasMany = array(
'Lease',
);
/**************************************************************************
**************************************************************************
**************************************************************************
* helpers: status enumerations
*/
function statusEnums() {
static $status_enums;
if (!isset($status_enums))
$status_enums = $this->getEnumValues('status');
return $status_enums;
}
function statusValue($enum) {
$enums = $this->statusEnums();
return $enums[$enum];
}
function occupiedEnumValue() {
return statusValue('OCCUPIED');
}
function conditionOccupied() {
return ('Unit.status >= ' . $this->statusValue('OCCUPIED'));
}
function conditionVacant() {
return ('Unit.status BETWEEN ' .
($this->statusValue('UNAVAILABLE')+1) .
' AND ' .
($this->statusValue('OCCUPIED')-1));
}
function conditionUnavailable() {
return ('Unit.status <= ' . $this->statusValue('UNAVAILABLE'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: updateStatus
* - Update the given unit to the given status
*/
function updateStatus($id, $status) {
$this->id = $id;
pr(compact('id', 'status'));
$this->saveField('status', $status);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: stats
* - Returns summary data from the requested customer.
*/
function stats($id = null) {
if (!$id)
return null;
// Get the basic information necessary
$unit = $this->find('first',
array('contain' => array
('Lease' => array
('fields' => array('Lease.id')),
'CurrentLease' => array
('fields' => array('CurrentLease.id'))),
'conditions' => array
(array('Unit.id' => $id)),
));
// Get the stats for the current lease
$stats['CurrentLease'] = $this->Lease->stats($unit['CurrentLease']['id']);
// Sum the stats for all leases together
foreach ($unit['Lease'] AS $lease) {
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
}
// Return the collection
return $stats;
}
}