<?php 
require "../config/Conexion.php"; 
if(strlen(session_id()) < 1)
session_start();
date_default_timezone_set('America/Lima'); 

?>

<!DOCTYPE html>
<html lang="es">
<head>
    <title>Sistema Panel - Campo Santo</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="author" content="Author Name">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="../files/camposanto.png"/>
    <!-- <link rel="shortcut icon" href="../files/logo_principal.png"> -->

    <!-- DataTables CSS -->
    <link rel="stylesheet" href="../static/lib/datatables-1.10.25/css/dataTables.bootstrap4.min.css"/>
    <link rel="stylesheet" href="../static/lib/datatables-1.10.25/plugins/responsive-2.2.9/css/responsive.bootstrap4.min.css"/>

    <!--CSS-->
    <link rel="stylesheet" href="../static/lib/bootstrap-4.6.0/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../static/lib/fontawesome-6.1.1/css/all.min.css"/>
    <link rel="stylesheet" href="../static/lib/jquery-ui-1.12.1/jquery-ui.css"/>

     <!--Javascript-->
    <script src="../static/lib/bootstrap-4.6.0/js/jquery.min.js"></script>
    <script src="../static/lib/jquery-ui-1.12.1/jquery-ui.min.js"></script>
    <script src="../static/lib/bootstrap-4.6.0/js/popper.min.js"></script>
    <script src="../static/lib/bootstrap-4.6.0/js/bootstrap.min.js"></script>
    <script src="../static/lib/adminlte-3.2.0/js/adminlte.min.js"></script>

    <!--Template-->
    <link rel="stylesheet" href="../static/lib/adminlte-3.2.0/css/adminlte.css"/>
    <!--Styles-->
    <link rel="stylesheet" href="../static/css/style.css"/>
   <!--Libs-->
    <script src="../static/lib/bootstrap-daterangepicker-3.1/js/moment.min.js"></script>
    <script src="../static/lib/bootstrap-daterangepicker-3.1/js/moment-with-locales.js"></script>
    <script src="../static/lib/jquery-confirm-3.3.4/js/jquery-confirm.min.js"></script>
    <link rel="stylesheet" href="../static/lib/jquery-confirm-3.3.4/css/jquery-confirm.min.css"/>
    <script src="../static/lib/sweetalert2-11.0.16/js/sweetalert2.all.min.js"></script>
    <link rel="../stylesheet" href="static/lib/sweetalert2-11.0.16/css/sweetalert2.min.css"/>
    <script src="../static/lib/jquery-loading-overlay-2.1.7/js/loadingoverlay.min.js"></script>
    <script src="../static/js/functions.js"></script>

    <script src="../static/lib/highcharts-9.1.1/highcharts.js"></script>
    <script src="../static/lib/highcharts-9.1.1/highcharts-3d.js"></script>
    <script src="../static/lib/highcharts-9.1.1/modules/exporting.js"></script>
    <script src="../static/lib/highcharts-9.1.1/modules/data.js"></script>
    <script src="../static/lib/highcharts-9.1.1/modules/drilldown.js"></script>
    


