change procurement product selection, keytoggle redirect change

This commit is contained in:
Roland Schneider 2016-03-01 21:18:39 +01:00
parent b07bc4eca9
commit 80b8f5a238
12 changed files with 184 additions and 35 deletions

View File

@ -25,5 +25,7 @@ class ProcurementCreateAsset extends AssetBundle
]; ];
public $depends = [ public $depends = [
'backend\assets\AppAsset', 'backend\assets\AppAsset',
'yii\jui\JuiAsset',
'common\assets\TypeAheadAsset',
]; ];
} }

View File

@ -100,6 +100,9 @@ class ProcurementController extends \backend\controllers\BackendController
$warehouses = Warehouse::read(null); $warehouses = Warehouse::read(null);
$products = Product::find()->all();
$products = Product::modelToMapIdNameLong( $products );
if ( count($warehouses) <= 0 ){ if ( count($warehouses) <= 0 ){
throw new NotFoundHttpException( Yii::t('common/procurement' ,'No active warehouse found.' )); throw new NotFoundHttpException( Yii::t('common/procurement' ,'No active warehouse found.' ));
} }
@ -112,10 +115,10 @@ class ProcurementController extends \backend\controllers\BackendController
try { try {
$product = Product::findOne( $model->id_product ); $product = $model->_product;
$model->stock = $product->stock; $model->stock = $product->stock;
$result = $model->save(false); $result = $model->save(false);
$model->id_account = $product->id_account;
$product->stock = $product->stock + $model->count; $product->stock = $product->stock + $model->count;
$result &= $product->save(false); $result &= $product->save(false);
@ -139,11 +142,17 @@ class ProcurementController extends \backend\controllers\BackendController
return $this->redirect(['index' ]); return $this->redirect(['index' ]);
} }
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
'warehouses' =>$warehouses, 'warehouses' =>$warehouses,
'accounts' => $accounts 'accounts' => $accounts,
'products' => $products
]); ]);
} }
} }
/** /**

View File

@ -28,7 +28,7 @@ class ProductController extends \backend\controllers\BackendController
'rules' => [ 'rules' => [
// allow authenticated users // allow authenticated users
[ [
'actions' => ['create','index','view','update','statistics'], 'actions' => ['create','index','view','update','statistics','find'],
'allow' => true, 'allow' => true,
'roles' => ['admin','employee','reception'], 'roles' => ['admin','employee','reception'],
], ],
@ -39,6 +39,18 @@ 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. * Lists all Product models.
* @return mixed * @return mixed

View File

@ -12,17 +12,20 @@ use yii\helpers\ArrayHelper;
<?php <?php
$warehouseOptions = ArrayHelper::map($warehouses, 'id_warehouse', 'name') ; $warehouseOptions = ArrayHelper::map($warehouses, 'id_warehouse', 'name') ;
$accountsOptions = ArrayHelper::map($accounts, 'id_account', 'name') ; //$accountsOptions = ArrayHelper::map($accounts, 'id_account', 'name') ;
?> ?>
<div class="procurement-form"> <div class="procurement-form">
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?= $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_warehouse')->dropDownList($warehouseOptions) ?>
<?= $form->field($model, 'id_account')->dropDownList($accountsOptions)->label('Kassza') ?> <?php // echo $form->field($model, 'id_account')->dropDownList($accountsOptions)->label('Kassza') ?>
<?= $form->field($model, 'count')->textInput() ?> <?= $form->field($model, 'count')->textInput() ?>

View File

@ -2,6 +2,7 @@
use yii\helpers\Html; use yii\helpers\Html;
use backend\assets\ProcurementCreateAsset; use backend\assets\ProcurementCreateAsset;
use yii\helpers\Url;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
@ -14,13 +15,36 @@ $this->params['breadcrumbs'][] = $this->title;
ProcurementCreateAsset::register($this); 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) .' );');
?> ?>
<div class="procurement-create"> <div class="procurement-create">
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
<div class="row">
<div class="col-md-6">
<table class="table table-striped">
<tr>
<th>Terméknév</th>
<td class="product-name"></td>
</tr>
<tr>
<th>Mennyiség</th>
<td class="product-stock"></td>
</tr>
<tr>
<th>Termék kategória</th>
<td class="product-category"></td>
</tr>
</table>
</div>
</div>
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'warehouses' => $warehouses, 'warehouses' => $warehouses,

View File

@ -4,22 +4,110 @@ function ProcurementCreate(o){
var defaults = { var defaults = {
'selector_product' : '#procurement-productidentifier', 'selector_product' : '#procurement-productidentifier',
'url_product_find' : 'product/find',
"products" : []
}; };
var product = null;
init(); init();
function init(){ function init(){
defaults = $.extend(defaults,o); defaults = $.extend(defaults,o);
console.info(defaults);
addPreventEnterToProduct(); addPreventEnterToProduct();
initAutocomplete();
} }
function addPreventEnterToProduct(){ function addPreventEnterToProduct(){
doPreventSubmit($(defaults.selector_product)); 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();
} }
} }

View File

@ -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 -0.0.45
- add inventory group - add inventory group
- fix contract already exists validator - fix contract already exists validator

View File

@ -4,7 +4,7 @@ return [
'supportEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu', 'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.45', 'version' => 'v0.0.46',
'company' => 'movar',//gyor 'company' => 'movar',//gyor
'company_name' => "Freimann Kft.", 'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global 'product_visiblity' => 'account',// on reception which products to display. account or global

View File

@ -25,6 +25,8 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
public $productIdentifier; public $productIdentifier;
public $id_account; public $id_account;
public $_product;
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -40,11 +42,11 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
{ {
return [ return [
[['id_warehouse', 'count', 'purchase_price' ], 'required'], [['id_warehouse', 'count', 'purchase_price' ], 'required'],
[['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ,'id_account'], 'required' , 'on' => 'create_general'], [['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ], 'required' , 'on' => 'create_general'],
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price','id_account'], 'integer'], [['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price' ], 'integer'],
[['description'], 'string', 'max' => 255], [['description'], 'string', 'max' => 255],
[['productIdentifier'], 'string', 'max' => 128], [['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){ public function validateProduct($attribute,$params){
$product = null; $this->_product = null;
if ( isset($this->productIdentifier)){ if ( isset($this->productIdentifier)){
$name = $this->productIdentifier; $this->_product = Product::findOne($this->id_product);
$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;
}
} }
if ( $product == null ){ if ( $this->_product == null ){
$this->addError('productIdentifier' , Yii::t("common/procurement", "Invalid product")); $this->addError('productIdentifier' , Yii::t("common/procurement", "Invalid product"));
} }

View File

@ -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){ public static function sellProduct($product,$count){
$product->stock = $product->stock - $count; $product->stock = $product->stock - $count;
} }

View File

@ -100,10 +100,12 @@ class KeyController extends Controller
$model->toggleKey(); $model->toggleKey();
} }
if ( isset($model->action ) && $model->action == 'unassign' ){ if ( isset( $model->keyCard ) ){
return $this->redirect(['product/sale', 'number' => $number ]); return $this->redirect(['product/sale', 'number' => $model->keyCard->number ]);
} }
return $this->redirect(['customer/reception', 'number' => $number ]); return $this->redirect(['customer/reception', 'number' => $number ]);
} }

View File

@ -8,6 +8,7 @@ use common\models\CardKeyAssignment;
use common\models\Key; use common\models\Key;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use common\components\Helper; use common\components\Helper;
use common\models\Card;
/** /**
* ContactForm is the model behind the contact form. * ContactForm is the model behind the contact form.
@ -19,7 +20,7 @@ class KeyToggleForm extends Model
public $customer; public $customer;
public $keyModel; public $keyModel;
public $action; public $action;
public $keyCard;
/** /**
@ -55,6 +56,7 @@ class KeyToggleForm extends Model
$this->keyModel = $query->one(); $this->keyModel = $query->one();
if ( isset($this->keyModel) ){ 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(); $assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
if ( count($assignments) > 0){ if ( count($assignments) > 0){
$this->unassign(); $this->unassign();