Files
pmgr/site/controllers/contacts_controller.php
abijah 4ebe1db2cc Cleaned up the controllers and now make use of the Linkable behavior for listing out items.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@53 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 04:36:28 +00:00

206 lines
6.5 KiB
PHP

<?php
class ContactsController extends AppController {
var $helpers = array('Html');
var $paginate = array('limit' => 100,
'group' => 'Contact.id',
'order' => array('Contact.last_name' => 'ASC',
'Contact.first_name' => 'ASC'));
var $sidemenu_links =
array(array('name' => 'Tenants', 'header' => true),
array('name' => 'Current', 'url' => array('controller' => 'contacts', 'action' => 'current')),
array('name' => 'Past', 'url' => array('controller' => 'contacts', 'action' => 'past')),
array('name' => 'All Tenants', 'url' => array('controller' => 'contacts', 'action' => 'tenants')),
array('name' => 'All Contacts', 'url' => array('controller' => 'contacts', '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: past
* - Lists all tenants, past and present
*/
function tenants() {
$this->paginate = array_merge
($this->paginate,
array('link' =>
array(// Models
'Lease' =>
array('fields' => array(),
'type' => 'INNER',
),
),
'conditions' => array('ContactsLease.type !=' => 'ALTERNATE')
));
$title = 'All Tenants';
$this->set('title', $title); $this->set('heading', $title);
$this->set('contacts', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* 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('ContactsLease.type !=' => 'ALTERNATE',
'Lease.close_date IS NULL')
));
$title = 'Current Tenants';
$this->set('title', $title); $this->set('heading', $title);
$this->set('contacts', $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('ContactsLease.type !=' => 'ALTERNATE',
'Lease.close_date IS NOT NULL')
));
$title = 'Past Tenants';
$this->set('title', $title); $this->set('heading', $title);
$this->set('contacts', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all contacts, including non-tenants
*/
function all() {
$title = 'All Contacts';
$this->set('title', $title); $this->set('heading', $title);
$this->set('contacts', $this->paginate());
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Displays information about a specific contact
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$this->Contact->Behaviors->attach('Containable');
$this->Contact->contain
(array(// Models
'ContactPhone',
'ContactEmail',
'ContactAddress',
'Lease' =>
array('order' => 'movein_date',
'conditions' => array('Lease.lease_date IS NOT NULL',
'ContactsLease.type !=' => 'ALTERNATE'),
// Models
'Unit' =>
array('order' => array('sort_order'),
'fields' => array('id', 'name'),
),
'Charge' =>
array('order' => array('charge_date'),
// Models
'ChargeType',
'Receipt',
)
)
)
);
$contact = $this->Contact->read(null, $id);
$outstanding_deposit = 0;
$outstanding_balance = 0;
foreach($contact['Lease'] AS $lease) {
foreach($lease['Charge'] AS $charge) {
$outstanding_balance += $charge['total'];
foreach ($charge['Receipt'] AS $receipt) {
$outstanding_balance -= $receipt['ChargesReceipt']['amount'];
// REVISIT <AP> 20090530:
// Using hardcoded value for security deposit...
// That can't be good!
if ($charge['charge_type_id'] == 1)
$outstanding_deposit += $receipt['ChargesReceipt']['amount'];
}
}
}
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
$title = $contact['Contact']['display_name'];
$this->set(compact('contact', 'title',
'outstanding_balance',
'outstanding_deposit'));
}
}