fast inventory item edit

This commit is contained in:
Roland Schneider 2016-08-08 18:46:58 +02:00
parent e79187c50e
commit c5bfae9ec1
5 changed files with 74 additions and 53 deletions

View File

@ -74,8 +74,6 @@ class InventoryItemController extends Controller
*/ */
protected function downloadIndexXls($dataProvider) protected function downloadIndexXls($dataProvider)
{ {
$defs = [['item_created_at', 'Létrehozva'], $defs = [['item_created_at', 'Létrehozva'],
['item_name', 'Termék/Termék csoport'], ['item_name', 'Termék/Termék csoport'],
['user_username', 'Felhasználó'], ['user_username', 'Felhasználó'],
@ -227,11 +225,24 @@ class InventoryItemController extends Controller
* @throws NotAcceptableHttpException * @throws NotAcceptableHttpException
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionUpdateItem($id) public function actionUpdateItem($idInventory = null,$id = null)
{ {
$model = $this->findModel($id); if ( !isset($idInventory ) && !isset($id)){
$inventory = Inventory::findOne($model->id_inventory); \Yii::error("Neither inventory id nor inventory item id");
}
if ( isset($id)){
$model = $this->findModel($id);
$inventory = Inventory::findOne($model->id_inventory);
}else{
$inventory = Inventory::findOne($idInventory);
$model = new InventoryItem();
}
if (!$inventory->isOpen()) {
throw new NotAcceptableHttpException("A leltár elem nem található");
}
if (Yii::$app->request->getIsAjax()) { if (Yii::$app->request->getIsAjax()) {
@ -244,6 +255,10 @@ class InventoryItemController extends Controller
return json_encode($arr); return json_encode($arr);
} else { } else {
if (Yii::$app->request->isPost && $model->isNewRecord ){
\Yii::error("Failed to save inventory-item: post , but no item id");
throw new Exception("Hiba történt mentés közben");
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
@ -256,7 +271,11 @@ class InventoryItemController extends Controller
throw new Exception("Nem sikerült elmenteni a leltár element"); throw new Exception("Nem sikerült elmenteni a leltár element");
} }
return $this->redirect(['update-item', 'id' => $model->id_inventory_item]); if ( isset($_POST['_next'])){
return $this->redirect(['update-item', 'idInventory' => $inventory->id_inventory]);
}else{
return $this->redirect(['index', 'id' => $inventory->id_inventory]);
}
} }
@ -275,7 +294,7 @@ class InventoryItemController extends Controller
->innerJoin("product_category", "product_category.id_product_category = product.id_product_category") ->innerJoin("product_category", "product_category.id_product_category = product.id_product_category")
->innerJoin("account", "product.id_account = account.id_account") ->innerJoin("account", "product.id_account = account.id_account")
->innerJoin("inventory_item", "inventory_item.id_product = product.id_product") ->innerJoin("inventory_item", "inventory_item.id_product = product.id_product")
->andWhere(["inventory_item.id_inventory" => $model->id_inventory])->all(); ->andWhere(["inventory_item.id_inventory" => $inventory->id_inventory])->all();
$productsRaw = $query->all(); $productsRaw = $query->all();
@ -289,9 +308,7 @@ class InventoryItemController extends Controller
$products[] = $arr; $products[] = $arr;
} }
if (!$inventory->isOpen()) {
throw new NotAcceptableHttpException("A leltár elem nem található");
}
return $this->render("update_item", [ return $this->render("update_item", [
'model' => $model, 'model' => $model,

View File

@ -7,19 +7,15 @@ use yii\widgets\ActiveForm;
/* @var $model common\models\InventoryItem */ /* @var $model common\models\InventoryItem */
/* @var $form yii\widgets\ActiveForm */ /* @var $form yii\widgets\ActiveForm */
?> ?>
<div id="inventory-form" class="inventory-item-form"> <div id="inventory-form" class="inventory-item-form">
<?php $form = ActiveForm::begin( ); ?> <?php $form = ActiveForm::begin( ); ?>
<?= $form->field($model, 'type')->hiddenInput()->label(false) ?> <?= $form->field($model, 'type')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'count')->textInput() ?> <?= $form->field($model, 'count')->textInput() ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton( Yii::t('common/inventory-item', 'Mentés/Következő')
, ['class' => 'btn btn-success',
'name'=> '_next' ]) ?>
<?= Html::submitButton( Yii::t('common/inventory-item', 'Mentés') , ['class' => 'btn btn-success' ]) ?> <?= Html::submitButton( Yii::t('common/inventory-item', 'Mentés') , ['class' => 'btn btn-success' ]) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>

View File

@ -175,17 +175,20 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
], ],
]) ; ]) ;
} }
] ],
'urlCreator' => function($action, $model, $key, $index){
$result = "";
if ( $action == 'update'){
$result = Url::toRoute( [ 'update-item' ,'id' => $model['item_id_inventory_item']]);
}
return $result;
}
] ; ] ;
} }
echo GridView::widget( [ echo GridView::widget( [
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'columns' => $columns 'columns' => $columns
]); ]);
?> ?>

View File

