Implemented the UnitSize controller and view. I would like to add controller navigation links for 1bd, 2bd, 3bd, and so on. Also, we need to make the number of available units part of the grid. It will require breaking a separate CountTables function, since we'll need to join with Units, but it shouldn't be a big deal. Whether or not we include occupancy percentage, or leave that to a report is undecided.
git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@782 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -180,6 +180,9 @@ class AppController extends Controller {
|
||||
$this->addSideMenuLink('Site Map',
|
||||
array('controller' => 'maps', 'action' => 'view', 1), null,
|
||||
'SITE');
|
||||
$this->addSideMenuLink('Unit Sizes',
|
||||
array('controller' => 'unit_sizes', 'action' => 'index'), null,
|
||||
'SITE');
|
||||
$this->addSideMenuLink('Units',
|
||||
array('controller' => 'units', 'action' => 'index'), null,
|
||||
'SITE');
|
||||
@@ -427,6 +430,10 @@ class AppController extends Controller {
|
||||
* helper: gridView
|
||||
* - called by derived controllers to create an index listing
|
||||
*/
|
||||
function index() {
|
||||
$names = Inflector::humanize(Inflector::pluralize($this->params['controller']));
|
||||
$this->gridView('All ' . $names, 'all');
|
||||
}
|
||||
|
||||
function gridView($title, $action = null, $element = null) {
|
||||
$this->sideMenuEnable('SITE', $this->op_area);
|
||||
|
||||
118
site/controllers/unit_sizes_controller.php
Normal file
118
site/controllers/unit_sizes_controller.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
class UnitSizesController extends AppController {
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* virtuals: gridData
|
||||
* - With the application controller handling the gridData action,
|
||||
* these virtual functions ensure that the correct data is passed
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function gridDataTables(&$params, &$model) {
|
||||
return array();
|
||||
}
|
||||
|
||||
function gridDataFields(&$params, &$model) {
|
||||
$fields = parent::gridDataFields($params, $model);
|
||||
$fields[] = 'ROUND(UnitSize.width/12, 1) AS width';
|
||||
$fields[] = 'ROUND(UnitSize.depth/12, 1) AS depth';
|
||||
$fields[] = 'ROUND(UnitSize.height/12, 1) AS height';
|
||||
$fields[] = 'ROUND(UnitSize.width/12 * UnitSize.depth/12, 0) AS sqft';
|
||||
$fields[] = 'ROUND(UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12, 0) AS cuft';
|
||||
$fields[] = 'ROUND(UnitSize.rent / (UnitSize.width/12 * UnitSize.depth/12), 2) AS sqcost';
|
||||
$fields[] = 'ROUND(UnitSize.rent / (UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12), 2) AS cucost';
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
||||
$links['UnitSize'] = array('name');
|
||||
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: view
|
||||
* - Displays information about a specific entry
|
||||
*/
|
||||
|
||||
function view($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('controller' => 'accounts', 'action'=>'index'));
|
||||
}
|
||||
|
||||
// Get the UnitSize and related fields
|
||||
$this->UnitSize->id = $id;
|
||||
$size = $this->UnitSize->find
|
||||
('first', array
|
||||
('contain' => array('UnitType'),
|
||||
'fields' => array('UnitSize.*', 'UnitType.*',
|
||||
'ROUND(UnitSize.width/12, 1) AS width',
|
||||
'ROUND(UnitSize.depth/12, 1) AS depth',
|
||||
'ROUND(UnitSize.height/12, 1) AS height',
|
||||
'ROUND(UnitSize.width/12 * UnitSize.depth/12, 0) AS sqft',
|
||||
'ROUND(UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12, 0) AS cuft'),
|
||||
));
|
||||
$size['UnitSize'] = $size[0] + $size['UnitSize'];
|
||||
unset($size[0]);
|
||||
|
||||
$this->set(compact('size'));
|
||||
$this->set('stats', $this->UnitSize->stats($id));
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Unit Size : {$size['UnitSize']['name']}";
|
||||
$this->set(compact('title'));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: edit
|
||||
* - Edit unit_size information
|
||||
*/
|
||||
|
||||
function edit($id = null) {
|
||||
$this->INTERNAL_ERROR('NOT READY');
|
||||
if (isset($this->data)) {
|
||||
// Check to see if the operation was cancelled.
|
||||
if (isset($this->params['form']['cancel'])) {
|
||||
if (empty($this->data['UnitSize']['id']))
|
||||
$this->redirect(array('action'=>'index'));
|
||||
|
||||
$this->redirect(array('action'=>'view', $this->data['UnitSize']['id']));
|
||||
}
|
||||
|
||||
// Make sure we have unit_size data
|
||||
if (empty($this->data['UnitSize']) || empty($this->data['UnitSize']['id']))
|
||||
$this->redirect(array('action'=>'index'));
|
||||
|
||||
// Save the unit_size and all associated data
|
||||
$this->UnitSize->create();
|
||||
$this->UnitSize->id = $this->data['UnitSize']['id'];
|
||||
if (!$this->UnitSize->save($this->data, false)) {
|
||||
$this->Session->setFlash("UNIT_SIZE SAVE FAILED", true);
|
||||
pr("UNIT_SIZE SAVE FAILED");
|
||||
}
|
||||
|
||||
$this->redirect(array('action'=>'view', $this->UnitSize->id));
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$this->data = $this->UnitSize->findById($id);
|
||||
} else {
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
|
||||
// Prepare to render.
|
||||
$title = ('UnitSize ' . $this->data['UnitSize']['name'] .
|
||||
" : Edit");
|
||||
$this->set(compact('title'));
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class UnitsController extends AppController {
|
||||
|
||||
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
||||
$links['Unit'] = array('name');
|
||||
//$links['UnitSize'] = array('name');
|
||||
$links['UnitSize'] = array('name');
|
||||
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,64 @@
|
||||
<?php
|
||||
class UnitSize extends AppModel {
|
||||
|
||||
var $name = 'UnitSize';
|
||||
var $validate = array(
|
||||
'id' => array('numeric'),
|
||||
'unit_type_id' => array('numeric'),
|
||||
'code' => array('notempty'),
|
||||
'name' => array('notempty'),
|
||||
'width' => array('numeric'),
|
||||
'depth' => array('numeric'),
|
||||
'deposit' => array('money'),
|
||||
'amount' => array('money')
|
||||
);
|
||||
var $belongsTo =
|
||||
array(
|
||||
'UnitType',
|
||||
);
|
||||
|
||||
var $belongsTo = array(
|
||||
'UnitType',
|
||||
);
|
||||
var $hasMany =
|
||||
array(
|
||||
'Unit',
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'Unit',
|
||||
);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: stats
|
||||
* - Returns summary data from the requested unit size.
|
||||
*/
|
||||
|
||||
function stats($id = null) {
|
||||
$this->prEnter(compact('id'));
|
||||
|
||||
// Right now, we only work with id not null
|
||||
if (!$id)
|
||||
return null;
|
||||
|
||||
$stats = array();
|
||||
|
||||
// Get the total number of units this size
|
||||
$stats['all'] =
|
||||
$this->find('count',
|
||||
array('link' => array('Unit'),
|
||||
'conditions' => array(array('UnitSize.id' => $id)),
|
||||
));
|
||||
|
||||
// Get numbers for units in the various states
|
||||
foreach (array('unavailable', 'vacant', 'occupied', 'locked', 'liened') AS $status) {
|
||||
$statusfunc = 'condition' . ucfirst($status);
|
||||
$stats[$status] =
|
||||
$this->find('count',
|
||||
array('link' => array('Unit'),
|
||||
'conditions' => array(array('UnitSize.id' => $id),
|
||||
$this->Unit->{$statusfunc}()),
|
||||
));
|
||||
}
|
||||
|
||||
// Count up each unit by physical status
|
||||
foreach
|
||||
($this->find('all',
|
||||
array('link' => array('Unit' => array('fields' => array())),
|
||||
'fields' => array('Unit.status', 'COUNT(Unit.id) AS total'),
|
||||
'conditions' => array(array('UnitSize.id' => $id)),
|
||||
'group' => 'Unit.status',
|
||||
)) AS $status) {
|
||||
$stats['status'][$status['Unit']['status']] = $status[0]['total'];
|
||||
}
|
||||
|
||||
// Return the collection
|
||||
return $this->prReturn($stats);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
24
site/views/elements/unit_sizes.ctp
Normal file
24
site/views/elements/unit_sizes.ctp
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
// Define the table columns
|
||||
$cols = array();
|
||||
$cols['Size'] = array('index' => 'UnitSize.name', 'formatter' => 'shortname');
|
||||
$cols['Width'] = array('index' => 'UnitSize.width', 'formatter' => 'number');
|
||||
$cols['Depth'] = array('index' => 'UnitSize.depth', 'formatter' => 'number');
|
||||
$cols['Height'] = array('index' => 'UnitSize.height', 'formatter' => 'number');
|
||||
$cols['Area'] = array('index' => 'sqft', 'formatter' => 'number');
|
||||
$cols['Volume'] = array('index' => 'cuft', 'formatter' => 'number');
|
||||
$cols['Deposit'] = array('index' => 'UnitSize.deposit', 'formatter' => 'currency');
|
||||
$cols['Rent'] = array('index' => 'UnitSize.rent', 'formatter' => 'currency');
|
||||
$cols['A. Cost'] = array('index' => 'sqcost', 'formatter' => 'currency');
|
||||
$cols['V. Cost'] = array('index' => 'cucost', 'formatter' => 'currency');
|
||||
$cols['Comment'] = array('index' => 'Unit.comment', 'formatter' => 'comment');
|
||||
|
||||
// Render the grid
|
||||
$grid
|
||||
->columns($cols)
|
||||
->sortField('Area')
|
||||
->defaultFields(array('Size', 'Area'))
|
||||
->searchFields(array('Size', 'Width', 'Depth', 'Area', 'Deposit', 'Rent'))
|
||||
->render($this, isset($config) ? $config : null,
|
||||
array_diff(array_keys($cols), array('Height', 'Volume', 'A. Cost', 'V. Cost', 'Comment')));
|
||||
88
site/views/unit_sizes/view.ctp
Normal file
88
site/views/unit_sizes/view.ctp
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
echo '<div class="unit-size view">' . "\n";
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
* UnitSize Detail Main Section
|
||||
*/
|
||||
|
||||
$unit_type = $size['UnitType'];
|
||||
$unit_size = $size['UnitSize'];
|
||||
|
||||
$rows = array();
|
||||
$rows[] = array('Name', $unit_size['name']);
|
||||
$rows[] = array('Type', $unit_type['name']);
|
||||
$rows[] = array('Width', $unit_size['width'] . ' Feet');
|
||||
$rows[] = array('Depth', $unit_size['depth'] . ' Feet');
|
||||
if (!empty($unit_size['height']))
|
||||
$rows[] = array('Height', $unit_size['height'] . ' Feet');
|
||||
if (!empty($unit_size['sqft']))
|
||||
$rows[] = array('Area', ($unit_size['sqft'] . ' Square Feet'
|
||||
. ' ('. FormatHelper::currency($unit_size['rent'] / $unit_size['sqft'])
|
||||
. ' / Square Foot)'));
|
||||
if (!empty($unit_size['cuft']))
|
||||
$rows[] = array('Volume', ($unit_size['cuft'] . ' Cubic Feet'
|
||||
. ' ('. FormatHelper::currency($unit_size['rent'] / $unit_size['cuft'])
|
||||
. ' / Cubic Foot)'));
|
||||
$rows[] = array('Deposit', FormatHelper::currency($unit_size['deposit']));
|
||||
$rows[] = array('Rent', FormatHelper::currency($unit_size['rent']));
|
||||
$rows[] = array('Comment', $unit_size['comment']);
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item unit_size detail',
|
||||
'caption' => 'Unit Size Detail',
|
||||
'rows' => $rows,
|
||||
'column_class' => array('field', 'value')));
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* UnitSize Info Box
|
||||
*/
|
||||
|
||||
echo '<div class="infobox">' . "\n";
|
||||
$rows = array();
|
||||
$rows[] = array($unit_size['name'] . ' Units:', $stats['all']);
|
||||
$rows[] = array('Unavailable:', $stats['unavailable']);
|
||||
$rows[] = array('Vacant:', $stats['vacant']);
|
||||
$rows[] = array('Occupied:', $stats['occupied']);
|
||||
echo $this->element('table',
|
||||
array('class' => 'summary',
|
||||
'rows' => $rows,
|
||||
'column_class' => array('field', 'value'),
|
||||
'suppress_alternate_rows' => true,
|
||||
));
|
||||
echo '</div>' . "\n";
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
* Supporting Elements Section
|
||||
*/
|
||||
|
||||
echo '<div CLASS="detail supporting">' . "\n";
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Ledger Entries
|
||||
*/
|
||||
|
||||
echo $this->element('units', array
|
||||
(// Grid configuration
|
||||
'config' => array
|
||||
('caption' => $unit_size['name'] . " Units",
|
||||
'filter' => array('unit_size_id' => $unit_size['id']),
|
||||
'include' => array('Deposit', 'Comment'),
|
||||
'exclude' => array('Size', 'Area', 'Balance'),
|
||||
)));
|
||||
|
||||
|
||||
/* End "detail supporting" div */
|
||||
echo '</div>' . "\n";
|
||||
|
||||
/* End page div */
|
||||
echo '</div>' . "\n";
|
||||
@@ -19,7 +19,10 @@ if (isset($unit['Unit']))
|
||||
$rows = array();
|
||||
$rows[] = array('Name', $unit['name']);
|
||||
$rows[] = array('Status', $unit['status']);
|
||||
$rows[] = array('Size', $unit_size['name']);
|
||||
$rows[] = array('Size', $html->link($unit_size['name'],
|
||||
array('controller' => 'unit_sizes',
|
||||
'action' => 'view',
|
||||
$unit_size['id'])));
|
||||
$rows[] = array('Deposit', FormatHelper::currency($unit['deposit']));
|
||||
$rows[] = array('Rent', FormatHelper::currency($unit['rent']));
|
||||
$rows[] = array('Comment', $unit['comment']);
|
||||
|
||||
Reference in New Issue
Block a user