</head>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">
        <!-- Header Template -->
        <header>
            <!-- Include the contents of 'vtc_header.html' -->
            <nav class="main-header navbar navbar-expand navbar-dark bg-primary">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link cursor-pointer collapsedMenu" id="collapsedMenu" data-widget="pushmenu">
                            <i class="fas fa-bars"></i>
                        </a>
                    </li>
                    <li class="nav-item d-none d-sm-inline-block">
                        <a href="index.php" class="nav-link">Inicio</a>
                    </li>
                </ul>
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item dropdown">
                        <a class="nav-link" data-toggle="dropdown" aria-expanded="false">
                            <i class="far fa-user"></i> Usuario: <?php echo $_SESSION['nombre']; ?>
                        </a>
                        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right" style="left: inherit; right: 0;">
                            <span class="dropdown-header">Datos de tu conexión</span>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item">
                                <p class="text-sm">Dirección IP</p>
                                <p class="text-sm text-muted">127.0.0.1</p>
                            </a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item">
                                <p class="text-sm">Dispositivo</p>
                                <p class="text-sm text-muted">Navegador Web</p>
                            </a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item">
                                <p class="text-sm">Perfil actual</p>
                                <p class="text-sm text-muted">PerfilEjemplo</p>
                            </a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item">
                                <p class="text-sm">Último acceso</p>
                                <p class="text-sm text-muted">2024-11-12 15:30</p>
                            </a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link" data-toggle="dropdown">
                        <i class="fa-solid fa-user-shield"></i> Perfil: <?php echo $_SESSION['nombrecargo']; ?>
                        </a>
                         <div class="dropdown-menu dropdown-menu-right">
                        <a href="#" class="dropdown-item">Otro Perfil</a>
                        </div>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link btnLogout" href="../ajax/usuario.php?op=salir">
                            <i class="fas fa-power-off"></i>
                        </a>
                    </li>
                </ul>
            </nav>
        </header>

        <!-- Sidebar Template -->
        <aside class="main-sidebar elevation-2 sidebar-dark-primary">
            <a href="" class="brand-link">
                <img src="../files/camposanto.png" alt="Logo" class="brand-image" style="opacity: .8">
                <span class="brand-text font-weight-light">Campo Santo </span>
            </a>
            <div class="sidebar">
                <div class="user-panel mt-3 pb-3 mb-3 d-flex">
                    <div class="image">
                        <img src="../media/empty.png" class="img-circle elevation-2" alt="User Image">
                    </div>
                    <div class="info">
                        <a class="d-block"><?php echo $_SESSION['nombre']; ?></a>
                    </div>
                </div>
                <nav class="mt-2">
                    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
                        <li class="nav-header">Módulos</li>
                        <!-- Module Types Loop -->
                        <?php 
        
                                if($_SESSION['compra']==1){
                                    echo' <li class="nav-item has-treeview" data-name="module_header" data-id="">
                                        <a class="nav-link" data-name="module_header">
                                            <i class="nav-icon icon-class fa-solid fas fa-boxes"></i>
                                            <p>Modulo Compras <i class="right fas fa-angle-left"></i></p>
                                        </a>
                                        <ul class="nav nav-treeview">
                                            <!-- Module Items Loop -->
                                            <li class="nav-item">
                                                <a href="#" class="nav-link" data-name="submodule" data-id="1">
                                                    <i class="icon-class nav-icon far fa-circle"></i>
                                                    <p>Registro Compra</p>
                                                </a>
                                            </li>                                    
                                        </ul>
                                    </li>';
                                    }
    
                                if($_SESSION['contrato']==1){
                                    echo' <li class="nav-item has-treeview" data-name="module_header" data-id="">
                                        <a class="nav-link" data-name="module_header">
                                            <i class="nav-icon icon-class fa-solid fa-shopping-cart"></i>
                                            <p>Modulo Contrato <i class="right fas fa-angle-left"></i></p>
                                        </a>
                                        <ul class="nav nav-treeview">
                                            <!-- Module Items Loop -->
                                            <li class="nav-item">
                                                <a href="'. BASE_URL .'contrato/list.php" class="nav-link" data-name="submodule" data-id="1">
                                                    <i class="icon-class nav-icon far fa-circle"></i>
                                                      <p>Registro Contratos</p>
                                                </a>
                                            </li>                                    
                                        </ul>
                                    </li>';
                                    }

                                    if($_SESSION['pabellon']==1){
                                        echo' <li class="nav-item has-treeview" data-name="module_header" data-id="">
                                            <a class="nav-link" data-name="module_header">
                                                <i class="nav-icon icon-class fa-solid fas fa-map"></i>
                                                <p>Modulo Pabellon <i class="right fas fa-angle-left"></i> </p>
                                            </a>
                                            <ul class="nav nav-treeview">
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'pabellon/list.php" class="nav-link" >
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Registro Pabellon</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'pabellon/list_detalle.php" class="nav-link" >
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Detalle Nichos</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'pabellon/grafico.php" class="nav-link" >
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Grafico Pabellon</p>
                                                    </a>
                                                </li>                                    
                                            </ul>

                                        </li>';
                                    }
                               
                                    if($_SESSION['cliente']==1){
                                        $contador_cliente = "SELECT count(idpersona) as cliente FROM persona WHERE  estado='1' and idtipo_persona='1'";  
                                        $fila = ejecutarConsultaSimpleFila($contador_cliente);
                                        $numero_cliente = $fila['cliente'];
                                        echo' <li class="nav-item has-treeview" data-name="module_header" data-id="">
                                            <a class="nav-link">
                                                <i class="nav-icon icon-class fa-solid fas fa-users-cog"></i>
                                                <p> Gestion Personal <i class="right fas fa-angle-left"></i></p>
                                            </a>
                                            <ul class="nav nav-treeview">
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'cliente/list.php" class="nav-link" >
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Cliente <span class="badge badge-danger right">'.$numero_cliente.'</span> </p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'empleado/list.php" class="nav-link" >
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Empleado</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'difunto/list.php" class="nav-link" >
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Difunto</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'funeraria/list.php" class="nav-link" >
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Funeraria</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                        </li>';
                                    }

                                     

                                     if($_SESSION['ingreso']==1){
                                        echo'  <li class="nav-header">MODULO CAJA</li>
                                        <li class="nav-item has-treeview" data-name="module_header" data-id="">
                                            <a class="nav-link" data-name="module_header">
                                                <i class="nav-icon icon-class fa-solid fas fa-line-chart"></i>
                                                <p>Modulo Caja<i class="right fas fa-angle-left"></i></p>
                                            </a>
                                            <ul class="nav nav-treeview">
                                                <!-- Module Items Loop -->
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'ingreso/list.php" class="nav-link" data-name="submodule" data-id="1">
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Ingreso</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <!-- Module Items Loop -->
                                                <li class="nav-item">
                                                      <a href="'. BASE_URL .'egreso/list.php" class="nav-link" data-name="submodule" data-id="1">
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Egreso</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                        </li>';
                                        }

                                        if($_SESSION['reporte']==1){
                                        echo'<li class="nav-header">REPORTES</li>  
                                        <li class="nav-item has-treeview" data-name="module_header" data-id="">
                                            <a class="nav-link" data-name="module_header">
                                                <i class="nav-icon icon-class fa-solid fa fa-folder"></i>
                                                <p>Reporte <i class="right fas fa-angle-left"></i> <span class="badge badge-danger right">Contrato</span> </p>
                                            </a>
                                            <ul class="nav nav-treeview">
                                                <!-- Module Items Loop -->
                                                <li class="nav-item">
                                                    <a href="#" class="nav-link" data-name="submodule" data-id="1">
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Reporte</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                        </li>';
                                        }
                                  
                                    if($_SESSION['acceso']==1){
                                        echo' <li class="nav-header">CONFIGURACIONES</li> 
                                        <li class="nav-item has-treeview" data-name="module_header" data-id="">
                                            <a class="nav-link" data-name="module_header">
                                                <i class="nav-icon icon-class fa-solid  fas fa-lock"></i>
                                                <p>Acceso<i class="right fas fa-angle-left"></i></p>
                                            </a>
                                            <ul class="nav nav-treeview">
                                                <!-- Module Items Loop -->
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'usuario/list.php" class="nav-link" data-name="submodule" data-id="1">
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Usuario</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                              <ul class="nav nav-treeview">
                                                <!-- Module Items Loop -->
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'venta/list.php" class="nav-link" data-name="submodule" data-id="1">
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Lista Venta</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <!-- Module Items Loop -->
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'caja/list.php" class="nav-link" data-name="submodule" data-id="1">
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Caja</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                            <ul class="nav nav-treeview">
                                                <!-- Module Items Loop -->
                                                <li class="nav-item">
                                                    <a href="'. BASE_URL .'permiso/list.php" class="nav-link" data-name="submodule" data-id="1">
                                                        <i class="icon-class nav-icon far fa-circle"></i>
                                                        <p>Permiso</p>
                                                    </a>
                                                </li>                                    
                                            </ul>
                                        </li>';
                                        } 
                                        if($_SESSION['acceso']==1){
                                        echo' <li class="nav-item">
                                                <a href="'. BASE_URL .'empresa/create.php?idconfiguracion=1" class="nav-link" data-name="single_module" data-id="">
                                                    <i class="nav-icon fas fa-building"></i>
                                                    <p>Empresa</p>
                                                </a>
                                            </li> ';
                                    }   
                                     
                                     
                            ?>           
                    </ul>
                </nav>
            </div>
        </aside>
        <!-- Content Section -->
        <div class="content-wrapper">
            <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="#">
                                            <i class="module-icon"></i> Escritorio
                                        </a>
                                    </li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </section>

            <?php