@ -7,9 +7,8 @@ use yii\widgets\DetailView;
/* @var $model common\models\InventoryItem */ /* @var $model common\models\InventoryItem */
$this->title = Yii::t('common/inventory-item', 'Leltár termék'); $this->title = Yii::t('common/inventory-item', 'Leltár termék');
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Leltár termék'), 'url' => ['inventory-item/index','id' => $inventory->id_inventory]];
$this->params['breadcrumbs'][] = ['label' => $model->id_inventory_item, 'url' => ['view', 'id' => $model->id_inventory_item]]; $this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Leltár mennyiség');
$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
\backend\assets\InventoryItemUpdateAsset::register($this); \backend\assets\InventoryItemUpdateAsset::register($this);
@ -41,6 +40,9 @@ $this->registerJs('FitnessAdmin.InventoryItem.Update.init( '. json_encode( $opti
], ],
]) ?> ]) ?>
<?php echo Html::a("Ugrás a leltárhoz",['inventory-item/index','id'=> $inventory->id_inventory ], ['class' => 'btn btn-primary']) ?>
<h2>Termék keresése a leltárban</h2>
<?php $form = \yii\widgets\ActiveForm::begin(); ?> <?php $form = \yii\widgets\ActiveForm::begin(); ?>
<?php echo Html::textInput("product_autocomplete","",['class' => 'form-control', 'id' => 'product_autocomplete','autocomplete' => 'off']) ?> <?php echo Html::textInput("product_autocomplete","",['class' => 'form-control', 'id' => 'product_autocomplete','autocomplete' => 'off']) ?>
@ -48,16 +50,15 @@ $this->registerJs('FitnessAdmin.InventoryItem.Update.init( '. json_encode( $opti
<?php \yii\widgets\ActiveForm::end(); ?> <?php \yii\widgets\ActiveForm::end(); ?>
<h2>Termék</h2> <div id="inventory-product">
<table class="table table-striped table-bordered detail-view"> <h2>Termék</h2>
<tbody><tr><th>Név</th><td id="inventory_product_name"> <?php echo Html::getAttributeValue($model, 'name') ?> </td></tr></tbody> <table class="table table-striped table-bordered detail-view">
</table> <tbody><tr><th>Név</th><td id="inventory_product_name"> <?php echo Html::getAttributeValue($model, 'name') ?> </td></tr></tbody>
</table>
<?= $this->render('_form', [
'model' => $model,
<?= $this->render('_form', [ ]) ?>
'model' => $model, </div>
]) ?>
</div> </div>

View File

@ -18,10 +18,10 @@ FitnessAdmin.InventoryItem.Update = new function(){
INVENTORY_PRODUCT_NAME: '#inventory_product_name', INVENTORY_PRODUCT_NAME: '#inventory_product_name',
INVENTORYITEM_TYPE: '#inventoryitem-type', INVENTORYITEM_TYPE: '#inventoryitem-type',
INVENTORYITEM_COUNT: '#inventoryitem-count', INVENTORYITEM_COUNT: '#inventoryitem-count',
INVENTORY_FORM: '#inventory-form' INVENTORY_FORM: '#inventory-product'
}; };
var product = null; var inventoryItem = null;
this.init = function (options) { this.init = function (options) {
defaults = $.extend(defaults,options); defaults = $.extend(defaults,options);
@ -37,6 +37,8 @@ FitnessAdmin.InventoryItem.Update = new function(){
$(defaults.selector_product).val(p.name); $(defaults.selector_product).val(p.name);
} }
} }
}else{
$(_SELECTORS.INVENTORY_FORM).hide();
} }
$(defaults.selector_product).focus().select(); $(defaults.selector_product).focus().select();
}; };
@ -65,12 +67,12 @@ FitnessAdmin.InventoryItem.Update = new function(){
} else { } else {
// This means it is only a partial match, you can either add a new item // This means it is only a partial match, you can either add a new item
// or take the active if you don't want new items // or take the active if you don't want new items
product = null; inventoryItem = null;
renderForm(); renderForm();
} }
} else { } else {
// Nothing is active so it is a new value (or maybe empty value) // Nothing is active so it is a new value (or maybe empty value)
product = null; inventoryItem = null;
renderForm(); renderForm();
} }
}); });
@ -78,7 +80,7 @@ FitnessAdmin.InventoryItem.Update = new function(){
var selectInventoryItem = function (data) { var selectInventoryItem = function (data) {
console.info('data',data); console.info('data',data);
product = data; inventoryItem = data;
}; };
var _findProduct = function (id){ var _findProduct = function (id){
@ -97,26 +99,28 @@ FitnessAdmin.InventoryItem.Update = new function(){
}; };
function renderForm( ) { function renderForm( ) {
console.info( "render",product); console.info( "render",inventoryItem);
var name = "",type = "",count = ""; var name = "",type = "",count = "";
if ( product){ if ( inventoryItem){
name = product.productName; name = inventoryItem.productName;
type = product.type; type = inventoryItem.type;
if ( product.count ){ if ( inventoryItem.count != null ){
count = product.count; count = inventoryItem.count;
} }
} }
$(_SELECTORS.INVENTORY_PRODUCT_NAME).html(name); $(_SELECTORS.INVENTORY_PRODUCT_NAME).html(name);
$(_SELECTORS.INVENTORYITEM_TYPE).html(type); $(_SELECTORS.INVENTORYITEM_TYPE).val(type);
$(_SELECTORS.INVENTORYITEM_COUNT).html(count); $(_SELECTORS.INVENTORYITEM_COUNT).val(count);
var formContainer = $(_SELECTORS.INVENTORY_FORM);
var form = $(_SELECTORS.INVENTORY_FORM).find('form'); var form = $(_SELECTORS.INVENTORY_FORM).find('form');
if ( product == null ){ if ( inventoryItem == null ){
form.hide(); formContainer.hide();
}else { }else {
form.show(); formContainer.show();
form.attr('action', defaults.url_save +"&id="+product.id_inventory_item); form.attr('action', defaults.url_save +"&id="+inventoryItem.id_inventory_item);
$(_SELECTORS.INVENTORYITEM_COUNT).focus().select();
} }
} }