var f1_pressed = false; var QueryString = function () { // This function is anonymous, is executed immediately and // the return value is assigned to QueryString! var query_string = {}; var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i parseInt($(el).find(".shipped").find("input").val())) { allok = false; } }); if(!allok) { prompt("Les quantités scannées sont inférieures aux quantités à envoyer. Confirmer l\'envoi ?", function() { $("#button4").attr("onclick", "").trigger("click"); }); } else { $("#button4").attr("onclick", "").trigger("click"); } } } function toggleMode(el) { $(el).parent().children("a").toggleClass("active"); $("body").toggleClass("mode_light"); if($("body").hasClass("mode_light")) { if($("#button_form").attr("action").indexOf("&mode=&") == -1) { $("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=normal", "&mode=light")); } else { $("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=", "") + "&mode=light"); } } else { if($("#button_form").attr("action").indexOf("&mode=&") == -1) { $("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=light", "&mode=normal")); } else { $("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=", "") + "&mode=normal"); } } } function checkParcelCarrier(el) { /*var carriers = $(el).parent().parent().attr("data-carrier"); var id_carriers = []; if(carriers != "") { id_carriers = carriers.split(","); } var notfound = 0; var carrier = $("#parcel_carrier").val() == 'laposte'? carriers_laposte: carriers_exapaq; $(id_carriers).each(function(id, el) { if(carrier.indexOf(el) == -1) { notfound++; } }); if(notfound == id_carriers.length) { confirm("Attention, ce produit ne peut pas être expédié avec le transporteur sélectionné"); }*/ } function qtyUp(el, max) { var input = $(el).parent().parent().children("input"); var current_weight = parseFloat($("#weight").val()); if(input.val() + 1 <= max) { $("#weight").val(ps_round(current_weight + parseFloat($(el).parent().parent().parent().attr("data-weight")), 2)); } input.val(Math.min(parseInt(input.val()) + 1, max)); if(parseInt(input.val()) > 0) { $(input).trigger("change"); } changeCarrier(); tryPrintLabel(); } function qtyDown(el) { var input = $(el).parent().parent().children("input"); var current_weight = parseFloat($("#weight").val()); if(input.val() - 1 >= 0) { $("#weight").val(ps_round(Math.max(current_weight - parseFloat($(el).parent().parent().parent().attr("data-weight")), 0), 2)); } input.val(Math.max(parseInt(input.val()) - 1, 0)); if(parseInt(input.val()) > 0) { $(input).trigger("change"); } changeCarrier(); } function confirm(message, callback) { $("#confirm").modal({ closeHTML: "x", position: ["30%",], overlayId: "confirm-overlay", containerId: "confirm-container", onShow: function (dialog) { var modal = this; $(".message", dialog.data[0]).append(message); // if the user clicks "yes" $(".yes", dialog.data[0]).click(function () { // call the callback if ($.isFunction(callback)) { callback.apply(); } // close the dialog modal.close(); // or $.modal.close(); }); } }); } function prompt(message, callback) { $("#prompt").modal({ closeHTML: "x", position: ["30%",], overlayId: "prompt-overlay", containerId: "prompt-container", onShow: function (dialog) { var modal = this; $(".message", dialog.data[0]).append(message); // if the user clicks "yes" $(".yes", dialog.data[0]).click(function () { // call the callback if ($.isFunction(callback)) { callback.apply(); } // close the dialog modal.close(); // or $.modal.close(); }); } }); } function changeCarrier() { if(isRelay == 1) { if($("#parcel_carrier").val() != "laposte") { confirm("Impression bloquée : point de livraison hors domicile non compatible avec ce transporteur"); $("#button4").css("opacity", .2); lockPrint = true; return; } } else if(isRelay == 2) { if($("#parcel_carrier").val() != "exapaq") { confirm("Impression bloquée : point de livraison hors domicile non compatible avec ce transporteur"); $("#button4").css("opacity", .2); lockPrint = true; return; } } $("#button4").css("opacity", 1); lockPrint = false; } function tryPrintLabel() { var toship_sum = 0; $("#button_form table.std tbody tr:not(.grey) .toship strong").each(function(id, el) { toship_sum += parseInt($(el).text()); }); if(toship_sum > 0) { var execprint = true; $("#button_form table.std tbody tr:not(.grey)").each(function(id, el) { if(parseInt($(el).find(".shipped input").val()) < parseInt($(el).find(".toship strong").text())) { execprint = false; } }); if(execprint) { $("#button4").trigger("click"); } } } var ean_timeout = null; function checkEAN() { clearTimeout(ean_timeout); ean_timeout = setTimeout(function() { var eanval = $("#eaninput").val(); if(eanval != "") { var eanval_item = $("#button_form tbody tr").filter(function() { if($(this).attr("rel") != eanval) { return $(this).attr("rel") == '0'+eanval; } return $(this).attr("rel") == eanval; }); if(eanval_item.length > 0) { $(eanval_item).each(function(id, el) { var current_val = parseInt($(el).find(".shipped input").val()); var max_val = parseInt($(el).find(".toship strong").text()); if(current_val < max_val) { qtyUp($(el).find(".shipped a")[0], max_val); } else { confirm("Quantité à envoyer déjà atteinte pour ce produit"); } }); } else { confirm("Aucun produit avec cet EAN13 ne figure dans cette commande"); } $("#eaninput").val(""); } }, 200); } function filterKeys(event) { if(event.keyCode == 13) { event.stopPropagation(); return false; } else if(event.keyCode == 112) { event.stopPropagation(); if(!f1_pressed) { f1_pressed = true; $("#button4").trigger("click"); } return false; } } $(document).ready(function() { if(window.location.hash == "#light" || QueryString.mode == "light") { $("body").toggleClass("mode_light"); } $("#barcodeinput").trigger("focus"); $("#barcodeinput").focus(function() { $(this).attr("placeholder", "En attente du code-barres"); }); $("#barcodeinput").blur(function() { $(this).attr("placeholder", "Cliquez ici et scannez un code-barres"); }); $(document).bind("keydown", "f1", function (evt) { if(!f1_pressed) { f1_pressed = true; $("#button4").trigger("click"); } return false; }); $(document).bind("keydown", "f2", function (evt) { $("#button3").trigger("click"); return false; }); $(document).bind("keydown", "f3", function (evt) { $("#button2").trigger("click"); return false; }); $(document).bind("keydown", "f4", function (evt) { $("#button1").trigger("click"); return false; }); $(document).bind("keydown", "f11", function (evt) { toggleMode($("#main fieldset legend.right a.active")); return false; }); $(document).bind("keydown", "f12", function (evt) { $("#eaninput").focus(); $(document).scrollTop($("#eaninput").position().top - 70); return false; }); $("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f1", function (evt) { if(!f1_pressed) { f1_pressed = true; $("#button4").trigger("click"); } return false; }); $("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f2", function (evt) { $("#button3").trigger("click"); return false; }); $("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f3", function (evt) { $("#button2").trigger("click"); return false; }); $("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f4", function (evt) { $("#button1").trigger("click"); return false; }); $("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f11", function (evt) { toggleMode($("#main fieldset legend.right a.active")); return false; }); $("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f12", function (evt) { $("#eaninput").focus(); $(document).scrollTop($("#eaninput").position().top - 70); return false; }); $("#barcodeinput").keyup(function(event) { if(!(event.keyCode == 112 || event.keyCode == 113 || event.keyCode == 114 || event.keyCode == 115 || event.keyCode == 123)) { $("#manualinput").val(""); if(event.keyCode == 32) { loadOrder(null, true); } } }); $("#manualinput").keyup(function(event) { if(!(event.keyCode == 112 || event.keyCode == 113 || event.keyCode == 114 || event.keyCode == 115 || event.keyCode == 123)) { if (event.keyCode == 13) { $("#barcodeinput").val(""); loadOrder(null, true); } } }); QueryString.id_order? loadOrder(parseInt(QueryString.id_order), false): true; $("#filter_id_sale").multiselect({ selectedList: 7, selectedText: function(numChecked, numTotal, checkedItems){ var seltext = ""; $(checkedItems).each(function(id, el) { seltext += ", " + $(el).parent().text(); }); return (numChecked > 1? "Ventes sélectionnées : ": "Vente sélectionnée : ") + seltext.slice(2); }, checkAllText: "Tout sélectionner", uncheckAllText: "Tout désélectionner", noneSelectedText: "Sélectionnez une ou plusieurs ventes", minWidth: 850 }).multiselectfilter({ label: "Filtrer :", autoReset: false, placeholder: "Entrez un nom ou un ID de vente" }); QueryString.id_order? $("#barcodeinput").focus(): true; });