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:
abijah
2009-06-10 02:41:23 +00:00
parent 4988d2717f
commit 9f8d4fa9b2
41 changed files with 1441 additions and 916 deletions

View File

@@ -156,74 +156,27 @@ class UnitsController extends AppController {
$this->Unit->contain
(array(// Models
'UnitSize',
//'CurrentLease' =>
'Lease' =>
array(//'order' => 'movein_date',
//'conditions' => array('Lease.lease_date IS NOT NULL',
//),
// Models
//'Contact' => array('alias' => 'PrimaryContact'),
// 'PrimaryContact',
'Customer' => array('fields' => array('id', 'name'),
// Models
'Transaction' =>
array('order' => array('stamp'),
// Models
'LedgerEntry' => array('DebitLedger' => array('Account'),
'CreditLedger' => array('Account'),
),
),
),
/* array(//'order' => array('sort_order'), */
/* 'fields' => array('id', 'display_name'), */
/* ), */
)
'Lease' => array('Customer'),
'CurrentLease' => array('Customer')
)
);
$unit = $this->Unit->read(null, $id);
$this->Unit->Behaviors->detach('Containable');
//$unit = $this->Unit->read(null, $id);
//pr($unit);
pr($unit);
$this->Unit->Lease->Customer->Transaction->LedgerEntry->Behaviors->attach('Containable');
$entries = $this->Unit->Lease->Customer->Transaction->LedgerEntry->find
('all',
array
(
'contain' =>
array('Transaction' =>
array('Customer' =>
array('Lease' =>
array('Unit' =>
array('conditions' => array('Unit.id' => $id)),
),
),
),
),
//'conditions' => 'xyz',
'limit' => 2,
));
pr($entries);
$this->autoRender = false;
$outstanding_deposit = 0;
$outstanding_balance = 0;
foreach($unit['Lease'] AS $lease) {
foreach($lease['Customer']['Transaction'] AS $transaction) {
foreach($transaction['LedgerEntry'] AS $entry) {
if ($entry['DebitLedger']['Account']['name'] === 'A/R')
$outstanding_balance += $entry['amount'];
if ($entry['CreditLedger']['Account']['name'] === 'A/R')
$outstanding_balance -= $entry['amount'];
if ($entry['DebitLedger']['Account']['name'] === 'Security Deposit')
$outstanding_deposit -= $entry['amount'];
if ($entry['CreditLedger']['Account']['name'] === 'Security Deposit')
$outstanding_deposit += $entry['amount'];
}
}
foreach ($unit['Lease'] AS &$lease) {
$stats = $this->Unit->Lease->stats($lease['id']);
$lease['balance'] = $stats['Account']['Ledger']['balance'];
}
$stats = $this->Unit->stats($id);
$deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']);
//pr($stats);
$outstanding_balance = $stats['CurrentLease']['Account']['Ledger']['balance'];
$outstanding_deposit = $deposits['summary']['balance'];
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =