2016-01-04 12:49:26 +01:00
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 < vars . length ; i ++ ) {
var pair = vars [ i ] . split ( "=" ) ;
// If first entry with this name
if ( typeof query _string [ pair [ 0 ] ] === "undefined" ) {
query _string [ pair [ 0 ] ] = pair [ 1 ] ;
// If second entry with this name
} else if ( typeof query _string [ pair [ 0 ] ] === "string" ) {
var arr = [ query _string [ pair [ 0 ] ] , pair [ 1 ] ] ;
query _string [ pair [ 0 ] ] = arr ;
// If third or later entry with this name
} else {
query _string [ pair [ 0 ] ] . push ( pair [ 1 ] ) ;
}
}
return query _string ;
} ( ) ;
function checkPrinting ( ) {
if ( lockPrint ) {
return false ;
}
var productsok = true ;
$ ( "#main table.std tbody tr.grey, #main table.std tbody tr.blocked, #main table.std tbody tr.fed_ship" ) . each ( function ( id , el ) {
if ( parseInt ( $ ( el ) . find ( ".shipped" ) . find ( "input" ) . val ( ) ) != 0 ) {
productsok = false ;
}
} ) ;
if ( ! productsok ) {
prompt ( "Les produits sélectionnés ne font pas partie des ventes actives. Confirmer l\'envoi ?" , function ( ) { $ ( "#button4" ) . attr ( "onclick" , "" ) . trigger ( "click" ) ; } ) ;
} else {
var allok = true ;
$ ( "#main table.std tbody tr:not(.grey):not(.blocked):not(.fed_ship)" ) . each ( function ( id , el ) {
if ( parseInt ( $ ( el ) . find ( ".toship" ) . text ( ) ) > 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 ) {
/ * v a r c a r r i e r s = $ ( e l ) . p a r e n t ( ) . p a r e n t ( ) . a t t r ( " d a t a - c a r r i e r " ) ;
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 : "<a href=\"#\" title=\"Fermer\" class=\"modal-close\">x</a>" ,
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 : "<a href=\"#\" title=\"Fermer\" class=\"modal-close\">x</a>" ,
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 ( ) {
2017-04-18 17:01:00 +02:00
if ( $ ( this ) . attr ( "rel" ) != eanval ) {
return $ ( this ) . attr ( "rel" ) == '0' + eanval ;
}
2016-01-04 12:49:26 +01:00
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 ( "" ) ;
2017-04-18 17:01:00 +02:00
loadOrder ( null , true ) ;
2016-01-04 12:49:26 +01:00
}
}
} ) ;
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 ;
} ) ;