<?php 
    session_start();
    include('../../validadores/validarSession.php');
    include('../StoGlobal/include/conexion.php');
    include('../StoGlobal/include/conexion1.php');
    include('../StoGlobal/include/conexion3.php');
    error_reporting(0);
?>


<!DOCTYPE html>
<html lang="en">
  <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <!-- <link rel="stylesheet" href="../../../Ulices/styles/principal.css" type="text/css"> -->
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>

      <link rel="shortcut icon" href="../../img/LogoBG.png">
      <title>Nueva - Venta</title>


    <script type="text/javascript" src="../../js/sweetalert2.js"></script>
    <script type="text/javascript" src="../../js/sweetalert2.min.js"></script>
    <link rel="stylesheet" href="../../css/sweetalert2.css" type="text/css">
    <link rel="stylesheet" href="../../css/sweetalert2.min.css" type="text/css">
    <script src="../../js/jquery-2.1.4.min.js"></script>


    <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script> 
    <style>
      body{
          transition: 1s  !important;
      }
    </style>
      
  </head>
  <body class="w-100" style="background-color: rgb(5 96 103);   ">
      <?php
          include('../../NavBar.php');
      ?>
    <div class="cssContainer">
      <div class="mb-3 mt-5 pt-5" style="text-align:center;">
        <h2>Modulo de Ventas</h2>
      </div>
      <div class="card mt-5" style="width: 96%;margin:auto;">



        <form class="row g-12 needs-validation text-center d-flex p-4" id="formulario" >

          <div class="form-floating mb-3 ">
              <select name="selector1" id="selector1"  class="form-select" required>
                <option value="0" selected>Tipo de Venta</option>
                      <option value="2">Para Proyecto</option>
                      <option value="1">Por Fuera</option>                  
              </select>
              <label for="floatingSelectGrid">Selecciona la operación</label>
          </div>

          <span id="TraerProyectos" class="col-md-12  "></span>

          <span id="TraerDatosPieza" class="col-md-12  "></span>



      
          <script type="text/javascript">
              $(document).ready(function(){
                  $('#selector1').val(0);
                  recargarLista1();

                  $('#selector1').change(function(){
                      recargarLista1();
                  });
              })

              function recargarLista1(){
                  $.ajax({
                      type:"POST",
                      url:"consulta1.php",
                      data:"estado1=" + $('#selector1').val(),
                      success:function(r){
                          $('#TraerProyectos').html(r);
                      }
                  });
              }
          </script>

          <script type="text/javascript">
              $(document).ready(function(){
                  $('#selector').val(1);
                  recargarLista();

                  $('#selector').change(function(){
                      recargarLista();
                  });
              })

              function recargarLista(){
                  $.ajax({
                      type:"POST",
                      url:"consulta1.php",
                      data:"estado=" + $('#selector').val(),
                      success:function(r){
                          $('#TraerDatosPieza').html(r);
                      }
                  });
              }
          </script>
         
          
            

          <div class="mb-2 mt-5">
            <button class="btn btn-success" type="submit" >Ingresar</button>
          </div>
        </form>
      </div>        
    </div>  

  </body>
</html>


            <script type="text/javascript">
              $(document).ready(function () {
                  $('#formulario').submit(function (e) {
                    $( "#BtnSubmit" ).on( "click", function() {
                      $(this).attr('disabled', true);
                    });
                      e.preventDefault();
                      var datos=$(this).serialize();
                      $.ajax({
                          type:"POST",
                          url:"index_insert.php",
                          data:datos,
                          dataType: 'json',
                            success:function(data){
                              
                                if (data.success) {
                                  const Toast = Swal.mixin({
                                    toast: true,
                                    position: 'top-end',
                                    showConfirmButton: false,
                                    timer: 1500,
                                    timerProgressBar: true,
                                    didOpen: (toast) => {
                                      toast.addEventListener('mouseenter', Swal.stopTimer)
                                      toast.addEventListener('mouseleave', Swal.resumeTimer)
                                    }
                                  })

                                  Toast.fire({
                                    icon: 'success',
                                    title: 'Signed in successfully'
                                  })
                                  document.getElementById("formulario").reset();
                                  setTimeout("location.href='index.php'",2000);
                                }
                                else {
                                  Swal.fire({
                                    title: 'Error!',
                                    text: 'Uno o m谩s datos no fueron ingresados correctamente.',
                                    icon: 'error',
                                    confirmButtonText: 'ok'
                                  })
                                }
                                
                            }     
                      });
                  });
              });
            </script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
