@include('header')
@include('navigator_no_cuit')
<link href="{{asset('components/datatables/media/css/jquery.dataTables.min.css')}}" rel="stylesheet">
<div class="container">
	<div class="col-md-12 text-center"><h3>CONSULTAS A REALIZAR A MIS APORTES</h3><h4 class="titulo-fidelitas"></div> 
    @if(Session::get('usuario')->user_id == 94437923 || Session::get('usuario')->user_id == 15342812) {{--usuarios sa y sistemas --}}
        <form id="frmproductos" method="post">
            <input type="hidden" name="_token" value="{{csrf_token()}}" id="__token">
            <input type="hidden" name="move" value="" id="_move">
            <div class="row">
                <div class="col-md-5 form-group">
                    <label for="disponibles">Productos</label>
                    <select name="disponibles" id="disponibles" size="11" class="form-control" multiple="multiple" style="height:85px">
                        @foreach($disponibles as $indica)
                        <option value="{{$indica->producto}}">{{$indica->nombre_producto}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-2 text-center" style="vertical-align: middle;">
                    <br>
                    <button type="button" class="btn btn-primary btn-fidelitas move" data-to="left"><i class="fa fa-arrow-left"></i></button>
                    <br>
                    <br>
                    <button type="button" class="btn btn-primary btn-fidelitas move" data-to="right"><i class="fa fa-arrow-right"></i></button>

                </div>
                <div class="col-md-5 form-group">
                    <label for="asignados">Productos que se toman en cuenta para la búsqueda</label>
                    <select name="asignados" id="asignados" size="11" class="form-control" multiple="multiple" style="height:85px">
                        @foreach($asignados as $indica)
                        <option value="{{$indica->producto}}">{{$indica->nombre_producto}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
        </form>
    @endif
    <!--  --> 
    <div class="row">
        <div class="col-md-12" id="datos"></div>
    </div>
    <div class="row" style="display:none;" id="loading-datos">
        <div class="col-md-2 col-md-offset-5">
            <br />
            <br />
            <img src="/images/loading.gif" class="img img-responsive" alt="" border="0" />
        </div>
    </div>
    <form name="buscar_consultas" id="buscar_consultas" method="post" class="form-signin">
        <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
    </form>
</div>
<!--  -->
<script type="text/javascript">
$(document).ready(function () {
    $('.move').on('click', function() {

        if($(this).data('to')=='right'){
            var _go = ( $('#disponibles').val() != null );  
        }else{
            var _go = ( $('#asignados').val() != null );
        }

        if(_go){

            $('#_move').val( $(this).data('to') );
            var disp = '';
            if ( $('#disponibles').val() != null ) {
                $.each($('#disponibles').val(), function(i, el) {
                    if (disp != '') {
                        disp = disp + ',';                  
                    }
                    disp = disp + el.toString();
                });             
            }

            var asig = '';
            if ( $('#asignados').val() != null ) {
                $.each($('#asignados').val(), function(i, el) {
                    if (asig != '') {
                        asig = asig + ',';                  
                    }
                    asig = asig + el.toString();
                });             
            }
            
            $.ajax({
                method : 'post',
                url : 'mis-aportes-productos-move',
                data : { '_token' : $('#__token').val() , 'move' : $('#_move').val() , 'disponibles' : disp , 'asignados' : asig },
                beforeSend : function() {},
                success : function(data) {
                    var r = eval(data);
                
                    $('#disponibles').empty();
                    $('#asignados').empty();
                    $.each(r[0], function(i, el) {
                        $('#disponibles').append($("<option />").val(el.producto).text(el.nombre_producto));
                    });
                    $.each(r[1], function(i, el) {
                        $('#asignados').append($("<option />").val(el.producto).text(el.nombre_producto));
                    });     
                    actualizarFancyDatos();                                                    
                },
            });
        }
    });

	Fancy.MODULESDIR = '/js/fancy/';
    var datosgrid;
    var seldatos;
    var boton_excel = '@traducir("Exportar a excel", "Exportar a excel")'; 
    var registros = '@traducir("Registros", "Registros")';  
    var pagina = '@traducir("Pagina", "Página")'; 
    var de = '@traducir("de", "de")'; 
    actualizarFancyDatos();

    function actualizarFancyDatos() {
        $('#loading-datos').show();
        
        if (ajax) {
            ajax.abort();
        }

        $.ajax({
            method: "post",
            url: "/tablasgenerales/misaportes-enriquecer",
            data: $('#buscar_consultas').serialize(),
            beforeSend: function () {
                $("#datos").html("");
            },
            success: function (response) {
                var data = JSON.parse(response);
                var values = data.data;
                var hay = data.hay;

                if (hay=='NO')
                {
                    $('#loading-datos').hide();
                    $("#datos").html("<div class='col-md-12 h4 text-center'>No hay consultas pendientes</div>");
                    return; 
                }
              
                $('#loading-datos').hide();

                if (hay == 'SI') {


					    var clientes = [];
					    var cli_codigos= [];

					   
					    //-----
					    for (let index = 0; index < values.length; index++) {
					        //-----

					        if (clientes.includes(values[index].CLIENTE) == false){
					            clientes.push(values[index].CLIENTE)
					        }
					        if (cli_codigos.includes(values[index].COD_CLIENTE) == false){
					            cli_codigos.push(values[index].COD_CLIENTE)
					        }
					        
					    }
				        clientes.sort();
				        cli_codigos.sort();
					    //---------


    var columns_v = [
        {
            type: "select",
            locked: true,
            width: 70,
            align: "center",
            cellAlign: "center",
            hidden : true
        },
        {
            type: "string",
            title: '@traducir("Cod.Cliente", "Cod.Cliente")',
            index: "COD_CLIENTE",
            width: 100,

            cellAlign: "center",
            sortable: true,
            resizable: true,
            align: "center",
            locked: true,
            type : "combo",
            data : cli_codigos,
            multiSelect: true,
            itemCheckBox: true,
           
            filter : {
                header : true,
                emptyText: " ", //"Buscar por cliente",
            }
        },
        {
            type: "string",
            title: '@traducir("Cliente", "Cliente")',
            index: "CLIENTE",
            flex: 1,
            cellAlign: "left",
            sortable: true,
            resizable: true,
            align: "center",
            locked: true,

            type : "combo",
            data : clientes,
            multiSelect: true,
            itemCheckBox: true,
           
            filter : {
                header : true,
                emptyText: " ", //"Buscar por cliente",
            }

        },
        {
            type: "string",
            title: '@traducir("CUIT", "CUIT")',
            index: "CUIT",
            width: 100,
            cellAlign: "center",
            sortable: true,
            resizable: true,
            align: "center",
            locked: true,
            filter : {header:true} 
        },
        {
            type: "string",
            title: '@traducir("Empleador", "Empleador")',
            index: "EMPLEADOR",
            flex: 1,

            cellAlign: "left",
            sortable: true,
            resizable: true,
            align: "center",
            locked: true,
            filter : {header:true} 
        },
     
        {
            type: "string",
            title: '@traducir("CUIL", "CUIL")',
            index: "CUIL",
            width: 100,
            cellAlign: "center",
            sortable: true,
            resizable: false,
            align: "center",
            locked: true,
            filter : {header:true} 
        },
        	{type: "string",
            title: '@traducir("Empleado", "Empleado")',
            index: "EMPLEADO",
            flex: 1,
            cellAlign: "left",
            sortable: true,
            resizable: true,
            align: "center",
            locked: true,
            filter : {header:true} 
        },
		/*
        { type : 'string' , 
          title : '@traducir("Período", "Período")',
          index : 'PERIODO' ,
          width : 100 ,
          cellAlign : 'center',
          sortable : true ,
          resizable : true ,
          align : 'center' ,
          locked : true 
        },
       	*/
        {
            type: "string",
            index: "edit",
            width: 120,
            cellAlign: "center",
            sortable: false,
            resizable: false,
            align: "center",
            hidden : true,
        }
    ];




                        datosgrid = new FancyGrid({

                        id : "tabla-cuiles",
				        //title : "CUILs a consultar",
				        theme : "blue",
				        renderTo : "datos",
                        height: 'fit',// 700,
				        data : values,
				        lang: {
                            paging: {
                                info: registros + ' [0] - [1] '+ de +' [2]',
                                page: pagina,
                                of: de + ' [0]'
                            },
                        }, 
				        paging : {
				            paging : true,
				            pageSize : 20,
				            refreshButton : true 
				        },
				        defaults: {
				            type : "string",
				            editable : false,
				            resizable : true,
				            sortable: true,
				            draggable : true,
				        },
				        columnClickData: true,

                         /* Excel */
                        exporter: true,
                        //subTBar: [
                        tbar: [
                         {
                          text: "<button style='background-color:#20a464; width:150px; margin-top: 0px;' type = 'button' class= 'form-control botones-paginador'><i class='fas fa-file-excel'></i>&nbsp;&nbsp;" + boton_excel + "</button>",
                          handler: function() {
                            this.exportToExcel({
                              fileName: 'datos',
                              all: true,
                              header: true, 
                              ignoreRender: true
                            });
                            }
                          },
                       
                        ],
                        columns: columns_v,
                       
                        selModel: { type: "rows", memory: true },
                        scrollable: true,
                        cellHeight: 26,
                        //Habilita el agregado de css en todas las celdas de un fila cuando se hace mouseover.
                        trackOver: true,   

                        events: [
                        ],
                    });
                }

                $("#datos").show();
            },
        });
    }


   

   
});
</script>

@include('footer')

