Got rid of LATE as a unit status, as it did not represent an physical condition. The logic was moved to Lease, where it is a much better fit. The sitemap still presents LATE units, as it is a useful view, but the underlying logic is driven from Lease, not Unit. This checkin also includes a small feature change to how late charges are assessed, as well as a menu item to kick off the charge assessments (both accidentally wedged in to this changeset).

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@547 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-13 20:55:19 +00:00
parent 97d16bd712
commit 1fee7646b6
8 changed files with 87 additions and 97 deletions

View File

@@ -426,6 +426,17 @@ class Lease extends AppModel {
$date = mktime(0, 0, 0, $date_parts['mon'], 11, $date_parts['year']);
}
// Don't assess a late charge if the late charge date hasn't
// even come yet. This is questionable whether we really
// should restrict, since the user could know what they're
// doing, and/or the server clock could be off (although that
// would certainly have much larger ramifications). But, the
// fact is that this check likely handles the vast majority
// of the expected behavior, and presents an issue for very
// few users, if any at all.
if ($date > time())
return $this->prReturn(null);
// Make sure we're not trying to assess late charges on a closed lease
$close_date = $this->field('close_date');
$this->pr(17, compact('close_date'));
@@ -449,6 +460,10 @@ class Lease extends AppModel {
// Determine if the customer is actually late. This is based on
// when they've paid through, plus 10 days before they're late.
// REVISIT <AP>: 20090813
// Of course, 10 days is a terrible hardcode. This should be
// driven from the late schedule, saved as part of the lease
// (when finally implemented).
$paid_through_date = strtotime($this->rentPaidThrough($id));
$this->pr(17, compact('date', 'paid_through_date')
+ array('date_str' => date('Y-m-d', $date),
@@ -512,6 +527,31 @@ class Lease extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* functions: delinquency
* - SQL fragments to determine whether a lease is delinquent
*/
function conditionDelinquent($table_name = 'Lease') {
if (empty($table_name)) $t = ''; else $t = $table_name . '.';
return ("({$t}close_date IS NULL AND" .
" NOW() > DATE_ADD({$t}paid_through_date, INTERVAL 15 DAY))");
}
function delinquentDaysSQL($table_name = 'Lease') {
if (empty($table_name)) $t = ''; else $t = $table_name . '.';
return ("IF(" . $this->conditionDelinquent($table_name) . "," .
" DATEDIFF(NOW(), {$t}paid_through_date)-1," .
" NULL)");
}
function delinquentField($table_name = 'Lease') {
return ($this->delinquentDaysSQL($table_name) . " AS 'delinquent'");
}
/**************************************************************************
**************************************************************************
**************************************************************************

View File

@@ -1,15 +0,0 @@
<?php
class MapsUnit extends AppModel {
var $name = 'MapsUnit';
var $validate = array(
'id' => array('numeric'),
'map_id' => array('numeric'),
'unit_id' => array('numeric'),
'pt_top' => array('numeric'),
'pt_left' => array('numeric'),
'transpose' => array('boolean')
);
}
?>

View File

@@ -25,7 +25,6 @@ class Unit extends AppModel {
var $hasMany = array(
'Lease',
'MapsUnit',
);
//var $default_log_level = array('log' => 30, 'show' => 15);
@@ -88,16 +87,6 @@ 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);
}
@@ -149,13 +138,6 @@ 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);
@@ -199,27 +181,6 @@ 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'");
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -227,11 +188,6 @@ class Unit extends AppModel {
* - Update any cached or calculated fields
*/
function update($id) {
$unit = $this->find('first',
array('contain' => array('CurrentLease'),
'conditions' => array('Unit.id' => $id),
));
}