<?php

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

  echo '<script>

    window.location = "inicio";

  </script>';

  return;

}

?>

<style>
.select2-container--default .select2-selection--single {
    background-color: #fff;
    border: 1px solid #aaa;
    border-radius: 4px;
    height: calc(2.25rem + 2px);
}
.hidden {
  display: none !important;
}


.visible-xs,
.visible-sm,
.visible-md,
.visible-lg {
  display: none !important;
}
.visible-xs-block,
.visible-xs-inline,
.visible-xs-inline-block,
.visible-sm-block,
.visible-sm-inline,
.visible-sm-inline-block,
.visible-md-block,
.visible-md-inline,
.visible-md-inline-block,
.visible-lg-block,
.visible-lg-inline,
.visible-lg-inline-block {
  display: none !important;
}
@media (max-width: 767px) {
  .visible-xs {
    display: block !important;
  }
  table.visible-xs {
    display: table !important;
  }
  tr.visible-xs {
    display: table-row !important;
  }
  th.visible-xs,
  td.visible-xs {
    display: table-cell !important;
  }
}
@media (max-width: 767px) {
  .visible-xs-block {
    display: block !important;
  }
}
@media (max-width: 767px) {
  .visible-xs-inline {
    display: inline !important;
  }
}
@media (max-width: 767px) {
  .visible-xs-inline-block {
    display: inline-block !important;
  }
}
@media (min-width: 768px) and (max-width: 991px) {
  .visible-sm {
    display: block !important;
  }
  table.visible-sm {
    display: table !important;
  }
  tr.visible-sm {
    display: table-row !important;
  }
  th.visible-sm,
  td.visible-sm {
    display: table-cell !important;
  }
}
@media (min-width: 768px) and (max-width: 991px) {
  .visible-sm-block {
    display: block !important;
  }
}
@media (min-width: 768px) and (max-width: 991px) {
  .visible-sm-inline {
    display: inline !important;
  }
}
@media (min-width: 768px) and (max-width: 991px) {
  .visible-sm-inline-block {
    display: inline-block !important;
  }
}
@media (min-width: 992px) and (max-width: 1199px) {
  .visible-md {
    display: block !important;
  }
  table.visible-md {
    display: table !important;
  }
  tr.visible-md {
    display: table-row !important;
  }
  th.visible-md,
  td.visible-md {
    display: table-cell !important;
  }
}
@media (min-width: 992px) and (max-width: 1199px) {
  .visible-md-block {
    display: block !important;
  }
}
@media (min-width: 992px) and (max-width: 1199px) {
  .visible-md-inline {
    display: inline !important;
  }
}
@media (min-width: 992px) and (max-width: 1199px) {
  .visible-md-inline-block {
    display: inline-block !important;
  }
}
@media (min-width: 1200px) {
  .visible-lg {
    display: block !important;
  }
  table.visible-lg {
    display: table !important;
  }
  tr.visible-lg {
    display: table-row !important;
  }
  th.visible-lg,
  td.visible-lg {
    display: table-cell !important;
  }
}
@media (min-width: 1200px) {
  .visible-lg-block {
    display: block !important;
  }
}
@media (min-width: 1200px) {
  .visible-lg-inline {
    display: inline !important;
  }
}
@media (min-width: 1200px) {
  .visible-lg-inline-block {
    display: inline-block !important;
  }
}
@media (max-width: 767px) {
  .hidden-xs {
    display: none !important;
  }
}
@media (min-width: 768px) and (max-width: 991px) {
  .hidden-sm {
    display: none !important;
  }
}
@media (min-width: 992px) and (max-width: 1199px) {
  .hidden-md {
    display: none !important;
  }
}
@media (min-width: 1200px) {
  .hidden-lg {
    display: none !important;
  }
}
.visible-print {
  display: none !important;
}
@media print {
  .visible-print {
    display: block !important;
  }
  table.visible-print {
    display: table !important;
  }
  tr.visible-print {
    display: table-row !important;
  }
  th.visible-print,
  td.visible-print {
    display: table-cell !important;
  }
}
.visible-print-block {
  display: none !important;
}
@media print {
  .visible-print-block {
    display: block !important;
  }
}
.visible-print-inline {
  display: none !important;
}
@media print {
  .visible-print-inline {
    display: inline !important;
  }
}
.visible-print-inline-block {
  display: none !important;
}
@media print {
  .visible-print-inline-block {
    display: inline-block !important;
  }
}
@media print {
  .hidden-print {
    display: none !important;
  }
}

</style>


