Added cached fields for charged_through and paid_through dates of a lease. Also, added the ability to dynamically determine whether a unit is late or not. In reality, we really need this to be part of the lease, not one of the status types for unit. The sitemap, however, is driven from unit information, so it's not clear whether we should move that information or not.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@543 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-13 02:37:37 +00:00
parent af935ffd39
commit b741bb6b01
8 changed files with 145 additions and 16 deletions

View File

@@ -25,6 +25,7 @@ class Unit extends AppModel {
var $hasMany = array(
'Lease',
'MapsUnit',
);
//var $default_log_level = array('log' => 30, 'show' => 15);
@@ -87,6 +88,16 @@ class Unit extends AppModel {
return $this->prReturn(true);
}
function delinquent($enum) {
INTERNAL_ERROR("NOT YET FULLY IMPLEMENTED (Need check for LATE)");
return $this->statusCheck($enum, 'OCCUPIED', true, null, false);
}
function conditionDelinquent() {
return ('(Unit.status > ' . $this->statusValue('OCCUPIED') .
" OR " . $this->delinquentTest() . ")");
}
function occupied($enum) {
return $this->statusCheck($enum, 'OCCUPIED', false, null, false);
}
@@ -138,6 +149,13 @@ class Unit extends AppModel {
($val < $this->occupiedEnumValue())) {
unset($enums[$enum]);
}
// REVISIT <AP>: 20090812
// LATE is the only temporal condition, and somehow
// feels like it should be treated differently than
// the rest. How can a unit be marked as LATE when
// it is not inherent, but a function of time?
if ($enum === 'LATE')
unset($enums[$enum]);
}
return $this->prReturn($enums);
@@ -181,6 +199,42 @@ class Unit extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: statusField
* - Returns the status field SQL query
*/
function delinquentTest() {
return ("(`status` = 'OCCUPIED' AND " .
/* "(DATE_ADD(CurrentLease.paid_through_date, INTERVAL 10 DAY)" . */
/* " < CurrentLease.charge_through_date)," . */
" (DATE_ADD(CurrentLease.paid_through_date, INTERVAL 15 DAY)" .
" < NOW()))");
}
function statusFields() {
return array(
//"IF(`status` = 'OCCUPIED' AND " . $this->delinquentTest() . "," .
"IF(" . $this->delinquentTest() . "," .
" 'LATE', `status`) AS 'status'");
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: update
* - Update any cached or calculated fields
*/
function update($id) {
$unit = $this->find('first',
array('contain' => array('CurrentLease'),
'conditions' => array('Unit.id' => $id),
));
}
/**************************************************************************
**************************************************************************
**************************************************************************