<?php
  include('conn.php');
  
  if ($_SESSION['CurrentIdUser'] == -1) {
    header("Location: login.php");
  }
?>
<!DOCTYPE html>
<html>
  <head>
    <?php include('head.php'); ?>
  </head>
  <body class="hold-transition skin-blue layout-top-nav">
    <div style="background-color: #3c4256;" class="wrapper">
      <header class="main-header">
        <nav class="navbar navbar-default navbar-fixed-top">
          <div class="container">
            <?php include('header.php'); ?>
          </div>
          <div class="container">
            <div class="row" style=" color: #ffffff">
              <div class="description-block col-xs-4" style="    padding-right: 0px;text-align: left;">
                <span class="titulos">Ventas <!-- <span class="" id="lblTitulo"> </span> --></span>
              </div>
              <div style="padding-left: 0px;text-align: right;" class="description-block col-xs-8">
                <a id='btnVerResultado' class="btn btn-default" href="#;" onclick="verResultado();" role="button" style="display: none;"><i style="color: #3c4256;" class="fa fa-chevron-circle-right"></i></a>
                <a id='btnVerFiltros' class="btn btn-default" href="#;" role="button" onclick="verFiltros();" style="display: none;"><i style="padding-right: 5px;color: #3c4256;" class="fa fa-chevron-circle-left"></i>Volver a Filtros</a>
                <div class="btn-group" id="btnConsultas">
                  <button style="margin-right: 3px;" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                    <span class="">Ejecutar Consulta<i style="color: #db5916;padding-left: 5px;" class="fa fa-caret-square-o-down"></i></span>
                  </button>
                  <ul class="dropdown-menu">
                    <li><a href="#" id='btn-funcion-1' style="color: #3c4256">Productos vs Perodos</a></li>
                    <li><a href="#" id='btn-funcion-2' style="color: #3c4256">Productos vs Locales</a></li>
                    <li><a href="#" style="color: #3c4256">Consulta 3</a></li>
                  </ul>
                </div>
                <div class="btn-group" id='btnTitulo' style="display: none;">
                  <!-- <button style="" type="button" class="btn btn-default dropdown-toggle" >
                  <span class="" id="lblTitulo"> </span>
                  </button> -->
                  <ul class="dropdown-menu">
                    <li><a href="#" style="color: #3c4256">Consulta 1</a></li>
                    <li><a href="#" style="color: #3c4256">Consulta 2</a></li>
                    <li><a href="#" style="color: #3c4256">Consulta 3</a></li>
                  </ul>
                </div>
                <button type="button" class="btn btn-default" id='btnLimpiarTodo'><i class="fa fa-eraser"></i></button>
              </div>
            </div>
          </div>       
          <!-- /.container-fluid -->
        </nav>
      </header>
      <!-- Full Width Column -->
      <div class="content-wrapper" style="padding-top: 105px;">
        <div class="container" id="conteFiltro">
          <!-- Content Header (Page header) -->
          <!-- Main content -->
          <section class="content">
            <div class="row">
              <div class=" col-md-12">
                <!-- MODULO PERIODOS -->
                <?php include('inc-periodos.php'); ?>
              </div>
            </div>

            <div class="row">
              <section class="col-lg-6 connectedSortable ui-sortable">
                <!-- /MODULO UNIDAD DE NEGOCIOS -->
                <?php include("inc-unidades.php") ?>
              </section>
              
              <section class="col-lg-6 connectedSortable ui-sortable">
                <!-- /MODULO CONCEPTOS COMPRA -->
                <?php include("inc-conceptos-venta.php"); ?>
              </section>
            </div>
            
            <div class="row">
              <section class="col-lg-6 connectedSortable ui-sortable">
                <!-- /MODULO RUBROS COMPRA -->
                <?php include("inc-rubros-venta.php") ?>
              </section>
              
              <section class="col-lg-6 connectedSortable ui-sortable">
                <!-- /MODULO COMPROBANTES COMPRA -->
                <?php include("inc-comprobantes-venta.php"); ?>
              </section>
            </div>
            
            <div class="row">
              <section class="col-lg-6 connectedSortable ui-sortable">
                 <?php include("inc-modulo-ventas.php"); ?>
              </section>
              <section class="col-lg-6 connectedSortable ui-sortable">
                 <?php include("inc-turnos.php"); ?>
              </section>
            </div>
          </section>
          <!-- /.content -->
        </div>
        <div class="container" id="conteResultado" style="display: none;">
          
          <section class="loadersection content" id="conteTabla" >

            <div class="loader"></div>
            
            <p class="ploader">Cargando...</p>

          </section>
       
        </div>
      </div>
    </div>
        <!-- /.content-wrapper -->
        <!-- /.login-box -->
    <?php include("footer.php"); ?>
    <?php include('scripts.php'); ?>
    
        <!-- <script>
        function toggleSelection(e){
        var el = '#' + e.data;
        console.log(arguments);
        if (this.checked) {
        $(el).attr('disabled', 'disabled');
        } else {
        $(el).removeAttr('disabled');
        }
        }
        $(function() {
        $('#worldcb').click('worldSelect', toggleSelection);
        });
        </script> -->
        <script>
        function autocomplete(inp, arr) {
        /*the autocomplete function takes two arguments,
        the text field element and an array of possible autocompleted values:*/
        var currentFocus;
        /*execute a function when someone writes in the text field:*/
        inp.addEventListener("input", function(e) {
        var a, b, i, val = this.value;
        /*close any already open lists of autocompleted values*/
        closeAllLists();
        if (!val) { return false;}
        currentFocus = -1;
        /*create a DIV element that will contain the items (values):*/
        a = document.createElement("DIV");
        a.setAttribute("id", this.id + "autocomplete-list");
        a.setAttribute("class", "autocomplete-items");
        /*append the DIV element as a child of the autocomplete container:*/
        this.parentNode.appendChild(a);
        /*for each item in the array...*/
        for (i = 0; i < arr.length; i++) {
        /*check if the item starts with the same letters as the text field value:*/
        if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
        /*create a DIV element for each matching element:*/
        b = document.createElement("DIV");
        /*make the matching letters bold:*/
        b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
        b.innerHTML += arr[i].substr(val.length);
        /*insert a input field that will hold the current array item's value:*/
        b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
        /*execute a function when someone clicks on the item value (DIV element):*/
        b.addEventListener("click", function(e) {
        /*insert the value for the autocomplete text field:*/
        inp.value = this.getElementsByTagName("input")[0].value;
        /*close the list of autocompleted values,
        (or any other open lists of autocompleted values:*/
        closeAllLists();
        });
        a.appendChild(b);
        }
        }
        });
        /*execute a function presses a key on the keyboard:*/
        inp.addEventListener("keydown", function(e) {
        var x = document.getElementById(this.id + "autocomplete-list");
        if (x) x = x.getElementsByTagName("div");
        if (e.keyCode == 40) {
        /*If the arrow DOWN key is pressed,
        increase the currentFocus variable:*/
        currentFocus++;
        /*and and make the current item more visible:*/
        addActive(x);
        } else if (e.keyCode == 38) { //up
        /*If the arrow UP key is pressed,
        decrease the currentFocus variable:*/
        currentFocus--;
        /*and and make the current item more visible:*/
        addActive(x);
        } else if (e.keyCode == 13) {
        /*If the ENTER key is pressed, prevent the form from being submitted,*/
        e.preventDefault();
        if (currentFocus > -1) {
        /*and simulate a click on the "active" item:*/
        if (x) x[currentFocus].click();
        }
        }
        });
        function addActive(x) {
        /*a function to classify an item as "active":*/
        if (!x) return false;
        /*start by removing the "active" class on all items:*/
        removeActive(x);
        if (currentFocus >= x.length) currentFocus = 0;
        if (currentFocus < 0) currentFocus = (x.length - 1);
        /*add class "autocomplete-active":*/
        x[currentFocus].classList.add("autocomplete-active");
        }
        function removeActive(x) {
        /*a function to remove the "active" class from all autocomplete items:*/
        for (var i = 0; i < x.length; i++) {
        x[i].classList.remove("autocomplete-active");
        }
        }
        function closeAllLists(elmnt) {
        /*close all autocomplete lists in the document,
        except the one passed as an argument:*/
        var x = document.getElementsByClassName("autocomplete-items");
        for (var i = 0; i < x.length; i++) {
        if (elmnt != x[i] && elmnt != inp) {
        x[i].parentNode.removeChild(x[i]);
        }
        }
        }
        /*execute a function when someone clicks in the document:*/
        document.addEventListener("click", function (e) {
        closeAllLists(e.target);
        });
        }
        /*An array containing all the country names in the world:*/
        var countries = ["Mesa 1", "Mesa 2", "Mesa 3", "Mesa 4", "Mesa 5", "Mesa 6", "Mesa 8", "Mesa 9", "Mesa 10", "Prueba 1", "Prueba 2", "Prueba 3", "Prueba 4", "Prueba 5", "Prueba 6", "Prueba 7", "Prueba 8", "Prueba 9", "Prueba 10", "Prueba 11", "Prueba 12", "Prueba 13", "Prueba 14", "Prueba 15", "Prueba 16", "Prueba 17", "Prueba 18", "Prueba 19", "Prueba 20", "Prueba 21", "Prueba 22", "Prueba 23", "Prueba 24", "Prueba 25", "Prueba 26", "Prueba 27", "Prueba 28", "Prueba 29", "Prueba 30", "Prueba 31", "Prueba 32", "Prueba 33", "Prueba 34", "Prueba 35", "Prueba 36", "Prueba 37", "Prueba 38", "Prueba 39"];
        /*initiate the autocomplete function on the "myInput" element, and pass along the countries array as possible autocomplete values:*/
        autocomplete(document.getElementById("myInput"), countries);
        </script>
      
        <script>
        var update_estado_check = function () {
        $("#estado").prop("disabled", !$('#estado_check').prop('checked'));
        };
        update_estado_check();
        $("#estado_check").change(update_estado_check);
        </script>
        <script>
        var update_importe_check = function () {
        $("#importe").prop("disabled", !$('#importe_check').prop('checked'));
        };
        update_importe_check();
        $("#importe_check").change(update_importe_check);
        </script>
        <script>
        var update_importe_check = function () {
        $("#importe2").prop("disabled", !$('#importe_check').prop('checked'));
        };
        update_importe_check();
        $("#importe_check").change(update_importe_check);
        </script>
        
        <script>
        document.getElementById('estado_observaciones').onchange = function() {
        document.getElementById('myInput').disabled = !this.checked;
        };
        </script>
        
        <script type="text/javascript" src="js/inc-unidades.js"></script>          
        <script type="text/javascript" src="js/inc-conceptos-venta.js"></script>          
        <script type="text/javascript" src="js/inc-rubros-venta.js"></script>          
        <script type="text/javascript" src="js/inc-comprobantes-venta.js"></script>          
        
              
        <script>
        $( function() {
          $.widget( "custom.combobox", {
            _create: function() {
              this.wrapper = $( "<span>" ).addClass( "custom-combobox" ).insertAfter( this.element );
          
              this.element.hide();
              this._createAutocomplete();
              this._createShowAllButton();
            },
          
            _createAutocomplete: function() {
              var selected = this.element.children( ":selected" ),
              value = selected.val() ? selected.text() : "";
          
              this.input = $( "<input >" )
                .appendTo( this.wrapper )
                .val( value )
                .attr( "title", "" )
                .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
                .autocomplete({
                  delay: 0,
                  minLength: 0,
                  source: $.proxy( this, "_source" )
                })
                .tooltip({
                  classes: {
                    "ui-tooltip": "ui-state-highlight"
                  }
                });
          
              this._on( this.input, {
                autocompleteselect: function( event, ui ) {
                  ui.item.option.selected = true;
                  this._trigger( "select", event, {
                    item: ui.item.option
                  });
                },
          
                autocompletechange: "_removeIfInvalid"
              });
            },
          
            _createShowAllButton: function() {
              var input = this.input,
              wasOpen = false
          
              $( "<a>" )
                .attr( "tabIndex", -1 )
                .attr( "title", "Mostrar Todas" )
                .attr( "height", "" )
                .tooltip()
                .appendTo( this.wrapper )
                .button({
                  icons: {
                    primary: "ui-icon-triangle-1-s"
                  },
                  text: "false"
                })
                .removeClass( "ui-corner-all" )
                .addClass( "custom-combobox-toggle ui-corner-right" )
                .on( "mousedown", function() {
                  wasOpen = input.autocomplete( "widget" ).is( ":visible" );
                })
                .on( "click", function() {
                  input.trigger( "focus" );
            
                  // Close if already visible
                if ( wasOpen ) {
                  return;
                }
            
                // Pass empty string as value to search for, displaying all results
                input.autocomplete( "search", "" );
              });
            },
            
            _source: function( request, response ) {
              var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
              response( this.element.children( "option" ).map(function() {
                var text = $( this ).text();
                if ( this.value && ( !request.term || matcher.test(text) ) )
                return {
                  label: text,
                  value: text,
                  option: this
                };
              }) );
            },
            
            _removeIfInvalid: function( event, ui ) {
              // Selected an item, nothing to do
              if ( ui.item ) {
                return;
              }
            
              // Search for a match (case-insensitive)
              var value = this.input.val(),
              valueLowerCase = value.toLowerCase(),
              valid = false;
              this.element.children( "option" ).each(function() {
                if ( $( this ).text().toLowerCase() === valueLowerCase ) {
                  this.selected = valid = true;
                  return false;
                }
              });
            
              // Found a match, nothing to do
              if ( valid ) {
                return;
              }
            
              // Remove invalid value
              this.input
                .val( "" )
                .attr( "title", value + " : no se encontro" )
                .tooltip( "open" );
              this.element.val( "" );
              this._delay(function() {
                this.input.tooltip( "close" ).attr( "title", "" );
              }, 2500 );
              this.input.autocomplete( "instance" ).term = "";
            },
            
            _destroy: function() {
              this.wrapper.remove();
              this.element.show();
            }
          });
            
          $( "#combobox" ).combobox();
          $( "#toggle" ).on( "click", function() {
            $( "#combobox" ).toggle();
          });
        });
        </script>
        
        <!-- script para filtro por perodo -->
        <script type="text/javascript" src="js/inc-periodos.js"></script>
            
        <script>
        $(function () {
          $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
          });
        });
        </script>
        
        <script>
        $(function () {
          //Initialize Select2 Elements
          $('.select2').select2()
          //iCheck for checkbox and radio inputs
          $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass   : 'iradio_minimal-blue'
          })
          //Red color scheme for iCheck
          $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
            checkboxClass: 'icheckbox_minimal-red',
            radioClass   : 'iradio_minimal-red'
          })
          //Flat red color scheme for iCheck
          $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass   : 'iradio_flat-green'
          })
          //Colorpicker
          $('.my-colorpicker1').colorpicker()
          //color picker with addon
          $('.my-colorpicker2').colorpicker()
          //Timepicker
          $('.timepicker').timepicker({
            showInputs: false
          })
        })
        </script>
        

        <script >
        var $exampleMulti = $(".js-example-programmatic-multi").select2();
        $(".js-programmatic-multi-clear").on("click", function () {
          $exampleMulti.val(null).trigger("change");
        });
        </script>
            
        <script>
        $("#ex3").slider({
          formatter: function(value) {
            return 'Current value: ' + value;
          }
        });
        var slider = new Slider('#ex3', {
          tooltip: 'always',
          tooltip_split: 'true'
        });
        tooltip: 'always'
        </script>
       
            
  </body>
</html>

<script type="text/javascript" src="js/ventas.js"></script>  