<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header" style="padding: 2px;">
      <div class="container-fluid">
        <div class="row mb-2">
        </div>
      </div><!-- /.container-fluid -->
    </section>

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

      <!-- Default box -->
      <div class="row">
        <!--=====================================
            EL FORMULARIO
            ======================================-->

        <div class="col-lg-5 col-xs-12">
        
          <div class="card card-outline card-primary" style="padding: 10px">
            
            <div class="box-header with-border"></div>

            <form role="form" method="post" class="formularioVenta">
              
              <div class="box-body">

                <div class="box">

                  <!--=====================================
                  ENTRADA DEL USUARIO
                  ======================================-->

                <div class="row">
                  <div class="col-md-6">
                      <div class="form-group">
                        <div class="input-group">
                          <div class="input-group-append">
                            <div class="input-group-text">
                              <span class="fas fa-user"></span>
                            </div>
                          </div> 
                          <?php 
                              $itemEmpleado = "id";
                              $valorEmpleado = $_SESSION["id_empleado"];

                              $empleado = ControladorEmpleado:: ctrMostrarEmpleado($itemEmpleado, $valorEmpleado);
                              ?>
                              <input type="text" class="form-control form-control-sm" id="nuevoVendedor" name="seleccionarVendedor" value="<?php echo $empleado["nombre"]; ?>" readonly>
                              <input type="hidden" name="idVendedor" value="<?php echo $_SESSION["id"]; ?>">
                              
                              <input type="hidden" class="perfil" name="perfil" id="perfil" value="<?php echo $_SESSION["nombre"]; ?>">
                        </div>
                      </div> 
                   </div>

                    <div class="col-md-6">
                        <div class="form-group">                        
                          <div class="input-group">
                            <div class="input-group-append">
                              <div class="input-group-text">
                                <span class="fas fa-calendar-alt"></span>
                              </div>
                            </div> 
                            <?php
                            date_default_timezone_set('America/Lima');
                            $fecha = date('Y-m-d');
                              echo '<input type="text" class="form-control form-control-sm" id="fecha1" name="fecha1" value="'.$fecha.'" readonly>';
                          
                            ?>
                          </div>
                        </div> 

                    </div>
                </div>

                  <!--=====================================
                  ENTRADA DEL CODIGO
                  ======================================-->

                  <div class = "row">

                    <div class="col-md-4">                  

                      <div class="form-group">
                      
                        <div class="input-group">
                          
                          <div class="input-group-append">

                            <div class="input-group-text">
                              <span class="fas fa-key"></span>
                            </div>

                          </div> 

                          <?php

                          date_default_timezone_set('America/Lima');
                          $fecha = date('Y-m-d');
                          $item = null;
                          $valor = null;
                          $ventas = ControladorVentas::ctrMostrarVentas($item, $valor);
                          if(!$ventas){
                            echo '<input type="text" class="form-control form-control-sm" id="nuevaVenta" name="nuevaVenta" value="10001" readonly>';
                          }else{
                            foreach ($ventas as $key => $value) {
                            }
                            $codigo = $value["codigo"] + 1;
                            $id = $value["id"] + 1;
                            echo '<input type="text" class="form-control form-control-sm" id="nuevaVenta" name="nuevaVenta" value="'.$codigo.'" readonly>
                                  <input type="hidden" class="form-control" id="nuevoid" name="nuevoid" value="'.$id.'">';
                          }
                          ?>
                        </div>

                      </div> 
                    </div>


                    <div class="col-md-4">                  
                      <div class="form-group">
                        <div class="input-group">
                          <div class="input-group-append">
                            <div class="input-group-text">
                              <span class="fas fa-key"></span>
                            </div>
                          </div> 
                          <select class="form-control form-control-sm seleccionarMoneda" id="seleccionarMoneda" name="seleccionarMoneda" required >
                            <option value="0">Tipo Moneda</option>
                            <option value="SOLES">SOLES</option>
                          </select>

                        </div>

                      </div> 
                    </div>


                  </div>

                  <!--=====================================
                  ENTRADA DEL CLIENTE
                  ======================================-->

                  <div class="form-group">
                  
                    <div class="input-group">
                      
                      <div class="input-group-append">

                        <div class="input-group-text">
                          <span class="fas fa-user"></span>
                        </div>

                      </div> 

                      <select class="form-control select2 form-control-sm" id="seleccionarCliente" name="seleccionarCliente"  required>

                        <option value="">Seleccionar cliente</option>

                        <?php

                        $item = null;
                        $valor = null;

                        $categorias = ControladorClientes::ctrMostrarClientes($item, $valor);

                        

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

                          echo '<option style="color: white;" estado="'.$value["estado"].'" value="'.$value["id"].'">'.$value["razon_social"]. ' - ' .$value["ruc_dni"].'</option>';

                        }

                        ?>

                      </select>

                      <span class="input-group-append"><button type="button" class="btn btn-warning btn-xs" data-toggle="modal" data-target="#modalAgregarCliente" data-dismiss="modal">Agregar cliente</button></span>

                    </div>

                  </div> 

                  <!--=====================================
                  ENTRADA PARA AGREGAR PRODUCTO
                  ======================================--> 
                  <div class="col-xs-8 pull-right">
                      
                      <table style="font-size:75%" class="table table-bordered productos">

                        <thead>

                          <tr>
                            <th><center>Producto</center></th>
                            <th style="text-align:right">Cantidad</th>
                            <th>Precio</th>  
                            <th>Total</th>    
                          </tr>

                        </thead>

                        <tbody class="nuevoProducto">

                        </tbody>
                      </table>
                  </div>

                  <input type="hidden" id="listaProductos" name="listaProductos">
                 
                  <!--=====================================
                  BOTÓN PARA AGREGAR PRODUCTO
                  ======================================-->

                  <button type="button" class="btn btn-warning btnAgregarProducto hidden-lg">Agregar producto</button>

                  <hr>

                  <div class="row">

                    <!--=====================================
                    ENTRADA IMPUESTOS Y TOTAL
                    ======================================-->
                    
                    <div class="col-xs-8 pull-right">
                      
                      <table style="font-size:75%" class="table table-bordered">

                        <thead>

                          <tr>
                            <th><center>SUBTOTAL</center></th>
                            <th><center>IGV</center></th>  
                            <th><center>TOTAL</center></th>    
                          </tr>

                        </thead>

                        <tbody>
                        
                          <tr>
                            
                            <td style="width: 30%">
                              
                              <div class="input-group">
                            
                                <div class="input-group-append">

                                  <div class="input-group-text">
                                  <span style = " height : 15px; width: 15px; margin: -15px -5px -5px" > <img src="vistas/dist/img/sol.png" width="20" alt=""></span>
                                  </div>

                                </div> 

                                <input type="text" class="form-control form-control-sm" id="nuevoPrecioImpuesto" name="nuevoPrecioImpuesto"  placeholder="00000" readonly required>

                                <input type="hidden" name="subtotal" id="subtotal">
                                
                          
                              </div>

                            </td>
                            <td style="width: 30%">
                              
                              <div class="input-group">
                            
                                <div class="input-group-append">

                                  <div class="input-group-text">
                                    <span style = " height : 15px; width: 15px; margin: -15px -5px -5px" > <img src="vistas/dist/img/sol.png" width="20" alt=""></span>
                                  </div>

                                </div> 

                                <input type="text" class="form-control form-control-sm" id="nuevoTotalVenta" name="nuevoTotalVenta"  placeholder="00000" readonly required>

                                <input type="hidden" name="igv" id="igv">
                                

                                
                          
                              </div>

                            </td>

                            <td style="width: 30%">
                              
                              <div class="input-group">
                            
                                <div class="input-group-append">

                                  <div class="input-group-text">
                                    <span style = " height : 15px; width: 15px; margin: -15px -5px -5px" > <img src="vistas/dist/img/sol.png" width="20" alt=""></span>
                                  </div>

                                </div> 

                                <input type="text" class="form-control form-control-sm" id="nuevoPrecioNeto" name="nuevoPrecioNeto" total="" placeholder="00000" readonly required>

                                <input type="hidden" name="totalVenta" id="totalVenta">
                                <input type="hidden" name="CostoTotal" id="totalCosto">
                                <input type="hidden" name="Utilidad" id="Utilidad">
                                
                          
                              </div>

                            </td>

                          </tr>

                        </tbody>

                      </table>

                    </div>

                  </div>

                  <div class="form-group">
                  
                    <div class="col-md-6" style="padding-right:0px">
                      
                      <div class="input-group">
                    
                        <select class="form-control form-control-sm" id="metodoPago" name="metodoPago" required>
                          <option value="">Seleccionar Metodo de Pago</option>
                          <option value="CONTADO">CONTADO</option>           
                        </select>    

                      </div>

                    </div>

                  </div>

                  <div class="cajasMetodoPago">

                  </div>
                  
                  <input type="hidden" id="listaMetodoPago" name="listaMetodoPago">
                  <hr>
                  <!--=====================================
                  ENTRADA MÉTODO DE PAGO
                  ======================================-->


                </div>

              </div>

              <div class="box-footer">

                <button type="submit" class="btn btn-warning btn-sm">Guardar</button>
                <button type="button" class="btn btn-info btn-sm" onclick="history.back()">VOLVER</button>

              </div>

            </form>
            <?php
              $guardarVenta = new ControladorVentas();
              $guardarVenta -> ctrCrearVenta();
        
          ?>
          </div>
        </div>
        <!--=====================================
          LA TABLA DE PRODUCTOS
        ======================================-->

          <div class="col-lg-7 hidden-md hidden-sm hidden-xs">
            
            <div class="card card-outline card-warning" style="padding: 10px">

              <div class="box-header with-border"></div>

              <div class="box-body">
                
                <table style="font-size:75%" class="table table-bordered table-hover table-sm dt-responsive tablaVentas">
                  
                  <thead>

                    <tr>
                      <th style="width: 10px">#</th>
                      <th>Descripcion</th>
                      <th>Marca</th>
                      <th>Stock</th>
                      <th>P Venta</th>
                      <th>Acciones</th>
                    </tr>

                  </thead>

                </table>

              </div>

            </div>


          </div>

      </div>
      <!-- /.row -->

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

    <!--=====================================
    MODAL AGREGAR CLIENTE
    ======================================-->

 <div class="modal fade" id="modalAgregarCliente">
        <div class="modal-dialog">
          <div class="modal-content">
    <form role="form" method="post" >

            <div class="modal-header" style="background: #007bff; color: white">
              <h4 class="modal-title">Agregar Cliente</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>

            <div class="modal-body">
              <div class="box-body">

              <div class="form-group">
                <div class="input-group mb-3">
                <div class="input-group-append">
                  <div class="input-group-text">
                    <span class="fas fa-key"></span>
                  </div>
                  </div>
                    <input type="number" class="form-control input-lg" name="nuevoRuc" id="nuevoRuc" placeholder="Ingresar RUC o DNI" required>
                  </div>
                </div>

                <div class="form-group">
                <div class="input-group mb-3">
                <div class="input-group-append">
                  <div class="input-group-text">
                    <span class="fas fa-user"></span>
                  </div>
                  </div>
                    <input type="text" class="form-control input-lg" name="nuevoNombre" id="nuevoNombre" placeholder="Ingresar Nombre o Razón social" required>
                  </div>
                </div>

                <div class="form-group">
                <div class="input-group mb-3">
                <div class="input-group-append">
                  <div class="input-group-text">
                    <span class="fas fa-envelope"></span>
                  </div>
                  </div>
                    <input type="email" class="form-control input-lg" name="nuevoCorreo" id="nuevoCorreo" placeholder="Ingresar Correo">
                  </div>
                </div>

                <div class="form-group">
                <div class="input-group mb-3">
                <div class="input-group-append">
                  <div class="input-group-text">
                    <span class="fas fa-phone"></span>
                  </div>
                  </div>
                    <input type="text" class="form-control input-lg" name="nuevoTelefono" id="nuevoTelefono" placeholder="Ingresar Telefono" data-inputmask="'mask':'(+51) 999-999-999'" data-mask>
                  </div>
                </div>
                 <!--=====================================
                  ENTRADA PARA SELECCIONAR DEPARTAMENTO
                   ======================================-->
                 
                    <div class="row">
                      <div class="col-9">
                        <div class="form-group">
                          <div class="input-group mb-3">
                            <div class="input-group-append">
                              <div class="input-group-text">
                                <span class="fas fa-map-marker"></span>
                              </div>
                            </div>
                            <input type="text" class="form-control input-lg" name="nuevoDireccion" id="nuevoDireccion" placeholder="Ingresar Direccion" required>
                          </div>
                        </div>
                      </div>
                      <div class="col-3">
                        <div class="form-group">
                          <div class="input-group mb-3">
                            <div class="input-group-append">
                              <div class="input-group-text">
                                <span class="fas fa-map-marker"></span>
                              </div>
                            </div>
                            <select  class="form-control input-lg" name="nuevoRuta" required>
                              <option value="A">A</option>
                              <option value="B">B</option>
                              <option value="C">C</option>
                              <option value="D">D</option>
                            </select>
                          </div>
                        </div>
                      </div>
                    </div>

  
              </div>
            </div>


            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Salir</button>
              <button type="submit" class="btn btn-primary">Guardar</button>
            </div>
            <?php 
            
            $crearCliente = new ControladorClientes();
            $crearCliente -> ctrCrearCliente();
            
            ?>
        </form>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
  </div>
      <!-- /.modal -->


      <div class="modal fade" id="modalimagen">
        <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>
            </div>
            <div class="modal-body" style=" width: 400px; height: 450px;">
              <div id="carousel">
                <figure style=" width: 400px; height: 400px;"><img class="img-thumbnail verImagen" width="400px"></figure>
                <input type="hidden" name="verImagen" id="verImagen">
              </div>
            </div>

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

      <script>
      $(function () {
        //Initialize Select2 Elements
        $('.select2bs4').select2({
          theme: 'bootstrap4'
        })

        //Initialize Select2 Elements
        $('.select2').select2()


      })

    </script>

<script type="text/javascript">
$(document).ready(function() {
    $("form").keypress(function(e) {
        if (e.which == 13) {
            return false;
        }
    });
});
</script>
<script>
      
      var elemento = document.getElementById("venta");
      elemento.className += " active";

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

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

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


