change procurement product selection, keytoggle redirect change

This commit is contained in:
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 = [
'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);
$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
]);
}
}
/**

View File

@@ -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.

View File

@@ -12,17 +12,20 @@ use yii\helpers\ArrayHelper;
<?php
$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">
<?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_account')->dropDownList($accountsOptions)->label('Kassza') ?>
<?php // echo $form->field($model, 'id_account')->dropDownList($accountsOptions)->label('Kassza') ?>
<?= $form->field($model, 'count')->textInput() ?>

View File

@@ -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) .' );');
?>
<div class="procurement-create">
<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', [
'model' => $model,

View File

@@ -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();
}
}