From 7770f13bf31bc635697e79f6e2780e0bfad678ed Mon Sep 17 00:00:00 2001 From: abijah Date: Thu, 11 Mar 2010 23:40:47 +0000 Subject: [PATCH] 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 --- site/app_controller.php | 19 ++++++-- site/controllers/units_controller.php | 66 +++++++++++++++++++++++++++ site/views/helpers/format.php | 7 +++ site/webroot/css/layout.css | 8 ++++ 4 files changed, 95 insertions(+), 5 deletions(-) diff --git a/site/app_controller.php b/site/app_controller.php index 5775c93..bb67e0c 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -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); } diff --git a/site/controllers/units_controller.php b/site/controllers/units_controller.php index 1cc50f2..ca4aae9 100644 --- a/site/controllers/units_controller.php +++ b/site/controllers/units_controller.php @@ -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')); + } + + /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/site/views/helpers/format.php b/site/views/helpers/format.php index 98242cb..5afa6c1 100644 --- a/site/views/helpers/format.php +++ b/site/views/helpers/format.php @@ -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; diff --git a/site/webroot/css/layout.css b/site/webroot/css/layout.css index c38a71e..236def7 100644 --- a/site/webroot/css/layout.css +++ b/site/webroot/css/layout.css @@ -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; } + /************************************************************ ************************************************************