<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Sistema de Ventas - Inventarios v2.0</title>

    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/css/icheck-bootstrap.min.css">
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/css/jquery-ui.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/css/adminlte.min.css">
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/DataTables/datatables.min.css">
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/css/dataTables.dateTime.min.css">
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/css/select2.min.css">
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/css/smoke.min.css">
    <link rel="stylesheet" href="<?php echo base_url; ?>Assets/css/custom.css">
    <link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet">    
    
</head>


<body class="hold-transition sidebar-mini layout-fixed layout-navbar-fixed layout-footer-fixed">
    <div class="wrapper">
        <!-- Navbar -->
        <nav class="main-header navbar navbar-expand navbar-<?php echo $_SESSION['color_header']?>">
            <!-- Left navbar links -->
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link text-light" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
                </li>
                <li class="nav-item d-sm-inline-block d-none">
                    <a href="#" class="nav-link"><span class="badge badge-warning"><?php echo date('d-M-Y'); ?></span></a>
                </li>
                <li class="nav-item d-sm-inline-block">
                    <a href="<?php echo base_url; ?>usuarios/salir" class="nav-link"><span class="badge badge-danger">Cerrar Sesión</span></a>
                </li>
            </ul>

            <!-- Right navbar links -->
            <ul class="navbar-nav ml-auto">
                <li class="nav-item">
                    <a class="nav-link text-light" data-widget="control-sidebar" data-slide="true" href="#" role="button">
                    <i class="fas fa-calendar-alt"></i>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link text-light" data-widget="fullscreen" href="#" role="button">
                        <i class="fas fa-expand-arrows-alt"></i>
                    </a>
                </li>
            </ul>
        </nav>

        <!-- /. navbar -->  
        <!-- Main Sidebar Container -->
        <style>
            .sidebar-dark-blue{
                background: <?php echo $_SESSION['color_navbar'] ?? '#031C30'; ?> !important;
            }
        </style>

        <aside class="main-sidebar sidebar-dark-blue  elevation-4">
            <!-- Brand Logo -->
            <a href="admin\inicio.php" class="brand-link">
                <img src="<?php echo base_url; ?>Assets/img/logo.png" alt="Logo" class="brand-image elevation-0" style="opacity: .9">
                <span class="brand-text font-weight-light"></span>
            </a>
            <!-- Sidebar -->
            <div class="sidebar">
                <!-- Sidebar user panel (optional) -->
                 <?php if ($_SESSION['permisos']['perfil de usuario']) {?>
                <div class="user-panel mt-3 pb-3 mb-3 d-flex">

                    <div class="image">
                        <?php if (!file_exists('Assets/img/usuarios/' . $_SESSION['id_usuario'] . '.png')) { ?>
                            <img class="img-thumbnail" src="<?php echo base_url; ?>Assets/img/avatar.svg" width="200">
                        <?php } else { ?>
                            <img class="img-thumbnail" src="<?php echo base_url; ?>Assets/img/usuarios/<?php echo $_SESSION['id_usuario']; ?>.png" width="200">
                        <?php } ?>
                    </div>

                    <div class="info">
                        <a href="<?php echo base_url; ?>usuarios/perfil" class="d-block"><?php echo $_SESSION['nombre'] ?></a> 
                    </div>
                </div>
                <?php } ?>
                
                <!-- Sidebar Menu -->
                <nav class="mt-2">
                    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">

                            <!-- Solo Muestra a usuarios Administrador 
                            <?php // if ((int)$_SESSION['tipousuario'] < 3) { ?>
                                <li class="nav-item">
                                <a href="<?php //echo base_url; ?>admin" class="nav-link">
                                        <i class="nav-icon fas fa-chart-pie" style='color:Gold'></i>
                                        <p>Escritorio</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                <a href="<?php //echo base_url; ?>crm" class="nav-link">
                                        <i class="nav-icon fa fa-bar-chart" style='color:Magenta'></i>
                                        <p>Actividad</p>
                                    </a>
                                </li>
                            <?php // } ?>

