<?php
include('../StoGlobal/include/conexion.php');
include('../StoGlobal/include/conexion1.php');
include('../StoGlobal/include/conexion2.php');
include('../StoGlobal/include/conexion3.php');


?>


<!DOCTYPE html>
<!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>Ingreso - Datos Mensual</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="js/linea_it.js"></script>
      <script type="text/javascript" src="https://znd7pgylblorbdefs-sii.siteintercept.qualtrics.com/SIE/?Q_ZID=ZN_d7pgyLBlORbDEfs"></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;color:#fff">
        <h2>Seleciona la factura asociada, para pasar a estado "Proceso de Pago"</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" >

            <?php 
            if(isset($_GET['idCodProy1'])){             
                ?>
                <input type="hidden" name="id_proyecto" id="id_proyecto" value="<?php echo $_GET['idCodProy1'];?>">
                <input type="hidden" name="id_cotizacion12" id="id_cotizacion12" value="<?php echo $_GET['idCotiz'];?>">
                <!-- <input type="text" name="num_fact" id="num_fact" > -->

                <!-- <div class='form-floating col-md-5 mt-3 m-auto  text-left' id='num_fact'>
                  <input type='number' class='form-control text-left' id='num_fact' name='num_fact' placeholder='Ingrese num Factura' required>
                  <label for='num_fact'>Ingrese num Factura</label>
                </div> -->

                <div class='form-floating col-md-10 mt-3 m-auto  text-left' >
                    <select name='num_fact' id='num_fact'  class='form-select' required>
                    <option value='0'>Selecciona una opción</option>
                    <?php


                          $query = "select * from sto_dte_venta where vent_tipo_estado='1' ";
                          $stmt1 = $DBcon->prepare( $query );
                          $stmt1->execute();  
                          
                          if($stmt1->rowCount() > 0) {
                              while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
                                  extract($row);

                                  echo "<option value='".$vent_folio."'>".$vent_folio." </option>";
                              }
                          }
                      
                      
                            

                    ?>

                    </select>
                    <label for='floatingSelectGrid'>Selecciona un Cliente asociado</label>
                </div>

                <?php
            }
            ?>

            <?php 
            if(isset($_GET['idCodProy'])){    
              
                
                ?>
                <input type="hidden" name="ultimo_proceso" id="ultimo_proceso" value="ultimo_proceso">

                <div class='form-floating col-md-5 mt-3 m-auto  text-left' id='id_cotizacion'>
                  <input type='text' class='form-control text-left' id='id_cotizacion' name='id_cotizacion' value="<?php echo $_GET['idCotiz'];?>" placeholder='Ingrese num Factura' required>
                  <label for='id_cotizacion'>id_cotizacion</label>
                </div>

                <div class='form-floating col-md-5 mt-3 m-auto  text-left' id='id_proyecto'>
                  <input type='text' class='form-control text-left' id='id_proyecto' name='id_proyecto'  value="<?php echo $_GET['idCodProy'];?>" placeholder='Ingrese num Factura' required>
                  <label for='id_proyecto'>id_proyecto</label>
                </div>

                <div class='form-floating col-md-5 mt-3 m-auto  text-left' id='num_fact1'>
                  <input type='text' class='form-control text-left' id='num_fact1' name='num_fact1'  value="<?php echo $_GET['idFolioFactura'];?>" placeholder='Ingrese num Factura' required>
                  <label for='num_fact1'>Id_factura</label>
                </div>
                <?php
            }
            ?>

            <?php 
            if(isset($_GET['idCodProy1111'])){             
                ?>
                <div class='d-flex'>
                <?php 

                $id_proyectos=$_GET['idCodProy'];
                
                $query = "select id_cliente from sto_proyectos where id='$id_proyectos' ";
                $stmt = $DBcon->prepare( $query );
                $stmt->execute();
                
                if($stmt->rowCount() > 0) {
                    while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
                        extract($row);
                        echo " <input type='hidden' name='id_clientes' id='id_clientes' value='$id_cliente'>";
                                
                    }
                }
                ?>
                <input type="hidden" name="id_proyecto" id="id_proyecto" value="<?php echo $_GET['idCodProy']; ?>">

                    <div class='form-floating col-md-10 mt-3 m-auto  text-left' >
                        <select name='id_cotizacion123' id='id_cotizacion123'  class='form-select' required>
                        <option value='0'>Selecciona una opción</option>
                        <?php


                                $query = "select * from clientes";
                                $stmt = $DBcon->prepare( $query );
                                $stmt->execute();
                                
                                if($stmt->rowCount() > 0) {
                                    while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
                                        extract($row);

                                        $query = "select * from sto_cotizacion ORDER BY id_cotizacion DESC";
                                        $stmt1 = $DBcon->prepare( $query );
                                        $stmt1->execute();  
                                        
                                        if($stmt1->rowCount() > 0) {
                                            while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
                                                extract($row);
                                                $Cantidad_proyectos=$Count_proyectos;    

                                                echo "<option value='".$id_cotizacion."'>".$id_cotizacion." - ".$tipo_cotizacion." </option>";
                                            }
                                        }
                                
                                    }
                                }

                        ?>

                        </select>
                        <label for='floatingSelectGrid'>Selecciona un Cliente asociado</label>
                    </div>

                </div>

                <?php 
            }
            ?>

                <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) {
                      e.preventDefault();
                      var datos=$(this).serialize();
                      $.ajax({
                          type:"POST",
                          url:"check_ejecut.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'
                                  })
                                }
                                else {
                                  Swal.fire({
                                    title: 'Error!',
                                    text: 'Ha ocurrido un error',
                                    icon: 'error',
                                    confirmButtonText: 'ok'
                                  })
                                }
                                document.getElementById("formulario").reset();
                                // setTimeout("location.href='index.php'",2000);
                               window.close();
                            }     
                      });
                  });
              });
            </script>

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


