Files
pmgr/models/lease.php
abijah 65acd0e181 Added routines to reconcile a new ledger entry against unreconciled entries. I haven't tested it robustly, but it seems to work on the surface at least.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@161 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-17 18:40:39 +00:00

157 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',
'Account',
'Customer',
'LateSchedule',
);
/**************************************************************************
**************************************************************************
**************************************************************************
* function: accountId
* - Returns the accountId of the given lease
*/
function accountId($id) {
$this->cacheQueries = true;
$lease = $this->find('first', array
('recursive' => -1,
'fields' => array('account_id'),
'conditions' => array(array('id' => $id)),
));
$this->cacheQueries = false;
return $lease['Lease']['account_id'];
}
/**************************************************************************
**************************************************************************
**************************************************************************
* 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'), */
/* )); */
$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, null, $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);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* 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, $fund, $amount) {
return $this->Account->reconcileNewLedgerEntry
($this->accountId($id), $fund, $amount);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: stats
* - Returns summary data from the requested lease.
*/
function stats($id = null) {
if (!$id)
return null;
// Find the associated account.
$lease = $this->find('first',
array('recursive' => -1,
'conditions' => array(array('Lease.id' => $id))));
// Pull the stats from the account.
$stats['Account'] = $this->Account->stats($lease['Lease']['account_id']);
return $stats;
}
}
?>