-->
                            <?php if ($_SESSION['permisos']['escritorio']){ ?>
                                <li class="nav-item">
                                <a href="<?php echo base_url; ?>admin" class="nav-link">
                                        <i class="nav-icon fas fa-chart-pie" style='color:Gold'></i>
                                        <p>Escritorio</p>
                                    </a>
                                </li>
                            <?php } ?>

                            <?php if ($_SESSION['permisos']['actividad']){ ?>
                                <li class="nav-item">
                                <a href="<?php echo base_url; ?>crm" class="nav-link">
                                        <i class="nav-icon fa fa-bar-chart" style='color:Magenta'></i>
                                        <p>Actividad</p>
                                    </a>
                                </li>
                            <?php } ?>

                            <?php if ($_SESSION['permisos']['agenda']) { ?>
                            <li class="nav-item">
                            <a href="<?php echo base_url; ?>eventos" class="nav-link">
                                    <i class="nav-icon fas fa-calendar-alt" style='color:DeepSkyBlue'></i>
                                    <p>Agenda</p>
                                </a>
                            </li>
                            <?php } ?>
                            


                        <?php
                        // MENU CLIENTES
                        if ($_SESSION['permisos']['clientes']) { ?>
                            <li class="nav-item">
                                <a href="#" class="nav-link">
                                    <i class="nav-icon fas fa-user"  style='color:White'></i>                                
                                    <p>Clientes<i class="fas fa-angle-right right"></i></p>
                                </a>
                                
                                <ul class="nav nav-treeview">
                                    <?php if ($_SESSION['permisos']['mantenimiento de clientes']) { ?>
                                        <li><hr></li>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>clientes" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Clientes</p>
                                            </a>
                                        </li>
                                    <?php } ?>
                                    <?php if ($_SESSION['permisos']['pago y abonos de clientes']) { ?>
                                        <li><hr></li>
                                        <!--
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>creditoventas" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Cuentas por Cobrar</p>
                                            </a>
                                        </li> -->

                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>creditoventas/abonos" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Pagos y Abonos</p>
                                            </a>
                                        </li>
                                        <li><hr></li>
                                    <?php } ?>
                                    <!--

                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>---creditoventas/abonos" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                        <p>Cambios y Devoluciones</p>
                                        </a>
                                    </li>

                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>cheques" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                        <p>Control de Cheques</p>
                                        </a>
                                    </li>
                                    -->
                                   
                                </ul>
                            </li>
                        <?php }

// MENU PRODUCTOS

                        if ($_SESSION['permisos']['productos']) { ?>
                            <li class="nav-item">
                                <a href="#" class="nav-link">
                                    <i class="nav-icon fas fas fa-tags"  style='color:White'></i>
                                    <p>Productos<i class="fas fa-angle-right right"></i></p>
                                </a>
                                <ul class="nav nav-treeview">
                                <?php 
                                    if ($_SESSION['permisos']['mantenimiento de productos']) { ?>
                                        <li><hr></li>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>productos" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Productos</p>
                                            </a>
                                        </li>
                                        <li><hr></li>
                                    <?php } 
                                    if ($_SESSION['permisos']['medidas de productos']) { ?>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>medidas" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Medidas</p>
                                            </a>
                                        </li>
                                    <?php }
                                    if ($_SESSION['permisos']['categorias de productos']) { ?>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>categorias" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Categorias</p>
                                            </a>
                                        </li>
                                    <?php }
                                    if ($_SESSION['permisos']['marcas de productos']) { ?>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>marcas" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Marcas</p>
                                            </a>
                                        </li>
                                    <?php }
                                    if ($_SESSION['permisos']['ingresos recientes de productos']) { ?>
                                        <li><hr></li>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>productos" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Ingresos Recientes</p>
                                            </a>
                                        </li>
                                        <li><hr></li>
                                    <?php } 
                                ?>
                                </ul>
                            </li>
                        <?php }







