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:
@@ -2,15 +2,15 @@
|
||||
|
||||
class CustomersController extends AppController {
|
||||
var $paginate = array('limit' => 100,
|
||||
'group' => 'Customer.id',
|
||||
'order' => array('Customer.name' => 'ASC'));
|
||||
'group' => 'Customer.id',
|
||||
'order' => array('Customer.name' => 'ASC'));
|
||||
|
||||
var $sidemenu_links =
|
||||
array(array('name' => 'Tenants', 'header' => true),
|
||||
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
||||
array('name' => 'Past', 'url' => array('controller' => 'customers', 'action' => 'past')),
|
||||
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
||||
);
|
||||
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
||||
array('name' => 'Past', 'url' => array('controller' => 'customers', 'action' => 'past')),
|
||||
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
||||
);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -46,14 +46,14 @@ class CustomersController extends AppController {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'Lease' =>
|
||||
array('fields' => array(),
|
||||
'type' => 'INNER',
|
||||
),
|
||||
),
|
||||
'conditions' => array('Lease.close_date IS NULL')
|
||||
));
|
||||
array(// Models
|
||||
'Lease' =>
|
||||
array('fields' => array(),
|
||||
'type' => 'INNER',
|
||||
),
|
||||
),
|
||||
'conditions' => array('Lease.close_date IS NULL')
|
||||
));
|
||||
|
||||
$title = 'Current Tenants';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
@@ -73,14 +73,14 @@ class CustomersController extends AppController {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'Lease' =>
|
||||
array('fields' => array(),
|
||||
'type' => 'INNER',
|
||||
),
|
||||
),
|
||||
'conditions' => array('Lease.close_date IS NOT NULL')
|
||||
));
|
||||
array(// Models
|
||||
'Lease' =>
|
||||
array('fields' => array(),
|
||||
'type' => 'INNER',
|
||||
),
|
||||
),
|
||||
'conditions' => array('Lease.close_date IS NOT NULL')
|
||||
));
|
||||
|
||||
$title = 'Past Tenants';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
@@ -120,58 +120,61 @@ class CustomersController extends AppController {
|
||||
$this->Customer->Behaviors->attach('Containable');
|
||||
$this->Customer->contain
|
||||
(array(// Models
|
||||
'Contact' =>
|
||||
array(// Models
|
||||
'ContactPhone',
|
||||
'ContactEmail',
|
||||
'ContactAddress',
|
||||
),
|
||||
'Transaction' =>
|
||||
array('order' => array('stamp'),
|
||||
// Models
|
||||
'Entry' =>
|
||||
array(// Models
|
||||
'DebitAccount',
|
||||
'CreditAccount'),
|
||||
),
|
||||
'Lease' =>
|
||||
array('order' => 'movein_date',
|
||||
'conditions' => array('Lease.lease_date IS NOT NULL'),
|
||||
// Models
|
||||
'Contact' =>
|
||||
array(// Models
|
||||
'ContactPhone',
|
||||
'ContactEmail',
|
||||
'ContactAddress',
|
||||
),
|
||||
'Account',
|
||||
'Lease' =>
|
||||
array(//'order' => 'movein_date',
|
||||
//'conditions' => array('Lease.lease_date IS NOT NULL'),
|
||||
// Models
|
||||
//'Account',
|
||||
'Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
)
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$customer = $this->Customer->read(null, $id);
|
||||
$this->Customer->Behaviors->detach('Containable');
|
||||
|
||||
foreach ($customer['Lease'] AS &$lease) {
|
||||
$stats = $this->Customer->Lease->stats($lease['id']);
|
||||
//pr($stats);
|
||||
$lease['balance'] = $stats['Account']['Ledger']['balance'];
|
||||
}
|
||||
|
||||
//pr($customer);
|
||||
|
||||
$outstanding_deposit = 0;
|
||||
$outstanding_balance = 0;
|
||||
foreach($customer['Transaction'] AS $transaction) {
|
||||
foreach($transaction['Entry'] AS $entry) {
|
||||
if ($entry['DebitAccount']['name'] === 'A/R')
|
||||
$outstanding_balance += $entry['amount'];
|
||||
if ($entry['CreditAccount']['name'] === 'A/R')
|
||||
$outstanding_balance -= $entry['amount'];
|
||||
$stats = $this->Customer->stats($id);
|
||||
$deposits = $this->Customer->findSecurityDeposits($id);
|
||||
|
||||
if ($entry['DebitAccount']['name'] === 'Security Deposit')
|
||||
$outstanding_deposit -= $entry['amount'];
|
||||
if ($entry['CreditAccount']['name'] === 'Security Deposit')
|
||||
$outstanding_deposit += $entry['amount'];
|
||||
}
|
||||
}
|
||||
$outstanding_balance = $stats['balance'];
|
||||
$outstanding_deposit = $deposits['summary']['balance'];
|
||||
|
||||
/* pr(array('Customer Stats', $stats)); */
|
||||
/* pr(array('Security Deposits', $deposits)); */
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Operations', 'header' => true);
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
||||
|
||||
|
||||
$customer['Account'] = array_merge($customer['Account'], $stats['Account']['Ledger']);
|
||||
//pr($stats);
|
||||
//unset($stats['Lease'], $stats['Account']);
|
||||
/* $customer['Account']['debits'] = 10; */
|
||||
/* $customer['Account']['credits'] = 20; */
|
||||
/* $customer['Account']['balance'] = 55; */
|
||||
|
||||
$title = $customer['Customer']['name'];
|
||||
$this->set(compact('customer', 'title',
|
||||
'outstanding_balance',
|
||||
'outstanding_deposit'));
|
||||
'outstanding_balance',
|
||||
'outstanding_deposit'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user