From e79187c50e866462de8e19260fe2c652d8dfddca Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 8 Aug 2016 07:41:31 +0200 Subject: [PATCH 1/4] add inventory item fast edit --- backend/assets/InventoryItemUpdateAsset.php | 31 ++ backend/controllers/InventoryController.php | 5 +- .../controllers/InventoryItemController.php | 316 ++++++++++++------ backend/controllers/UgiroController.php | 3 + backend/views/inventory-item/_form.php | 4 +- backend/views/inventory-item/update_item.php | 63 ++++ backend/web/js/inventory,item.update.js | 123 +++++++ backend/web/js/waste.create.js | 5 +- common/models/InventoryItem.php | 2 +- 9 files changed, 433 insertions(+), 119 deletions(-) create mode 100644 backend/assets/InventoryItemUpdateAsset.php create mode 100644 backend/views/inventory-item/update_item.php create mode 100644 backend/web/js/inventory,item.update.js diff --git a/backend/assets/InventoryItemUpdateAsset.php b/backend/assets/InventoryItemUpdateAsset.php new file mode 100644 index 0000000..792649b --- /dev/null +++ b/backend/assets/InventoryItemUpdateAsset.php @@ -0,0 +1,31 @@ + + * @since 2.0 + */ +class InventoryItemUpdateAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/app.js', + 'js/inventory,item.update.js', + ]; + public $depends = [ + 'backend\assets\AppAsset', + 'yii\jui\JuiAsset', + 'common\assets\TypeAheadAsset', + ]; +} diff --git a/backend/controllers/InventoryController.php b/backend/controllers/InventoryController.php index 4b9712e..8167db5 100644 --- a/backend/controllers/InventoryController.php +++ b/backend/controllers/InventoryController.php @@ -2,15 +2,14 @@ namespace backend\controllers; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; use common\models\Inventory; use backend\models\InventorySearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use common\models\User; -use yii\db\Query; -use backend\models\InventoryItemSearch; use common\models\InventoryItem; use common\components\Helper; diff --git a/backend/controllers/InventoryItemController.php b/backend/controllers/InventoryItemController.php index 627898a..09a52d0 100644 --- a/backend/controllers/InventoryItemController.php +++ b/backend/controllers/InventoryItemController.php @@ -2,9 +2,12 @@ namespace backend\controllers; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; use common\models\InventoryItem; use backend\models\InventoryItemSearch; +use yii\base\Exception; +use yii\db\Query; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -33,107 +36,115 @@ class InventoryItemController extends Controller /** * Lists all InventoryItem models. + * @param $id * @return mixed + * @throws NotFoundHttpException */ public function actionIndex($id) { - $inventory = Inventory::findOne($id); - - if ( !isset($inventory)){ - throw new NotFoundHttpException("Leltár nem található"); - } - - $searchModel = new InventoryItemSearch(['inventory' => $inventory]); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - $productOptions = Product::buildProductAndInventoryGroupList(); - - if ($searchModel->output == 'xls') { - $this->downloadIndexXls($dataProvider); - }else{ - Url::remember(Url::current(),"inventory-item-index"); + $inventory = Inventory::findOne($id); + + if (!isset($inventory)) { + throw new NotFoundHttpException("Leltár nem található"); } - + $searchModel = new InventoryItemSearch(['inventory' => $inventory]); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + $productOptions = Product::buildProductAndInventoryGroupList(); + + if ($searchModel->output == 'xls') { + $this->downloadIndexXls($dataProvider); + } else { + Url::remember(Url::current(), "inventory-item-index"); + } + + return $this->render('index', [ - 'model' => $inventory, + 'model' => $inventory, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, - 'productOptions' =>$productOptions + 'productOptions' => $productOptions ]); } - - protected function downloadIndexXls($dataProvider){ - - - $defs = [['item_created_at', 'Létrehozva'], - ['item_name', 'Termék/Termék csoport'], - ['user_username', 'Felhasználó'], - ['item_count_prev', 'Előző leltár (db)'], - ['item_count_sold', 'Eladott mennyiség (db)'], - ['item_count_in', 'Beszerzett mennyiség (db)'], - ['item_count', 'Leltározott mennyiség (db)'], - ['item_difference', 'Különbség (db)'], - ['item_count_system', 'Rendszer szerinti mennyiség (db)'], - ]; - $cols = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P']; - - $models = $dataProvider->getModels (); - $objPHPExcel = new \PHPExcel (); - - $sheet = $objPHPExcel->setActiveSheetIndex ( 0 ); - /** - * Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva - */ - $row = 1; - $col = 0; - foreach ( $defs as $def ) { - $sheet->setCellValue ( $cols [$col] . $row, $def [1] ); - $col ++; - } - - foreach ( $models as $model ) { - $row ++; - $col = 0; - foreach ( $defs as $def ) { - $sheet->setCellValue ( $cols [$col] . $row, $model[$def [0]] ); - $col ++; - } - } - - $styleArray = array ( - 'font' => array ( - 'bold' => true - ) - ); - // 'color' => array('rgb' => 'FF0000'), - // 'size' => 15, - // 'name' => 'Verdana' - - - - foreach ( range ( 'A', 'I' ) as $columnID ) { - $sheet->getColumnDimension ( $columnID )->setAutoSize ( true ); - $sheet->getStyle ( $columnID . '1' )->applyFromArray ( $styleArray ); - } - - // Redirect output to a client’s web browser (Excel5) - header ( 'Content-Type: application/vnd.ms-excel' ); - header ( 'Content-Disposition: attachment;filename="leltar.xls"' ); - header ( 'Cache-Control: max-age=0' ); - // If you're serving to IE 9, then the following may be needed - header ( 'Cache-Control: max-age=1' ); - // If you're serving to IE over SSL, then the following may be needed - header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past - header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified - header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1 - header ( 'Pragma: public' ); // HTTP/1.0 - $objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' ); - $objWriter->save ( 'php://output' ); - exit (); + + /** + * @param $dataProvider + */ + protected function downloadIndexXls($dataProvider) + { + + + $defs = [['item_created_at', 'Létrehozva'], + ['item_name', 'Termék/Termék csoport'], + ['user_username', 'Felhasználó'], + ['item_count_prev', 'Előző leltár (db)'], + ['item_count_sold', 'Eladott mennyiség (db)'], + ['item_count_in', 'Beszerzett mennyiség (db)'], + ['item_count', 'Leltározott mennyiség (db)'], + ['item_difference', 'Különbség (db)'], + ['item_count_system', 'Rendszer szerinti mennyiség (db)'], + ]; + $cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P']; + + /** @noinspection PhpUndefinedMethodInspection */ + $models = $dataProvider->getModels(); + /** @noinspection PhpUndefinedClassInspection */ + $objPHPExcel = new \PHPExcel (); + + $sheet = $objPHPExcel->setActiveSheetIndex(0); + /** + * Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva + */ + $row = 1; + $col = 0; + foreach ($defs as $def) { + $sheet->setCellValue($cols [$col] . $row, $def [1]); + $col++; + } + + foreach ($models as $model) { + $row++; + $col = 0; + foreach ($defs as $def) { + $sheet->setCellValue($cols [$col] . $row, $model[$def [0]]); + $col++; + } + } + + $styleArray = array( + 'font' => array( + 'bold' => true + ) + ); + // 'color' => array('rgb' => 'FF0000'), + // 'size' => 15, + // 'name' => 'Verdana' + + + foreach (range('A', 'I') as $columnID) { + $sheet->getColumnDimension($columnID)->setAutoSize(true); + $sheet->getStyle($columnID . '1')->applyFromArray($styleArray); + } + + // Redirect output to a client’s web browser (Excel5) + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename="leltar.xls"'); + header('Cache-Control: max-age=0'); + // If you're serving to IE 9, then the following may be needed + header('Cache-Control: max-age=1'); + // If you're serving to IE over SSL, then the following may be needed + header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified + header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 + header('Pragma: public'); // HTTP/1.0 + /** @noinspection PhpUndefinedClassInspection */ + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); + $objWriter->save('php://output'); + exit (); } - + /** * Displays a single InventoryItem model. * @param integer $id @@ -149,16 +160,18 @@ class InventoryItemController extends Controller /** * Creates a new InventoryItem model. * If creation is successful, the browser will be redirected to the 'view' page. + * @param Integer $id the item id * @return mixed + * @throws \Exception */ public function actionCreate($id) { $model = new InventoryItemForm([ - 'id_inventory' => $id + 'id_inventory' => $id ]); $model->read(); - + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['inventory-item/index', 'id' => $model->inventory->id_inventory]); } else { @@ -173,38 +186,123 @@ class InventoryItemController extends Controller * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed + * @throws NotAcceptableHttpException + * @throws NotFoundHttpException */ public function actionUpdate($id) { $model = $this->findModel($id); $inventory = Inventory::findOne($model->id_inventory); - - if ( !$inventory->isOpen()){ - throw new NotAcceptableHttpException("A leltár elem nem található"); + + if (!$inventory->isOpen()) { + throw new NotAcceptableHttpException("A leltár elem nem található"); } - + if ($model->load(Yii::$app->request->post()) && $model->validate()) { - - $model->recalculateTotalPriceBrutto(); - - $model->save(false); - - $prev = Url::previous("inventory-item-index"); - - if ( isset($prev)){ - return $this->redirect($prev); - }else{ - return $this->redirect([ 'index', 'id' => $inventory->id_inventory ]); - } - + + $model->recalculateTotalPriceBrutto(); + + $model->save(false); + + $prev = Url::previous("inventory-item-index"); + + if (isset($prev)) { + return $this->redirect($prev); + } else { + return $this->redirect(['index', 'id' => $inventory->id_inventory]); + } + } else { return $this->render('update', [ 'model' => $model, - 'inventory' => $inventory, + 'inventory' => $inventory, ]); } } + /** + * @param integer $id the inventory item id + * @return string + * @throws Exception + * @throws NotAcceptableHttpException + * @throws NotFoundHttpException + */ + public function actionUpdateItem($id) + { + + $model = $this->findModel($id); + $inventory = Inventory::findOne($model->id_inventory); + + + if (Yii::$app->request->getIsAjax()) { + $arr = [ + 'id_inventory_item' => $model->id_inventory_item, + 'productName' => $model->productName, + 'count' => $model->count, + 'type' => $model->type + ]; + + return json_encode($arr); + } else { + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + $model->recalculateTotalPriceBrutto(); + + if ( $model->save(false) ){ + \Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db'); + }else{ + \Yii::error("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]); + + } + + + $query = new Query(); + $query->select([ + 'product.id_product as product_id_product', + 'product.name as product_name', + 'account.name as account_name', + 'product_category.name as product_category_name', + 'inventory_item.id_inventory_item as inventory_item_id_inventory_item', + ]); + $query->from(['product']); + + $query + ->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(); + $productsRaw = $query->all(); + + + $products = []; + foreach ($productsRaw as $product ){ + $arr = []; + $arr['id_inventory_item'] = $product['inventory_item_id_inventory_item']; + $arr['id_product'] = $product['product_id_product']; + $arr['name'] = $product['product_name'] ."( ". $product['account_name'].")"; + $arr['product_name'] = $product['account_name'] ; + $products[] = $arr; + } + + if (!$inventory->isOpen()) { + throw new NotAcceptableHttpException("A leltár elem nem található"); + } + + return $this->render("update_item", [ + 'model' => $model, + 'inventory' => $inventory, + 'products' => $products + ]); + } + + } + + /** * Deletes an existing InventoryItem model. * If deletion is successful, the browser will be redirected to the 'index' page. diff --git a/backend/controllers/UgiroController.php b/backend/controllers/UgiroController.php index dcc9d44..61035da 100644 --- a/backend/controllers/UgiroController.php +++ b/backend/controllers/UgiroController.php @@ -373,14 +373,17 @@ class UgiroController extends Controller { * @return mixed */ public function actionDelete($id) { + $this->findModel ( $id )->delete (); return $this->redirect ( [ 'index' ] ); + } public function actionDetsta() { $ugiro = Ugiro::findOne ( 31 ); + $model = new DetStatProcessor ( [ 'koteg' => $ugiro ] ); diff --git a/backend/views/inventory-item/_form.php b/backend/views/inventory-item/_form.php index e804144..a5e53fb 100644 --- a/backend/views/inventory-item/_form.php +++ b/backend/views/inventory-item/_form.php @@ -8,9 +8,9 @@ use yii\widgets\ActiveForm; /* @var $form yii\widgets\ActiveForm */ ?> -
+
- + field($model, 'type')->hiddenInput()->label(false) ?> field($model, 'count')->textInput() ?> diff --git a/backend/views/inventory-item/update_item.php b/backend/views/inventory-item/update_item.php new file mode 100644 index 0000000..fc4288f --- /dev/null +++ b/backend/views/inventory-item/update_item.php @@ -0,0 +1,63 @@ +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'); + +\backend\assets\InventoryItemUpdateAsset::register($this); + +$options = []; +$options['products'] = $products; +$options['url_find_inventory_item'] = \yii\helpers\Url::toRoute(['inventory-item/update-item']); +$options['url_save'] = \yii\helpers\Url::toRoute(['inventory-item/update-item']); +$options['id_product'] = $model->id_product; + +$this->registerJs('FitnessAdmin.InventoryItem.Update.init( '. json_encode( $options ) .' );'); +?> +
+ +

title) ?>

+ +

Leltár

+ $inventory, + 'attributes' => [ + 'id_inventory', + 'name', + ['attribute'=>'id_user', + 'value'=>$inventory->userName + ], + ['attribute'=>'id_account', + 'value'=>$inventory->accountName + ], + 'created_at:datetime', + ], + ]) ?> + + + + 'form-control', 'id' => 'product_autocomplete','autocomplete' => 'off']) ?> + 'product_id','autocomplete' => 'off']) ?> + + + +

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 new file mode 100644 index 0000000..70a3275 --- /dev/null +++ b/backend/web/js/inventory,item.update.js @@ -0,0 +1,123 @@ +var FitnessAdmin; + +FitnessAdmin = {}; + +FitnessAdmin.InventoryItem = {}; + +FitnessAdmin.InventoryItem.Update = new function(){ + + var defaults = { + 'selector_product' : '#product_autocomplete', + 'url_find_inventory_item' : 'inventory-item/update-item', + "products" : [], + "url_save" : '', + "id_product": null + }; + + var _SELECTORS = { + INVENTORY_PRODUCT_NAME: '#inventory_product_name', + INVENTORYITEM_TYPE: '#inventoryitem-type', + INVENTORYITEM_COUNT: '#inventoryitem-count', + INVENTORY_FORM: '#inventory-form' + }; + + var product = null; + + this.init = function (options) { + defaults = $.extend(defaults,options); + createGUI(); + preselectProduct(); + }; + + var preselectProduct = function () { + if ( defaults.id_product ){ + for (var i = 0; i < defaults.products.length ;i++ ){ + var p = defaults.products[i]; + if ( p.id_product == defaults.id_product){ + $(defaults.selector_product).val(p.name); + } + } + } + $(defaults.selector_product).focus().select(); + }; + + var createGUI = function () { + initAutoComplete(); + }; + + var initAutoComplete = function () { + var $input = $(defaults.selector_product); + $input.typeahead({source : defaults.products, + autoSelect: true, + items: 20, + minLength: 3 + }); + $input.change(function() { + var current = $input.typeahead("getActive"); + $("#filter_text").val(''); + if (current) { + // Some item from your model is active! + if (current.name == $input.val()) { + // This means the exact match is found. Use toLowerCase() if you want case insensitive match. + //noinspection JSUnresolvedVariable + console.info(current); + _findProduct(current.id_inventory_item); + } 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; + renderForm(); + } + } else { + // Nothing is active so it is a new value (or maybe empty value) + product = null; + renderForm(); + } + }); + }; + + var selectInventoryItem = function (data) { + console.info('data',data); + product = data; + }; + + var _findProduct = function (id){ + var data, url; + + url = defaults.url_find_inventory_item; + data = { + 'id' : id + }; + + $.ajax({ + dataType: "json", + url: url, + data: data + }).then(selectInventoryItem).then(renderForm); + }; + + function renderForm( ) { + console.info( "render",product); + var name = "",type = "",count = ""; + if ( product){ + name = product.productName; + type = product.type; + if ( product.count ){ + count = product.count; + } + } + $(_SELECTORS.INVENTORY_PRODUCT_NAME).html(name); + $(_SELECTORS.INVENTORYITEM_TYPE).html(type); + $(_SELECTORS.INVENTORYITEM_COUNT).html(count); + + var form = $(_SELECTORS.INVENTORY_FORM).find('form'); + + if ( product == null ){ + form.hide(); + }else { + form.show(); + form.attr('action', defaults.url_save +"&id="+product.id_inventory_item); + } + } + +}; \ No newline at end of file diff --git a/backend/web/js/waste.create.js b/backend/web/js/waste.create.js index 75a339b..7e4e57f 100644 --- a/backend/web/js/waste.create.js +++ b/backend/web/js/waste.create.js @@ -26,8 +26,6 @@ function WasteCreate(o){ function initAutocomplete(){ -// var colors = ["red", "blue", "green", "yellow", "brown", "black"]; -// $('#product_search').typeahead( {source: colors } ); var $input = $(defaults.selector_product); console.info("len:" + $input.length); @@ -69,10 +67,9 @@ function WasteCreate(o){ function _findProduct(id){ var data, url; - url = defaults.url_product_find; data = { - 'id' : id, + 'id' : id }; $.ajax({ diff --git a/common/models/InventoryItem.php b/common/models/InventoryItem.php index 651d90c..c20442c 100644 --- a/common/models/InventoryItem.php +++ b/common/models/InventoryItem.php @@ -23,11 +23,11 @@ use common\components\ProductAwareBehavior; * @property integer $id_inventory_group * @property integer $id_user * @property integer $id_inventory_item_prev - * @property integer $id_user * @property integer $price_brutto * @property integer $total_price_brutto * @property string $created_at * @property string $updated_at + * @property mixed productName */ class InventoryItem extends BaseFitnessActiveRecord { From c5bfae9ec1ae2c2c6bfcbd5a7d73829be55cd5f5 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 8 Aug 2016 18:46:58 +0200 Subject: [PATCH 2/4] fast inventory item edit --- .../controllers/InventoryItemController.php | 37 +++++++++++++----- backend/views/inventory-item/_form.php | 10 ++--- backend/views/inventory-item/index.php | 15 +++++--- backend/views/inventory-item/update_item.php | 27 ++++++------- backend/web/js/inventory,item.update.js | 38 ++++++++++--------- 5 files changed, 74 insertions(+), 53 deletions(-) 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(); } } From f30acbc7d26cd366e0e2f8bf7dfdf39ecd771f4f Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 8 Aug 2016 18:56:55 +0200 Subject: [PATCH 3/4] add changes --- backend/views/inventory-item/index.php | 296 ++++++++++++------------- 1 file changed, 141 insertions(+), 155 deletions(-) diff --git a/backend/views/inventory-item/index.php b/backend/views/inventory-item/index.php index 2a1b17c..a5b2718 100644 --- a/backend/views/inventory-item/index.php +++ b/backend/views/inventory-item/index.php @@ -9,6 +9,7 @@ use backend\assets\InventoryItemIndexAsset; /* @var $this yii\web\View */ /* @var $searchModel backend\models\InventoryItemSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ +/* @var $model \common\models\Inventory */ $this->title = Yii::t('common/inventory-item', 'Leltár részletei'); $this->params['breadcrumbs'][] = $this->title; @@ -19,177 +20,162 @@ InventoryItemIndexAsset::register($this); $options = []; $options['products'] = $productOptions; -$this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );'); +$this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );'); ?> -
-

title) ?>

- $model, 'attributes' => [ 'id_inventory', - 'name', - ['attribute'=>'id_user', - 'value'=>$model->userName - ], - ['attribute'=>'id_account', - 'value'=>$model->accountName - ], - ['attribute'=>'status', - 'value'=>$model->getStatusHuman(), - 'label' => "Állapot" - ], + 'name', + ['attribute' => 'id_user', + 'value' => $model->userName + ], + ['attribute' => 'id_account', + 'value' => $model->accountName + ], + ['attribute' => 'status', + 'value' => $model->getStatusHuman(), + 'label' => "Állapot" + ], 'created_at:datetime', ], ]) ?> - - isOpen()){ - echo Html::a("Lezárás",['inventory/close' , 'id' => $model->id_inventory ] ,['data-method' =>'post', 'class' => 'btn btn-danger']); - } - ?> - - render('_search', ['model' => $searchModel]); ?> + isOpen()) { + echo Html::a("Lezárás", ['inventory/close', 'id' => $model->id_inventory], ['data-method' => 'post', 'class' => 'btn btn-danger']); + } + ?> + render('_search', ['model' => $searchModel]); ?> +

