diff --git a/modules/movimenti/actions.php b/modules/movimenti/actions.php index a4b69a518..0ca024854 100644 --- a/modules/movimenti/actions.php +++ b/modules/movimenti/actions.php @@ -12,7 +12,7 @@ switch (post('op')) { $qta = ( post('direzione') == 'Carico manuale' ) ? post('qta') : -post('qta'); if( post('direzione') == 'Carico manuale' ){ - if( $idsede_partenza == 0){ + if( $idsede_partenza == 0 && $idsede_destinazione != 0){ $qta = -post('qta'); } elseif( $idsede_partenza != 0 && $idsede_destinazione == 0){ $qta = post('qta'); @@ -20,7 +20,7 @@ switch (post('op')) { $idsede_destinazione = post('idsede_partenza'); } } else { - if( $idsede_destinazione == 0){ + if( $idsede_partenza != 0 && $idsede_destinazione == 0){ $qta = -post('qta'); $idsede_partenza = post('idsede_destinazione'); $idsede_destinazione = post('idsede_partenza'); diff --git a/modules/movimenti/add.php b/modules/movimenti/add.php index 4f2daae47..06f56ccdf 100644 --- a/modules/movimenti/add.php +++ b/modules/movimenti/add.php @@ -13,7 +13,7 @@ $_SESSION['superselect']['idsede_destinazione'] = 0; ?> -
+ @@ -42,7 +42,7 @@ $_SESSION['superselect']['idsede_destinazione'] = 0;
-
+
{[ "type": "select", "label": "", "name": "idsede_destinazione", "ajax-source": "sedi_azienda", "value": "0", "required":1 ]}
@@ -52,10 +52,10 @@ $_SESSION['superselect']['idsede_destinazione'] = 0;
-
+
- +
@@ -67,21 +67,68 @@ $_SESSION['superselect']['idsede_destinazione'] = 0; }); $('#direzione').trigger('change'); - $('#idarticolo').select2('open'); + + // Lettura codici da lettore barcode + var keys = ''; + + $(document).unbind('keyup'); + + $(document).on('keyup', function (evt) { + if(window.event) { // IE + keynum = evt.keyCode; + } else if(evt.which){ // Netscape/Firefox/Opera + keynum = evt.which; + } + + if (evt.which === 13) { + var search = keys; + + // Ricerca via ajax del barcode negli articoli + $.get( + globals.rootdir + '/ajax_select.php?op=articoli&search='+search, + function(data){ + data = $.parseJSON(data); + + // Articolo trovato + if( data.results.length == 1 ){ + var record = data.results[0].children[0]; + $('#idarticolo').selectSetNew( record.id, record.text ); + ajax_submit( search, record.text ); + } + + // Articolo non trovato + else { + $('#buttons').next('hr').remove(); + $('#buttons').next('div.alert').remove(); + $('#buttons').after( '
Articolo ' + barcode + ' non trovato!
' ); + } + } + ); + keys = ''; + } else { + keys += String.fromCharCode( evt.keyCode ); + } + }); }); - function ajax_submit() { + function ajax_submit( barcode, articolo ) { //Controllo che siano presenti tutti i dati richiesti if( $("#add-form").parsley().validate() ){ submitAjax( $('#add-form'), {}, - function() { - $("#idarticolo").selectReset(); - $("#qta").val(1); - renderMessages(); - }, function(){} + function() {}, + function(){} ); + + $('#buttons').next('hr').remove(); + $('#buttons').next('div.alert').remove(); + + if( barcode != '' || articolo != '' ){ + $('#buttons').after( '
Inserito movimento articolo
' + barcode +'
' + articolo + '!
' ); + } + + $("#qta").val(1); } }