<script class='controller'>
    setTimeout(function() {

        /*           ACTUALIZAR CONTADORES               */
        $(document).off('click', "#updateCharts");
        $(document).on('click', '#updateCharts', function(e) {
            var userIntel = JSON.parse(window.localStorage.getItem("userIntel")),
                panelToShow = userIntel.panelUsuario,
                userId = $('#sidebarLoaded').attr('userIdPanel');
            $("#loading").fadeIn("fast", function() {
                showPanel(panelToShow, userId);
            });
        });
		
		$(document).on('click', '#ChangeCant',function(){
		  var valor = $('.unidXDevolver').val();
		  var valor2 = $(document).find('.unidXDevolver').val();
		  alert("Valor ingresado: "+ valor2);
		  $(document).find('.thisCantAcum').val(valor2);
		  $(document).find('.thisCantAcum').html(valor2);
		});
		
		
        /** CUANDO INICIA EL MODULO CARGAMOS LAS PRIMERAS TARJETAS */
        $('.anim1').velocity("transition.slideUpBigIn", {
            stagger: 250,
            complete: function() {
                $('#buscarDevol').focus();
            }
        });

        /** BUSCAMOS LA ORDEN DE DEVOLUCION POR EL BOTON O POR LA PISTOLA */
        $(document).off('click', ".buscarDevolBox button");
        $(document).on('click', '.buscarDevolBox button', function(e) {

            var devolVal = $(document).find('#buscarDevol').val();
            if (devolVal == '') {
                $.growl.error({
                    message: "Debe ingresar el codigo de la Orden"
                });
                return;
            }
            getThisDevol();
        });
        $(document).find('#buscarDevol').keypress(function(e) {
            if (e.which == 13) {

                var devolVal = $(document).find('#buscarDevol').val();
                if (devolVal == '') {
                    $.growl.error({
                        message: "Debe ingresar el codigo de la Orden"
                    });
                    return;
                }
                getThisDevol();
            }
        });

        /** LE RESTAMOS 1 UNIDAD AL LISTADO SELECCIONADO */
        $(document).off('click', ".restarUnidad");
        $(document).on('click', '.restarUnidad', function(e) {

            var codigoBarrasDevuelto = $(this).parent().parent().parent().find('.codigoBarrasDevuelto').html(),
                unidTotales = $(this).parent().parent().parent().find('.unidTotales').html(),
                unidXDevolver = $(this).parent().parent().parent().find('.unidXDevolver').html();

            unidXDevolver--;
            if (unidXDevolver == 0) {
                $(this).parent().parent().parent().parent().remove();
                return;
            }
            var newPropor = (+unidXDevolver * 100) / +unidTotales
            $(this).parent().parent().parent().find('.unidXDevolver').html(unidXDevolver);
            $(this).parent().parent().parent().find('.unidXDevolverPropor').attr('style', 'width: ' + newPropor.toFixed(0) + '%');
        });

        /** ELIMINAMOS EL LISTADO SELECCIONADO */
        $(document).off('click', ".eliminarUnidades");
        $(document).on('click', '.eliminarUnidades', function(e) {
            var codigoBarrasDevuelto = $(this).parent().parent().parent().find('.codigoBarrasDevuelto').html(),
                unidTotales = $(this).parent().parent().parent().find('.unidTotales').html(),
                isListed = 0,
                unidXDevolver = $(this).parent().parent().parent().find('.unidXDevolver').html();

            $(document).find('.listadoDevol tbody tr').each(function(i, n) {
                var codbarras = $(n).find('.codigoBarras').html();

                if (codbarras == codigoBarrasDevuelto && isListed == 0) {
                    isListed = 1;
                    $(n).find('.unidadesLeidas').html('0');
                    $(n).removeClass('fullyReadPicki');
                    $(n).slideDown('slow');
                }

            });

            var totalEscan = $('.unidadesEscaenadasTotal span').html();
            totalEscan = +totalEscan - +unidXDevolver;
            $('.unidadesEscaenadasTotal span').html(totalEscan);

            $(this).parent().parent().parent().parent().remove();
            return;
        });

        /** GUARDAMOS LA  DEVOLUCION */
        $(document).off('click', "#saveNewDevol");
        $(document).on('click', '#saveNewDevol', function(e) {
			
			alert("Accion iniciada");

            var rowsCount = 0,
                devoldetail = [],
                userId = $('#sidebarLoaded').attr('userIdPanel'),
                locationBox = $('#locationBox').val();

            if (locationBox == '') {
                $.growl.error({
                    message: "Debe ingresar la ubicacion"
                });
                return;
            }
			//var idtransaccion = userId + locationBox + new Date();
			var idtransaccion = (Date.now());
            //idtransaccion = Math.abs(idtransaccion.hashCode());
            $(document).find('.porDevolInfoBox').each(function(i, n) {
                $(n).find('.thisReadDevol tbody tr').each(function(ii, nn) {

                    var devolRow = {};
                    devolRow.codarticulo = $(nn).find('.codarticuloRead').html();
                    devolRow.talla = $(nn).find('.tallaRead').html();
                    devolRow.color = $(nn).find('.colorRead').html();
                    devolRow.oldquantity = $(nn).find('.oldquantityRead').html();
                    devolRow.type = '2';
                    devolRow.barcode = $(nn).find('.barcodeRead').html();
                    devolRow.returnquantity = $(nn).find('.thisCantAcum').html();
                    devolRow.cajamas = $(nn).find('.cajMasRead').html();
                    devolRow.ubi = locationBox;
                    devolRow.doc = $(nn).find('.docRead').html();
                    devolRow.usuario = userId;
                    devolRow.carrito = '0';
					devolRow.idtransaccion = idtransaccion;
                    devolRow.idlinea = rowsCount;

                    devoldetail.push(devolRow);

                    rowsCount++;
                });
            });
			alert("Documento preparado");
            if (rowsCount > 0) {

                $(this).velocity("transition.slideUpOut", {
                    duration: 200,
                    complete: function() {
                        $('#saveNewDevolFake').velocity("transition.slideUpIn", {
                            duration: 200,
                            complete: function() {
                                var formData = new FormData(),
                                    userId = $('#sidebarLoaded').attr('userIdPanel');
                                formData.append('userDevol', userId);
                                formData.append('devol', JSON.stringify(devoldetail));
                                formData.append('meth', 'saveNewReceps');
                                apiCall(formData, function(data) {
									alert("Metodos invocados");
                                    console.log(data);
                                    if (data.status == "saved") {
                                        $('.anim3,.porDevolInfoBox,#saveNewDevolFake').velocity("transition.slideUpOut", {
                                            duration: 200,
                                            complete: function() {
                                                swal({
                                                    title: "Felicitaciones",
                                                    text: "Su Recepcion ha sido registrada exitosamente.",
                                                    type: "success",
                                                    showCancelButton: false,
                                                    confirmButtonText: 'Entendido',
                                                    cancelButtonText: 'salir'
                                                });
                                                $('.porDevolInfoBox').remove();
                                                $('.anim11,#saveNewDevol').velocity("transition.slideUpIn", {
                                                    duration: 200
                                                })
                                            }
                                        });
                                    } else {
                                        $('#saveNewDevolFake').velocity("transition.slideUpOut", {
                                            duration: 200,
                                            complete: function() {
                                                swal({
                                                    title: "Lo Sentimos",
                                                    text: "Hubo un problema para guardar sus datos, intente de nuevo",
                                                    type: "error",
                                                    showCancelButton: false,
                                                    confirmButtonText: 'Entendido',
                                                    cancelButtonText: 'salir'
                                                });
                                                $('#saveNewDevol').velocity("transition.slideUpIn", {
                                                    duration: 200
                                                })
                                            }
                                        });
                                    }
                                });

                            }
                        });
                    }
                });
            } else {
                $.growl.error({
                    message: "No hay productos leidos para recibir"
                });
            }

        });

        /** CONSULTAMOS LA UBICAION */
        $(document).off('change', "#locationBox");
        $(document).on('change', "#locationBox", function(e) {
            var formData = new FormData(),
                codUbi = $(document).find('#locationBox').val();
            formData.append('codUbi', codUbi);
            formData.append('meth', 'consultarUbic');
            apiCall(formData, function(data) {
                console.log(data);
                if (data.status == "gotProd") {
                    $(document).find('#saveNewDevol').removeAttr('disabled');
                } else {
                    $.growl.error({
                        message: "Codigo de Ubicacion no existe en el sistema ",
                        duration: 6000
                    });
                    $(document).find('#locationBox').val('');
                    $(document).find('#locationBox').focus();
                }
            });
        });

        $(document).find('#saveNewDevol').attr('disabled', 'disabled');
        enterSubm();
    }, 1000);

    /** OBTENEMOS LOS DATOS DE LA ORDEN DE DEVOLUCION */
    function getThisDevol() {
        $('.searchingBtn').html('<i class="fa fa-spinner fa-spin"></i>');
        var devolVal = $(document).find('#buscarDevol').val(),
            formData = new FormData();
        formData.append('devolVal', devolVal);
        formData.append('meth', 'consultarReceps');
        apiCall(formData, function(data) {
            $('.searchingBtn').html('<i class="fa fa-search"></i>');
            var resp = JSON.parse(data.resp.GetReturnOrdenByNumberResult);
            console.log(resp);
            console.log(resp.pedidoList.length);
            if (resp.pedidoList.length > 0) {
                $('.anim3').velocity("transition.slideUpBigOut", {
                    duration: 200,
                    complete: function() {
                        var code = '';
                        $('.listadoDevol tbody').html(code);
                        $('.ordenTitleNumbr').html(devolVal);
                        for (i = 0; i < resp.pedidoList.length; i++) {
                            $('.listadoDevol tbody').append(' <tr class="thisDevolProd">' +
                                '<td class="codArticulo" data-valtype="codArticulo">' + resp.pedidoList[i].codArticulo + '</td>' +
                                '<td class="codigoBarras" data-valtype="codigoBarras">' + resp.pedidoList[i].codigoBarras + '</td> ' +
                                '<td class="descricion" data-valtype="descricion">' + resp.pedidoList[i].descricion + '</td> ' +
                                '<td class="referencia" data-valtype="referencia">' + resp.pedidoList[i].referencia + '</td> ' +
                                '<td class="unidadesTotales" data-valtype="unidadesTotales">' + resp.pedidoList[i].unidadesTotales + '</td> ' +
                                '<td class="unidadesLeidas" data-valtype="unidadesLeidas">0</td> ' +
                                '<td class="offscreen talla" data-valtype="talla">' + resp.pedidoList[i].talla + '</td> ' +
                                '<td class="offscreen color" data-valtype="color">' + resp.pedidoList[i].color + '</td> ' +
                                '<td class="offscreen suPedido" data-valtype="suPedido">' + resp.pedidoList[i].suPedido + '</td> ' +
								'<td class="cb2" data-valtype="cb2">' + resp.pedidoList[i].cb2 + '</td> ' +
								'<td class="cBar3" data-valtype="cBar3">' + resp.pedidoList[i].cBar3 + '</td> ' +
                                ' </tr>');
                            console.log(resp.pedidoList[i]);
                        }
                        $('.anim11').velocity("transition.slideUpBigOut", {
                            stagger: 250,
                            complete: function() {
                                $('.anim3').velocity("transition.slideUpBigIn", {
                                    stagger: 250,
                                    complete: function() {
                                        $('#cajamasterBox').focus();
                                    }
                                });
                            }
                        });
                    }
                });
            } else {
                $.growl.error({
                    message: "No existen documentos por procesar"
                });
                return;}
        });}
 /** AL LEER CON PISTOLA UN CODIGO DE BARRA */
    function getThisProd() {
        var codbar = $(document).find('#productoBox').val(),
            locatRead = $(document).find('#locationBox').val(),
            cajMasRead = $(document).find('#cajamasterBox').val(),
            isInvoked = 0,
            isListed = 0,
            isPresent = 0;
        $(document).find('.listadoDevol tbody tr').not('.fullyReadPicki').each(function(i, n) {
            var codigoBarras = $(n).find('.codigoBarras').html(),
			cb2 = $(n).find('.cb2').html(),
		    cBar3 = $(n).find('.cBar3').html(),
                codarticuloRead = $(n).find('.codArticulo').html(),
                tallaRead = $(n).find('.talla').html(),
                colorRead = $(n).find('.color').html(),
                docRead = $(n).find('.suPedido').html(),
                totalUnidades = $(n).find('.unidadesTotales').html();

            if ((codigoBarras == codbar) || (cb2 == codbar) || (cBar3 == codbar) ) {
				
				//if ((codigoBarras == codbar) || (cb2 == codbar) || (cBar3 == codbar) ) {
                isPresent = 1;
                $(document).find('.porDevolInfoBox').not('.fullyReadPicki').each(function(ii, nn) {
                    var codigoBarrasDevuelto = $(nn).find('.codigoBarrasDevuelto').html();
                    if (codigoBarras == codigoBarrasDevuelto) {
                        isInvoked = 1;
                        var unidXDevolver = $(nn).find('.unidXDevolver').html();
                        if (+unidXDevolver < +totalUnidades) {
                            unidXDevolver++;
                            var newPropor = (+unidXDevolver * 100) / +totalUnidades
                            $(nn).find('.unidXDevolver').html(unidXDevolver);
                            $(nn).find('.unidXDevolverPropor').attr('style', 'width: ' + newPropor.toFixed(0) + '%');
                            if (+unidXDevolver == +totalUnidades) {
                                $(nn).find('.card').addClass('bg-info text-white');
                                $(n).addClass('fullyReadPicki');
                                $(n).slideUp('slow');
                            }
                            $(nn).find('.thisReadDevol tbody tr').each(function(iii, nnn) {
                                var thisLocation = $(nnn).find('.locatRead').html(),
                                    thisCajaMas = $(nnn).find('.cajMasRead').html(),
                                    thisCant = $(nnn).find('.thisCantAcum').html();
                                if (thisLocation == locatRead && thisCajaMas == cajMasRead) {
                                    isListed = 1;
                                    thisCant++;
                                    $(nnn).find('.thisCantAcum').html(thisCant);
                                }
                            });
                            if (isListed == 0) {
                                var listThis = `
                                            <tr>
                                                <td class="offscreen text-dark locatRead text-center">` + locatRead + `</td>
                                                <td class="text-dark cajMasRead text-center">` + cajMasRead + `</td>
                                                <td class="text-dark thisCantAcum text-center">1</td>
                                                <td class="offscreen codarticuloRead text-center">` + codarticuloRead + `</td>
                                                <td class="offscreen tallaRead text-center">` + tallaRead + `</td>
                                                <td class="offscreen colorRead text-center">` + colorRead + `</td>
                                                <td class="offscreen oldquantityRead text-center">` + totalUnidades + `</td>
                                                <td class="offscreen barcodeRead text-center">` + codigoBarras + `</td>
                                                <td class="offscreen docRead text-center">` + docRead + `</td>
                                            </tr>
                                            `;
                                $(nn).find('.thisReadDevol tbody').append(listThis);

                            }
                            var totalEscan = $('.unidadesEscaenadasTotal span').html();
                            totalEscan++;
                            $('.unidadesEscaenadasTotal span').html(totalEscan);
                        } else {
                            $.growl.error({
                                message: "No puedes exceder el límite de la Orden"
                            });
                        }
                    }
                });
                if (isInvoked == 0) {

                    fullCard = '';
                    if (totalUnidades == 1) {
                        fullCard = 'bg-info text-white';
                        $(n).addClass('fullyReadPicki');
                        $(n).slideUp('slow');
                    }
                    var newPropor = 100 / +totalUnidades
                    var invoke = `
                        <div class="col-sm-12 col-lg-12 col-xl-6 porDevolInfoBox">
                            <div class="card anim cod_` + codigoBarras + `  ` + fullCard + `">
                                <div class="card-header">
                                    <div class="card-title"><i class="fa fa-barcode "></i> <strong class=" codigoBarrasDevuelto">` + codigoBarras + `</strong></div>
                                    <div class="card-options ">
                                        <span class="btn btn-info mr30 float-left restarUnidad"><i class="fa fa-minus"></i> </span>
                                        <span class="btn btn-join text-white float-left pull-left mr10 eliminarUnidades"><i class="fa fa-times  "></i> </span>
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <table class="table table-bordered border-top card-table table-vcenter text-nowrap table-primary thisReadDevol">
                                        <thead class="bg-info text-white text-center">
                                            <tr>
                                                <th class="text-white offscreen">Ubicacion</th>
                                                <th class="text-white">Caja Master</th>
                                                <th class="text-white">Cantidad</th>
                                                <th class="offscreen">codarticulo</th>
                                                <th class="offscreen">talla</th>
                                                <th class="offscreen">color</th>
                                                <th class="offscreen">oldquantity</th>
                                                <th class="offscreen">barcode</th>
                                                <th class="offscreen">doc</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td class="text-dark locatRead text-center offscreen">` + locatRead + `</td>
                                                <td class="text-dark cajMasRead text-center">` + cajMasRead + `</td>
                                                <td class="text-dark thisCantAcum text-center" >1</td>
                                                <td class="offscreen codarticuloRead text-center">` + codarticuloRead + `</td>
                                                <td class="offscreen tallaRead text-center">` + tallaRead + `</td>
                                                <td class="offscreen colorRead text-center">` + colorRead + `</td>
                                                <td class="offscreen oldquantityRead text-center">` + totalUnidades + `</td>
                                                <td class="offscreen barcodeRead text-center">` + codigoBarras + `</td>
                                                <td class="offscreen docRead text-center">` + docRead + `</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <div class="offscreen "></div>
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col text-center">
                                            <label class="tx-12">Unidades Totales</label>
                                            <h2 class="font-weight-normal unidTotales">` + totalUnidades + `</h2>
                                        </div>
                                        <div class="col border-left text-center">
                                            <label class="tx-12">Unidades leídas</label>
                                            <input type="number" class="font-weight-normal unidXDevolver" style = "text-align: center;"><button id= "ChangeCant"><i class="fa fa-check" aria-hidden="true"></i></button>
                                        </div>
                                    </div>
                                    <div class="progress mt-4">
                                        <div class="progress-bar progress-bar-striped progress-bar-animated bg-join unidXDevolverPropor" style="width: ` + newPropor + `%"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        `;

                    var totalEscan = $('.unidadesEscaenadasTotal span').html();
                    totalEscan++;
                    $('.unidadesEscaenadasTotal span').html(totalEscan);

                    $(invoke).insertAfter('.readerPistolBox');
                    $('.cod_' + codigoBarras).velocity("transition.slideUpBigIn", {
                        stagger: 250
                    });
                }
            }
        });
        if (isPresent == 0) {

            var docRead = 0;
            $(document).find('.listadoDevol tbody tr').not('.fullyReadPicki').each(function(i, n) {
                docRead = $(n).find('.suPedido').html();
            });
            $(document).find('.porDevolInfoBox').each(function(ii, nn) {
                var codigoBarrasDevuelto = $(nn).find('.codigoBarrasDevuelto').html();
                if (codbar == codigoBarrasDevuelto) {
                    isInvoked = 1;
                    var unidXDevolver = $(nn).find('.unidXDevolver').html();
                    unidXDevolver++;
                    var newPropor = 100;
                    $(nn).find('.unidXDevolver').html(unidXDevolver);
                    //$(nn).find('.unidTotales').html(unidXDevolver);
                    $(nn).find('.unidXDevolverPropor').attr('style', 'width: ' + newPropor.toFixed(0) + '%');
                    var talla = 0,
                        color = 0;
                    $(nn).find('.thisReadDevol tbody tr').each(function(iii, nnn) {
                        var thisLocation = $(nnn).find('.locatRead').html(),
                            thisCajaMas = $(nnn).find('.cajMasRead').html(),
                            thisCant = $(nnn).find('.thisCantAcum').html();
                        talla = $(nnn).find('.tallaRead').html();
                        color = $(nnn).find('.colorRead').html();
                        if (thisLocation == locatRead && thisCajaMas == cajMasRead) {
                            isListed = 1;
                            thisCant++;
                            $(nnn).find('.thisCantAcum').html(thisCant);
                        }
                    });
                    if (isListed == 0) {

                        var listThis = `
                                            <tr>
                                                <td class="offscreen text-dark locatRead text-center">` + locatRead + `</td>
                                                <td class="text-dark cajMasRead text-center">` + cajMasRead + `</td>
                                                <td class="text-dark thisCantAcum text-center">1</td>
                                                <td class="offscreen codarticuloRead text-center">0</td>
                                                <td class="offscreen tallaRead text-center">` + talla + `</td>
                                                <td class="offscreen colorRead text-center">` + color + `</td>
                                                <td class="offscreen oldquantityRead text-center">0</td>
                                                <td class="offscreen barcodeRead text-center">` + codbar + `</td>
                                                <td class="offscreen docRead text-center">` + docRead + `</td>
                                            </tr>
                                            `;
                        $(nn).find('.thisReadDevol tbody').append(listThis);
                    }
                    var totalEscan = $('.unidadesEscaenadasTotal span').html();
                    totalEscan++;
                    $('.unidadesEscaenadasTotal span').html(totalEscan);
                }
            });
            if (isInvoked == 0) {
                var talla = 0,
                    color = 0,
                    codArt = 0,
                    formData = new FormData();
                formData.append('codbar', codbar);
                formData.append('meth', 'consultarPNL');
                apiCall(formData, function(data) {
                    if (data.status == "gotProd") {

                        $.growl.warning({
                            message: "Este producto no se encuentra en la Orden de Recepcion escaneada, será agregado en la lista como producto adicional ",
                            duration: 8000
                        });

                        if (data.rows.length > 0) {
                            talla = data.rows[0]['TALLA'];
                            color = data.rows[0]['COLOR'];
                            codArt = data.rows[0]['CODARTICULO'];
                        } else {
                            if (data.rows2.length > 0) {
                                talla = data.rows2[0]['TALLA'];
                                color = data.rows2[0]['COLOR'];
                                codArt = data.rows2[0]['CODARTICULO'];
                            } else {
                                if (data.rows3.length > 0) {
                                    talla = data.rows3[0]['TALLA'];
                                    color = data.rows3[0]['COLOR'];
                                    codArt = data.rows3[0]['CODARTICULO'];
                                }
                            }
                        }

                        var newPropor = 100;
                        var invoke = `
                        <div class="col-sm-12 col-lg-12 col-xl-6 porDevolInfoBox productoAdicional">
                            <div class="card anim cod_` + codbar + ` bg-warning text-white">
                                <div class="card-header">
                                    <div class="card-title"><i class="fa fa-barcode "></i> <strong class=" codigoBarrasDevuelto">` + codbar + `</strong></div>
                                    <div class="card-options ">
                                        <span class="btn btn-info mr30 float-left restarUnidad"><i class="fa fa-minus"></i> </span>
                                        <span class="btn btn-join text-white float-left pull-left mr10 eliminarUnidades"><i class="fa fa-times  "></i> </span>
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <table class="table table-bordered border-top card-table table-vcenter text-nowrap table-primary thisReadDevol">
                                        <thead class="bg-info text-white text-center">
                                            <tr>
                                                <th class="text-white offscreen">Ubicacion</th>
                                                <th class="text-white">Caja Master</th>
                                                <th class="text-white">Cantidad</th>
                                                <th class="offscreen">codarticulo</th>
                                                <th class="offscreen">talla</th>
                                                <th class="offscreen">color</th>
                                                <th class="offscreen">oldquantity</th>
                                                <th class="offscreen">barcode</th>
                                                <th class="offscreen">doc</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td class="offscreen text-dark locatRead text-center">` + locatRead + `</td>
                                                <td class="text-dark cajMasRead text-center">` + cajMasRead + `</td>
                                                <td class="text-dark thisCantAcum text-center">1</td>
                                                <td class="offscreen codarticuloRead text-center">` + codArt + `</td>
                                                <td class="offscreen tallaRead text-center">` + talla + `</td>
                                                <td class="offscreen colorRead text-center">` + color + `</td>
                                                <td class="offscreen oldquantityRead text-center">0</td>
                                                <td class="offscreen barcodeRead text-center">` + codbar + `</td>
                                                <td class="offscreen docRead text-center">` + docRead + `</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <div class="offscreen "></div>
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col text-center">
                                            <label class="tx-12">Unidades Totales</label>
                                            <h2 class="font-weight-normal unidTotales">1</h2>
                                        </div>
                                        <div class="col border-left text-center">
                                            <label class="tx-12">Unidades leídas</label>
                                            <input type="number" class="font-weight-normal unidXDevolver" style = "text-align: center;"><button id= "ChangeCant"><i class="fa fa-check" aria-hidden="true"></i></button>
                                        </div>
                                    </div>
                                    <div class="progress mt-4">
                                        <div class="progress-bar progress-bar-striped progress-bar-animated bg-join unidXDevolverPropor" style="width: ` + newPropor + `%"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        `;


                        var totalEscan = $('.unidadesEscaenadasTotal span').html();
                        totalEscan++;
                        $('.unidadesEscaenadasTotal span').html(totalEscan);

                        $(invoke).insertAfter('.readerPistolBox');
                        $('.cod_' + codbar).velocity("transition.slideUpBigIn", {
                            stagger: 250
                        });
                    } else {
                        $.growl.error({
                            message: "Codigo de barras no existe en el sistema ",
                            duration: 6000
                        });
                    }
                });
            }
        }
        $(document).find('#productoBox').val('');
        $(document).find('#productoBox').focus();

    }


    /** FUNCIONALIDAD DE LOS INPUT */
    function enterSubm() {
        $('.cajamasterBoxInp').keypress(function(e) {
            if (e.which == 13) {
                $('.productoBoxInp').val('');
                $('.productoBoxInp').focus();
            }
        });
        $('.productoBoxInp').keypress(function(e) {
            if (e.which == 13) {
                var devolVal = $(document).find('#productoBox').val(),
                    calaVal = $(document).find('#cajamasterBox').val(); //,
                //locatVal = $(document).find('#locationBox').val();
                if (devolVal == '' || calaVal == '' /* || locatVal == ''*/ ) {
                    $.growl.error({
                        message: "Debe llenar todos los campos"
                    });
                    return;
                }
                getThisProd();
            }
        });

        //$(document).find('#locationBox').val('0000');
        $(document).off('change', "input[type=radio][name=caja-radios]");
        $(document).on('change', "input[type=radio][name=caja-radios]", function(e) {
            console.log(this.value);
            if (this.value == 'sincajamaster') {
                //$(document).find('#locationBox').val('');
                $(document).find('.cajamasterBoxInpG').slideUp('slow');
                //$(document).find('.locationBoxInpG').slideDown('slow');
                $(document).find('#cajamasterBox').val('0000');
                //$('.locationBoxInp').focus();
            } else if (this.value == 'cajamaster') {
                $(document).find('#cajamasterBox').val('');
                $(document).find('.cajamasterBoxInpG').slideDown('slow');
                //$(document).find('.locationBoxInpG').slideUp('slow');
                //$(document).find('#locationBox').val('0000');
                $('.cajamasterBoxInp').focus();
            }
        });

        /** AL PRESIONAR EL BOTON EL CODIGO DE BARRA Y LO CARGAMOS AL LISTADO */
        $(document).off('click', ".readerPistolBox button.envi");
        $(document).on('click', '.readerPistolBox button.envi', function(e) {

            var devolVal = $(document).find('#productoBox').val(),
                calaVal = $(document).find('#cajamasterBox').val(); //,
            //locatVal = $(document).find('#locationBox').val();
            if (devolVal == '' || calaVal == '' /* || locatVal == ''*/ ) {
                $.growl.error({
                    message: "Debe llenar todos los campos"
                });
                return;
            }
            getThisProd();
        });
		
		

    }
</script>