+ Magyarázat: +

    +
  • + Előző leltár (db): az előző leltárban összeszámolt mennyiség. Ha ez a termék első leltározása akkor 0. +
  • +
  • + Beszerzett mennyiség: Az előző leltár óta történt beszerzett mennyiségek összege +
  • +
  • + Eladott mennyiség: Az előző leltár óta eladott darabszám összege +
  • +
  • + Leltározott mennyiség: A felhasználó által összeszámolt és leltár létrehozásakor beírt mennyiség +
  • +
  • + Rendszer szerinti mennyiség: a rendszer által számolt és aktuális látott mennyiség +
  • +
  • + Különbség: = "Leltározott mennyiség - ( "Előző leltár" + "Beszerzett mennyiség" - "Eladott mennyiség" ) +
  • +
+

+

+ 'xls']), ['class' => 'btn btn-primary']) ?> +

+ 'item_name', + 'label' => 'Név', + + ], + [ + 'attribute' => 'inventory_prev_name', + 'label' => 'Utolsó leltár' + ], + [ + 'attribute' => 'item_count_system', + 'label' => 'Rendszer szerinti mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count', + 'label' => 'Leltározott mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count_prev', + 'label' => 'Előzö leltár (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count_in', + 'label' => 'Beszerzett mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count_sold', + 'label' => 'Eladott mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_difference', + 'label' => 'Különbség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_price_brutto', + 'label' => 'Eladási ár (Ft)', + 'contentOptions' => ['class' => 'numeric'] + ], + [ + 'attribute' => 'item_total_price_brutto', + 'label' => 'Összeg (Ft)', + 'contentOptions' => ['class' => 'numeric'] + ], - -

