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')),
);
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
* - 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->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: data
* -
*/
function data($fields_str) {
/* pr(array('fields' => $fields, */
/* 'explode' => explode(";", $fields_str))); */
$fields = explode(";", $fields_str);
//$fields=array();
/* foreach (explode(";", $fields_str) AS $i => $field) { */
/* pr(array('field' => $field, */
/* 'explode' => explode(".", $field))); */
/* list($tbl, $col) = explode(".", $field); */
/* unset($fields[$i]); */
/* $fields[$tbl][] = $field; */
/* } */
//pr(array('fields' => $fields));
$debug = true;
if (isset($this->passedArgs['debug']))
$debug = $this->passedArgs['debug'];
$this->autoRender = false;
if (!$debug) {
$this->layout = null;
$this->autoLayout = false;
$this->autoRender = false;
Configure::write('debug', '0');
}
$page = 1; // page number
$rows = 20; // rows in the grid - rowNum parameter
$sidx = 'Customer.id'; // sort column - index from colModel
$sord = 'ASC'; // sort order
if (isset($this->params['url']) && is_array($this->params['url']))
extract($this->params['url']);
// calculate the number of rows for the query. We need this for paging the result
$row = $this->Customer->findCount();
$count = $row;
// calculate the total pages for the query
if( $count > 0 ) {
$total_pages = ceil($count/$rows);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
// calculate the starting position of the rows
$start = $rows*$page - $rows;
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
// the actual query for the grid data
$customers = $this->Customer->find
('all',
array('contain' => array
(// Models
/* 'Contact' => */
/* array(// Models */
/* 'ContactPhone', */
/* 'ContactEmail', */
/* 'ContactAddress', */
/* ), */
'Account' =>
array('fields' => array('Account.id')),
'CurrentLease' =>
array('fields' => array(),
'Unit' =>
array('fields' => array('name')),
),
),
//'link' => array('fields' => $fields),
'order' => "$sidx $sord",
'limit' => "$start, $rows",
));
//pr($customers);
if ($debug) {
ob_start();
}
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$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')); } }