Implemented mechanism for automatic assessment of monthly rent
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@505 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -400,6 +400,18 @@ class LeasesController extends AppController {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: assess_rent
|
||||
* - Assesses the new monthly rent charge, if need be
|
||||
*/
|
||||
|
||||
function assess_rent($id, $date = null) {
|
||||
$this->Lease->assessMonthlyRent($id, $date);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -267,6 +267,81 @@ class Lease extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: assessMonthlyRent
|
||||
* - Charges rent for the month, if not already charged.
|
||||
*/
|
||||
|
||||
function assessMonthlyRent($id, $date = null) {
|
||||
$this->prEnter(compact('id', 'date'));
|
||||
$this->id = $id;
|
||||
|
||||
if (empty($date))
|
||||
$date = time();
|
||||
|
||||
if (is_string($date))
|
||||
$date = strtotime($date);
|
||||
|
||||
// REVISIT <AP>: 20090808
|
||||
// Anniversary Billing not supported
|
||||
$anniversary = 0 && $this->field('anniversary_billing');
|
||||
if (empty($anniversary)) {
|
||||
$date_parts = getdate($date);
|
||||
$date = mktime(0, 0, 0, $date_parts['mon'], 1, $date_parts['year']);
|
||||
}
|
||||
|
||||
// Make sure we're not trying to assess rent on a closed lease
|
||||
$close_date = $this->field('close_date');
|
||||
$this->pr(17, compact('close_date'));
|
||||
if (!empty($close_date))
|
||||
return $this->prReturn(null);
|
||||
|
||||
// Don't assess rent after customer has moved out
|
||||
$moveout_date = $this->field('moveout_date');
|
||||
$this->pr(17, compact('moveout_date'));
|
||||
if (!empty($moveout_date) && strtotime($moveout_date) < $date)
|
||||
return $this->prReturn(null);
|
||||
|
||||
// Determine when the customer has already been charged through
|
||||
// and, of course, don't charge them if they've already been.
|
||||
$charge_through_date = strtotime($this->rentChargeThrough($id));
|
||||
$this->pr(17, compact('date', 'charge_through_date')
|
||||
+ array('date_str' => date('Y-m-d', $date),
|
||||
'charge_through_date_str' => date('Y-m-d', $charge_through_date)));
|
||||
if ($charge_through_date >= $date)
|
||||
return $this->prReturn(null);
|
||||
|
||||
// OK, it seems we're going to go ahead and charge the customer
|
||||
// on this lease. Calculate the new charge through date, which
|
||||
// is 1 day shy of 1 month from $date. For example, if we're
|
||||
// charging for 8/1/09, charge through will be 8/31/09, and
|
||||
// charging for 8/15/09, charge through will be 9/14/09.
|
||||
$date_parts = getdate($date);
|
||||
$charge_through_date = mktime(0, 0, 0,
|
||||
$date_parts['mon']+1,
|
||||
$date_parts['mday']-1,
|
||||
$date_parts['year']);
|
||||
|
||||
// Build the invoice transaction
|
||||
$invoice = array('Transaction' => array(), 'Entry' => array());
|
||||
//$invoice['Transaction']['stamp'] = date('Y-m-d', $date);
|
||||
$invoice['Entry'][] =
|
||||
array('effective_date' => date('Y-m-d', $date),
|
||||
'through_date' => date('Y-m-d', $charge_through_date),
|
||||
'amount' => $this->field('rent'),
|
||||
'account_id' => $this->StatementEntry->Account->rentAccountId(),
|
||||
);
|
||||
|
||||
// Record the invoice and return the result
|
||||
$this->pr(21, compact('invoice'));
|
||||
$result = $this->StatementEntry->Transaction->addInvoice
|
||||
($invoice, null, $id);
|
||||
return $this->prReturn($result);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -461,9 +461,8 @@ class Transaction extends AppModel {
|
||||
// Automatically figure out the customer if we have the lease
|
||||
if (!empty($transaction['lease_id']) && empty($transaction['customer_id'])) {
|
||||
$L = new Lease();
|
||||
$L->recursive = -1;
|
||||
$lease = $L->read(null, $transaction['lease_id']);
|
||||
$transaction['customer_id'] = $lease['Lease']['customer_id'];
|
||||
$L->id = $transaction['lease_id'];
|
||||
$transaction['customer_id'] = $L->field('customer_id');
|
||||
}
|
||||
|
||||
// Break each entry out of the combined statement/ledger entry
|
||||
|
||||
Reference in New Issue
Block a user