- Magyarázat: -

    -
  • - Előző leltár (db): az előző leltárban összeszámolt mennyiség. Ha ez a termék első leltározása akkor 0. -
  • -
  • - Beszerzett mennyiség: Az előző leltár óta történt beszerzett mennyiségek összege -
  • -
  • - Eladott mennyiség: Az előző leltár óta eladott darabszám összege -
  • -
  • - Leltározott mennyiség: A felhasználó által összeszámolt és leltár létrehozásakor beírt mennyiség -
  • -
  • - Rendszer szerinti mennyiség: a rendszer által számolt és aktuális látott mennyiség -
  • -
  • - Különbség: = "Leltározott mennyiség - ( "Előző leltár" + "Beszerzett mennyiség" - "Eladott mennyiség" ) -
  • -
-

+ ]; + if ($model->isOpen()) { + $columns[] = ['class' => 'yii\grid\ActionColumn', + 'template' => '{update}', + 'buttons' => [ + 'update' => function ($url) { + return Html::a('Módosítás', $url, ['class' => 'btn btn-xs btn-success', + 'data' => [ + ], + ]); + } + ], + 'urlCreator' => function ($action, $model) { + $result = ""; + if ($action == 'update') { + $result = Url::toRoute(['update-item', 'id' => $model['item_id_inventory_item']]); + } + return $result; + } + ]; + } -

