From 80b8f5a238bf07db83128078e2364441d0485fd0 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Tue, 1 Mar 2016 21:18:39 +0100 Subject: [PATCH] change procurement product selection, keytoggle redirect change --- backend/assets/ProcurementCreateAsset.php | 2 + backend/controllers/ProcurementController.php | 15 ++- backend/controllers/ProductController.php | 14 ++- backend/views/procurement/_form.php | 9 +- backend/views/procurement/create.php | 26 +++++- backend/web/js/procurement.create.js | 92 ++++++++++++++++++- changelog.txt | 3 + common/config/params.php | 2 +- common/models/Procurement.php | 30 ++---- common/models/Product.php | 16 ++++ frontend/controllers/KeyController.php | 6 +- frontend/models/KeyToggleForm.php | 4 +- 12 files changed, 184 insertions(+), 35 deletions(-) diff --git a/backend/assets/ProcurementCreateAsset.php b/backend/assets/ProcurementCreateAsset.php index bb82517..09484b2 100644 --- a/backend/assets/ProcurementCreateAsset.php +++ b/backend/assets/ProcurementCreateAsset.php @@ -25,5 +25,7 @@ class ProcurementCreateAsset extends AssetBundle ]; public $depends = [ 'backend\assets\AppAsset', + 'yii\jui\JuiAsset', + 'common\assets\TypeAheadAsset', ]; } diff --git a/backend/controllers/ProcurementController.php b/backend/controllers/ProcurementController.php index eee905c..c6e07c2 100644 --- a/backend/controllers/ProcurementController.php +++ b/backend/controllers/ProcurementController.php @@ -100,6 +100,9 @@ class ProcurementController extends \backend\controllers\BackendController $warehouses = Warehouse::read(null); + $products = Product::find()->all(); + $products = Product::modelToMapIdNameLong( $products ); + if ( count($warehouses) <= 0 ){ throw new NotFoundHttpException( Yii::t('common/procurement' ,'No active warehouse found.' )); } @@ -112,10 +115,10 @@ class ProcurementController extends \backend\controllers\BackendController try { - $product = Product::findOne( $model->id_product ); + $product = $model->_product; $model->stock = $product->stock; $result = $model->save(false); - + $model->id_account = $product->id_account; $product->stock = $product->stock + $model->count; $result &= $product->save(false); @@ -139,11 +142,17 @@ class ProcurementController extends \backend\controllers\BackendController return $this->redirect(['index' ]); } } else { + + + return $this->render('create', [ 'model' => $model, 'warehouses' =>$warehouses, - 'accounts' => $accounts + 'accounts' => $accounts, + 'products' => $products ]); + + } } /** diff --git a/backend/controllers/ProductController.php b/backend/controllers/ProductController.php index 6b13e6a..9a072cc 100644 --- a/backend/controllers/ProductController.php +++ b/backend/controllers/ProductController.php @@ -28,7 +28,7 @@ class ProductController extends \backend\controllers\BackendController 'rules' => [ // allow authenticated users [ - 'actions' => ['create','index','view','update','statistics'], + 'actions' => ['create','index','view','update','statistics','find'], 'allow' => true, 'roles' => ['admin','employee','reception'], ], @@ -37,7 +37,19 @@ class ProductController extends \backend\controllers\BackendController ], ]; } + + public function actionFind($id = null) { + $result = [ ]; + $product = Product::findOne ( $id ); + $product = Product::modelToArray ( $product ); + + $result ['product'] = $product; + + \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + + return $result; + } /** * Lists all Product models. diff --git a/backend/views/procurement/_form.php b/backend/views/procurement/_form.php index 8df1a3c..faea914 100644 --- a/backend/views/procurement/_form.php +++ b/backend/views/procurement/_form.php @@ -12,17 +12,20 @@ use yii\helpers\ArrayHelper;
- field($model, 'productIdentifier')->textInput()->hint(Yii::t('common/procurement', "Product name, product number or barcode"))->label('Vonalkód vagy termékszám') ?> + field($model, 'productIdentifier')->textInput(['autocomplete' => 'off'])->label('Írja be a termék nevét') ?> + + field($model, 'id_product')->hiddenInput()->label(false) ?> + field($model, 'id_warehouse')->dropDownList($warehouseOptions) ?> - field($model, 'id_account')->dropDownList($accountsOptions)->label('Kassza') ?> + field($model, 'id_account')->dropDownList($accountsOptions)->label('Kassza') ?> field($model, 'count')->textInput() ?> diff --git a/backend/views/procurement/create.php b/backend/views/procurement/create.php index adec3e6..745cb57 100644 --- a/backend/views/procurement/create.php +++ b/backend/views/procurement/create.php @@ -2,6 +2,7 @@ use yii\helpers\Html; use backend\assets\ProcurementCreateAsset; +use yii\helpers\Url; /* @var $this yii\web\View */ @@ -14,12 +15,35 @@ $this->params['breadcrumbs'][] = $this->title; ProcurementCreateAsset::register($this); -$this->registerJs(' new ProcurementCreate( { } );'); +$options = []; +$options['products'] = $products; +$options['url_product_find'] = Url::toRoute(['product/find']); + +$this->registerJs(' new ProcurementCreate( '. json_encode($options) .' );'); ?>

