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@81 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -13,27 +13,15 @@ class Unit extends AppModel {
|
||||
);
|
||||
|
||||
var $belongsTo = array(
|
||||
'UnitSize' => array(
|
||||
'className' => 'UnitSize',
|
||||
'foreignKey' => 'unit_size_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
),
|
||||
'UnitSize',
|
||||
);
|
||||
|
||||
var $hasOne = array(
|
||||
'CurrentLease' => array(
|
||||
'className' => 'Lease',
|
||||
'foreignKey' => 'current_lease_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
//'foreignKey' => 'unit_id',
|
||||
'conditions' => 'CurrentLease.close_date IS NULL',
|
||||
),
|
||||
/* 'Map' => array( */
|
||||
/* 'className' => 'MapsUnit', */
|
||||
/* 'foreignKey' => 'unit_id', */
|
||||
/* 'conditions' => '', */
|
||||
/* 'fields' => '', */
|
||||
/* 'order' => '' */
|
||||
/* ) */
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
@@ -41,14 +29,6 @@ class Unit extends AppModel {
|
||||
'className' => 'Lease',
|
||||
'foreignKey' => 'unit_id',
|
||||
'dependent' => false,
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'offset' => '',
|
||||
'exclusive' => '',
|
||||
'finderQuery' => '',
|
||||
'counterQuery' => ''
|
||||
)
|
||||
);
|
||||
|
||||
@@ -83,4 +63,32 @@ class Unit extends AppModel {
|
||||
return ('Unit.status <= ' . $this->statusValue('UNAVAILABLE'));
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: stats
|
||||
* - Returns summary data from the requested customer.
|
||||
*/
|
||||
|
||||
function stats($id = null) {
|
||||
if (!$id)
|
||||
return null;
|
||||
|
||||
$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))));
|
||||
$this->Behaviors->detach('Containable');
|
||||
|
||||
$stats['CurrentLease'] = $this->Lease->stats($unit['CurrentLease']['id']);
|
||||
|
||||
foreach ($unit['Lease'] AS $lease) {
|
||||
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user