add transaction/summary, fix transaction/index, add reception product typeahead

This commit is contained in:
2015-12-29 22:22:11 +01:00
parent 3b2f19b909
commit 6eb0e69b1b
20 changed files with 535 additions and 8 deletions

View File

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