- 'xls']),['class' =>'btn btn-primary'])?> -

- - 'item_name', - 'label' => 'Név', - - ], - [ - 'attribute' => 'inventory_prev_name', - 'label' => 'Utolsó leltár' - ], - [ - 'attribute' => 'item_count_system', - 'label' => 'Rendszer szerinti mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count', - 'label' => 'Leltározott mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count_prev', - 'label' => 'Előzö leltár (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count_in', - 'label' => 'Beszerzett mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count_sold', - 'label' => 'Eladott mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_difference', - 'label' => 'Különbség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_price_brutto', - 'label' => 'Eladási ár (Ft)', - 'contentOptions' => ['class' => 'numeric'] - ], - [ - 'attribute' => 'item_total_price_brutto', - 'label' => 'Összeg (Ft)', - 'contentOptions' => ['class' => 'numeric'] - ], - - - ]; - - if ( $model->isOpen() ){ - - $columns[] = ['class' => 'yii\grid\ActionColumn', - 'template' => '{update}', - 'urlCreator' => function ($action, $model, $key, $index){ - return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ; - }, - 'buttons' =>[ - 'update' =>function ($url, $model, $key) { - return Html::a('Módosítás', $url,['class' => 'btn btn-xs btn-success', - 'data' => [ - ], - ]) ; - } - ], - '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 - ]); - ?> + echo GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => $columns + ]); + ?>
From 2a59952b2d46366f50b1937c68b22f07e8219d2e Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 8 Aug 2016 19:59:24 +0200 Subject: [PATCH 4/4] change version to v.0.0.84 --- changelog.txt | 2 ++ common/config/params.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 71a669a..ffd66e7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,5 @@ +-0.0.84 + - add faster inventory item edit -0.0.83 - add rfid ascii char fix to key save/update -0.0.82 diff --git a/common/config/params.php b/common/config/params.php index 6a1eac3..9e5736b 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -5,7 +5,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.83', + 'version' => 'v0.0.84', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global