Another attempt to get the customer table working. Cake's query mechanism is really torquing me, it never seems to be able to do what I need (perhaps because they've generalized it to work with so many SQL engines. I'm just going to pull unit information out all together, and I can add it back in another day if needed.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@106 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -25,122 +25,39 @@ class CustomersController extends AppController {
|
|||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* action: index
|
* action: index / current / past / all
|
||||||
* - Lists all current tenants
|
* - Creates a list of tenants
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function index() {
|
function jqGridSetup($action, $title) {
|
||||||
$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('title', $title); $this->set('heading', $title);
|
||||||
$this->set('customers', $this->paginate());
|
// 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');
|
$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: 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
|
* action: jqGridData
|
||||||
* - Lists all customers, including non-tenants
|
* - Fetches the actual data requested by jqGrid as XML
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function all() {
|
function jqGridData() {
|
||||||
$title = 'All Customers';
|
// Assume we're debugging.
|
||||||
$this->set('title', $title); $this->set('heading', $title);
|
// The actual jqGrid request will set this to false
|
||||||
$this->set('params', $this->params);
|
|
||||||
$this->render('index');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: data
|
|
||||||
* -
|
|
||||||
*/
|
|
||||||
|
|
||||||
function jqGridData($debug = true) {
|
|
||||||
/* pr(array('fields' => $fields, */
|
|
||||||
/* 'explode' => explode(";", $fields_str))); */
|
|
||||||
|
|
||||||
/* $debug=true; */
|
|
||||||
|
|
||||||
/* $tf = unserialize($fields); */
|
|
||||||
/* $tp = unserialize($params); */
|
|
||||||
|
|
||||||
/* $fields = array('Customer.id'); */
|
|
||||||
|
|
||||||
//$action_params = unserialize($action_params);
|
|
||||||
//$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;
|
$debug = true;
|
||||||
|
|
||||||
if (isset($this->passedArgs['debug']))
|
if (isset($this->passedArgs['debug']))
|
||||||
$debug = $this->passedArgs['debug'];
|
$debug = $this->passedArgs['debug'];
|
||||||
|
|
||||||
$this->autoRender = false;
|
|
||||||
if (!$debug) {
|
if (!$debug) {
|
||||||
$this->layout = null;
|
$this->layout = null;
|
||||||
$this->autoLayout = false;
|
$this->autoLayout = false;
|
||||||
@@ -148,88 +65,91 @@ class CustomersController extends AppController {
|
|||||||
Configure::write('debug', '0');
|
Configure::write('debug', '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = 1; // page number
|
// Set up some defaults
|
||||||
$rows = 20; // rows in the grid - rowNum parameter
|
$page = 1; // page number
|
||||||
$sidx = 'Customer.id'; // sort column - index from colModel
|
$rows = 20; // rows in the grid - rowNum parameter
|
||||||
$sord = 'ASC'; // sort order
|
$sidx = 'Customer.id'; // sort column - index from colModel
|
||||||
|
$sord = 'ASC'; // sort order
|
||||||
|
$action = 'current'; // specific customer list
|
||||||
|
|
||||||
$fields = array('Customer.id');
|
// Extract the actual settings from the jqGrid request
|
||||||
|
|
||||||
if (isset($this->params['url']) && is_array($this->params['url']))
|
if (isset($this->params['url']) && is_array($this->params['url']))
|
||||||
extract($this->params['url']);
|
extract($this->params['url']);
|
||||||
|
|
||||||
|
// Unserialize our complex structure
|
||||||
if (isset($fields))
|
if (isset($fields))
|
||||||
$fields = unserialize($fields);
|
$fields = unserialize($fields);
|
||||||
else
|
else
|
||||||
$fields = array('Customer.id');
|
$fields = array('Customer.id', 'Customer.name');
|
||||||
|
|
||||||
if (isset($params))
|
// Set up the basic 'contain' field to query the
|
||||||
$params = unserialize($params);
|
// pertinent information.
|
||||||
else
|
$contain =
|
||||||
$params = array('action' => 'all');
|
array(// Models
|
||||||
|
'PrimaryContact',
|
||||||
// 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;
|
|
||||||
|
|
||||||
$cond = array();
|
|
||||||
if ($params['action'] == 'current') {
|
|
||||||
|
|
||||||
} elseif ($params['action'] == 'past') {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// the actual query for the grid data
|
|
||||||
$customers = $this->Customer->find
|
|
||||||
('all',
|
|
||||||
array('contain' => array
|
|
||||||
(// Models
|
|
||||||
'PrimaryContact',
|
|
||||||
/* array(// Models */
|
/* array(// Models */
|
||||||
/* 'ContactPhone', */
|
/* 'ContactPhone', */
|
||||||
/* 'ContactEmail', */
|
/* 'ContactEmail', */
|
||||||
/* 'ContactAddress', */
|
/* 'ContactAddress', */
|
||||||
/* ), */
|
/* ), */
|
||||||
|
|
||||||
'Account' =>
|
/* 'Account' => */
|
||||||
array('fields' => array('Account.id')),
|
/* array('fields' => array('Account.id')), */
|
||||||
|
|
||||||
'CurrentLease' =>
|
'CurrentLease' =>
|
||||||
array('fields' => array(),
|
array('fields' => array(),
|
||||||
'Unit' =>
|
'Unit' =>
|
||||||
array('fields' => array('name')),
|
array('fields' => array('name')),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
//'link' => array('fields' => $fields),
|
|
||||||
'order' => "$sidx $sord",
|
// Calculate the number of rows for the query, and figure out
|
||||||
'limit' => "$start, $rows",
|
// 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",
|
||||||
));
|
));
|
||||||
|
|
||||||
//pr($customers);
|
/* $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) {
|
if ($debug) {
|
||||||
ob_start();
|
ob_start();
|
||||||
|
print_r(compact('count', 'rows', 'total_pages', 'page', 'start', 'customers'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
|
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ jQuery(document).ready(function(){
|
|||||||
url: '<?php echo $url; ?>',
|
url: '<?php echo $url; ?>',
|
||||||
datatype: 'xml',
|
datatype: 'xml',
|
||||||
mtype: 'GET',
|
mtype: 'GET',
|
||||||
postData: { params: '<?php echo serialize($params); ?>',
|
postData: { action: '<?php echo $action; ?>',
|
||||||
fields: '<?php echo serialize($colFields); ?>' },
|
fields: '<?php echo serialize($colFields); ?>' },
|
||||||
colNames: [ '<?php echo implode("', '", array_keys($cols)); ?>' ],
|
colNames: [ '<?php echo implode("', '", array_keys($cols)); ?>' ],
|
||||||
colModel: [ <?php echo "\n " . implode(",\n ", $colModels); ?> ],
|
colModel: [ <?php echo "\n " . implode(",\n ", $colModels); ?> ],
|
||||||
|
|||||||
Reference in New Issue
Block a user