git-svn-id: file:///svn-source/pmgr/branches/single_AR_20090622@181 97e9348a-65ac-dc4b-aefc-98561f571b83
158 lines
5.4 KiB
PHP
158 lines
5.4 KiB
PHP
<?php
|
|
class Lease extends AppModel {
|
|
|
|
var $name = 'Lease';
|
|
var $validate = array(
|
|
'id' => array('numeric'),
|
|
'number' => array('alphanumeric'),
|
|
'lease_type_id' => array('numeric'),
|
|
'unit_id' => array('numeric'),
|
|
'late_schedule_id' => array('numeric'),
|
|
'lease_date' => array('date'),
|
|
'movein_planned_date' => array('date'),
|
|
'movein_date' => array('date'),
|
|
'moveout_date' => array('date'),
|
|
'moveout_planned_date' => array('date'),
|
|
'notice_given_date' => array('date'),
|
|
'notice_received_date' => array('date'),
|
|
'close_date' => array('date'),
|
|
'deposit' => array('money'),
|
|
'amount' => array('money'),
|
|
'next_amount' => array('money'),
|
|
'next_amount_date' => array('date')
|
|
);
|
|
|
|
var $belongsTo = array(
|
|
'LeaseType',
|
|
'Unit',
|
|
'Customer',
|
|
'LateSchedule',
|
|
);
|
|
|
|
var $hasMany = array(
|
|
'LedgerEntry',
|
|
|
|
// Cheat to get Account set as part of this class
|
|
'Account',
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: accountId
|
|
* - Returns the accountId of the given lease
|
|
*/
|
|
function accountId($id) {
|
|
return $this->Account->invoiceAccountID();
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: findAccountEntries
|
|
* - Returns an array of ledger entries from the account of the given
|
|
* lease.
|
|
*/
|
|
function findAccountEntries($id, $all = false, $cond = null, $link = null) {
|
|
/* pr(array('function' => 'Lease::findAccountEntries', */
|
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
|
/* )); */
|
|
|
|
if (!isset($cond))
|
|
$cond = array();
|
|
$cond[] = array('LedgerEntry.lease_id' => $id);
|
|
|
|
$entries = $this->Account->findLedgerEntries($this->accountId($id),
|
|
$all, $cond, $link);
|
|
|
|
/* pr(array('function' => 'Lease::findAccountEntries', */
|
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
|
/* 'vars' => compact('lease'), */
|
|
/* 'return' => compact('entries'), */
|
|
/* )); */
|
|
return $entries;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: findSecurityDeposits
|
|
* - Returns an array of security deposit entries
|
|
*/
|
|
function findSecurityDeposits($id, $link = null) {
|
|
/* pr(array('function' => 'Lease::findSecurityDeposits', */
|
|
/* 'args' => compact('id', 'link'), */
|
|
/* )); */
|
|
|
|
$entries = $this->Account->findLedgerEntriesRelatedToAccount
|
|
($this->accountId($id),
|
|
$this->Account->securityDepositAccountID(),
|
|
true, array('LedgerEntry.lease_id' => $id), $link);
|
|
|
|
/* pr(array('function' => 'Lease::findSecurityDeposits', */
|
|
/* 'args' => compact('id', 'link'), */
|
|
/* 'vars' => compact('lease'), */
|
|
/* 'return' => compact('entries'), */
|
|
/* )); */
|
|
return $entries;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: findUnreconciledLedgerEntries
|
|
* - Returns ledger entries that are not yet reconciled
|
|
* (such as charges not paid).
|
|
*/
|
|
|
|
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
|
|
return $this->Account->findUnreconciledLedgerEntries
|
|
($this->accountId($id), $fundamental_type, array('LedgerEntry.lease_id' => $id));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: reconcileNewLedgerEntry
|
|
* - Returns which ledger entries a new credit/debit would
|
|
* reconcile, and how much.
|
|
*
|
|
* - REVISIT <AP> 20090617
|
|
* This should be subject to different algorithms, such
|
|
* as apply to oldest charges first, newest first, to fees
|
|
* before rent, etc. Until we get there, I'll hardcode
|
|
* whatever algorithm is simplest.
|
|
*/
|
|
|
|
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
|
|
return $this->Account->reconcileNewLedgerEntry
|
|
($this->accountId($id), $fundamental_type, $amount, array('LedgerEntry.lease_id' => $id));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: stats
|
|
* - Returns summary data from the requested lease.
|
|
*/
|
|
|
|
function stats($id = null) {
|
|
if (!$id)
|
|
return null;
|
|
|
|
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
|
|
array('LedgerEntry.lease_id' => $id));
|
|
|
|
// Pull to the top level and return
|
|
$stats = $stats['Ledger'];
|
|
return $stats;
|
|
}
|
|
|
|
}
|
|
?>
|