<?php

if($_SESSION["nombre"] == "Inventario "){

  echo '<script>

    window.location = "inicio";

  </script>';

  return;

}

?>
<div class="content-wrapper">

<section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Administrar Pedidos Validados</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="inicio">Inicio</a></li>
              <li class="breadcrumb-item active">Administrar Pedidos Validados</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>


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

      <!-- Default box -->
      <div class="card">
        <div class="card-header">
          
          <button type="button" class="btn btn-default float-right pull-right  btn-sm" id="daterange-btn">
         
           <span>
             <i class="fa fa-calendar"></i> Rango de fecha
           </span>

           <i class="fa fa-caret-down"></i>

        </button>

        </div>
        <div class="card-body">
        <table style="font-size:75%;" class="table table-bordered table-hover table-striped dt-responsive pedidosValidados table-sm" style="font-size:90%; line-height:14px ">
         
         <thead>
          
          <tr>
            
            <th style="width:10px">#</th>
            <th style="width:5%">#codigo</th>
            <th style="width:5%">Area</th>
            <th style="width:25%" >Jefe de Area</th>
            <th>Fecha</th>
            <th>Hora</th>
            <th>Estado Validacion</th>
            <th>Estado Despacho</th>
            <th>Acciones</th>
 
          </tr> 
 
         </thead>
 
         <tbody>
           
         <?php


            if(isset($_GET["fechaInicial"])){

              $fechaInicial = $_GET["fechaInicial"];
              $fechaFinal = $_GET["fechaFinal"];
              
    
            }else{
    
              $fechaInicial = null;
              $fechaFinal = null;
            
    
            }
    
              $respuesta = ControladorVentas::ctrPedidosValidados($fechaInicial, $fechaFinal);
        

          foreach ($respuesta as $key => $value) {

          echo '<tr>

                  <td>'.($key+1).'</td>

                  <td>'.$value["codigo"].'</td>';

                  $itemUsuario = "id";
                  $valorUsuario = $value["id_usuario"];

                  $respuestaUsuario = ControladorUsuarios::ctrMostrarUsuarios($itemUsuario, $valorUsuario);

                  $itemEmpleado = "id";
                  $valorEmpleado = $respuestaUsuario["id_empleado"];

                  $empleado = ControladorEmpleado:: ctrMostrarEmpleado($itemEmpleado, $valorEmpleado);


                  $fecha = date_create($value["fecha"]);
                  $fecha1 = date_format($fecha, "d/m/Y");

                  echo '<td>'.$value["nombre"].'</td>';
                  echo '<td>'.$empleado["nombre"].'</td>';
                  echo '<td>'.$fecha1.'</td>';
                  echo '<td>'.$value["hora"].'</td>';

                  if($value["estado_validacion"] == 0 ){
                    echo '<td><button class="btn btn-warning btn-xs">PENDIENTE</button></td>';
                  }else if ($value["estado_validacion"] == 1){
                    echo '<td><button class="btn btn-success btn-xs">VALIDADO</button></td>';
                  } else if ($value["estado_validacion"] == 2) {
                    echo '<td><button class="btn btn-info btn-xs">OBSERVADO</button></td>';
                  } else {
                    echo '<td><button class="btn btn-danger btn-xs">RECHAZADO</button></td>';
                  }

                  if($value["estado_despacho"] == 0 ){
                    echo '<td><button class="btn btn-warning btn-xs">PENDIENTE</button></td>';
                  }else{
                    echo '<td><button class="btn btn-success btn-xs">DESPACHADO</button></td>';
                  }

                  echo'<td>

                    <div class="btn-group">
                        
                      <button class="btn btn-info btnVerVale" codigoVenta="'.$value["codigo"].'"><i class="fa fa-print"></i></button>
                      <button class="btn btn-warning btnEditarPedidoValidado"  data-toggle="modal" data-target="#modalEditarPedidoValidado" idVenta="'.$value["id"].'"><i class="fas fa-pencil-alt"></i></button>';

                    echo'</div>  

                  </td>

                </tr>';
            }

          ?>
 

           
         </tbody>
         <tfoot style="background-color: #000">
                  <tr>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
    
        
              
                    </tr>
          </tfoot>

 
        </table>
        <input type="hidden" value="<?php echo $_SESSION['nombre'];?>" id="perfilOculto">
        <?php

     

        ?>
        </div>
        <!-- /.card-body -->
      </div>
      <!-- /.card -->

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

  <!--=====================================
MODAL EDITAR PEDIDO
======================================-->

