<?php 

include('../Stoglobal/include/conexion.php');
include('../Stoglobal/include/conexion1.php');
// include('../Stoglobal/include/conexion2.php');
include('../Stoglobal/include/conexion3.php');
 error_reporting(0);
$continente=$_POST['estado'];



      date_default_timezone_set('America/Santiago');
      $fechasa=date("Y-m-d");

      $fechasa1=date("Y-m");
      $nuevafecha = strtotime('-1 months', strtotime($fechasa1));
      $nuevafecha = date('Y-m' , $nuevafecha);
      $nuevafecha1=$nuevafecha."-25";


      $aa=$_POST['estado1'];


      if($aa=='2'){
        echo $cadena="  

                    <div class='d-flex'>
                      <div class='form-floating col-md-10 mt-3 m-auto  text-left' id='detalle'>
                      <h5>Seleccione el proyecto</h5>
                      </div>
                    </div>

                    

                    <div class='d-flex'>              
                      <div class='form-floating col-md-5 mt-3 m-auto  text-left' id='precio_venta'>
                        <select name='cod_proyecto' id='cod_proyecto'  class='form-select' required>
                          <option value=''>Seleciona un Proyecto</option>
        ";
                            $query = 'select * from sto_proyectos ORDER BY `sto_proyectos`.`id` desc';
                            $stmt = $DBcon->prepare( $query );
                            $stmt->execute();
                            
                            if($stmt->rowCount() > 0) {
                                while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
                                    extract($row);
                          
        echo $cadena="
                                <option value='$cod_proyecto'>
        ";
                                echo $cod_proyecto; 
                                echo " / ";
                                echo $nombre;
        echo $cadena="

                                </option>
        ";
                       
                              }
                            }
                        
          echo $cadena="
                        </select>                      
                      </div>
                    </div> 
                    </br>
          ";

          ?>

            <!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 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>

                    <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>
                        var myTable = document.querySelector("table"); 
                        function agregarFila(){ 

                              // var is = 1;
                              var i = $("#ContadorCeldas").val();
                              var row = myTable.insertRow(myTable.rows.length);
                              var cell1 = row.insertCell(0);
                              var cell2 = row.insertCell(1);
                              var cell3 = row.insertCell(2);
                              var cell4 = row.insertCell(3);
                              var cell5 = row.insertCell(4);

                            
                                if (i < 100) {

                                  cell1.innerHTML = '<div class="form-floating m-auto  text-left"><input type="text" class="form-control text-left" id="num_romano_0" name="num_romano_0" value="'+i+'"  readonly></div>';
                                  cell2.innerHTML = '<div class="form-floating mb-3 "><select name="id_producto_'+i+'" id="id_producto_'+i+'"  class="form-select" required><option value="1" selected>Seleciona un Producto</option>'+"<?php $query = "select * from sto_bodega where stock_actual>0 ORDER BY `sto_bodega`.`id_producto` desc";$stmt = $DBcon->prepare( $query );$stmt->execute();if($stmt->rowCount() > 0) {while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {extract($row);echo "<option value='$cod_producto'>$cod_producto / $stock_actual / ".number_format($precio_venta,0,',','.')." / $nombre </option>";}}?>"+'</select><label for="floatingSelectGrid">Selecciona la operación </label></div>';
                                  cell3.innerHTML = '<div class="form-floating m-auto  text-left" id="cantidad_'+i+'"><input type="number" class="form-control text-left" id="cantidad_'+i+'" name="cantidad_'+i+'" required><label for="cantidad_'+i+'">Cantidad</label></div>';
                                  cell4.innerHTML = '<div class="form-floating m-auto  text-left" id="precio_venta_'+i+'"><input type="number" class="form-control text-left" id="precio_venta_'+i+'" name="precio_venta_'+i+'" required><label for="precio_venta_'+i+'">Precio Venta</label></div>';
                                  cell5.innerHTML = '<div class="form-floating m-auto  text-left" id="detalle_'+i+'"><textarea class="form-control" maxlength="86" name="detalle_'+i+'" id="detalle_'+i+'" required></textarea><label for="detalle_'+i+'">Detalle</label></div>';

                                  
                                  document.getElementById('ContadorCeldas').value++;
                                } 
                                else{
                                  cell1.innerHTML = '<div class="form-floating m-auto  text-left" id="producto_100"><input type="text" class="form-control text-left" id="producto_100" name="producto_100" value="10" required><label for="producto_100">Tipo de Producto</label></div> ';
                                  cell2.innerHTML = '<div class="form-floating m-auto  text-left" id="valor_neto_100"><input type="number" class="form-control text-left" id="valor_neto_100" name="valor_neto_100" required><label for="valor_neto_100">Precio Neto</label></div>';
                                  cell3.innerHTML = '<div class="form-floating m-auto  text-left" id="cantidad_100"><input type="number" class="form-control text-left" id="cantidad_100" name="cantidad_100" required><label for="cantidad_100">Cantidad</label></div>';
                            
                                  
                                }

                            
                          }

                          function eliminarFila(){
                          var rowCount = myTable.rows.length;
                          if(rowCount <= 2) {
                            alert('No se puede eliminar el encabezado');
                          } else {
                            myTable.deleteRow(rowCount -1);
                            document.getElementById('ContadorCeldas').value--;
                          }
                      
                        }

                    </script>

                  </head>
                  <body>
                              <button type="button" class="btn btn-danger  rounded-pill" onclick="eliminarFila()"> Eliminar fila</button> 
                              <button type="button" class="btn btn-primary  rounded-pill" onclick="agregarFila()"> Agregar fila</button> 
                              </br>
                              <table class="table">
                                  <thead>
                                    <tr>
                                      <th width="52px">#</th>
                                      <th>ID_Prod / Stock / Precio Venta / Descripción </th>
                                      <th>Cantidad</th>
                                      <th>Precio Venta</th>
                                      <th>Detalle</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <tr>
                                      <input type="hidden" class="form-control text-left" id="ContadorCeldas" name="ContadorCeldas" value="2" readonly>
                                      <td><div class="form-floating m-auto  text-left"><input type="text" class="form-control text-left"  id="num_romano_1" name="num_romano_1" value="1" readonly></div></td>

                                      <td>
                                          <div class="form-floating mb-3 ">
                                              <select name="id_producto_1" id="id_producto_1"  class="form-select" required>
                                                <option value="1" selected>Seleciona un Producto</option>
                                                <?php 
                                                  $query = "select * from sto_bodega where stock_actual>=1 ORDER BY `sto_bodega`.`id_producto` desc";
                                                  $stmt = $DBcon->prepare( $query );
                                                  $stmt->execute();
                                                  
                                                  if($stmt->rowCount() > 0) {
                                                      while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
                                                          extract($row);
                                                ?>
                                                      <option value="<?php echo $cod_producto;?>"><?php echo $cod_producto;?> / <?php echo $stock_actual;?> / <?php echo " $";echo number_format($precio_venta,0,",","."); ?> / <?php echo $nombre; ?> </option>
                                                <?php 
                                                  }
                                                  }
                                                ?>
                                              </select>
                                              <label for="floatingSelectGrid">Selecciona la operación </label>
                                          </div>
                                      </td>
                                      
                                      <td><div class="form-floating m-auto  text-left" id="cantidad_1"><input type="number" class="form-control text-left" id="cantidad_1" name="cantidad_1"  required><label for="cantidad_1">Cantidad</label></div></td>     
                                      <td><div class="form-floating m-auto  text-left" id="precio_venta_1"><input type="number" class="form-control text-left" id="precio_venta_1" name="precio_venta_1"  required><label for="precio_venta_1">Precio Venta</label></div></td>     
                                      <td><div class="form-floating m-auto  text-left" id="detalle_1"><textarea class="form-control" maxlength="2000" name="detalle_1" id="detalle_1" required></textarea><label for="detalle_1">Detalle</label></div></td>

                                    </tr>             
                                  </tbody>
                                </table>

                  </body>
                </html>

          <?php
      }
      


      if($aa=='1'){
        echo $cadena="  
          <div class='d-flex'>
              <div class='form-floating col-md-5 mt-3 m-auto'  id='fecha' >
                  <input type='date' id='fecha' name='fecha' class='form-control date' value='$fechasa'>
                  <label for='floatingSelectGrid'>Fecha</label>
              </div> 
          </div>

        ";
     

          ?>
</br></br>
            <!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 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>

                    <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>
                        var myTable = document.querySelector("table"); 
                        function agregarFila(){ 

                              // var is = 1;
                              var i = $("#ContadorCeldas").val();
                              var row = myTable.insertRow(myTable.rows.length);
                              var cell1 = row.insertCell(0);
                              var cell2 = row.insertCell(1);
                              var cell3 = row.insertCell(2);
                              var cell4 = row.insertCell(3);
                              var cell5 = row.insertCell(4);

                            
                                if (i < 100) {

                                  cell1.innerHTML = '<div class="form-floating m-auto  text-left"><input type="text" class="form-control text-left" id="num_romano_0" name="num_romano_0" value="'+i+'"  readonly></div>';
                                  cell2.innerHTML = '<div class="form-floating mb-3 "><select name="id_producto_'+i+'" id="id_producto_'+i+'"  class="form-select" required><option value="1" selected>Seleciona un Producto</option>'+"<?php $query = "select * from sto_bodega where stock_actual>0 ORDER BY `sto_bodega`.`id_producto` desc";$stmt = $DBcon->prepare( $query );$stmt->execute();if($stmt->rowCount() > 0) {while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {extract($row);echo "<option value='$cod_producto'>$cod_producto / $stock_actual / ".number_format($precio_venta,0,',','.')." / $nombre </option>";}}?>"+'</select><label for="floatingSelectGrid">Selecciona la operación </label></div>';
                                  cell3.innerHTML = '<div class="form-floating m-auto  text-left" id="cantidad_'+i+'"><input type="number" class="form-control text-left" id="cantidad_'+i+'" name="cantidad_'+i+'" required><label for="cantidad_'+i+'">Cantidad</label></div>';
                                  cell4.innerHTML = '<div class="form-floating m-auto  text-left" id="precio_venta_'+i+'"><input type="number" class="form-control text-left" id="precio_venta_'+i+'" name="precio_venta_'+i+'" required><label for="precio_venta_'+i+'">Precio Venta</label></div>';
                                  cell5.innerHTML = '<div class="form-floating m-auto  text-left" id="detalle_'+i+'"><textarea class="form-control" maxlength="86" name="detalle_'+i+'" id="detalle_'+i+'" required></textarea><label for="detalle_'+i+'">Detalle</label></div>';

                                  
                                  document.getElementById('ContadorCeldas').value++;
                                } 
                                else{
                                  cell1.innerHTML = '<div class="form-floating m-auto  text-left" id="producto_100"><input type="text" class="form-control text-left" id="producto_100" name="producto_100" value="10" required><label for="producto_100">Tipo de Producto</label></div> ';
                                  cell2.innerHTML = '<div class="form-floating m-auto  text-left" id="valor_neto_100"><input type="number" class="form-control text-left" id="valor_neto_100" name="valor_neto_100" required><label for="valor_neto_100">Precio Neto</label></div>';
                                  cell3.innerHTML = '<div class="form-floating m-auto  text-left" id="cantidad_100"><input type="number" class="form-control text-left" id="cantidad_100" name="cantidad_100" required><label for="cantidad_100">Cantidad</label></div>';
                            
                                  
                                }

                            
                          }

                          function eliminarFila(){
                          var rowCount = myTable.rows.length;
                          if(rowCount <= 2) {
                            alert('No se puede eliminar el encabezado');
                          } else {
                            myTable.deleteRow(rowCount -1);
                            document.getElementById('ContadorCeldas').value--;
                          }
                      
                        }

                    </script>

                  </head>
                  <body>
                              <button type="button" class="btn btn-danger  rounded-pill" onclick="eliminarFila()"> Eliminar fila</button> 
                              <button type="button" class="btn btn-primary  rounded-pill" onclick="agregarFila()"> Agregar fila</button> 
                              </br>
                              <table class="table">
                                  <thead>
                                    <tr>
                                      <th width="52px">#</th>
                                      <th>ID_Prod / Stock / Precio Venta / Descripción </th>
                                      <th>Cantidad</th>
                                      <th>Precio Venta</th>
                                      <th>Detalle</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <tr>
                                      <input type="hidden" class="form-control text-left" id="ContadorCeldas" name="ContadorCeldas" value="2" readonly>
                                      <td><div class="form-floating m-auto  text-left"><input type="text" class="form-control text-left"  id="num_romano_1" name="num_romano_1" value="1" readonly></div></td>

                                      <td>
                                          <div class="form-floating mb-3 ">
                                              <select name="id_producto_1" id="id_producto_1"  class="form-select" required>
                                                <option value="1" selected>Seleciona un Producto</option>
                                                <?php 
                                                  $query = "select * from sto_bodega where stock_actual>=1 ORDER BY `sto_bodega`.`id_producto` desc";
                                                  $stmt = $DBcon->prepare( $query );
                                                  $stmt->execute();
                                                  
                                                  if($stmt->rowCount() > 0) {
                                                      while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
                                                          extract($row);
                                                ?>
                                                      <option value="<?php echo $cod_producto;?>"><?php echo $cod_producto;?> / <?php echo $stock_actual;?> / <?php echo " $";echo number_format($precio_venta,0,",","."); ?> / <?php echo $nombre; ?> </option>
                                                <?php 
                                                  }
                                                  }
                                                ?>
                                              </select>
                                              <label for="floatingSelectGrid">Selecciona la operación </label>
                                          </div>
                                      </td>
                                      
                                      <td><div class="form-floating m-auto  text-left" id="cantidad_1"><input type="number" class="form-control text-left" id="cantidad_1" name="cantidad_1"  required><label for="cantidad_1">Cantidad</label></div></td>     
                                      <td><div class="form-floating m-auto  text-left" id="precio_venta_1"><input type="number" class="form-control text-left" id="precio_venta_1" name="precio_venta_1"  required><label for="precio_venta_1">Precio Venta</label></div></td>     
                                      <td><div class="form-floating m-auto  text-left" id="detalle_1"><textarea class="form-control" maxlength="2000" name="detalle_1" id="detalle_1" required></textarea><label for="detalle_1">Detalle</label></div></td>

                                    </tr>             
                                  </tbody>
                                </table>

                  </body>
                </html>

          <?php
        

}




?>


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

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

              function recargarLista(){
                  $.ajax({
                      type:"POST",
                      url:"consulta2.php",
                      data:"productonum=" + $('#selector10').val(),
                      success:function(r){
                          $('#TraerDatosPieza1').html(r);
                      }
                  });
              }
          </script> -->
         

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