if($_SESSION['escritorio']==1 ){

    $contador_contrato= "SELECT count(idcontrato) as cantidadc FROM contrato";  
    $fila = ejecutarConsultaSimpleFila($contador_contrato);
    $numero_contrato = $fila['cantidadc'];

    $contador_usuario= "SELECT count(idusuario) as cantidadu FROM usuario ";  
    $fila = ejecutarConsultaSimpleFila($contador_usuario);
    $numero_usuario = $fila['cantidadu'];

    $contador_difunto= "SELECT count(iddifunto) as cantidadd FROM difunto";  
    $fila = ejecutarConsultaSimpleFila($contador_difunto);
    $numero_difunto = $fila['cantidadd'];
?>

            <section class="content">
                <div class="container-fluid">
                    <!-- Your dynamic content goes here -->
                    <div class="row">
                        <div class="col-md-3 col-sm-6 col-12">
                            <div class="info-box">
                                <span class="info-box-icon bg-info"><i class="fas fa-user-friends"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">Clientes</span>
                                    <span class="info-box-number"><?php echo $numero_cliente; ?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3 col-sm-6 col-12">
                            <div class="info-box">
                                <span class="info-box-icon bg-success"><i class="fas fa-truck"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">Contratos</span>
                                    <span class="info-box-number"><?php echo $numero_contrato; ?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3 col-sm-6 col-12">
                            <div class="info-box">
                                <span class="info-box-icon bg-warning"><i class="fas fa-truck-loading"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">Usuarios</span>
                                    <span class="info-box-number"><?php echo $numero_usuario; ?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3 col-sm-6 col-12">
                            <div class="info-box">
                                <span class="info-box-icon bg-danger"><i class="fas fa-box"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">Difuntos</span>
                                    <span class="info-box-number"><?php echo $numero_difunto; ?></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="card">
                                <div class="card-header">
                                    <h3 class="card-title"><i class="fas fa-chart-bar"></i> Top Nichos Vendidos por Mes</h3>
                                </div>
                                <div class="card-body p-0">
                                    <div class="container-fluid p-3">
                                    <div id="topProductosChart" style="height: 57vh;"></div>
                                    </div>
                                </div>
                            </div> 
                        </div>
                        <div class="col-md-6">
                            <div class="card">
                                <div class="card-header">
                                    <h3 class="card-title"><i class="fas fa-box"></i> Total Contratos Anual</h3>
                                </div>
                                <div class="card-body p-0">
                                    <div id="graph-stock-products" style="height: 57vh;"></div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-header">
                                    <h3 class="card-title"><i class="fas fa-calendar-check"></i> Ingresos y Egresos del Año <?php echo date("Y")?></h3>
                                </div>
                                <div class="card-body p-0">
                                    <div class="container-fluid p-3" id="graph-purchase-vs-sale"></div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="card">
                                <div class="card-header">
                                    <h3 class="card-title"><i class="fas fa-chart-bar"></i> Total Nichos Enterrados,Futuro,Libres</h3>
                                </div>
                                <div class="card-body p-0">
                                    <div class="container-fluid p-3">
                                    <div id="topNichoChart" style="height: 57vh;"></div>
                                    </div>
                                </div>
                            </div> 
                        </div>
                    </div>
                </section>
            </div>

            <?php

}
?>
            <!-- Modal para mostrar detalles -->