/**                            if ($_SESSION['permisos']['cotizaciones']) { ?>

                            <li class="nav-item">

                                <a href="#" class="nav-link">

                                    <i class="nav-icon fas fa-money-bill-alt"></i>

                                    <p>

                                        Cotizaciones

                                        <i class="fas fa-angle-left right"></i>

                                    </p>

                                </a>

                                <ul class="nav nav-treeview">

                                    <li class="nav-item">

                                        <a href="<?php echo base_url; ?>cotizaciones" class="nav-link">

                                            <i class="fas fa-hand-holding-usd"></i>

                                            <p>Nueva Cotización</p>

                                        </a>

                                    </li>

                                    <li class="nav-item">

                                        <a href="<?php echo base_url; ?>cotizaciones/historial" class="nav-link">

                                            <i class="fas fa-file-invoice-dollar"></i>

                                            <p>Manejo de Cotizaciones</p>

                                        </a>

                                    </li>

                                </ul>

                            </li>

                        <?php }



//      -- MENU VENTAS --


                        if ($_SESSION['permisos']['ventas']) { ?>
                            <li class="nav-item">
                                <a href="#" class="nav-link">
                                    <i class="nav-icon fa fa-usd"  style='color:White'></i>
                                    <p>Ventas<i class="fas fa-angle-right right"></i></p>
                                </a>
                                <ul class="nav nav-treeview">
                                    <li><hr></li>
                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>cotizaciones/historial" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Cotizaciones</p>
                                        </a>
                                    </li>
                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>apartados/historial" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Pedidos</p>
                                        </a>
                                    </li>
                                    <li class="nav-item">
                                            <a href="<?php echo base_url; ?>ventas/historial" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Ventas</p>
                                            </a>
                                    </li>
                                    <li><hr></li>
                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>vendedores" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Notas de Cambio</p>
                                        </a>
                                    </li>
                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>cotizaciones/historial" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Notas de Descuento</p>
                                        </a>
                                    </li>
                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>apartados/historial" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Devoluciones</p>
                                        </a>
                                    </li>
                                    <li><hr></li>
                                </ul>
                            </li>

                        <?php }

*/
//      -- MENU VENDEDORES --
                        ?>                



                        <?php if ($_SESSION['permisos']['vendedores']) { 
                        //  ($_SESSION['permisos']['ventas']) { ?> 
                            <li class="nav-item">
                                <a href="#" class="nav-link">
                                    <i class="nav-icon fa fa-handshake"  style='color:White'></i>
                                    <p>Vendedores<i class="fas fa-angle-right right"></i></p>
                                </a>
                                <ul class="nav nav-treeview">
                                    <?php if ($_SESSION['permisos']['mantenimiento de vendedores']) { ?>
                                    <li><hr></li>
                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>vendedores" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Vendedores</p>
                                        </a>
                                    </li>
                                     <?php } ?>
                                    <?php if ($_SESSION['permisos']['ruta vendedores']) { ?>
                                    <li class="nav-item">
                                        <a href="<?php echo base_url; ?>rutas" class="nav-link">
                                        <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Rutas</p>
                                        </a>
                                    </li>
                                     <?php } ?>

                                </ul>

                            </li>
                        <?php } ?>

                            <?php if ($_SESSION['permisos']['ventas']) { ?>
                                <li class="nav-item">
                                    <a href="#" class="nav-link">
                                        <i class="nav-icon fa fa-handshake"  style='color:White'></i>
                                        <p>Ventas<i class="fas fa-angle-right right"></i></p>
                                    </a>
                                    <ul class="nav nav-treeview">
                                        <?php if ($_SESSION['permisos']['cotizaciones de ventas']) { ?>
                                            <li><hr></li>

                                            <li class="nav-item">
                                                <a href="<?php echo base_url; ?>cotizaciones/historial_ss" class="nav-link">
                                                <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Cotizaciones</p>
                                                </a>
                                            </li>
                                        <?php } ?>
                                        <?php if ($_SESSION['permisos']['pedidos de ventas']) { ?>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>pedidos/historial_ss" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                            <p>Pedidos</p>
                                            </a>
                                        </li>
                                        <?php } ?>
                                        <?php if ($_SESSION['permisos']['facturas de ventas']) { ?>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>ventas/historial_ss" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Facturas</p>
                                            </a>
                                        </li>
                                        <?php } ?>
                                        <?php if ($_SESSION['permisos']['envios de ventas']) { ?>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>envios/**historial_ss" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Envios</p>
                                            </a>
                                        </li>
                                        <?php } ?>
                                        <?php if ($_SESSION['permisos']['historial de ventas']) { ?>
                                        <li><hr></li>
                                            <li class="nav-item">
                                                <a href="<?php echo base_url; ?>productos" class="nav-link">
                                                <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Historial de Ventas</p>
                                                </a>
                                            </li>
                                        <li><hr></li>
                                        <?php } ?>
                                    </ul>
                                </li>
                            <?php } ?>


                            <?php if ($_SESSION['permisos']['devoluciones']) { ?>
                                <li class="nav-item">
                                    <a href="#" class="nav-link">
                                        <i class="nav-icon fa fa-handshake"  style='color:White'></i>
                                        <p>Devoluciones<i class="fas fa-angle-right right"></i></p>
                                    </a>
                                    <ul class="nav nav-treeview">
                                        <?php if ($_SESSION['permisos']['notas de cambio devoluciones']) { ?>
                                        <li><hr></li>

                                            <li class="nav-item">
                                                <a href="<?php echo base_url; ?>cambios/historial_ss" class="nav-link">
                                                <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Notas de Cambio</p>
                                                </a>
                                            </li>
                                        <?php } ?>
                                        <?php if ($_SESSION['permisos']['notas de devoluciones']) { ?>
                                            <li class="nav-item">
                                                <a href="<?php echo base_url; ?>devoluciones/historial_ss" class="nav-link">
                                                <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Notas de Devolucion</p>
                                                </a>
                                            </li>
                                            <li><hr></li>
                                        <?php } ?>
                                    </ul>
                                </li>
                             <?php } ?>

                          

                        <?php if ($_SESSION['permisos']['configuracion']) {?>
                            <li class="nav-item">
                                <a href="#" class="nav-link">
                                    <i class="nav-icon fas fa-cogs" style='color:#3498DB'></i>
                                    <p>Configuracion<i class="fas fa-angle-right right"></i></p>
                                </a>
                                <ul class="nav nav-treeview">
                                    <?php if ($_SESSION['permisos']['configuracion de bancos']) {?>
                                        <li><hr></li>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>**" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Bancos</p>
                                            </a>
                                        </li>
                                    <?php } ?>
                                    <?php if ($_SESSION['permisos']['configuracion de usuarios']) {?>
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>usuarios" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Usuarios</p>
                                            </a>
                                        </li>
                                    <?php } ?>
                                    <?php if ($_SESSION['permisos']['configuracion general']) {?>    
                                        <li class="nav-item">
                                            <a href="<?php echo base_url; ?>admin/datos" class="nav-link">
                                            <i class="fa fa-caret-right nav-icon"></i>
                                                <p>Configuración General</p>
                                            </a>
                                        </li>
                                        <li><hr></li>
                                    <?php } ?>
                                </ul>
                            </li>

                        <?php } ?>

                    </ul>

                </nav>

                <!-- /.sidebar-menu -->

            </div>

            <!-- /.sidebar -->

        </aside>



        <!-- Content Wrapper. Contains page content -->

        <div class="content-wrapper fondo">

            <!-- /.content-header -->



            <!-- Main content -->

            <section class="content">

                <div class="container-fluid">

                    <br>

                    <!-- Small boxes (Stat box) -->