Added a Unit overview action. It's a bit quick and dirty, but it's intended for admins only.
git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@957 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -52,6 +52,15 @@ class AppController extends Controller {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: dev/admin()
|
||||
* - Indicates if the user has dev/admin access
|
||||
*/
|
||||
function dev() { return !empty($this->params['dev']); }
|
||||
function admin() { return !empty($this->params['admin']); }
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -246,7 +255,7 @@ class AppController extends Controller {
|
||||
$this->addSideMenuLink('New Deposit',
|
||||
array('controller' => 'tenders', 'action' => 'deposit'), null,
|
||||
'SITE', $this->op_area);
|
||||
if (!empty($this->params['admin']))
|
||||
if ($this->admin())
|
||||
$this->addSideMenuLink('Assess Charges',
|
||||
array('controller' => 'leases', 'action' => 'assess_all'), null,
|
||||
'SITE', $this->op_area);
|
||||
@@ -308,19 +317,19 @@ class AppController extends Controller {
|
||||
$this->params['admin'] = $this->Option->enabled('admin');
|
||||
$this->params['dev'] = devbox();
|
||||
|
||||
if ($this->params['dev'] && !$this->Option->enabled('dev'))
|
||||
if ($this->dev() && !$this->Option->enabled('dev'))
|
||||
$this->redirect("/");
|
||||
|
||||
if (!$this->params['dev'])
|
||||
if (!$this->dev())
|
||||
Configure::write('debug', '0');
|
||||
|
||||
$this->addDefaultSideMenuLinks();
|
||||
//$this->sideMenuEnable('SITE', $this->op_area, false);
|
||||
|
||||
foreach ($this->sidemenu['areas'] AS $area_name => $area) {
|
||||
if (empty($this->params['dev']))
|
||||
if (!$this->dev())
|
||||
$this->sideMenuEnable($area_name, $this->dev_area, false);
|
||||
if (empty($this->params['admin']))
|
||||
if (!$this->admin())
|
||||
$this->sideMenuEnable($area_name, $this->admin_area, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ class UnitsController extends AppController {
|
||||
$this->addSideMenuLink('All',
|
||||
array('controller' => 'units', 'action' => 'all'), null,
|
||||
'CONTROLLER');
|
||||
if ($this->admin())
|
||||
$this->addSideMenuLink('Overview',
|
||||
array('controller' => 'units', 'action' => 'overview'), null,
|
||||
'CONTROLLER');
|
||||
}
|
||||
|
||||
|
||||
@@ -225,6 +229,68 @@ class UnitsController extends AppController {
|
||||
function unlock($id) { $this->status($id, 'OCCUPIED'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: overview
|
||||
* - Displays overview information for all units
|
||||
*/
|
||||
function overview() {
|
||||
$result = $this->Unit->find
|
||||
('all',
|
||||
array('link' => array('UnitSize' => array('fields' => array(), 'UnitType' => array('fields' => array('name')))),
|
||||
'fields' => array('status', 'COUNT(Unit.id) AS cnt', 'SUM(Unit.rent) AS rents'),
|
||||
//'conditions' => array('
|
||||
'group' => array('UnitType.id', 'Unit.status'),
|
||||
'order' => array('UnitType.name', 'Unit.status')
|
||||
));
|
||||
//pr($result);
|
||||
|
||||
$overview = array('types' => array(), 'count' => 0, 'rents' => 0);
|
||||
foreach ($result AS $row) {
|
||||
$utname = $row['UnitType']['name'];
|
||||
if (empty($overview['types'][$utname]))
|
||||
$overview['types'][$utname] = array('name' => $utname,
|
||||
'subs' => array(),
|
||||
'count' => 0,
|
||||
'rents' => 0,
|
||||
'phys_pct' => 0,
|
||||
'econ_pct' => 0);
|
||||
$type = &$overview['types'][$utname];
|
||||
$type['subs'][] = array('name' => $row['Unit']['status'],
|
||||
'count' => $row[0]['cnt'],
|
||||
'rents' => $row[0]['rents'],
|
||||
'phys_subpct' => 0,
|
||||
'phys_totpct' => 0,
|
||||
'econ_subpct' => 0,
|
||||
'econ_totpct' => 0);
|
||||
|
||||
|
||||
$type['count'] += $row[0]['cnt'];
|
||||
$type['rents'] += $row[0]['rents'];
|
||||
|
||||
$overview['count'] += $row[0]['cnt'];
|
||||
$overview['rents'] += $row[0]['rents'];
|
||||
}
|
||||
|
||||
foreach ($overview['types'] AS &$type) {
|
||||
foreach ($type['subs'] AS &$sub) {
|
||||
$sub['phys_subpct'] = $sub['count'] / $type['count'];
|
||||
$sub['econ_subpct'] = $sub['rents'] / $type['rents'];
|
||||
$sub['phys_totpct'] = $sub['count'] / $overview['count'];
|
||||
$sub['econ_totpct'] = $sub['rents'] / $overview['rents'];
|
||||
}
|
||||
$type['phys_pct'] = $type['count'] / $overview['count'];
|
||||
$type['econ_pct'] = $type['rents'] / $overview['rents'];
|
||||
}
|
||||
//pr($overview);
|
||||
|
||||
// Prepare to render.
|
||||
$this->set('title', 'Unit Overview');
|
||||
$this->set(compact('overview'));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -47,6 +47,13 @@ class FormatHelper extends AppHelper {
|
||||
return $currency;
|
||||
}
|
||||
|
||||
function percent($amount, $precision = 2) {
|
||||
if (!isset($amount))
|
||||
return '-';
|
||||
|
||||
return self::$number->toPercentage($amount*100, $precision);
|
||||
}
|
||||
|
||||
function date($date, $age = false, $class = null, $time = false) {
|
||||
if (!$date) return null;
|
||||
|
||||
|
||||
@@ -266,6 +266,14 @@ form#collected-form input[type=button] { float : left;
|
||||
/* NSF items */
|
||||
.nsf-tender { text-decoration: line-through; }
|
||||
|
||||
/* Overview lists */
|
||||
table.overview td.grand { border-top : 4px double #000; }
|
||||
table.overview td.subheader { padding-top: 1em; padding-left: 0.5em; font-size: 150%; }
|
||||
table.overview td:first-child.subitem { padding-left: 2em; }
|
||||
table.overview td:first-child { text-align: left; }
|
||||
table.overview td { text-align: right; }
|
||||
table.overview td.oddrow { background : #f4f4f4; }
|
||||
|
||||
|
||||
/************************************************************
|
||||
************************************************************
|
||||
|
||||
Reference in New Issue
Block a user