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@543 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -201,6 +201,29 @@ class Customer extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: update
|
||||
* - Update any cached or calculated fields
|
||||
*/
|
||||
function update($id) {
|
||||
|
||||
// REVISIT <AP>: 20090812
|
||||
// updateLeaseCount is handled directly when needed.
|
||||
// Should we simplify by just doing it anyway?
|
||||
//$this->updateLeaseCount($id);
|
||||
|
||||
$current_leases =
|
||||
$this->find('all',
|
||||
array('link' => array('CurrentLease' => array('type' => 'INNER')),
|
||||
'conditions' => array('Customer.id' => $id)));
|
||||
|
||||
foreach ($current_leases AS $lease)
|
||||
$this->Lease->update($lease['CurrentLease']['id']);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -12,7 +12,7 @@ class Lease extends AppModel {
|
||||
'StatementEntry',
|
||||
);
|
||||
|
||||
//var $default_log_level = array('log' => 30, 'show' => 15);
|
||||
//var $default_log_level = array('log' => 30, 'show' => 30);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -745,6 +745,23 @@ class Lease extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: update
|
||||
* - Update any cached or calculated fields
|
||||
*/
|
||||
function update($id) {
|
||||
$this->id = $id;
|
||||
$this->saveField('charge_through_date', $this->rentChargeThrough($id));
|
||||
$this->saveField('paid_through_date', $this->rentPaidThrough($id));
|
||||
|
||||
$moveout = $this->field('moveout_date');
|
||||
if (empty($moveout))
|
||||
$this->Unit->update($this->field('unit_id'));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -663,6 +663,7 @@ class Transaction extends AppModel {
|
||||
$ret['error'] = true;
|
||||
}
|
||||
|
||||
$this->Customer->update($transaction['customer_id']);
|
||||
return $this->prReturn($ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user