Primarly a cleanup checkin, although a couple minor bugfixes were included as well.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@82 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-10 05:14:08 +00:00
parent ffd1b64580
commit e0d9edc4a8
15 changed files with 151 additions and 519 deletions

View File

@@ -19,17 +19,12 @@ class Unit extends AppModel {
var $hasOne = array(
'CurrentLease' => array(
'className' => 'Lease',
//'foreignKey' => 'unit_id',
'conditions' => 'CurrentLease.close_date IS NULL',
),
);
var $hasMany = array(
'Lease' => array(
'className' => 'Lease',
'foreignKey' => 'unit_id',
'dependent' => false,
)
'Lease',
);
function statusEnums() {
@@ -74,20 +69,30 @@ class Unit extends AppModel {
if (!$id)
return null;
// Get the basic information necessary
$this->Behaviors->attach('Containable');
$unit = $this->find('first',
array('contain' => array
('Lease' => array('fields' => array('Lease.id')),
'CurrentLease' => array('fields' => array('CurrentLease.id'))),
'conditions' => array(array('Unit.id' => $id))));
('Lease' => array
('fields' => array('Lease.id')),
'CurrentLease' => array
('fields' => array('CurrentLease.id'))),
'conditions' => array
(array('Unit.id' => $id)),
));
$this->Behaviors->detach('Containable');
// Get the stats for the current lease
$stats['CurrentLease'] = $this->Lease->stats($unit['CurrentLease']['id']);
// Sum the stats for all leases together
foreach ($unit['Lease'] AS $lease) {
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
}
// Return the collection
return $stats;
}