Significant changes to work with the new account/ledger structure. Removed much of the auto-generated model association code. Added helper functions into the models to perform model related work, such as model 'stats' (a bad name for a function to return a summary of pertinent financial information from a given model instance). There is a ton of cleanup to do, but first I want to get it all captured.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@81 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
177
models/lease.php
177
models/lease.php
@@ -23,36 +23,155 @@ class Lease extends AppModel {
|
||||
);
|
||||
|
||||
var $belongsTo = array(
|
||||
'LeaseType' => array(
|
||||
'className' => 'LeaseType',
|
||||
'foreignKey' => 'lease_type_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
),
|
||||
'Unit' => array(
|
||||
'className' => 'Unit',
|
||||
'foreignKey' => 'unit_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
),
|
||||
'LateSchedule' => array(
|
||||
'className' => 'LateSchedule',
|
||||
'foreignKey' => 'late_schedule_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
),
|
||||
'Customer' => array(
|
||||
'className' => 'Customer',
|
||||
'foreignKey' => 'customer_id',
|
||||
'dependent' => false,
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
),
|
||||
'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;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user