Added logging
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@459 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -20,6 +20,8 @@ class Lease extends AppModel {
|
|||||||
* - Returns an array of security deposit entries
|
* - Returns an array of security deposit entries
|
||||||
*/
|
*/
|
||||||
function securityDeposits($id, $query = null) {
|
function securityDeposits($id, $query = null) {
|
||||||
|
$this->prFunctionLevel(30);
|
||||||
|
$this->prEnter(compact('id', 'query'));
|
||||||
$this->queryInit($query);
|
$this->queryInit($query);
|
||||||
|
|
||||||
$A = new Account();
|
$A = new Account();
|
||||||
@@ -37,8 +39,8 @@ class Lease extends AppModel {
|
|||||||
$set['summary'] = array('total' => $set['summary']['Charge']['total'],
|
$set['summary'] = array('total' => $set['summary']['Charge']['total'],
|
||||||
'balance' => $set['summary']['Charge']['reconciled'],
|
'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) {
|
function rentLastCharges($id) {
|
||||||
|
$this->prEnter(compact('id'));
|
||||||
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
||||||
$entries = $this->find
|
$entries = $this->find
|
||||||
('all',
|
('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) {
|
function rentChargeGaps($id) {
|
||||||
|
$this->prEnter(compact('id'));
|
||||||
$entries = $this->rentLastCharges($id);
|
$entries = $this->rentLastCharges($id);
|
||||||
if ($entries && count($entries) > 1)
|
if ($entries && count($entries) > 1)
|
||||||
return true;
|
return $this->prReturn(true);
|
||||||
return false;
|
return $this->prReturn(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -112,12 +116,13 @@ class Lease extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function rentChargeThrough($id) {
|
function rentChargeThrough($id) {
|
||||||
|
$this->prEnter(compact('id'));
|
||||||
$entries = $this->rentLastCharges($id);
|
$entries = $this->rentLastCharges($id);
|
||||||
if (!$entries)
|
if (!$entries)
|
||||||
return false;
|
return $this->prReturn(false);
|
||||||
if (count($entries) != 1)
|
if (count($entries) != 1)
|
||||||
return null;
|
return $this->prReturn(null);
|
||||||
return $entries[0]['StatementEntry']['through_date'];
|
return $this->prReturn($entries[0]['StatementEntry']['through_date']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +134,7 @@ class Lease extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function rentPaidThrough($id) {
|
function rentPaidThrough($id) {
|
||||||
|
$this->prEnter(compact('id'));
|
||||||
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
||||||
|
|
||||||
// First, see if we can find any unpaid entries. Of course,
|
// First, see if we can find any unpaid entries. Of course,
|
||||||
@@ -149,10 +155,10 @@ class Lease extends AppModel {
|
|||||||
'order' => array('StatementEntry.effective_date'),
|
'order' => array('StatementEntry.effective_date'),
|
||||||
),
|
),
|
||||||
true);
|
true);
|
||||||
//pr($rent);
|
$this->pr(20, $rent, "Unpaid rent");
|
||||||
|
|
||||||
if ($rent['entries'])
|
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
|
// 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'),
|
'order' => array('StatementEntry.through_date DESC'),
|
||||||
),
|
),
|
||||||
false);
|
false);
|
||||||
//pr($rent);
|
$this->pr(20, $rent, "Paid rent");
|
||||||
|
|
||||||
if ($rent['entries'])
|
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
|
// After all that, having found that there are no unpaid
|
||||||
// charges, and in fact, no paid charges either, we cannot
|
// charges, and in fact, no paid charges either, we cannot
|
||||||
// possibly say when the customer is paid through.
|
// 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,
|
function moveIn($customer_id, $unit_id,
|
||||||
$deposit = null, $rent = null,
|
$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',
|
$lt = $this->LeaseType->find('first',
|
||||||
array('conditions' =>
|
array('conditions' =>
|
||||||
@@ -244,7 +253,7 @@ class Lease extends AppModel {
|
|||||||
'deposit' => $deposit,
|
'deposit' => $deposit,
|
||||||
'rent' => $rent,
|
'rent' => $rent,
|
||||||
'comment' => $comment), false)) {
|
'comment' => $comment), false)) {
|
||||||
return null;
|
return $this->prReturn(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the lease number to be the same as the lease ID
|
// 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.
|
// was waived, pro-rated, etc.
|
||||||
|
|
||||||
// Return the new lease ID
|
// 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',
|
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
|
// Use NOW if not given a moveout date
|
||||||
if (!isset($stamp))
|
if (!isset($stamp))
|
||||||
$stamp = date('Y-m-d G:i:s');
|
$stamp = date('Y-m-d G:i:s');
|
||||||
@@ -307,8 +319,10 @@ class Lease extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function close($id, $stamp = null) {
|
function close($id, $stamp = null) {
|
||||||
|
$this->prEnter(compact('id', 'stamp'));
|
||||||
|
|
||||||
if (!$this->closeable($id))
|
if (!$this->closeable($id))
|
||||||
return false;
|
return $this->prReturn(false);
|
||||||
|
|
||||||
// Reset the data
|
// Reset the data
|
||||||
$this->create();
|
$this->create();
|
||||||
@@ -323,7 +337,7 @@ class Lease extends AppModel {
|
|||||||
|
|
||||||
// Save it!
|
// Save it!
|
||||||
$this->save($this->data, false);
|
$this->save($this->data, false);
|
||||||
return true;
|
return $this->prReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -335,16 +349,18 @@ class Lease extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function closeable($id) {
|
function closeable($id) {
|
||||||
|
$this->prEnter(compact('id'));
|
||||||
|
|
||||||
$this->recursive = -1;
|
$this->recursive = -1;
|
||||||
$this->read(null, $id);
|
$this->read(null, $id);
|
||||||
|
|
||||||
// We can't close a lease that's still in use
|
// We can't close a lease that's still in use
|
||||||
if (!isset($this->data['Lease']['moveout_date']))
|
if (!isset($this->data['Lease']['moveout_date']))
|
||||||
return false;
|
return $this->prReturn(false);
|
||||||
|
|
||||||
// We can't close a lease that's already closed
|
// We can't close a lease that's already closed
|
||||||
if (isset($this->data['Lease']['close_date']))
|
if (isset($this->data['Lease']['close_date']))
|
||||||
return false;
|
return $this->prReturn(false);
|
||||||
|
|
||||||
$deposits = $this->securityDeposits($id);
|
$deposits = $this->securityDeposits($id);
|
||||||
$stats = $this->stats($id);
|
$stats = $this->stats($id);
|
||||||
@@ -352,10 +368,10 @@ class Lease extends AppModel {
|
|||||||
// A lease can only be closed if there are no outstanding
|
// A lease can only be closed if there are no outstanding
|
||||||
// security deposits, and if the account balance is zero.
|
// security deposits, and if the account balance is zero.
|
||||||
if ($deposits['summary']['balance'] != 0 || $stats['balance'] != 0)
|
if ($deposits['summary']['balance'] != 0 || $stats['balance'] != 0)
|
||||||
return false;
|
return $this->prReturn(false);
|
||||||
|
|
||||||
// Apparently this lease meets all the criteria!
|
// 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) {
|
function stats($id = null, $query = null) {
|
||||||
|
$this->prEnter(compact('id', 'query'));
|
||||||
if (!$id)
|
if (!$id)
|
||||||
return null;
|
return $this->prReturn(null);
|
||||||
|
|
||||||
$this->queryInit($query);
|
$this->queryInit($query);
|
||||||
|
|
||||||
@@ -407,7 +424,7 @@ class Lease extends AppModel {
|
|||||||
$query['group'] = null;
|
$query['group'] = null;
|
||||||
|
|
||||||
$stats = $this->StatementEntry->find('first', $query);
|
$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,
|
// The fields are all tucked into the [0] index,
|
||||||
// and the rest of the array is useless (empty).
|
// and the rest of the array is useless (empty).
|
||||||
@@ -417,7 +434,7 @@ class Lease extends AppModel {
|
|||||||
if (!isset($stats['balance']))
|
if (!isset($stats['balance']))
|
||||||
$stats['balance'] = 0;
|
$stats['balance'] = 0;
|
||||||
|
|
||||||
return $stats;
|
return $this->prReturn($stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user