<?php

include_once '../bd/bd_os.inc';
include "../auxiliar/datas.inc";
include "../auxiliar/parametros.inc";
include_once '../bd/bd_loja.php';
include_once "../idiomas/config.inc";

$lojas = getAllStores(true);

$statusDigitacaoDescricao = getStatusDescription($p_codstatus);

$statusFinalizadoDescricao = getStatusDescription($p_codstatusfin);

?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AFV 2 | <?php echo $b_historico_de_vendas;?></title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="./../web/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="./../web/bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="./../web/bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="./../web/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="./../web/dist/css/skins/_all-skins.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="./../web/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>

<body class="hold-transition skin-blue sidebar-mini">
    <!-- Site wrapper -->
    <div class="wrapper">

        <header class="main-header">
            <!-- Logo -->
            <a href="./cadastro.php" class="logo">
                <!-- mini logo for sidebar mini 50x50 pixels -->
                <span class="logo-mini">ADV</span>
                <!-- logo for regular state and mobile devices -->
                <span class="logo-lg"><b>AFV</b> - ADV Tecnologia </span>
            </a>
            <!-- Header Navbar: style can be found in header.less -->
            <nav class="navbar navbar-static-top">
                <!-- Sidebar toggle button-->
                <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>
            </nav>
        </header>









        <!-- =============================================== -->
        <!-- Inserir modal aqui-->
        <div class="modal fade" id="modal-busca-cliente">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title"><?php echo $m_buscar_cliente;?></h4>
                    </div>
                    <div class="modal-body">
                        <div id="clientSearchContainer"></div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default pull-left" data-dismiss="modal"><?php echo $bt_sair;?> </button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
        <!-- -->













        <!-- =============================================== -->
        <!-- Inserir modal aqui-->
        <div class="modal fade" id="modal-default">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title"><?php echo $m_relatorios; ?></h4>
                    </div>
                    <div class="modal-body">
                        <p>
                            <?php
                            include 'relatorios.php';
                            ?>
                        </p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default pull-left" data-dismiss="modal"><?php echo $bt_sair;?></button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->




        <?php
        include_once '../bd/funcoes.inc';
        if (lecookie("codos")) {
            echo " <SCRIPT>
                          self.location.href='../html/produtos_consulta.php';
                        </SCRIPT>";
            exit;
        }
        ?>

        <?php include "../modais/modal_cliente_search.php" ?>



        <!-- Fim do modal -->

        <!-- Left side column. contains the sidebar -->
        <aside class="main-sidebar">
            <!-- sidebar: style can be found in sidebar.less -->
            <section class="sidebar">
                <!-- Sidebar user panel -->
                <div class="user-panel">
                    <div class="pull-left image">
                        <img src="./../icons/frame.png" class="img-circle" alt="User Image">
                    </div>
                    <div class="pull-left info">
                        <p>
                            <?php
                            include_once '../bd/funcoes.inc';
                            $p_codusu = lecookie("codusu");
                            echo (TrazValorCampo('senhas', 'usuario', 'codusu', lecookie('codusu')));
                            ?>
                        </p>
                    </div>
                </div>

                <!-- sidebar menu: : style can be found in sidebar.less -->
                <ul class="sidebar-menu" data-widget="tree">
                    <li class="header"><?php echo $g_painel_navegacao;?></li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-dashboard"></i> <span><?php echo $m_vendas;?></span>
                            <span class="pull-right-container">
                                <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="./buscahistvnd.php"><i class="fa fa-circle-o"></i> <?php echo $m_historico_venda;?></a></li>
                            <li><a href="#" data-toggle="modal" data-target="#modal-buscarcliente"><i class="fa fa-circle-o"></i>
                            <?php echo $m_nova_venda;?></a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="glyphicon glyphicon-user"></i> <span><?php echo $m_clientes;?></span>
                            <span class="pull-right-container">
                                <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="./cadastronovo.php"><i class="fa fa-circle-o"></i> <?php echo $m_cadastrar_cliente;?></a></li>
                            <li><a href="#" data-toggle="modal" data-target="#modal-buscarcliente"><i class="fa fa-circle-o"></i>
                            <?php echo $m_localizar_cliente;?></a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#" data-toggle="modal" data-target="#modal-default">
                            <i class="fa fa-files-o"></i>
                            <span><?php echo $m_relatorios; ?></span>
                        </a>
                    </li>
                    <li>
                        <a href="./produtos_consulta.php">
                            <i class="glyphicon glyphicon-search"></i> <span><?php echo $m_consulta_produtos; ?></span>
                        </a>
                    </li>
                    <li>
                        <a href="./../php/logoff.php">
                            <i class="glyphicon glyphicon-off"></i>
                            <span><?php echo $m_Logout;?></span>
                        </a>
                    </li>
                </ul>
            </section>
            <!-- /.sidebar -->
        </aside>

        <!-- =============================================== -->

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    <?php echo $b_historico_de_vendas;?>
                </h1>
                <ol class="breadcrumb">
                    <!-- controle de paginas aqui-->
                    <li><a href="#"><i class="fa fa-dashboard"></i> <?php echo $g_inicio;?></a></li>
                    <li><a href="#"><?php echo $b_historico_de_vendas;?></a></li>
                </ol>
            </section>

            <!-- Main content -->
            <section class="content">

                <!-- Default box -->
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $b_consultar_historico_vendas;?></h3>

                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                                <i class="fa fa-minus"></i></button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                                <i class="fa fa-times"></i></button>
                        </div>
                    </div>
                    <div class="box-body">
                        <!-- Inserir aqui-->


                        <form action='../php/buscahistvnd.php' method="post" name="histvnd" target="histvnd">

                            <div class="form-group">

                                <label><?php echo $b_status_da_venda;?> </label><br />
                                <div class="form-group">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="statusVenda" id="statusVenda1" value="aberta" checked="">
                                            <?php echo $statusDigitacaoDescricao; ?>
                                        </label>
                                        <label>
                                            <input type="radio" name="statusVenda" id="statusVenda2" value="finalizada">
                                            <?php echo $statusFinalizadoDescricao; ?>
                                        </label>
                                        <label>
                                            <input type="radio" name="statusVenda" id="statusVenda3" value="todos">
                                            <?php echo $b_todos; ?>
                                        </label>
                                    </div>
                                    <div class="radio">
                                    </div>
                                </div>


                                <?php if ($p_lancar_orcamentos == 1) : ?>
                                    <label><?php echo $coluna_hist_tipo; ?>: </label><br />
                                    <div class="form-group">
                                        <div class="radio">

                                            <label>
                                                <input type="radio" name="tipoVenda" id="tipoVenda2" value="2"><?php echo $m_vendas; ?>
                                            </label>&nbsp;
                                            <label>
                                                <input type="radio" name="tipoVenda" id="tipoVenda3" value="1" checked=""><?php echo $b_orcamento; ?>
                                            </label>&nbsp;
                                            <label>
                                                <input type="radio" name="tipoVenda" id="tipoVenda1" value="todas"><?php echo $b_todos; ?>
                                            </label>

                                        </div>
                                    </div>
                                <?php endif; ?>

                                <br>

                                <label><?php echo $b_filtrar_por_data; ?> </label><br />
                                <div class="form-group">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="tipoData" id="tipoData1" value="dataos" checked="">
                                            <?php echo $b_abertura; ?>
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="tipoData" id="tipoData2" value="dataosfin">
                                            <?php echo $b_finalizacao; ?>
                                        </label>
                                    </div>
                                </div>

                                <label><?php echo $b_inicio_data; ?></label>

                                <div class="col-sm-12 input-group">
                                    <div class="input-group-addon" id='calendarIni'>
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input id="dtini" name="dtini" type="text" size="36" readonly value="<?php echo IncDiasData(date("d/m/Y"), -$p_diasfilthistvnd) ?>" class="form-control" type="text" />

                                </div>

                                <label><?php echo $b_fim_data; ?></label>

                                <div class="col-sm-12 input-group">
                                    <div class="input-group-addon" id='calendarFim'>
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input class="form-control" readonly id="dtfin" name="dtfin" type="text" value="<?php echo date(" d/m/Y") ?>" type="text" />
                                </div>

                                <label><?php echo $b_cliente; ?></label><br />
                                <div class="col-sm-12 input-group">
                                    <input name="razao" type="text" class="form-control" id="razaoCliente" disabled="true">
                                    <input name="codcli" id="codCli" type="hidden">
                                    <span class="input-group-btn">
                                        <button onclick="loadClientSearch()" data-toggle='modal' data-target='#modal-busca-cliente' type="button" class="btn btn-success btn-flat"><?php echo $bt_pesquisar; ?></button>
                                    </span>
                                    <span class="input-group-btn">
                                        <button onclick="clearClientSearch()" type="button" class="btn btn-info btn-flat"><?php echo $bt_limpar; ?></button>
                                    </span>
                                </div>



                                <div class="col-sm-12 input-group">
                                    <div>
                                        <label><?php echo $b_loja; ?> </label><br />
                                        <select name="loja" id="selectLoja" class="form-control">
                                            <?php foreach ($lojas as $loja) : ?>
                                                <option value="<?php echo $loja['codloja'] ?>">
                                                    <?php echo $loja['codloja'] ?> - <?php echo $loja['descloja'] ?> (<?php echo $loja['loja'] ?>)
                                                </option>
                                            <?php endforeach; ?>
                                        </select>

                                    </div>
                                </div>


                                <div class="col-sm-12 input-group">
                                    <div>
                                        <label><?php echo $b_tipo_de_saida; ?> </label><br />
                                        <select name="tipoDeSaida" id="selectTipoDeSaida" class="form-control">
                                            <?php foreach (getTiposDeSaida() as $tipoSaida) : ?>
                                                <option value="<?php echo $tipoSaida['codtiposai'] ?>">
                                                    <?php echo $tipoSaida['descricao']; ?>
                                                </option>
                                            <?php endforeach; ?>
                                        </select>

                                    </div>
                                </div>



                                <br>
                                <div>
                                    <button class="btn btn-primary" id='loadClientes' type='button' name='Enviar' value='Enviar'><?php echo $bt_consultar; ?></button>
                                </div>

                                <script>
                                    document.histvnd.razao.focus();
                                </script>

                            </div>
                        </form>

                        <div id='content'></div>
                    </div>
                </div>
                <!-- Finalizar aqui-->
        </div>

        <!-- /.box-body -->

        <!-- /.box-footer-->
    </div>
    <!-- /.box -->

    </section>
    <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

    <?php  include_once '../html/footer.php'; ?>
    
    </div>
    <!-- ./wrapper -->

    <!-- jQuery 3 -->
    <script src="../web/bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="../web/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="../web/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../web/bower_components/fastclick/lib/fastclick.js"></script>
    <!-- AdminLTE App -->
    <script src="../web/dist/js/adminlte.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../web/dist/js/demo.js"></script>

    <!-- Select2 -->
    <script src="../web/bower_components/select2/dist/js/select2.full.min.js"></script>
    <!-- InputMask -->
    <script src="../web/plugins/input-mask/jquery.inputmask.js"></script>
    <script src="../web/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="../web/plugins/input-mask/jquery.inputmask.extensions.js"></script>

    <!-- DataTables -->
    <script src="../web/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="../web/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <!-- Page script -->
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="../web/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <script src="../web/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <script src="../web/bower_components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.pt-BR.min.js"></script>


    <?php
    echo ("
    <script>
        $(function () {
            //Initialize Select2 Elements
            $('.select2').select2()
            //Datemask dd/mm/yyyy
            $('#datemask').inputmask('dd/mm/yyyy', {
                'placeholder': 'dd/mm/yyyy'
            })
            //Datemask2 mm/dd/yyyy
            $('#datemask2').inputmask('mm/dd/yyyy', {
                'placeholder': 'mm/dd/yyyy'
            })
            //Money Euro
            $('[data-mask]').inputmask()         
        })

    $(function () {
        $('#example2').DataTable()
    });  
    
   
    </script>
        ");

    ?>
    <script>
        $(document).ready(function() {
            $('#calendarIni').click(function() {
                $('#dtini').focus()
            });

            $('#calendarFim').click(function() {
                $('#dtfin').focus()
            });

            var datePickerConfigs = {
                format: 'dd/mm/yyyy',
                language: 'pt-BR',
                autoclose: true,
                orientation: 'bottom right'
            }
            $('#dtini').datepicker(datePickerConfigs);

            $('#dtfin').datepicker(datePickerConfigs);

        });

        var loadClientSearch = function() {
            $('#clientSearchContainer').html("<h3>Carregando ... </h3>");

            $('#clientSearchContainer')
                .load('../php/busca_de_clientes.php');
        }


        var clearClientSearch = function() {
            $("#razaoCliente").val('');
            $("#codCli").val('');
        }

        $('#clientSearchContainer').on("cliente-selecionado", function(event, cliente) {
            $("#razaoCliente").val(cliente.razao);
            $("#codCli").val(cliente.codcli);
        })

        var obrigaASelecionarCliente = <?php echo ($p_obgclihistvnd == 1) ? "true" : "false" ?>

        $('#loadClientes').click(function() {
            let dtini = $("#dtini").val();
            let dtfin = $("#dtfin").val();
            let razao = $("#razao").val();
            let codCli = $("#codCli").val();
            let tipoData = $("input[name=tipoData]:checked").val();
            let statusVenda = $("input[name=statusVenda]:checked").val();

            <?php if ($p_lancar_orcamentos == 1) : ?>
                let tipoVenda = $("input[name=tipoVenda]:checked").val();
            <?php else : ?>
                let tipoVenda = "2";
            <?php endif; ?>
            let tipoDeSaida = $("#selectTipoDeSaida").val()

            let selectLoja = $("#selectLoja").val();

            if (obrigaASelecionarCliente && !codCli)
                return alert('Você deve filtrar um Cliente')


            $('#content')
                .load('../php/buscahistvnd.php?dtini=' + dtini + '&dtfin=' + encodeURIComponent(dtfin) + '&razao=' + encodeURIComponent(razao) + '&loja=' + selectLoja + '&codcli=' + codCli + '&tipoData=' + tipoData + '&statusVenda=' + statusVenda + '&tipoDeSaida=' + tipoDeSaida + '&tipoVenda=' + tipoVenda);
        });

        <?php if ($p_obgclihistvnd == 1) : ?>
        <?php endif; ?>
    </script>
</body>


</html>