Index/Add views for StockUnitType and ItemType, View/Update for Item, Style to apply on all tables, DataTables used on details and indexes

This commit is contained in:
mareksebera 2014-09-10 22:16:10 +02:00
parent be2b39c5eb
commit 5d4d209549
15 changed files with 322 additions and 313 deletions

View file

@ -1,104 +1,32 @@
<?php
App::uses('AppController', 'Controller');
/**
* ItemTypes Controller
*
* @property ItemType $ItemType
* @property PaginatorComponent $Paginator
*/
class ItemTypesController extends AppController {
class ItemTypesController extends AppController
{
/**
* Components
*
* @var array
*/
public $components = array('Paginator');
/**
* index method
*
* @return void
*/
public function index()
{
if ($this->request->is('post')) {
$this->ItemType->create();
if ($this->ItemType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
/**
* index method
*
* @return void
*/
public function index() {
$this->ItemType->recursive = 0;
$this->set('itemTypes', $this->Paginator->paginate());
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->ItemType->exists($id)) {
throw new NotFoundException(__('Invalid item type'));
}
$options = array('conditions' => array('ItemType.' . $this->ItemType->primaryKey => $id));
$this->set('itemType', $this->ItemType->find('first', $options));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->ItemType->create();
if ($this->ItemType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->ItemType->exists($id)) {
throw new NotFoundException(__('Invalid item type'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->ItemType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('ItemType.' . $this->ItemType->primaryKey => $id));
$this->request->data = $this->ItemType->find('first', $options);
}
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->ItemType->id = $id;
if (!$this->ItemType->exists()) {
throw new NotFoundException(__('Invalid item type'));
}
$this->request->allowMethod('post', 'delete');
if ($this->ItemType->delete()) {
$this->Session->setFlash(__('The item type has been deleted.'));
} else {
$this->Session->setFlash(__('The item type could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
}
$this->ItemType->recursive = 0;
$this->set('itemTypes', $this->ItemType->find('list'));
}
}

View file

@ -30,11 +30,19 @@ class ItemsController extends AppController
public function view($id = null)
{
if (!$this->ItemType->exists($id)) {
if (!$this->Item->exists($id)) {
throw new NotFoundException(__('Invalid item type'));
}
$options = array('conditions' => array('ItemType.id' => $id));
$this->set('itemType', $this->ItemType->find('first', $options));
if ($this->request->is(array('post', 'put'))) {
$this->StockHistory->create();
if ($this->StockHistory->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
$options = array('conditions' => array('Item.id' => $id));
$this->set('item', $this->Item->find('first', $options));
}
public function edit($id = null)
@ -50,8 +58,10 @@ class ItemsController extends AppController
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('ItemType.id' => $id));
$this->request->data = $this->ItemType->find('first', $options);
$options = array('conditions' => array('Item.id' => $id));
$this->request->data = $this->Item->find('first', $options);
$this->set('itemTypes', $this->ItemType->find('list'));
$this->set('stockUnitTypes', $this->StockUnitType->find('list'));
}
}

View file

@ -0,0 +1,22 @@
<?php
App::uses('AppController', 'Controller');
class StockUnitTypesController extends AppController
{
public function index()
{
if ($this->request->is('post')) {
$this->StockUnitType->create();
if ($this->StockUnitType->save($this->request->data)) {
$this->Session->setFlash(__('The item type has been saved.'));
} else {
$this->Session->setFlash(__('The item type could not be saved. Please, try again.'));
}
}
$this->StockUnitType->recursive = 0;
$this->set('items', $this->StockUnitType->find('list'));
}
}

View file

@ -8,5 +8,17 @@ class ItemType extends AppModel
public $name = 'ItemType';
public $displayField = 'name';
public $hasMany = array('Item');
public $validate = array(
'name' => array(
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'Name must be unique'
),
'minLength' => array(
'rule' => array('minLength', 3),
'message' => 'Name must be at least 3 letters'
)
)
);
}

View file

@ -8,5 +8,17 @@ class StockUnitType extends AppModel
public $name = 'StockUnitType';
public $displayField = 'name';
public $hasMany = array('Item');
public $validate = array(
'name' => array(
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'Name must be unique'
),
'minLength' => array(
'rule' => array('minLength', 3),
'message' => 'Name must be at least 3 letters'
)
)
);
}

View file

@ -1,19 +0,0 @@
<div class="itemTypes form">
<?php echo $this->Form->create('ItemType'); ?>
<fieldset>
<legend><?php echo __('Add Item Type'); ?></legend>
<?php
echo $this->Form->input('name');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Item Types'), array('action' => 'index')); ?></li>
<li><?php echo $this->Html->link(__('List Items'), array('controller' => 'items', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Item'), array('controller' => 'items', 'action' => 'add')); ?> </li>
</ul>
</div>

View file

@ -1,21 +0,0 @@
<div class="itemTypes form">
<?php echo $this->Form->create('ItemType'); ?>
<fieldset>
<legend><?php echo __('Edit Item Type'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('name');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $this->Form->value('ItemType.id')), array(), __('Are you sure you want to delete # %s?', $this->Form->value('ItemType.id'))); ?></li>
<li><?php echo $this->Html->link(__('List Item Types'), array('action' => 'index')); ?></li>
<li><?php echo $this->Html->link(__('List Items'), array('controller' => 'items', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Item'), array('controller' => 'items', 'action' => 'add')); ?> </li>
</ul>
</div>

View file

@ -1,50 +1,47 @@
<div class="itemTypes index">
<h2><?php echo __('Item Types'); ?></h2>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('name'); ?></th>
<th><?php echo $this->Paginator->sort('modified'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($itemTypes as $itemType): ?>
<tr>
<td><?php echo h($itemType['ItemType']['id']); ?>&nbsp;</td>
<td><?php echo h($itemType['ItemType']['name']); ?>&nbsp;</td>
<td><?php echo h($itemType['ItemType']['modified']); ?>&nbsp;</td>
<td><?php echo h($itemType['ItemType']['created']); ?>&nbsp;</td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $itemType['ItemType']['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $itemType['ItemType']['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $itemType['ItemType']['id']), array(), __('Are you sure you want to delete # %s?', $itemType['ItemType']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<div class="paging">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('New Item Type'), array('action' => 'add')); ?></li>
<li><?php echo $this->Html->link(__('List Items'), array('controller' => 'items', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Item'), array('controller' => 'items', 'action' => 'add')); ?> </li>
</ul>
<script type="text/javascript">
$(document).ready(function () {
var table = $("#item-types-table").DataTable({
paging: false,
orderMulti: true,
info: false,
columns: [
{searchable: true},
{searchable: true}
],
search: {
caseInsensitive: true
}
});
});
</script>
<div id="item-type-add">
<?php
echo $this->Form->create('ItemType');
echo $this->Form->inputs(array(), array('created', 'modified'));
echo $this->Form->end(__('Submit'));
?>
</div>
<br class="clear"/>
<hr/>
<table id="item-types-table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php foreach ($itemTypes as $id => $name): ?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</tfoot>
</table>

View file

@ -1,75 +0,0 @@
<div class="itemTypes view">
<h2><?php echo __('Item Type'); ?></h2>
<dl>
<dt><?php echo __('Id'); ?></dt>
<dd>
<?php echo h($itemType['ItemType']['id']); ?>
&nbsp;
</dd>
<dt><?php echo __('Name'); ?></dt>
<dd>
<?php echo h($itemType['ItemType']['name']); ?>
&nbsp;
</dd>
<dt><?php echo __('Modified'); ?></dt>
<dd>
<?php echo h($itemType['ItemType']['modified']); ?>
&nbsp;
</dd>
<dt><?php echo __('Created'); ?></dt>
<dd>
<?php echo h($itemType['ItemType']['created']); ?>
&nbsp;
</dd>
</dl>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('Edit Item Type'), array('action' => 'edit', $itemType['ItemType']['id'])); ?> </li>
<li><?php echo $this->Form->postLink(__('Delete Item Type'), array('action' => 'delete', $itemType['ItemType']['id']), array(), __('Are you sure you want to delete # %s?', $itemType['ItemType']['id'])); ?> </li>
<li><?php echo $this->Html->link(__('List Item Types'), array('action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Item Type'), array('action' => 'add')); ?> </li>
<li><?php echo $this->Html->link(__('List Items'), array('controller' => 'items', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Item'), array('controller' => 'items', 'action' => 'add')); ?> </li>
</ul>
</div>
<div class="related">
<h3><?php echo __('Related Items'); ?></h3>
<?php if (!empty($itemType['Item'])): ?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php echo __('Id'); ?></th>
<th><?php echo __('Item Type Id'); ?></th>
<th><?php echo __('Name'); ?></th>
<th><?php echo __('Stock Unit Type Id'); ?></th>
<th><?php echo __('Detail'); ?></th>
<th><?php echo __('Modified'); ?></th>
<th><?php echo __('Created'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
<?php foreach ($itemType['Item'] as $item): ?>
<tr>
<td><?php echo $item['id']; ?></td>
<td><?php echo $item['item_type_id']; ?></td>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['stock_unit_type_id']; ?></td>
<td><?php echo $item['detail']; ?></td>
<td><?php echo $item['modified']; ?></td>
<td><?php echo $item['created']; ?></td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('controller' => 'items', 'action' => 'view', $item['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('controller' => 'items', 'action' => 'edit', $item['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'items', 'action' => 'delete', $item['id']), array(), __('Are you sure you want to delete # %s?', $item['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $this->Html->link(__('New Item'), array('controller' => 'items', 'action' => 'add')); ?> </li>
</ul>
</div>
</div>

View file

@ -1,5 +1,5 @@
<?php
echo $this->Form->create('Item');
echo $this->Form->inputs(array(), array('created', 'modified'));
echo $this->Form->inputs(array(), array('created', 'modified', 'is_deleted'));
echo $this->Form->end(__('Save'));

View file

@ -1,46 +1,4 @@
<script type="text/javascript">
jQuery.fn.DataTable.ext.type.search.string = function (data) {
return !data ?
'' :
typeof data === 'string' ?
data
.replace(/\n/g, ' ')
.replace(/á/g, 'a')
.replace(/é/g, 'e')
.replace(/í/g, 'i')
.replace(/ó/g, 'o')
.replace(/ú/g, 'u')
.replace(/ê/g, 'e')
.replace(/î/g, 'i')
.replace(/ô/g, 'o')
.replace(/è/g, 'e')
.replace(/ï/g, 'i')
.replace(/ü/g, 'u')
.replace(/ě/g, 'e')
.replace(/š/g, 's')
.replace(/č/g, 'c')
.replace(/ř/g, 'r')
.replace(/ž/g, 'z')
.replace(/ý/g, 'y')
.replace(/ö/g, 'o')
.replace(/ä/g, 'a')
.replace(/ň/g, 'n')
.replace(/Ě/g, 'e')
.replace(/Š/g, 's')
.replace(/Č/g, 'c')
.replace(/Ř/g, 'r')
.replace(/Ž/g, 'z')
.replace(/Ý/g, 'y')
.replace(/Á/g, 'a')
.replace(/Í/g, 'i')
.replace(/É/g, 'e')
.replace(/Ň/g, 'n')
.replace(/Ť/g, 't')
.replace(/Ď/g, 'd')
.replace(/ç/g, 'c') :
data;
};
$(document).ready(function () {
var table = $("#items-table").DataTable({
paging: false,

89
app/View/Items/view.ctp Normal file
View file

@ -0,0 +1,89 @@
<table class="dataTable">
<tr>
<td>ID</td>
<td><?php echo $item['Item']['id']; ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo $item['Item']['name']; ?></td>
</tr>
<tr>
<td>Type</td>
<td><?php echo $item['ItemType']['name']; ?></td>
</tr>
<tr>
<td>Stock Quantity</td>
<td><?php echo $item['StockHistory'][0]['amount_in_stock'] . ' ' . $item['StockUnitType']['name']; ?></td>
</tr>
<tr>
<td>Placement</td>
<td><?php echo $item['StockHistory'][0]['location']; ?></td>
</tr>
</table>
<br class="clear"/>
<hr/>
<h2>Update Stock Quantity and Placement</h2>
<?php
echo $this->Form->create('StockHistory');
echo $this->Form->hidden('item_id', array('value' => $item['Item']['id']));
echo $this->Form->inputs(array(), array('created', 'modified', 'item_id'));
echo $this->Form->end(__('Save'));
?>
<br class="clear"/>
<hr/>
<h2>Item Stock History</h2>
<script type="text/javascript">
$(document).ready(function () {
var table = $("#item-stock-history").DataTable({
paging: false,
orderMulti: true,
info: false,
columns: [
{searchable: true},
{searchable: true},
{searchable: true},
{searchable: true},
],
order: [
[3, 'desc']
],
search: {
caseInsensitive: true
}
});
});
</script>
<table id="item-stock-history">
<thead>
<tr>
<td>ID</td>
<td>Quantity</td>
<td>Placement</td>
<td>When</td>
</tr>
</thead>
<?php
foreach ($item['StockHistory'] as $history) {
printf(
'<tr>
<td>%d</td>
<td>%d</td>
<td>%s</td>
<td>%s</td>
</tr>',
$history['id'],
$history['amount_in_stock'],
$history['location'],
$history['created']
);
}
?>
<tfoot>
<tr>
<td>ID</td>
<td>Quantity</td>
<td>Placement</td>
<td>When</td>
</tr>
</tfoot>
</table>

View file

@ -20,6 +20,49 @@
echo $this->fetch('css');
echo $this->fetch('script');
?>
<script type="text/javascript">
jQuery.fn.DataTable.ext.type.search.string = function (data) {
return !data ?
'' :
typeof data === 'string' ?
data
.replace(/\n/g, ' ')
.replace(/á/g, 'a')
.replace(/é/g, 'e')
.replace(/í/g, 'i')
.replace(/ó/g, 'o')
.replace(/ú/g, 'u')
.replace(/ê/g, 'e')
.replace(/î/g, 'i')
.replace(/ô/g, 'o')
.replace(/è/g, 'e')
.replace(/ï/g, 'i')
.replace(/ü/g, 'u')
.replace(/ě/g, 'e')
.replace(/š/g, 's')
.replace(/č/g, 'c')
.replace(/ř/g, 'r')
.replace(/ž/g, 'z')
.replace(/ý/g, 'y')
.replace(/ö/g, 'o')
.replace(/ä/g, 'a')
.replace(/ň/g, 'n')
.replace(/Ě/g, 'e')
.replace(/Š/g, 's')
.replace(/Č/g, 'c')
.replace(/Ř/g, 'r')
.replace(/Ž/g, 'z')
.replace(/Ý/g, 'y')
.replace(/Á/g, 'a')
.replace(/Í/g, 'i')
.replace(/É/g, 'e')
.replace(/Ň/g, 'n')
.replace(/Ť/g, 't')
.replace(/Ď/g, 'd')
.replace(/ç/g, 'c') :
data;
};
</script>
</head>
<body>
<div id="container">
@ -28,8 +71,8 @@
<ul id="top-menu">
<li><?php echo $this->Html->link(__('All Items'), array('controller' => 'items', 'action' => 'index')) ?></li>
<li><?php echo $this->Html->link(__('Add Item'), array('controller' => 'items', 'action' => 'add')) ?></li>
<li><?php echo $this->Html->link(__('Add Item Type'), array('controller' => 'item_types', 'action' => 'add')) ?></li>
<li><?php echo $this->Html->link(__('Add Unit Type'), array('controller' => 'unit_types', 'action' => 'add')) ?></li>
<li><?php echo $this->Html->link(__('Add Item Type'), array('controller' => 'item_types', 'action' => 'index')) ?></li>
<li><?php echo $this->Html->link(__('Add Unit Type'), array('controller' => 'stock_unit_types', 'action' => 'index')) ?></li>
</ul>
<br class="clear"/>
</div>

View file

@ -0,0 +1,47 @@
<script type="text/javascript">
$(document).ready(function () {
var table = $("#item-units-table").DataTable({
paging: false,
orderMulti: true,
info: false,
columns: [
{searchable: true},
{searchable: true}
],
search: {
caseInsensitive: true
}
});
});
</script>
<div id="item-units-add">
<?php
echo $this->Form->create('StockUnitType');
echo $this->Form->inputs(array(), array('created', 'modified'));
echo $this->Form->end(__('Submit'));
?>
</div>
<br class="clear"/>
<hr/>
<table id="item-units-table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $id => $name): ?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</tfoot>
</table>

View file

@ -33,22 +33,22 @@ h1 {
clear: both;
}
#items-table {
.dataTable {
width: 100%;
margin: 15px;
}
#items-table thead > tr > td, #items-table tfoot > tr > td {
.dataTable thead > tr > td, .dataTable tfoot > tr > td {
font-weight: bold;
padding-top: 10px;
padding-bottom: 10px;
}
#items-table tbody > tr, thead > tr {
.dataTable tbody > tr, thead > tr {
border-bottom: 1px solid #ececec;
}
#items-table tbody > tr > td {
.dataTable tbody > tr > td {
padding-top: 5px;
padding-bottom: 5px;
}
@ -58,11 +58,11 @@ table .actions a {
padding-right: 5px;
}
#items-table_filter {
.dataTables_filter {
padding: 10px;
}
#items-table_filter input[type=search] {
.dataTables_filter input[type=search] {
padding: 10px;
font-size: 15px;
width: 200px;
@ -95,4 +95,10 @@ form .input select {
#flashMessage {
padding: 20px;
background-color: #fafafa;
}
hr {
width: 100%;
background-color: black;
color: black;
}