<div class="modal fade" id="modalEditarPedidoValidado">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <form role="form" method="post" enctype="multipart/form-data" class="formularioVenta">

                    <div class="modal-header" style="background: #EAA354; color: white">
                      <h4 class="modal-title">Detalle del Pedido</h4>
                     
                      <button type="button" class="close"  onclick="salir1()" data-dismiss="modal" aria-label="Close" id="cerrar">

                        <span aria-hidden="true">&times;</span>
                      </button>
                    </div>

                    <div class="modal-body">
                      <div class="box-body">
                        <div class="row">
   
                           <div class="col-6">
                            <div class="form-group">
                              <label>Area Solicitante (*):</label>
                              <div class="input-group mb-3">
                                <div class="input-group-append">
                                  <div class="input-group-text">
                                    
                                    <span class="fas fa-th"></span>
                                  </div>
                                </div>
                                  <input type="text" class="form-control form-control-sm" name="area" id="area" readonly required>
                                    
                              </div>
                            </div>
                          </div>

                          <div class="col-6">
                            <div class="form-group">
                              <label>codigo Venta (*):</label>
                              <div class="input-group mb-3">
                                <div class="input-group-append">
                                  <div class="input-group-text">
                                    
                                    <span class="fas fa-th"></span>
                                  </div>
                                </div>
                                  <input type="text" class="form-control form-control-sm" name="codigopedido" id="codigopedido" readonly required>
                                    
                              </div>
                            </div>
                          </div>

                        </div>

                        <div class="row">
                
                           <div class="col-6">
                            <div class="form-group">
                              <label>Autorizado Por (*):</label>
                              <div class="input-group mb-3">
                                <div class="input-group-append">
                                  <div class="input-group-text">
                                    
                                    <span class="fas fa-th"></span>
                                  </div>
                                </div>
                                  <input type="text" class="form-control form-control-sm" name="jefearea" id="jefearea" readonly required>
                                    
                              </div>
                            </div>
                          </div>

                          <div class="col-6">
                            <div class="form-group">
                              <label>Fecha (*):</label>
                              <div class="input-group mb-3">
                                <div class="input-group-append">
                                  <div class="input-group-text">
                                    
                                    <span class="fas fa-th"></span>
                                  </div>
                                </div>
                                  <input type="text" class="form-control form-control-sm" name="fecha" id="fecha" readonly required>
                                    
                              </div>
                            </div>
                          </div>

                        </div>

                        <div class="row">
     
                           <div class="col-6">
                            <div class="form-group">
                              <label> Numero DNI(*):</label>
                              <div class="input-group mb-3">
                                <div class="input-group-append">
                                  <div class="input-group-text">
                                    
                                    <span class="fas fa-th"></span>
                                  </div>
                                </div>
                                  <input type="text" class="form-control form-control-sm" name="dni" id="dni" readonly required>
                                    
                              </div>
                            </div>
                          </div>

                          <div class="col-6">
                            <div class="form-group">
                              <label> Sustentacion del Requirimiento</label>
                              <div class="input-group mb-3">
                              
                                  <textarea type="text" class="form-control form-control-sm" name="sustentacion" id="sustentacion" readonly required></textarea>
                                    
                              </div>
                            </div>
                          </div>

                        </div>

                 
            
                          <div class="form-group">
                    
                              <table  class="table table-bordered table-striped dt-responsive table-sm" id="tablaProductos" style="font-size:90%; line-height:14px ">

                                <thead>

                                  <tr>
                                    <th style="width:10px">N°</th>
                                    <th style="width:10px">Centro Costo</th>
                                    <th style="width:10px">Codigo</th>
                                    <th>Descripcion</th>
                                    <th>Und</th>
                                    <th style="width:5%">Cantidad</th>
                                  </tr> 

                                </thead>
                                <tbody class="listaProducto2" id="lista">
                                

                                </tbody>
                                  
                                </table>

                          </div>

                          <div class="cajasMetodoPago"></div>

          
                            <div class="form-group">
                              <label> CONFIRMAR(*):</label>
                              <div class="input-group mb-3">
                                <div class="input-group-append">
                                  <div class="input-group-text">
                                    
                                    <span class="fas fa-th"></span>
                                  </div>
                                </div>
                                  <select class="form-control form-control-sm" name="validar" id="validar" required>
                                    <option value="">Seleccionar</option>
                                    <option value="1">Pedido Despachado</option>
                                  </select>

                                  <input type="hidden" id="listaProductos" name="listaProductos">
<br>
                                  <select class="form-control form-control-sm" name="vehiculo" id="vehiculo" style="display: none">

                                    <option value="">Seleccionar Vehiculo</option>
                                    <?php
                                  
                                      $item = null;
                                      $valor = null;
                                      
                                      $vehiculo = ControladorVehiculo:: ctrMostrarVehiculo($item, $valor);
                                        foreach($vehiculo as $key => $value){

                                          echo '<option value="'.$value["id_vehiculo"].'">'.$value["placa"].'</option>';


                                        }

                                    ?>

                                    </select>

                                 
                                    
                              </div>
                            </div>
                     

                      </div>
                      <div class="modal-footer justify-content-between">
                      <button type="button" onclick="salir1()" id="salir" class="btn btn-default cerrar" data-dismiss="modal">Salir</button>
                      <button type="submit" class="btn btn-warning">Guardar</button>
                    </div>

                    <?php 
                    
                    $editarPedido = new ControladorVentas();
                    $editarPedido -> ctrEditarPedido2();
                    
                    ?>
                    </div>

                   
                     
                    
                    
            </form>
            </div>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->

        <script>

              function salir1(){

                console.log("vamos");

                window.location.reload();


              }
 
            </script>

 
  <script>

      
      var elemento = document.getElementById("logistica");
      elemento.className += " active";

      var elemento = document.getElementById("log");
      elemento.className += " menu-open";

      var elemento = document.getElementById("pedidosValidados");
      elemento.className += " active";
</script>

<script src="vistas/js/pedidosValidados.js"></script>
<script src="vistas/js/ventas.js"></script>