Added logging

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@459 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-31 18:35:39 +00:00
parent 645a3a4797
commit f210388f6c

View File

@@ -20,6 +20,8 @@ class Lease extends AppModel {
* - Returns an array of security deposit entries
*/
function securityDeposits($id, $query = null) {
$this->prFunctionLevel(30);
$this->prEnter(compact('id', 'query'));
$this->queryInit($query);
$A = new Account();
@@ -37,8 +39,8 @@ class Lease extends AppModel {
$set['summary'] = array('total' => $set['summary']['Charge']['total'],
'balance' => $set['summary']['Charge']['reconciled'],
);
//pr(compact('set'));
return $set;
return $this->prReturn($set);
}
@@ -54,6 +56,7 @@ class Lease extends AppModel {
*/
function rentLastCharges($id) {
$this->prEnter(compact('id'));
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
$entries = $this->find
('all',
@@ -80,8 +83,8 @@ class Lease extends AppModel {
),
)
);
//pr(compact('entries'));
return $entries;
return $this->prReturn($entries);
}
@@ -93,10 +96,11 @@ class Lease extends AppModel {
*/
function rentChargeGaps($id) {
$this->prEnter(compact('id'));
$entries = $this->rentLastCharges($id);
if ($entries && count($entries) > 1)
return true;
return false;
return $this->prReturn(true);
return $this->prReturn(false);
}
@@ -112,12 +116,13 @@ class Lease extends AppModel {
*/
function rentChargeThrough($id) {
$this->prEnter(compact('id'));
$entries = $this->rentLastCharges($id);
if (!$entries)
return false;
return $this->prReturn(false);
if (count($entries) != 1)
return null;
return $entries[0]['StatementEntry']['through_date'];
return $this->prReturn(null);
return $this->prReturn($entries[0]['StatementEntry']['through_date']);
}
@@ -129,6 +134,7 @@ class Lease extends AppModel {
*/
function rentPaidThrough($id) {
$this->prEnter(compact('id'));
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
// First, see if we can find any unpaid entries. Of course,
@@ -149,10 +155,10 @@ class Lease extends AppModel {
'order' => array('StatementEntry.effective_date'),
),
true);
//pr($rent);
$this->pr(20, $rent, "Unpaid rent");
if ($rent['entries'])
return $rent['entries'][0]['StatementEntry']['paid_through'];
return $this->prReturn($rent['entries'][0]['StatementEntry']['paid_through']);
// If we don't have any unpaid charges (great!), then the
@@ -168,16 +174,16 @@ class Lease extends AppModel {
'order' => array('StatementEntry.through_date DESC'),
),
false);
//pr($rent);
$this->pr(20, $rent, "Paid rent");
if ($rent['entries'])
return $rent['entries'][0]['StatementEntry']['through_date'];
return $this->prReturn($rent['entries'][0]['StatementEntry']['through_date']);
// After all that, having found that there are no unpaid
// charges, and in fact, no paid charges either, we cannot
// possibly say when the customer is paid through.
return null;
return $this->prReturn(null);
}
@@ -190,7 +196,10 @@ class Lease extends AppModel {
function moveIn($customer_id, $unit_id,
$deposit = null, $rent = null,
$stamp = null, $comment = null) {
$stamp = null, $comment = null)
{
$this->prEnter(compact('customer_id', 'unit_id',
'deposit', 'rent', 'stamp', 'comment'));
$lt = $this->LeaseType->find('first',
array('conditions' =>
@@ -244,7 +253,7 @@ class Lease extends AppModel {
'deposit' => $deposit,
'rent' => $rent,
'comment' => $comment), false)) {
return null;
return $this->prReturn(null);
}
// Set the lease number to be the same as the lease ID
@@ -261,7 +270,7 @@ class Lease extends AppModel {
// was waived, pro-rated, etc.
// Return the new lease ID
return $this->id;
return $this->prReturn($this->id);
}
@@ -273,7 +282,10 @@ class Lease extends AppModel {
*/
function moveOut($id, $status = 'VACANT',
$stamp = null, $close = false) {
$stamp = null, $close = false)
{
$this->prEnter(compact('id', 'status', 'stamp', 'close'));
// Use NOW if not given a moveout date
if (!isset($stamp))
$stamp = date('Y-m-d G:i:s');
@@ -307,8 +319,10 @@ class Lease extends AppModel {
*/
function close($id, $stamp = null) {
$this->prEnter(compact('id', 'stamp'));
if (!$this->closeable($id))
return false;
return $this->prReturn(false);
// Reset the data
$this->create();
@@ -323,7 +337,7 @@ class Lease extends AppModel {
// Save it!
$this->save($this->data, false);
return true;
return $this->prReturn(true);
}
@@ -335,16 +349,18 @@ class Lease extends AppModel {
*/
function closeable($id) {
$this->prEnter(compact('id'));
$this->recursive = -1;
$this->read(null, $id);
// We can't close a lease that's still in use
if (!isset($this->data['Lease']['moveout_date']))
return false;
return $this->prReturn(false);
// We can't close a lease that's already closed
if (isset($this->data['Lease']['close_date']))
return false;
return $this->prReturn(false);
$deposits = $this->securityDeposits($id);
$stats = $this->stats($id);
@@ -352,10 +368,10 @@ class Lease extends AppModel {
// A lease can only be closed if there are no outstanding
// security deposits, and if the account balance is zero.
if ($deposits['summary']['balance'] != 0 || $stats['balance'] != 0)
return false;
return $this->prReturn(false);
// Apparently this lease meets all the criteria!
return true;
return $this->prReturn(true);
}
@@ -379,8 +395,9 @@ class Lease extends AppModel {
*/
function stats($id = null, $query = null) {
$this->prEnter(compact('id', 'query'));
if (!$id)
return null;
return $this->prReturn(null);
$this->queryInit($query);
@@ -407,7 +424,7 @@ class Lease extends AppModel {
$query['group'] = null;
$stats = $this->StatementEntry->find('first', $query);
//pr(compact('query', 'stats'));
//$this->pr(20, compact('query', 'stats'));
// The fields are all tucked into the [0] index,
// and the rest of the array is useless (empty).
@@ -417,7 +434,7 @@ class Lease extends AppModel {
if (!isset($stats['balance']))
$stats['balance'] = 0;
return $stats;
return $this->prReturn($stats);
}
}