100, 'group' => 'Unit.id', 'order' => array('Unit.sort_order' => 'ASC')); var $sidemenu_links = array(array('name' => 'Units', 'header' => true), array('name' => 'Occupied', 'url' => array('controller' => 'units', 'action' => 'occupied')), array('name' => 'Vacant', 'url' => array('controller' => 'units', 'action' => 'vacant')), array('name' => 'Unavailable', 'url' => array('controller' => 'units', 'action' => 'unavailable')), array('name' => 'All', 'url' => array('controller' => 'units', '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 units */ function index() { $this->all(); } /************************************************************************** ************************************************************************** ************************************************************************** * action: unavailable * - Lists unavailable units */ function unavailable() { $this->paginate = array_merge ($this->paginate, array('link' => array(// Models 'UnitSize' => array('fields' => array('name')), ), 'conditions' => $this->Unit->conditionUnavailable() )); $title = 'Unavailable Units'; $this->set('title', $title); $this->set('heading', $title); $this->set('units', $this->paginate()); $this->render('index'); } /************************************************************************** ************************************************************************** ************************************************************************** * action: vacant * - Lists vacant units */ function vacant() { $this->paginate = array_merge ($this->paginate, array('link' => array(// Models 'UnitSize' => array('fields' => array('name')), ), 'conditions' => $this->Unit->conditionVacant() )); $title = 'Vacant Units'; $this->set('title', $title); $this->set('heading', $title); $this->set('units', $this->paginate()); $this->render('index'); } /************************************************************************** ************************************************************************** ************************************************************************** * action: occupied * - Lists occupied units */ function occupied() { $this->paginate = array_merge ($this->paginate, array('link' => array(// Models 'UnitSize' => array('fields' => array('name')), 'Lease' => array('fields' => array(), // Models 'Contact' => array('fields' => array('display_name'), //'type' => 'LEFT', ), ), ), 'conditions' => $this->Unit->conditionOccupied() )); $title = 'Occupied Units'; $this->set('title', $title); $this->set('heading', $title); $this->set('units', $this->paginate()); $this->render('index'); } /************************************************************************** ************************************************************************** ************************************************************************** * action: all * - Lists all units */ function all() { $this->paginate = array_merge ($this->paginate, array('link' => array(// Models 'UnitSize' => array('fields' => array('name')), ), )); $title = 'All Units'; $this->set('title', $title); $this->set('heading', $title); $this->set('units', $this->paginate()); $this->render('index'); } /************************************************************************** ************************************************************************** ************************************************************************** * action: view * - Displays information about a specific unit */ function view($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid Item.', true)); $this->redirect(array('action'=>'')); } $this->Unit->Behaviors->attach('Containable'); $this->Unit->contain (array(// Models 'UnitSize', 'Lease' => array('Customer'), 'CurrentLease' => array('Customer') ) ); $unit = $this->Unit->read(null, $id); $this->Unit->Behaviors->detach('Containable'); // Get the balance on each lease. foreach ($unit['Lease'] AS &$lease) { $stats = $this->Unit->Lease->stats($lease['id']); $lease['balance'] = $stats['Account']['Ledger']['balance']; } // Figure out the outstanding balance of the current lease. $stats = $this->Unit->stats($id); $outstanding_balance = $stats['CurrentLease']['Account']['Ledger']['balance']; // Figure out the total security deposit for the current lease. $deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']); $outstanding_deposit = $deposits['summary']['balance']; $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 = 'Unit ' . $unit['Unit']['name']; $this->set(compact('unit', 'title', 'outstanding_balance', 'outstanding_deposit')); } }