<div class="modal fade" id="modalDetalles" tabindex="-1" role="dialog" aria-labelledby="tituloModal" aria-hidden="true">
  <div class="modal-dialog modal-xl" role="document">
    <div class="modal-content">
      <div class="modal-header bg-primary text-white">
        <h5 class="modal-title" id="tituloModal">Detalles del Producto</h5>
        <button type="button" class="close text-white" data-dismiss="modal" aria-label="Cerrar">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <table id="tablaDetallesModal" class="table table-bordered table-striped table-sm" style="width:100%">
          <thead>
            <tr id="cabeceraModal"></tr>
          </thead>
          <tbody id="cuerpoModal"></tbody>
        </table>
      </div>
    </div>
  </div>
</div>
        <!-- Footer Template -->
        <footer class="main-footer">
            <div class="text-center">
                © Copyright <strong>Mi Sistema Panel - Campo Santo</strong>. Todos los derechos reservados<br>
                <a href="#" target="_blank">Desarrollado por el equipo de Tecnologia Campo Santo.</a>
            </div>
        </footer>
    </div>
   
    <script>
        // Example script for displaying error messages if they exist
        var errors = '';
        // Add messages dynamically here
        if (errors) {
            alert(errors); // Replace with your own error display logic
        }
    </script>
   
</body>
<!-- JavaScript for DataTable -->
    <script src="../static/lib/datatables-1.10.25/js/jquery.dataTables.js"></script>
    <script src="../static/lib/datatables-1.10.25/js/dataTables.bootstrap4.min.js"></script>
    <script src="../static/lib/datatables-1.10.25/plugins/responsive-2.2.9/js/dataTables.responsive.min.js"></script>
    <script src="../static/lib/datatables-1.10.25/plugins/responsive-2.2.9/js/responsive.bootstrap4.min.js"></script>
    <script src="../static/js/main.js"></script>
</html>
<script type="text/javascript" src="../scripts/escritorio.js"></script>