Made the app controller include the action by default. Added virtual callouts for data order and limit. Changed fields to use formatting, including a custom format for currency and id. Added a function for auto conversion from PHP variables to javascript. Fixed some minor bugs in the controllers already converted to jqGrid. Moved leases onto jqGrid.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@118 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-14 19:50:09 +00:00
parent 67d640b1a0
commit 92d8387e8c
10 changed files with 260 additions and 254 deletions

View File

@@ -30,9 +30,9 @@ class CustomersController extends AppController {
*/
function index() { $this->current(); }
function current() { $this->jqGridView('current', 'Current Tenants'); }
function past() { $this->jqGridView('past', 'Past Tenants'); }
function all() { $this->jqGridView('all', 'All Tenants'); }
function current() { $this->jqGridView('Current Tenants'); }
function past() { $this->jqGridView('Past Tenants'); }
function all() { $this->jqGridView('All Tenants', 'all'); }
/**************************************************************************

View File

@@ -1,10 +1,6 @@
<?php
class LeasesController extends AppController {
var $paginate = array
('limit' => 100,
'group' => 'Lease.id',
'order' => array('Lease.movein_date' => 'DESC'));
var $sidemenu_links =
array(array('name' => 'Leases', 'header' => true),
@@ -28,24 +24,52 @@ class LeasesController extends AppController {
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index
* - Lists current leases
* action: index / active / closed / all
* - Generate a listing of leases
*/
function index() {
$this->active();
}
function index() { $this->all(); }
function active() { $this->jqGridView('Active Leases'); }
function closed() { $this->jqGridView('Closed Leases'); }
function all() { $this->jqGridView('All Leases'); }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: active
* - Lists all active leases
* virtuals: jqGridData
* - With the application controller handling the jqGridData action,
* these virutal functions ensure that the correct data is passed
* to jqGrid.
*/
function active() {
$leases = $this->paginate(array('Lease.close_date IS NULL'));
function jqGridDataSetup(&$params) {
parent::jqGridDataSetup($params);
if (!isset($params['action']))
$params['action'] = 'all';
}
function jqGridDataTables(&$params) {
return array
('link' => array('Unit' => array('fields' => array('Unit.name')),
'Customer' => array('fields' => array('Customer.name'))));
}
function jqGridDataConditions(&$params) {
$conditions = parent::jqGridDataConditions($params);
if ($params['action'] === 'active') {
$conditions[] = 'Lease.close_date IS NULL';
}
elseif ($params['action'] === 'closed') {
$conditions[] = 'Lease.close_date IS NOT NULL';
}
return $conditions;
}
function jqGridDataRecords(&$params, $model, $query) {
$leases = parent::jqGridDataRecords($params, $model, $query);
// Get the balance on each lease.
foreach ($leases AS &$lease) {
@@ -53,56 +77,7 @@ class LeasesController extends AppController {
$lease['Lease']['balance'] = $stats['Account']['Ledger']['balance'];
}
$title = 'Active Leases';
$this->set('title', $title); $this->set('heading', $title);
$this->set('leases', $leases);
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: closed
* - Lists all closed (inactive) leases
*/
function closed() {
$leases = $this->paginate(array('Lease.close_date IS NOT NULL'));
// Get the balance on each lease.
foreach ($leases AS &$lease) {
$stats = $this->Lease->stats($lease['Lease']['id']);
$lease['Lease']['balance'] = $stats['Account']['Ledger']['balance'];
}
$title = 'Past Leases';
$this->set('title', $title); $this->set('heading', $title);
$this->set('leases', $leases);
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all leases
*/
function all() {
$leases = $this->paginate();
// Get the balance on each lease.
foreach ($leases AS &$lease) {
$stats = $this->Lease->stats($lease['Lease']['id']);
$lease['Lease']['balance'] = $stats['Account']['Ledger']['balance'];
}
$title = 'All Leases';
$this->set('title', $title); $this->set('heading', $title);
$this->set('leases', $leases);
$this->render('index');
return $leases;
}

View File

@@ -1,9 +1,6 @@
<?php
class UnitsController extends AppController {
var $paginate = array('limit' => 100,
'group' => 'Unit.id',
'order' => array('Unit.sort_order' => 'ASC'));
var $sidemenu_links =
array(array('name' => 'Units', 'header' => true),
@@ -28,15 +25,15 @@ class UnitsController extends AppController {
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index / current / past / all
* - Creates a list of tenants
* action: index / unavailable / vacant / occupied / all
* - Generate a listing of units
*/
function index() { $this->all(); }
function unavailable() { $this->jqGridView('unavailable', 'Unavailable Units'); }
function vacant() { $this->jqGridView('vacant', 'Vacant Units'); }
function occupied() { $this->jqGridView('occupied', 'Occupied Units'); }
function all() { $this->jqGridView('all', 'All Units'); }
function unavailable() { $this->jqGridView('Unavailable Units'); }
function vacant() { $this->jqGridView('Vacant Units'); }
function occupied() { $this->jqGridView('Occupied Units'); }
function all() { $this->jqGridView('All Units', 'all'); }
/**************************************************************************
@@ -89,40 +86,13 @@ class UnitsController extends AppController {
return $conditions;
}
function zzjqGridDataRecordCount(&$params, $model, $query) {
// We don't have a good way to use the query to obtain
// our count. The problem is that we're relying on the
// group by for the query, which will destroy the count,
// whether we omit the group by or leave it in.
// So, build a fresh query for counting.
$query['conditions'] = parent::jqGridDataConditions($params);
$count = $model->find('count',
array_merge(array('link' => array_diff_key($query['link'],
array('CurrentLease'=>1))),
array_diff_key($query, array('link'=>1))));
if ($params['action'] === 'all')
return $count;
$query['conditions'][] = 'CurrentLease.id IS NULL';
$count_past = $model->find('count', $query);
// Since we can't easily count 'current' directly, we
// can quickly derive it since 'current' customers
// are mutually exclusive to 'past' customers.
if ($params['action'] == 'current')
$count = $count - $count_past;
elseif ($params['action'] == 'past') {
$count = $count_past;
function jqGridDataOrder(&$params, $index, $direction) {
if ($index === 'Unit.name') {
$index = 'Unit.sort_order';
}
return $count;
return parent::jqGridDataOrder($params, $index, $direction);
}
/**************************************************************************
**************************************************************************
**************************************************************************