'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')), ); //var $components = array('RequestHandler'); /************************************************************************** ************************************************************************** ************************************************************************** * override: sideMenuLinks * - Generates controller specific links for the side menu */ function sideMenuLinks() { return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); } /************************************************************************** ************************************************************************** ************************************************************************** * action: index / current / past / all * - Creates a list of tenants */ function jqGridSetup($action, $title) { $this->set('title', $title); $this->set('heading', $title); // The resulting page will contain a jqGrid, which will // use ajax to obtain the actual data for this action $this->set('action', $action); $this->render('index'); } function index() { $this->current(); } function current() { $this->jqGridSetup('current', 'Current Tenants'); } function past() { $this->jqGridSetup('past', 'Past Tenants'); } function all() { $this->jqGridSetup('all', 'All Tenants'); } /************************************************************************** ************************************************************************** ************************************************************************** * action: jqGridData * - Fetches the actual data requested by jqGrid as XML */ function jqGridData() { // Assume we're debugging. // The actual jqGrid request will set this to false $debug = true; if (isset($this->passedArgs['debug'])) $debug = $this->passedArgs['debug']; if (!$debug) { $this->layout = null; $this->autoLayout = false; $this->autoRender = false; Configure::write('debug', '0'); } // Set up some defaults $page = 1; // page number $rows = 20; // rows in the grid - rowNum parameter $sidx = 'Customer.id'; // sort column - index from colModel $sord = 'ASC'; // sort order $action = 'current'; // specific customer list // Extract the actual settings from the jqGrid request if (isset($this->params['url']) && is_array($this->params['url'])) extract($this->params['url']); // Unserialize our complex structure if (isset($fields)) $fields = unserialize($fields); else $fields = array('Customer.id', 'Customer.name'); // Set up the basic 'contain' field to query the // pertinent information. $contain = array(// Models 'PrimaryContact', /* array(// Models */ /* 'ContactPhone', */ /* 'ContactEmail', */ /* 'ContactAddress', */ /* ), */ /* 'Account' => */ /* array('fields' => array('Account.id')), */ 'CurrentLease' => array('fields' => array(), 'Unit' => array('fields' => array('name')), ), ); // Calculate the number of rows for the query, and figure out // any special query conditions that will be necessary $count = $this->Customer->find('count'); if ($action != 'all') { $count_past = $this->Customer->find('count', array('link' => array('CurrentLease'), 'conditions' => 'CurrentLease.id IS NULL')); if ($action == 'current') { $count = $count - $count_past; $contain['CurrentLease']['conditions'] = 'CurrentLease.id IS NOT NULL'; } elseif ($action == 'past') { $count = $count_past; $contain['CurrentLease']['conditions'] = 'CurrentLease.id IS NULL'; } } // Verify a few parameters and determine our starting row $total_pages = ($count < 0) ? 0 : ceil($count/$rows); $page = ($page < 1) ? 1 : (($page > $total_pages) ? $total_pages : $page); $start = $rows*$page - $rows; // the actual query for the grid data $customers = $this->Customer->find ('all', array('contain' => $contain, 'order' => "$sidx $sord", 'limit' => "$start, $rows", )); /* $query['order'] = "$sidx $sord"; */ /* $query['limit'] = "$start, $rows"; */ /* $query['group'] = 'Customer.id', */ /* $query = array('link' => */ /* array(// Models */ /* 'PrimaryContact', */ /* 'CurrentLease' => */ /* array('fields' => array(), */ /* 'Unit' => */ /* array('fields' => array('name')), */ /* ), */ /* ), */ /* ); */ if ($debug) { ob_start(); print_r(compact('count', 'rows', 'total_pages', 'page', 'start', 'customers')); } else { if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) { header("Content-type: application/xhtml+xml;charset=utf-8"); } else { header("Content-type: text/xml;charset=utf-8"); } echo "\n"; } echo "\n"; /* echo " \n"; */ /* echo " \n"; */ /* echo " \n"; */ /* echo " \n"; */ /* echo " \n"; */ /* echo " params, true) . "]]>\n"; */ /* echo " passedArgs, true) . "]]>\n"; */ /* echo " \n"; */ /* echo " \n"; */ /* echo " \n"; */ echo " ".$page."\n"; echo " ".$total_pages."\n"; echo " ".$count."\n"; // be sure to put text data in CDATA foreach ($customers AS $customer) { $customer['Customer']['units'] = implode("; ", array_map(create_function ('$lease', 'return $lease["Unit"]["name"];'), $customer['CurrentLease'])); echo " \n"; foreach ($fields AS $field) { list($tbl, $col) = explode(".", $field); echo " \n"; } echo " \n"; } echo "\n"; if ($debug) { $xml = ob_get_contents(); ob_end_clean(); $xml = preg_replace("/&/", "&", $xml); $xml = preg_replace("//", ">", $xml); echo ("\n
\n$xml\n
\n"); } } /************************************************************************** ************************************************************************** ************************************************************************** * 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')); } $customer = $this->Customer->details($id); $outstanding_balance = $customer['stats']['balance']; $outstanding_deposit = $customer['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 = $customer['Customer']['name']; $this->set(compact('customer', 'title', 'outstanding_balance', 'outstanding_deposit')); } /************************************************************************** ************************************************************************** ************************************************************************** * action: payment * - Sets up the payment entry page for the given customer. */ function payment($id = null) { /* if (!$id) { */ /* $this->Session->setFlash(__('Invalid Item.', true)); */ /* $this->redirect(array('action'=>'index')); */ /* } */ if ($this->RequestHandler->isPost()) { pr($this->data); //$this->redirect(array('action'=>'index')); $customer = $this->data; } elseif (isset($id)) { $customer = $this->Customer->details($id); unset($customer['deposits']['Entries']); } else { $customer = null; } $title = 'Payment Entry'; $this->set(compact('customer', 'title')); } }