- = $form->field($model, 'productIdentifier')->textInput()->hint(Yii::t('common/procurement', "Product name, product number or barcode"))->label('Vonalkód vagy termékszám') ?>
+ = $form->field($model, 'productIdentifier')->textInput(['autocomplete' => 'off'])->label('Írja be a termék nevét') ?>
+
+ = $form->field($model, 'id_product')->hiddenInput()->label(false) ?>
+
= $form->field($model, 'id_warehouse')->dropDownList($warehouseOptions) ?>
- = $form->field($model, 'id_account')->dropDownList($accountsOptions)->label('Kassza') ?>
+ field($model, 'id_account')->dropDownList($accountsOptions)->label('Kassza') ?>
= $form->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) .' );');
?>
= Html::encode($this->title) ?>
+
+
+
+
+
+ | Terméknév |
+ |
+
+
+ | Mennyiség |
+ |
+
+
+ | Termék kategória |
+ |
+
+
+
+
= $this->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();