diff --git a/backend/controllers/InventoryItemController.php b/backend/controllers/InventoryItemController.php index 09a52d0..75eba2e 100644 --- a/backend/controllers/InventoryItemController.php +++ b/backend/controllers/InventoryItemController.php @@ -74,8 +74,6 @@ class InventoryItemController extends Controller */ protected function downloadIndexXls($dataProvider) { - - $defs = [['item_created_at', 'Létrehozva'], ['item_name', 'Termék/Termék csoport'], ['user_username', 'Felhasználó'], @@ -227,11 +225,24 @@ class InventoryItemController extends Controller * @throws NotAcceptableHttpException * @throws NotFoundHttpException */ - public function actionUpdateItem($id) + public function actionUpdateItem($idInventory = null,$id = null) { - $model = $this->findModel($id); - $inventory = Inventory::findOne($model->id_inventory); + if ( !isset($idInventory ) && !isset($id)){ + \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()) { @@ -244,6 +255,10 @@ class InventoryItemController extends Controller return json_encode($arr); } 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()) { @@ -256,7 +271,11 @@ class InventoryItemController extends Controller 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("account", "product.id_account = account.id_account") ->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(); @@ -289,9 +308,7 @@ class InventoryItemController extends Controller $products[] = $arr; } - if (!$inventory->isOpen()) { - throw new NotAcceptableHttpException("A leltár elem nem található"); - } + return $this->render("update_item", [ 'model' => $model, diff --git a/backend/views/inventory-item/_form.php b/backend/views/inventory-item/_form.php index a5e53fb..74eb942 100644 --- a/backend/views/inventory-item/_form.php +++ b/backend/views/inventory-item/_form.php @@ -7,19 +7,15 @@ use yii\widgets\ActiveForm; /* @var $model common\models\InventoryItem */ /* @var $form yii\widgets\ActiveForm */ ?> -
- - field($model, 'type')->hiddenInput()->label(false) ?> field($model, 'count')->textInput() ?> - -
+ 'btn btn-success', + 'name'=> '_next' ]) ?> 'btn btn-success' ]) ?>
- -
diff --git a/backend/views/inventory-item/index.php b/backend/views/inventory-item/index.php index 8619897..2a1b17c 100644 --- a/backend/views/inventory-item/index.php +++ b/backend/views/inventory-item/index.php @@ -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( [ 'dataProvider' => $dataProvider, 'columns' => $columns - ]); ?> diff --git a/backend/views/inventory-item/update_item.php b/backend/views/inventory-item/update_item.php index fc4288f..2b50988 100644 --- a/backend/views/inventory-item/update_item.php +++ b/backend/views/inventory-item/update_item.php @@ -7,9 +7,8 @@ use yii\widgets\DetailView; /* @var $model common\models\InventoryItem */ $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' => $model->id_inventory_item, 'url' => ['view', 'id' => $model->id_inventory_item]]; -$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Leltár termék'), 'url' => ['inventory-item/index','id' => $inventory->id_inventory]]; +$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Leltár mennyiség'); \backend\assets\InventoryItemUpdateAsset::register($this); @@ -41,6 +40,9 @@ $this->registerJs('FitnessAdmin.InventoryItem.Update.init( '. json_encode( $opti ], ]) ?> + $inventory->id_inventory ], ['class' => 'btn btn-primary']) ?> + +

Termék keresése a leltárban

'form-control', 'id' => 'product_autocomplete','autocomplete' => 'off']) ?> @@ -48,16 +50,15 @@ $this->registerJs('FitnessAdmin.InventoryItem.Update.init( '. json_encode( $opti -

Termék

- - -
Név
- - - - render('_form', [ - 'model' => $model, - ]) ?> +
+

Termék

+ + +
Név
+ render('_form', [ + 'model' => $model, + ]) ?> +
diff --git a/backend/web/js/inventory,item.update.js b/backend/web/js/inventory,item.update.js index 70a3275..7570d9e 100644 --- a/backend/web/js/inventory,item.update.js +++ b/backend/web/js/inventory,item.update.js @@ -18,10 +18,10 @@ FitnessAdmin.InventoryItem.Update = new function(){ INVENTORY_PRODUCT_NAME: '#inventory_product_name', INVENTORYITEM_TYPE: '#inventoryitem-type', INVENTORYITEM_COUNT: '#inventoryitem-count', - INVENTORY_FORM: '#inventory-form' + INVENTORY_FORM: '#inventory-product' }; - var product = null; + var inventoryItem = null; this.init = function (options) { defaults = $.extend(defaults,options); @@ -37,6 +37,8 @@ FitnessAdmin.InventoryItem.Update = new function(){ $(defaults.selector_product).val(p.name); } } + }else{ + $(_SELECTORS.INVENTORY_FORM).hide(); } $(defaults.selector_product).focus().select(); }; @@ -65,12 +67,12 @@ FitnessAdmin.InventoryItem.Update = new function(){ } else { // 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 - product = null; + inventoryItem = null; renderForm(); } } else { // Nothing is active so it is a new value (or maybe empty value) - product = null; + inventoryItem = null; renderForm(); } }); @@ -78,7 +80,7 @@ FitnessAdmin.InventoryItem.Update = new function(){ var selectInventoryItem = function (data) { console.info('data',data); - product = data; + inventoryItem = data; }; var _findProduct = function (id){ @@ -97,26 +99,28 @@ FitnessAdmin.InventoryItem.Update = new function(){ }; function renderForm( ) { - console.info( "render",product); + console.info( "render",inventoryItem); var name = "",type = "",count = ""; - if ( product){ - name = product.productName; - type = product.type; - if ( product.count ){ - count = product.count; + if ( inventoryItem){ + name = inventoryItem.productName; + type = inventoryItem.type; + if ( inventoryItem.count != null ){ + count = inventoryItem.count; } } $(_SELECTORS.INVENTORY_PRODUCT_NAME).html(name); - $(_SELECTORS.INVENTORYITEM_TYPE).html(type); - $(_SELECTORS.INVENTORYITEM_COUNT).html(count); + $(_SELECTORS.INVENTORYITEM_TYPE).val(type); + $(_SELECTORS.INVENTORYITEM_COUNT).val(count); + var formContainer = $(_SELECTORS.INVENTORY_FORM); var form = $(_SELECTORS.INVENTORY_FORM).find('form'); - if ( product == null ){ - form.hide(); + if ( inventoryItem == null ){ + formContainer.hide(); }else { - form.show(); - form.attr('action', defaults.url_save +"&id="+product.id_inventory_item); + formContainer.show(); + form.attr('action', defaults.url_save +"&id="+inventoryItem.id_inventory_item); + $(_SELECTORS.INVENTORYITEM_COUNT).focus().select(); } }