add transaction/summary, fix transaction/index, add reception product typeahead
This commit is contained in:
@@ -26,5 +26,7 @@ class ProductSellAsset extends AssetBundle
|
||||
public $depends = [
|
||||
'frontend\assets\AppAsset',
|
||||
'yii\jui\JuiAsset',
|
||||
'common\assets\TypeAheadAsset',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class ProductController extends Controller
|
||||
],
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className(),
|
||||
'only' => [ 'sale','payout-customer-cart','payout-user-cart', 'lookup'],
|
||||
'only' => [ 'sale','payout-customer-cart','payout-user-cart', 'lookup','find'],
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
@@ -82,6 +82,11 @@ class ProductController extends Controller
|
||||
$model->customer = $this->customer;
|
||||
$model->card = $this->card;
|
||||
|
||||
$products = Product::read();
|
||||
$products = Product::modelToMapIdName($products);
|
||||
|
||||
$model->products = $products;
|
||||
|
||||
if (Yii::$app->request->isAjax) {
|
||||
|
||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||
@@ -203,6 +208,23 @@ class ProductController extends Controller
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ class ProductLookupForm extends Model
|
||||
{
|
||||
|
||||
public $filter_text;
|
||||
public $product_search;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,6 +36,7 @@ class ProductLookupForm extends Model
|
||||
{
|
||||
return [
|
||||
'filter_text' => Yii::t('frontend/product','Barcode or product code') ,
|
||||
'product_search' => Yii::t("frontend/product", "Name"),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,8 @@ class ProductSaleForm extends Model
|
||||
|
||||
public $customerCart;
|
||||
|
||||
public $products;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,8 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
|
||||
],
|
||||
] )?>
|
||||
<div class='col-md-12'>
|
||||
<!-- <input type='text' name='product_search' id="product_search" > -->
|
||||
<?php echo $form->field($lookupModel,'product_search')->textInput(['id'=>'product_search']); ?>
|
||||
<?php echo $form->field($lookupModel,'filter_text')->textInput(['id'=>'filter_text']); ?>
|
||||
</div>
|
||||
<?php ActiveForm::end()?>
|
||||
|
||||
@@ -16,8 +16,10 @@ ProductSellAsset::register($this);
|
||||
$options = [];
|
||||
|
||||
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
||||
$options['find_product_url'] = Url::toRoute(['product/find']);
|
||||
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart']);
|
||||
$options['user_cart'] = $userTransfers;
|
||||
$options['products'] = $model->products;
|
||||
if ( isset($model->card) ){
|
||||
$options['url_pay_customer_card'] = Url::toRoute(['product/payout-customer-cart','number' => $model->card->number]);
|
||||
$options['customer_cart'] = $model->customerCart;
|
||||
|
||||
@@ -18,6 +18,7 @@ function ProductSell(o){
|
||||
url_pay_user_cart: '',
|
||||
/** ajax url for lookup service*/
|
||||
lookup_product_url: '',
|
||||
find_product_url: '',
|
||||
/**the id of form*/
|
||||
selector_form: '#product_form',
|
||||
/**form contains error text*/
|
||||
@@ -28,6 +29,7 @@ function ProductSell(o){
|
||||
discounts: [],
|
||||
customer_cart: [],
|
||||
id_account: null,
|
||||
products : [],
|
||||
|
||||
};
|
||||
|
||||
@@ -51,6 +53,8 @@ function ProductSell(o){
|
||||
|
||||
productChanged();
|
||||
addDocumentKeypressedListener();
|
||||
|
||||
initAutocomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +121,7 @@ function ProductSell(o){
|
||||
var word;
|
||||
word = data.word;
|
||||
if ( word.length > 0){
|
||||
if ( word.length >= 6 && word.length <= 8 ){
|
||||
if ( word.length >= 6 && word.length <= 9 ){
|
||||
//lookupuser
|
||||
}else{
|
||||
$("#filter_text").val(data.word);
|
||||
@@ -175,11 +179,20 @@ function ProductSell(o){
|
||||
$( app.defaults.selector_filter_text ).keypress(function( event ) {
|
||||
if ( event.which == 13 ) {
|
||||
event.preventDefault();
|
||||
$('#product_search').val('');
|
||||
$(this).val( fixBarcode($(this).val()));
|
||||
lookupProduct();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fixBarcode(s){
|
||||
var result;
|
||||
result = s;
|
||||
result = result.replace(/ö/g, "0");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**listen for enter key pressed on #productsaleform-count*/
|
||||
function addBehaviorCountEnterPressedListener(){
|
||||
$( '#productsaleform-count' ).keypress(function( event ) {
|
||||
@@ -249,6 +262,22 @@ function ProductSell(o){
|
||||
});
|
||||
}
|
||||
|
||||
function _findProduct(id){
|
||||
var data, url;
|
||||
|
||||
url = app.defaults.find_product_url;
|
||||
data = {
|
||||
'id' : id,
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: url,
|
||||
data: data,
|
||||
success: onLookupProductReady
|
||||
});
|
||||
}
|
||||
|
||||
/**succes event handler after lookup product event*/
|
||||
function onLookupProductReady( data ){
|
||||
app.product = data.product;
|
||||
@@ -278,6 +307,7 @@ function ProductSell(o){
|
||||
$('#productsaleform-id_product').val('');
|
||||
$('#productsaleform-id_account').val( app.defaults.id_account ? app.defaults.id_account : '');
|
||||
$("#productsaleform-count").val(1);
|
||||
//
|
||||
}
|
||||
|
||||
function applyProduct(product){
|
||||
@@ -374,6 +404,7 @@ function ProductSell(o){
|
||||
clearForm();
|
||||
refreshCalculatedValues();
|
||||
$("#filter_text").val('');
|
||||
$("#product_search").val('');
|
||||
setFocus();
|
||||
app.defaults.user_cart = response.transfers;
|
||||
app.defaults.customer_cart = response.customer_cart;
|
||||
@@ -486,7 +517,7 @@ function ProductSell(o){
|
||||
|
||||
function normalizePrice( price ){
|
||||
var result;
|
||||
result = hufRound(price);
|
||||
// result = hufRound(price);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -499,4 +530,44 @@ function ProductSell(o){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function initAutocomplete(){
|
||||
// var colors = ["red", "blue", "green", "yellow", "brown", "black"];
|
||||
// $('#product_search').typeahead( {source: colors } );
|
||||
|
||||
var $input = $('#product_search');
|
||||
$input.typeahead({source: app.defaults.products,
|
||||
autoSelect: true,
|
||||
items: 12,
|
||||
minLength: 3,
|
||||
// displayText: function (item){
|
||||
// return item.
|
||||
// }
|
||||
|
||||
});
|
||||
$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');
|
||||
app.product = null;
|
||||
productChanged();
|
||||
}
|
||||
} else {
|
||||
// Nothing is active so it is a new value (or maybe empty value)
|
||||
console.info('incactive');
|
||||
app.product = null;
|
||||
productChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user