Files
pmgr/site/controllers/customers_controller.php
abijah 55b896a9f0 Primarly a cleanup checkin, although a couple minor bugfixes were included as well.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@82 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-10 05:14:08 +00:00

171 lines
6.0 KiB
PHP

<?php
class CustomersController extends AppController {
var $paginate = array('limit' => 100,
'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')),
);
/**************************************************************************
**************************************************************************
**************************************************************************
* override: sideMenuLinks
* - Generates controller specific links for the side menu
*/
function sideMenuLinks() {
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index
* - Lists all current tenants
*/
function index() {
$this->current();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: current
* - Lists all current tenants
*/
function current() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
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);
$this->set('customers', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: past
* - Lists all past tenants
*/
function past() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
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);
$this->set('customers', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all customers, including non-tenants
*/
function all() {
$title = 'All Customers';
$this->set('title', $title); $this->set('heading', $title);
$this->set('customers', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Displays information about a specific customer
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$this->Customer->Behaviors->attach('Containable');
$this->Customer->contain
(array(// Models
'Contact' =>
array(// Models
'ContactPhone',
'ContactEmail',
'ContactAddress',
),
'Account',
'Lease' =>
array('Unit' =>
array('order' => array('sort_order'),
'fields' => array('id', 'name'),
),
),
)
);
$customer = $this->Customer->read(null, $id);
$this->Customer->Behaviors->detach('Containable');
// Add the lease balance to each lease.
foreach ($customer['Lease'] AS &$lease) {
$stats = $this->Customer->Lease->stats($lease['id']);
$lease['balance'] = $stats['Account']['Ledger']['balance'];
}
// Figure out the outstanding balance of the current lease.
$stats = $this->Customer->stats($id);
$outstanding_balance = $stats['balance'];
// Figure out the total security deposit for the current lease.
$deposits = $this->Customer->findSecurityDeposits($id);
$outstanding_deposit = $deposits['summary']['balance'];
// Add statistics into the customer account.
$customer['Account'] = array_merge($customer['Account'],
$stats['Account']['Ledger']);
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
// Prepare to render.
$title = $customer['Customer']['name'];
$this->set(compact('customer', 'title',
'outstanding_balance',
'outstanding_deposit'));
}
}