title) ?>

+ +
+
+ + + + + + + + + + + + + +
Terméknév
Mennyiség
Termék kategória
+
+
render('_form', [ 'model' => $model, diff --git a/backend/web/js/procurement.create.js b/backend/web/js/procurement.create.js index 64f11ba..64d5619 100644 --- a/backend/web/js/procurement.create.js +++ b/backend/web/js/procurement.create.js @@ -4,22 +4,110 @@ function ProcurementCreate(o){ var defaults = { 'selector_product' : '#procurement-productidentifier', + 'url_product_find' : 'product/find', + "products" : [] }; + var product = null; + init(); function init(){ defaults = $.extend(defaults,o); - console.info(defaults); addPreventEnterToProduct(); + initAutocomplete(); } function addPreventEnterToProduct(){ doPreventSubmit($(defaults.selector_product)); - console.info('event handler added'); + } + + + function initAutocomplete(){ +// var colors = ["red", "blue", "green", "yellow", "brown", "black"]; +// $('#product_search').typeahead( {source: colors } ); + + var $input = $('#procurement-productidentifier'); + console.info("len:" + $input.length); + console.info('products: ' + defaults.products.length); + $input.typeahead({source : defaults.products, + autoSelect: true, + items: 20, + minLength: 3, +// displayText: function (item){ +// return item.text; +// } + + }); + $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. +// console.info(current); + _findProduct(current.id_product); + } 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 +// console.info('partial'); + product = null; + updateTableProduct(); + } + } else { + // Nothing is active so it is a new value (or maybe empty value) +// console.info('incactive'); + product = null; + updateTableProduct(); + } + }); + } + + + function _findProduct(id){ + var data, url; + + url = defaults.url_product_find; + data = { + 'id' : id, + }; + + $.ajax({ + dataType: "json", + url: url, + data: data, + success: onFindProductReady + }); + } + + function clearTableProduct(){ + $('.product-name').html(''); + $('.product-stock').html(''); + $('.product-category').html(''); + $('#procurement-id_product').val(''); + } + + function fillTableProduct(){ + $('.product-name').html(product.name); + $('.product-stock').html(product.stock); + $('.product-category').html(product.category); + $('#procurement-id_product').val(product.id_product); + } + + function updateTableProduct(){ + clearTableProduct(); + fillTableProduct(); + } + + + function onFindProductReady(json){ + product = json.product; + fillTableProduct(); } + } \ No newline at end of file diff --git a/changelog.txt b/changelog.txt index 15c3b54..c88a3a8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +-0.0.46 + - procurement ( beszerzés ) termék lista vonalkód helyett + - kulcs ki/be átirányítás változás -0.0.45 - add inventory group - fix contract already exists validator diff --git a/common/config/params.php b/common/config/params.php index e75efd0..d1c0e83 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -4,7 +4,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.45', + 'version' => 'v0.0.46', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global diff --git a/common/models/Procurement.php b/common/models/Procurement.php index 8a7add7..2a4e712 100644 --- a/common/models/Procurement.php +++ b/common/models/Procurement.php @@ -25,6 +25,8 @@ class Procurement extends \common\models\BaseFitnessActiveRecord public $productIdentifier; public $id_account; + public $_product; + /** * @inheritdoc */ @@ -40,11 +42,11 @@ class Procurement extends \common\models\BaseFitnessActiveRecord { return [ [['id_warehouse', 'count', 'purchase_price' ], 'required'], - [['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ,'id_account'], 'required' , 'on' => 'create_general'], - [['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price','id_account'], 'integer'], + [['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ], 'required' , 'on' => 'create_general'], + [['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price' ], 'integer'], [['description'], 'string', 'max' => 255], [['productIdentifier'], 'string', 'max' => 128], - [['productIdentifier'] ,'validateProductIdentifier', 'on' => 'create_general'] + [['id_product'] ,'validateProduct', 'on' => 'create_general','skipOnEmpty' => false, 'skipOnError' => false] ]; } @@ -68,28 +70,14 @@ class Procurement extends \common\models\BaseFitnessActiveRecord } - public function validateProductIdentifier($attribute,$params){ - $product = null; + public function validateProduct($attribute,$params){ + $this->_product = null; if ( isset($this->productIdentifier)){ - $name = $this->productIdentifier; - $id = Helper::fixAsciiChars( $this->productIdentifier ); -// $conditionProductName = ['name' =>$id]; - $conditionProductNumber = ['product_number' =>$id]; - $conditionBarcode= ['barcode' =>$id]; - $query = Product::find() - ->andWhere(['or', ['product_number' =>$id] ,['barcode' =>$id] ] ); - if ( Helper::isProductVisibilityAccount() ){ - $query->andWhere(['id_account' => $this->id_account]); - } - $products = $query->all(); - if ( count($products) == 1 ){ - $product = $products[0]; - $this->id_product = $product->id_product; - } + $this->_product = Product::findOne($this->id_product); } - if ( $product == null ){ + if ( $this->_product == null ){ $this->addError('productIdentifier' , Yii::t("common/procurement", "Invalid product")); } diff --git a/common/models/Product.php b/common/models/Product.php index 927787a..4618d14 100644 --- a/common/models/Product.php +++ b/common/models/Product.php @@ -244,6 +244,22 @@ class Product extends \common\models\BaseFitnessActiveRecord { ]); } + public static function modelToMapIdNameLong($product,$default = null){ + + if ( $product == null ){ + return $default; + } + + return ArrayHelper::toArray($product, [ + 'common\models\Product' => [ + 'id_product', + 'name' => function ($product) { + return $product->name . " - " .$product->productCategoryName . " (" . $product->accountName . ")"; + }, + ], + ]); + } + public static function sellProduct($product,$count){ $product->stock = $product->stock - $count; } diff --git a/frontend/controllers/KeyController.php b/frontend/controllers/KeyController.php index a4948aa..a9eb5bf 100644 --- a/frontend/controllers/KeyController.php +++ b/frontend/controllers/KeyController.php @@ -100,10 +100,12 @@ class KeyController extends Controller $model->toggleKey(); } - if ( isset($model->action ) && $model->action == 'unassign' ){ - return $this->redirect(['product/sale', 'number' => $number ]); + if ( isset( $model->keyCard ) ){ + return $this->redirect(['product/sale', 'number' => $model->keyCard->number ]); } + + return $this->redirect(['customer/reception', 'number' => $number ]); } diff --git a/frontend/models/KeyToggleForm.php b/frontend/models/KeyToggleForm.php index 67da92f..6e7d59b 100644 --- a/frontend/models/KeyToggleForm.php +++ b/frontend/models/KeyToggleForm.php @@ -8,6 +8,7 @@ use common\models\CardKeyAssignment; use common\models\Key; use yii\helpers\ArrayHelper; use common\components\Helper; +use common\models\Card; /** * ContactForm is the model behind the contact form. @@ -19,7 +20,7 @@ class KeyToggleForm extends Model public $customer; public $keyModel; public $action; - + public $keyCard; /** @@ -55,6 +56,7 @@ class KeyToggleForm extends Model $this->keyModel = $query->one(); if ( isset($this->keyModel) ){ + $this->keyCard = Card::find()->innerJoin('card_key_assignment','card.id_card = card_key_assignment.id_card')->andWhere('card_key_assignment.id_key = ' .$this->keyModel->id_key)->one(); $assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all(); if ( count($assignments) > 0){ $this->unassign();