<?php include "Views/templates/header.php"; ?>

<?php if ($_SESSION['permisos']['agregar producto']) {?>
    <button class="btn btn-outline-primary mb-2" type="button" onclick="frmProducto();"><i class="fas fa-plus"></i></button>
<?php } ?>
<?php if ($_SESSION['permisos']['editar producto']) {?>
    <button class="btn btn-primary mb-2 btn-toolbar-status" disabled type="button" onclick="btnEditarPro(active_row);"><i class="fas fa-edit"></i></button>
<?php } ?>
<?php if ($_SESSION['permisos']['eliminar producto']) {?>
    <button class="btn btn-danger mb-2 btn-toolbar-status btn-eliminar" disabled type="button" onclick="btnEliminarPro(active_row);"><i class="fas fa-trash-alt"></i></button>
<?php } ?>
<?php if ($_SESSION['permisos']['reingresar producto']) {?>
    <button class="btn btn-success mb-2 btn-toolbar-status btn-recuperar" disabled type="button" onclick="btnReingresarPro(active_row);" style="display: none;"><i class="fas fa-toggle-on"></i></button>
<?php } ?>
<?php if ($_SESSION['permisos']['ver producto']) {?>
    <button class="btn btn-outline-secondary mb-2 btn-toolbar-status" disabled type="button" onclick="btnVerPro(active_row);"><i class="fas fa-barcode"></i></button>
<?php } ?>
<?php if ($_SESSION['permisos']['listar precios productos']) {?>
    <div class="btn-group">
        <button type="button" class="btn btn-success  mb-2"><i class="fas fa-file-pdf" data-toggle="tooltip" data-placement="top" title="Listados"></i></button>
        <button type="button" class="btn btn-success  mb-2 dropdown-toggle dropdown-toggle-split" data-toggle="dropdown"></button>
        <div class="dropdown-menu">
            <?php if ($_SESSION['permisos']['lista de precios pdf productos']) {?>
                <a class="dropdown-item" onclick="btnReporteproductoPDF();">Lista de Precios PDF</a>
            <?php } ?>
            <?php if ($_SESSION['permisos']['lista de precios excel productos']) {?>
                <a class="dropdown-item" onclick="btnReporteproductoEXCEL();">Lista de Precios Excel</a>
            <?php } ?>
        </div>
    </div>
<?php } ?>
<?php if ($_SESSION['permisos']['opciones de catalogo']) {?>
    <div class="btn-group">
        <button type="button" class="btn btn-warning  mb-2"><i class="fas fa-image" data-toggle="tooltip" data-placement="top" title="Catalogo"></i></button>
        <button type="button" class="btn btn-warning  mb-2 dropdown-toggle dropdown-toggle-split" data-toggle="dropdown"></button>
        <div class="dropdown-menu">
            <?php if ($_SESSION['permisos']['ficha tecnica productos']) {?>
                <a class="dropdown-item" onclick="btnFicha(active_row)">Ficha Tecnica</a>
            <?php } ?>
            <?php if ($_SESSION['permisos']['catalogo de productos']) {?>
                <a class="dropdown-item" onclick="btnReporteproductoPDFCat();">Catalogo de Productos</a>
            <?php } ?>
        </div>
    </div>
<?php } ?>
<?php if ($_SESSION['permisos']['kardex']) {?>
    <button class="btn btn-outline-info mb-2 btn-toolbar-status" disabled type="button" onclick="btnVerKardex(active_row);" title='Kardex'><i class="fas fa-table"></i></button>
<?php } ?>





<!-- <a class="btn btn-outline-secondary mb-2" href="<?php echo base_url; ?>productos/barcode" target="_blank"><i class="fas fa-barcode"></i></a> -->
<!-- <a class="btn btn-outline-danger mb-2" href="<?php echo base_url; ?>productos/pdf" target="_blank"><i class="fas fa-file-pdf"></i></a> -->
<!-- <a class="btn btn-outline-danger mb-2" onclick="btnReporteproductoPDF()"><i class="fas fa-file-pdf"></i></a>-->
<!-- <a class="btn btn-outline-success mb-2" onclick="btnReporteproductoPDFCat()"><i class="fas fa-file-pdf"></i></a>-->
<!-- <a class="btn btn-outline-success mb-2" href="<?php echo base_url; ?>productos/excel"><i class="fas fa-file-excel"></i></a> -->
<!-- <a class="btn btn-outline-success mb-2" onclick="btnReporteproductoEXCEL()"><i class="fas fa-file-excel"></i></a>-->

