git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@81 97e9348a-65ac-dc4b-aefc-98561f571b83
177 lines
6.3 KiB
PHP
177 lines
6.3 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_planed_date' => array('date'),
|
|
'movein_date' => array('date'),
|
|
'moveout_date' => array('date'),
|
|
'moveout_planed_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: 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'), */
|
|
/* )); */
|
|
|
|
$lease = $this->find('first', array
|
|
('recursive' => -1,
|
|
'fields' => array('account_id'),
|
|
'conditions' => array(array('id' => $id)),
|
|
));
|
|
|
|
$entries = $this->Account->findLedgerEntries($lease['Lease']['account_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'), */
|
|
/* )); */
|
|
|
|
$lease = $this->find('first', array
|
|
('recursive' => -1,
|
|
'fields' => array('account_id'),
|
|
'conditions' => array(array('id' => $id)),
|
|
));
|
|
|
|
/* $sd_account_id = $this->Account->securityDepositAccountID(); */
|
|
/* $sd_ledger_ids = $this->Account->ledgers($sd_account_id); */
|
|
/* $cond = conditionEntryAsCreditOrDebit($sd_ledger_ids); */
|
|
|
|
$entries = $this->Account->findLedgerEntriesRelatedToAccount
|
|
($lease['Lease']['account_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: findSecurityDeposits
|
|
* - Returns an array of security deposit entries
|
|
*/
|
|
function findAccountDeposits($id, $link = null) {
|
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
|
'checkpoint' => 'begin'),
|
|
compact('id', 'link')));
|
|
$lease = $this->find('first', array
|
|
('recursive' => -1,
|
|
'fields' => array('account_id'),
|
|
'conditions' => array(array('id' => $id)),
|
|
));
|
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
|
'checkpoint' => 'get-lease'),
|
|
compact('lease')));
|
|
|
|
$deposits = $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
|
'checkpoint' => 'return'),
|
|
compact('deposits')));
|
|
return $deposits;
|
|
//return $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: findSecurityDeposits
|
|
* - Returns an array of security deposit entries
|
|
*/
|
|
function qqfindSecurityDeposits($id, $link = null) {
|
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
|
'checkpoint' => 'begin'),
|
|
compact('id', 'link')));
|
|
$lease = $this->find('first', array
|
|
('recursive' => -1,
|
|
'fields' => array('account_id'),
|
|
'conditions' => array(array('id' => $id)),
|
|
));
|
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
|
'checkpoint' => 'get-lease'),
|
|
compact('lease')));
|
|
|
|
return $this->Account->findAccountRelatedEntries($id, $relaccount, $link);
|
|
$deposits = $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
|
'checkpoint' => 'return'),
|
|
compact('deposits')));
|
|
return $deposits;
|
|
//return $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* 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;
|
|
}
|
|
|
|
}
|
|
?>
|