<?php
ob_start();
ini_set('session.gc_maxlifetime', 14400);
session_set_cookie_params(14400);
session_start();

if (!isset($_SESSION["nombre"]))
{
    header("Location: ../../login/login.php");
}
else
{
    require '../header.php';

if($_SESSION['ventas']==1){

    $sql="SELECT count(idventa)+1 as contador FROM venta ORDER BY idventa desc";
      $respuesta= ejecutarConsulta($sql);

      $fila = mysqli_fetch_assoc($respuesta);
      $con= '000'.$fila['contador'];

?>

            <div class="content-wrapper">
                <!-- Breadcrumb Section -->
                <section class="content-header">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <nav aria-label="breadcrumb">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item">
                                            <a href="#"><i class="fas fa-home"></i> Panel</a>
                                        </li>
                                        <li class="breadcrumb-item active" aria-current="page">
                                            <a href="list.php">
                                                <i class="module-icon"></i> Venta
                                            </a>
                                        </li>
                                    </ol>
                                </nav>
                            </div>
                          
                            <div class="col-sm-12" style="margin-top: 20px;">
                                <form class="form" method="post"  id="frmForm" autocomplete="off">
                                    <div class="card">
                                        <div class="card-header">
                                            <h3 class="card-title" id="idtitle" >
                                                <i class="fas fa-plus"></i> <!-- Icono para agregar -->
                                                Registro Venta Productos<!-- Título del formulario -->
                                            </h3>
                                        </div>
                                        <div class="card-body" style="display: block;">
                                            <div class="container-fluid">
                                                <div class="form-group col-lg-4 col-md-4 col-sm-4 col-xs-12">
                                                    <strong>NRO CORRELATIVO: </strong><strong id="nrocorrelativo_texto" name="nrocorrelativo_texto" style="background-color: green; color: white; padding: 5px; border-radius: 3px;"><?php echo $con; ?> </strong>
                                                    <input type="hidden" name="nrocorrelativo" id="nrocorrelativo" value="<?php echo $con; ?>">
                                                </div>
                                                <input type="hidden" name="idventa" id="idventa">
                                                <div class="row">
                                                    <!-- Primera columna -->
                                                    <div class="col-12 col-sm-12 col-md-8">
                                                        <div class="form-group">
                                                            <label for="idpersona">Nombre Cliente:</label>
                                                            <select  name="idpersona" id="idpersona" class="form-control"  data-live-search="true" data-style="btn-default" required>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <!-- Segunda columna -->
                                                    <div class="col-12 col-sm-12 col-md-4">
                                                        <div class="form-group">
                                                            <label >Fecha:</label>
                                                            <input type="datetime-local" class="form-control" name="fecha_hora" id="fecha_hora" required="" readonly>
                                                        </div>
                                                    </div>
                                                    <div class="col-12 col-sm-12 col-md-6">
                                                        <div class="form-group">
                                                            <label >Tipo Comprobante:</label>
                                                            <select  name="tipo_comprobante" id="tipo_comprobante" class="form-control select2"   data-live-search="true" data-style="btn-default" >
                                                            <option value="">Seleccione Comprobante</option>
                                                            <option value="1">Boleta</option>
                                                            <option value="2">Factura</option>
                                                            </select>
                                                        </div>
                                                    </div>

                                                    <div class="col-12 col-sm-12 col-md-3">
                                                        <div class="form-group">
                                                            <br>
                                                            <button id="btnAgregarArt" type="button" class="btn btn-warning btn-xs btn-flat" data-toggle="modal" data-target="#myModalIngreso">
                                                                <span class="fa fa-plus"></span>&nbsp;&nbsp;Agregar productos
                                                            </button>
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12 table-responsive">
                                                        <table id="detalles" class="table table-striped table-bordered table-condensed table-hover">
                                                            <thead>
                                                                <th style="background-color:#000000;color: white;">Opciones</th>
                                                                <th style="background-color:#000000;color: white;">Articulo</th>
                                                                <th style="background-color:#000000;color: white;">Codigo</th>
                                                                <th style="background-color:#000000;color: white;">Marca</th>
                                                                <th style="background-color:#000000;color: white;">Mac</th>
                                                                <th style="background-color:#000000;color: white;">Cantidad</th>
                                                                <th style="background-color:#000000;color: white;">Precio Compra</th>
                                                                <th style="background-color:#000000;color: white;">Precio Venta</th>
                                                                <th style="background-color:#000000;color: white;">Subtotal</th>

                                                            </thead>
                                                            <tfoot>
                                                            <tr>
                                                                <th style="height:2px; text-align: right; font-size: 15px;" colspan="8">VENTA GRAVADO</th>
                                                                <th style="height:2px; text-align: right;" colspan="1">
                                                                    <input type="text" class="form-control" name="subtotal_total" id="subtotal_total" placeholder="0.00" readonly>
                                                                </th>
                                                                </tr>
                                                                <tr>
                                                                <th style="height:2px; text-align: right; font-size: 15px;" colspan="8">IGV 18%</th>
                                                                <th style="height:2px; text-align: right;" colspan="1">
                                                                    <input type="text" class="form-control" name="total_igv" id="total_igv" placeholder="0.00" readonly>
                                                                </th>
                                                                </tr>
                                                                <tr>
                                                                <th style="height:2px; text-align: right; font-size: 15px;" colspan="8">TOTAL VENTA</th>
                                                                <th style="height:2px; text-align: right;" colspan="1">
                                                                    <input type="text" class="form-control" name="total_venta" id="total_venta" placeholder="0.00" readonly>
                                                                </th>
                                                                </tr>
                                                                <th id="tipo-pago-th" style="height:2px; text-align: right; font-size: 15px;" colspan="8">TIPO PAGO</th>
                                                                    <th style="height:2px; text-align: right;" colspan="1">
                                                                        <select class="form-control" name="tipopago" id="tipopago" data-live-search="true" data-style="btn-default">
                                                                            <option value="">Selecciones Tipo Pago</option>
                                                                            <option value="2">Efectivo</option>
                                                                            <option value="3">Transferencia</option>
                                                                        </select>
                                                                        <br>
                                                                        <div id="deposito-fields" style="display: none; text-align: left;">
                                                                            <div class="col-12 col-sm-12 col-md-12">
                                                                                <label style="text-align: left; display: block;">Banco:</label>
                                                                                <select class="form-control" type="text" name="idbanco" id="idbanco"></select>
                                                                            </div>
                                                                            <br>
                                                                            <div class="col-12 col-sm-12 col-md-12">
                                                                            <label>Nro Operación:</label>
                                                                            <input class="form-control" type="text" name="nroperacion" id="nroperacion" placeholder="Nro Operación"></input>
                                                                            </div>
                                                                        </div>
                                                                    </th>
                                                            </tfoot>
                                                            <tbody>
                                                            </tbody>
                                                        </table>
                                                     </div>
                                                </div>  
                                            </div>
                                        </div>
                                        <div class="card-footer">
                                            <!-- Botones de acción -->
                                            <button  id="btnGuardar" class="btn btn-primary btn-flat">
                                                <i class="fas fa-save"></i> Guardar registro
                                            </button>
                                            <a href="list.php" class="btn btn-danger btn-flat">
                                                <i class="fas fa-times"></i> Cancelar
                                            </a>
                                            <button id="btnBuscar" type="button" class="btn btn-success btn-flat" data-toggle="modal" data-target="#myModalBuscar">
                                                <i class="fas fa-box"></i> Buscar Producto
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </section>                
            </div>


            <div class="modal fade" id="myModalIngreso" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
                <div class="modal-dialog modal-xl" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="modalLabel"><i class="fa-solid fa-magnifying-glass"></i> Busqueda de producto</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Cerrar">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                            <div class="modal-body">
                                <!-- Campo para mostrar el dato -->
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <table style="width:100%;" class="table table-bordered" id="modalproducto">
                                        <thead>
                                             <th  style="width: 65% !important;">Nombre Producto</th>
                                            <th>Codigo</th>
                                            <th>Marca</th>                  
                                            <th>Mac</th>
                                            <th>Serie</th>
                                            <th>Precio Compra</th>
                                            <th>Precio Venta</th>
                                            <th>Estado Material</th>
                                            <th>Stock</th>
                                            <th>Opciones</th>
                                        </thead>
                                        </tbody>
                                        <tfoot>
                                        <th  style="width: 65% !important;">Nombre Producto</th>
                                            <th>Codigo</th>
                                            <th>Marca</th>                  
                                            <th>Mac</th>
                                            <th>Serie</th>
                                            <th>Precio Compra</th>
                                            <th>Precio Venta</th>
                                            <th>Estado Material</th>
                                            <th>Stock</th>
                                            <th>Opciones</th>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="myModalBuscar" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
                <div class="modal-dialog modal-xl" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="modalLabel"><i class="fa-solid fa-magnifying-glass"></i> Busqueda por Almacenes</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Cerrar">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                            <div class="modal-body">
                                <!-- Campo para mostrar el dato -->
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <table style="width:100%;" class="table table-bordered" id="modalbuscar">
                                        <thead>
                                            <th  style="width: 18% !important;">Almacen</th>
                                            <th>Nombre Producto</th>
                                            <th>Codigo</th>
                                            <th>Marca</th>                  
                                            <th>Mac</th>
                                            <th>Serie</th>
                                            <th>Precio Compra</th>
                                            <th>Precio Venta</th>
                                            <th>Estado Material</th>
                                            <th>Stock</th>
                                            
                                        </thead>
                                        </tbody>
                                        <tfoot>
                                            <th  style="width: 18% !important;">Almacen</th>
                                            <th>Nombre Producto</th>
                                            <th>Codigo</th>
                                            <th>Marca</th>                  
                                            <th>Mac</th>
                                            <th>Serie</th>
                                            <th>Precio Compra</th>
                                            <th>Precio Venta</th>
                                            <th>Estado Material</th>
                                            <th>Stock</th>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                    </div>
                </div>
            </div>


               
<?php
}
require '../footer.php';
?>
<script type="text/javascript" src="../../scripts/venta.js"></script>
<?php 
}
ob_end_flush();
?>