<!-- <button class="btn btn-outline-info mb-2 btn-toolbar-status" disabled type="button" onclick="btnFicha(active_row);" title='Kardex'><i class="fas fa-image"></i></button>-->
<!-- <button class="btn btn-outline-dark mb-2" type="button" id="btnEtiqueta"><i class="fas fa-tags"></i> Etiquetas</button> -->

<div class="card shadow-lg">
    <div class="card-body">

        <div class="row">

            <div class="d-block d-md-flex flex-row justify-content-end align-items-center w-100 mb-1">
                <div class="m-2">
                    <label for="">Desde</label>
                    <input class="form-control" id="min" type="date" name="venta_desde">                    
                </div>
                <div class="m-2">
                    <label for="">Hasta</label>
                    <input class="form-control" id="max" type="date" name="venta_hasta">
                </div>
                <div class="m-2">
                    <label for="estados">Categoria</label>
                    <select class="form-control" id="categoria" name="categoria">
                        <option value="">Seleccionar</option>
                        <?php foreach ($data['categorias'] as $categoria) { ?>
                            <option value="<?php echo $categoria['id']; ?>"><?php echo $categoria['categoria']; ?></option>
                        <?php } ?>
                    </select>
                </div>

                <div class="m-2">
                    <label for="estados">Marca</label>
                    <select class="form-control" id="marca" name="marca">
                        <option value="">Seleccionar</option>
                        <?php foreach ($data['marcas'] as $marca) { ?>
                            <option value="<?php echo $marca['id']; ?>"><?php echo $marca['marca']; ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="m-2">
                        <label for="my-input">&nbsp;</label><br>
                        <button class="btn btn-outline-primary btn-block" type="button" name="historial_ventas" onclick="limpiar_busqueda()"><i class="fa fa-eraser" aria-hidden="true"></i>Filtro</button>
                </div>
            </div>        

        </div>

    
        <div class="table-responsive">
            <table class="table table-striped display responsive table-bordered" id="t_pro" style="width: 100%;">
                <thead class= "thead-dark">
                    <tr>
                        <th>Foto</th>
                        <th>Código</th>
                        <th>Código Alterno</th>                        
                        <th>Descripción</th>
                        <th>Detalles</th>
                        <th>Precio C</th>
                        <th>Precio B</th>
                        <th>Precio A</th>
                        <th>Existencia</th>
                        <th>Categoria</th>                        
                        <th>Marca</th>
                        <th>Estado</th>
                        <th>Ultima Venta</th>                        
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</div>
<div id="nuevo_producto" class="modal fade" data-focus="false" role="dialog" aria-labelledby="my-modal-title" aria-hidden="true">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header bg-primary">
                <h5 class="modal-title text-white" id="title">Nuevo Producto</h5>
                <button class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form id="formulario" class="needs-validation" novalidate autocomplete="off">
                <input type="hidden" id="id" name="id">

                <div class="modal-body" style='height:75vh;overflow-y:auto;'>

                    <ul class="nav nav-tabs" id="myTab" role="tablist">

                            <li class="nav-item">
                                <a class="nav-link active" id="generales-tab" data-toggle="tab" href="#generales" role="tab" aria-controls="generales" aria-selected="true"><i class="fas fa-shopping-cart"></i> <span class='d-none d-lg-inline-block'>Generales</span></a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" id="tprecios-tab" data-toggle="tab" href="#tprecios" role="tab" aria-controls="tdireccion" aria-selected="true"><i class="fas fa-dollar-sign"></i> <span class='d-none d-lg-inline-block'>Precios y Costos</span></a>
                            </li>                            
                            <li class="nav-item">
                                <a class="nav-link" id="tstock-tab" data-toggle="tab" href="#tstock" role="tab" aria-controls="parametros" aria-selected="false"><i class="fas fa-boxes"></i> <span class='d-none d-lg-inline-block'>Stock</span></a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" id="tnotes-tab" data-toggle="tab" href="#tnotes" role="tab" aria-controls="tcontacto" aria-selected="false"><i class="fas fa-sticky-note"></i> <span class='d-none d-lg-inline-block'>Observaciones</span></a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" id="timage-tab" data-toggle="tab" href="#timage" role="tab" aria-controls="tcontacto" aria-selected="false"><i class="fas fa-image"></i> <span class='d-none d-lg-inline-block'>Imagen</span></a>
                            </li>

                    </ul>

                        
                    <div class="tab-content" id="myTabContent">
                        
                        <!-- CAMPOS GENERAL -->
                        <div class="tab-pane fade show active pt-3" id="generales" role="tabpanel" aria-labelledby="generales-tab">
                            
                                <div class="row">

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="codigo">Código *</label>
                                            <input id="codigo" class="form-control" type="text" name="codigo" placeholder="Código" required  maxlength="20">
                                            <div class="valid-feedback">
                                                Correcto
                                            </div>
                                            <div class="invalid-feedback">
                                                El código es requerido
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="codigo_alter">Código Alternativo</label>
                                            <input id="codigo_alter" name="codigo_alter" class="form-control" type="text" placeholder="Código Alternativo" maxlength="30">
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="codigo_proveedor">Código Proveedor</label>
                                            <input id="codigo_proveedor" name="codigo_proveedor" class="form-control" type="text" placeholder="Código Proveedor" maxlength="30">
                                        </div>
                                    </div>

                                    <div class="col-12">
                                        <div class="form-group">
                                            <label for="descripcion">Descripción</label>
                                            <input id="descripcion" name="descripcion" class="form-control" type="text" placeholder="Descripción" maxlength="255">
                                        </div>
                                    </div>

                                    <div class="col-12">
                                        <div class="form-group">
                                            <label for="detalles">Detalles</label>
                                            <input id="detalles" name="detalles" class="form-control" type="text" placeholder="Detalles" maxlength="250">
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="tipo">Tipo</label>
                                            <select id="tipo" name="tipo" class="form-control">
                                                <option value="">Seleccionar</option>
                                                <option value="1">Producto</option>
                                                <option value="2">Servicio</option>
                                                <option value="3">Insumo</option>
                                                <option value="4">Promocional</option>
                                                <option value="5">Otros</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="proveedor">Proveedor</label>
                                            <select id="proveedor" name="proveedor" class="form-control">
                                                <option value="">Seleccionar</option>
                                                <?php foreach ($data['proveedor'] as $medida) { ?>
                                                    <option value="<?php echo $medida['id']; ?>"><?php echo $medida['nombre']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="medidas">Medidas</label>
                                            <select id="medidas" name="medidas" class="form-control">
                                                <option value="">Seleccionar</option>
                                                <?php foreach ($data['medidas'] as $medida) { ?>
                                                    <option value="<?php echo $medida['id']; ?>"><?php echo $medida['medida']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="categorias">Categoria</label>
                                            <select id="categorias" name="categorias" class="form-control">
                                                <option value="">Seleccionar</option>
                                                <?php foreach ($data['categorias'] as $categoria) { ?>
                                                    <option value="<?php echo $categoria['id']; ?>"><?php echo $categoria['categoria']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="marcas">Marca</label>
                                            <select id="marcas" name="marcas" class="form-control">
                                                <option value="">Seleccionar</option>
                                                <?php foreach ($data['marcas'] as $marca) { ?>
                                                    <option value="<?php echo $marca['id']; ?>"><?php echo $marca['marca']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="form-group">
                                            <label for="clasificacion">Clasificación</label>
                                            <input id="clasificacion" name="clasificacion" class="form-control" type="text" placeholder="Clasificación" maxlength="5">
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="custom-control custom-switch pt-4">
                                            <input type="checkbox" class="custom-control-input" id="estado" name='estado' checked>
                                            <label class="custom-control-label" for="estado">Estado</label>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-4">
                                        <div class="custom-control custom-switch pt-4">
                                            <input type="checkbox" class="custom-control-input" id="imprime" name='imprime'>
                                            <label class="custom-control-label" for="imprime">Imprime</label>
                                        </div>
                                    </div>                                    

                                </div>
                                
                        </div>

                        <!-- CAMPOS PRECIOS -->
                        <div class="tab-pane fade pt-3" id="tprecios" role="tabpanel" aria-labelledby="tprecios-tab">
                            
                            <div class="row">
                                <div class="col-12 col-md-9 col-lg-4">
                                    <div class="form-group">
                                        <label for="precio_compra">Precio Compra (Opcional)</label>
                                        <input id="precio_compra" class="form-control" type="number" name="precio_compra" step="0.01" placeholder="Precio Compra">
                                    </div>

                                    <div class="form-group">
                                        <label for="precio_venta">Precio Venta (Opcional)</label>
                                        <input id="precio_venta" class="form-control" type="number" name="precio_venta" step="0.01" placeholder="Precio Venta">
                                    </div>

                                    <div class="form-group">
                                        <label for="precio1">Precio 1 (Opcional)</label>
                                        <input id="precio1" class="form-control" type="number" name="precio1" step="0.01" placeholder="Precio 1">
                                    </div>

                                    <div class="form-group">
                                        <label for="precio2">Precio 2 (Opcional)</label>
                                        <input id="precio2" class="form-control" type="number" name="precio2" step="0.01" placeholder="Precio 2">
                                    </div>
                                    <div class="form-group">
                                        <label for="precio3">Precio 3 (Opcional)</label>
                                        <input id="precio3" class="form-control" type="number" name="precio3" step="0.01" placeholder="Precio 3">
                                    </div>
                                    <div class="form-group">
                                        <label for="precio4">Precio 4 (Opcional)</label>
                                        <input id="precio4" class="form-control" type="number" name="precio4" step="0.01" placeholder="Precio 4">
                                    </div>
                                    <div class="form-group">
                                        <label for="precio5">Precio 5 (Opcional)</label>
                                        <input id="precio5" class="form-control" type="number" name="precio5" step="0.01" placeholder="Precio 5">
                                    </div>

                                </div>                            
                                <div class="col-12 col-lg-6 offset-lg-2">
                                    <div class="form-group">
                                        <label>Fecha última compra</label>
                                        <p id='fieldFechaUltimaCompra'>Ninguna</p>
                                    </div>
                                    <div class="form-group">
                                        <label>Último costo</label>
                                        <p id='fieldUltimoCosto'>Sin costo</p>
                                    </div>
                                    <div class="form-group">
                                        <label>Costo promedio</label>
                                        <p id='fieldCostoPromedio'>Sin promedio</p>
                                    </div>                                
                                </div>
                            </div>
                        </div>

                        <!-- CAMPOS STOCK -->
                        <div class="tab-pane fade pt-3" id="tstock" role="tabpanel" aria-labelledby="tstock-tab">

                            <div class="row">
                                <div class="col-12 col-md-9 col-lg-4">
                                    <div class="form-group">
                                        <label for="minimo">Stock Mínimo *</label>
                                        <input type="number" class="form-control" name="minimo" id="minimo" placeholder="Stock mínimo">
                                    </div>
                                    <div class="form-group">
                                        <label for="maximo">Stock Máximo *</label>
                                        <input type="number" class="form-control" min="0" name="maximo" id="maximo" placeholder="Stock máximo">
                                    </div>                                    
                                    <div class="form-group">
                                        <label for="ubicacion">Ubicación</label>
                                        <input id="ubicacion" class="form-control" type="text" name="ubicacion" placeholder="Ubicación" maxlength="75">
                                    </div>                                    
                                </div>
                                <div class="col-12 col-lg-6 offset-lg-2">
                                    <div class="form-group">
                                        <label>Cantidad</label>
                                        <p id='fieldCantidad'>Sin cantidad</p>
                                    </div>
                                </div>                                
                            </div>

                        </div>

                        <!-- CAMPOS NOTES -->
                        <div class="tab-pane fade pt-3" id="tnotes" role="tabpanel" aria-labelledby="tnotes-tab">
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group">
                                        <label for="observaciones">Observaciones</label>
                                        <textarea class="form-control" id="observaciones" name="observaciones" rows="10" placeholder="Observaciones"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- CAMPOS IMAGES -->
                        <div class="tab-pane fade pt-3" id="timage" role="tabpanel" aria-labelledby="timage-tab">
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group">
                                        <label>Foto (Opcional)</label>
                                        <label for="imagen" id="icon-image">
                                            <img class="img-thumbnail" id="img-preview" src="<?php echo base_url; ?>Assets/img/logo.png" width="200" height="200">
                                        </label>
                                        <span id="icon-cerrar"></span>
                                        <input id="imagen" class="d-none" type="file" name="imagen" onchange="preview(event)">
                                        <input type="hidden" id="foto_actual" name="foto_actual">
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
                <div class="modal-footer">
                    <button class="btn btn-outline-primary" type="submit" id="btnAccion">Registrar</button>
                    <button class="btn btn-outline-danger" type="button" data-dismiss="modal">Cancelar</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="barcode" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="my-modal-title" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header bg-info">
                <h5 class="modal-title">Generar Código de Barras</h5>
                <button class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form id="frmEtiqueta" method="post" autocomplete="off" action="<?php echo base_url; ?>productos/generarEtiqueta" target="_blank">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-8">
                            <div class="form-group">
                                <label for="codigo_barra">Código de barras</label>
                                <input id="codigo_barra" class="form-control" type="text" name="codigo_barra" placeholder="Código de barras" required>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="cantidad_etiqueta">Cantidad</label>
                                <input id="cantidad_etiqueta" class="form-control" type="number" name="cantidad_etiqueta" placeholder="Cantidad etiqueta" required>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-outline-primary" type="submit"><i class="fas fa-barcode"></i> Generar</button>
                    <button class="btn btn-outline-danger" type="button" data-dismiss="modal">Cancelar</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php include "Views/templates/footer.php"; ?>