<?php
//Activamos el almacenamiento en el buffer
ob_start();
session_start();

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

    if ($_SESSION['contabilidad'] == 1) {
?>
<!--Contenido-->
<div class="content-wrapper">        
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h1 class="box-title"><i class="fa fa-bar-chart"></i> Contabilidad Médica Avanzada</h1>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <!-- Filtros Superiores -->
                        <div class="row">
                            <div class="form-group col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                <label>Rango de Fechas:</label>
                                <div class="input-group">
                                    <input type="date" class="form-control" name="fecha_inicio" id="fecha_inicio" value="<?php echo date("Y-m-01"); ?>">
                                    <span class="input-group-addon">al</span>
                                    <input type="date" class="form-control" name="fecha_fin" id="fecha_fin" value="<?php echo date("Y-m-d"); ?>">
                                </div>
                            </div>
                            <div class="form-group col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                <label>Médico / Especialista:</label>
                                <select id="idempleado_filtro" class="form-control selectpicker" data-live-search="true">
                                    <option value="0">Todos los Médicos</option>
                                </select>
                            </div>
                            <div class="form-group col-lg-2 col-md-2 col-sm-6 col-xs-12">
                                <label>&nbsp;</label>
                                <button class="btn btn-primary btn-block" onclick="actualizarDashboard()"><i class="fa fa-refresh"></i> Actualizar</button>
                            </div>
                        </div>

                        <hr>

                        <!-- Tarjetas de Resumen -->
                        <div class="row">
                            <div class="col-lg-3 col-xs-6">
                                <div class="small-box bg-aqua">
                                    <div class="inner">
                                        <h3 id="txt_total_ingresos">$ 0.00</h3>
                                        <p>Total Ingresos</p>
                                    </div>
                                    <div class="icon"><i class="fa fa-money"></i></div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-xs-6">
                                <div class="small-box bg-green">
                                    <div class="inner">
                                        <h3 id="txt_total_atenciones">0</h3>
                                        <p>Atenciones Totales</p>
                                    </div>
                                    <div class="icon"><i class="fa fa-users"></i></div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-xs-6">
                                <div class="small-box bg-yellow">
                                    <div class="inner">
                                        <h3 id="txt_promedio_consulta">$ 0.00</h3>
                                        <p>Promedio por Consulta</p>
                                    </div>
                                    <div class="icon"><i class="fa fa-calculator"></i></div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-xs-6">
                                <div class="small-box bg-purple">
                                    <div class="inner">
                                        <h3 id="txt_total_medicos">0</h3>
                                        <p>Médicos Activos</p>
                                    </div>
                                    <div class="icon"><i class="fa fa-user-md"></i></div>
                                </div>
                            </div>
                        </div>

                        <!-- Gráfico de Tendencia -->
                        <div class="row">
                            <div class="col-md-12">
                                <div class="nav-tabs-custom">
                                    <ul class="nav nav-tabs">
                                        <li class="active"><a href="#tab_diario" data-toggle="tab" onclick="cargarGrafico('diarios')">Diario</a></li>
                                        <li><a href="#tab_semanal" data-toggle="tab" onclick="cargarGrafico('semanales')">Semanal</a></li>
                                        <li><a href="#tab_mensual" data-toggle="tab" onclick="cargarGrafico('mensuales')">Mensual</a></li>
                                    </ul>
                                    <div class="tab-content">
                                        <div class="tab-pane active" id="tab_diario">
                                            <div class="chart">
                                                <canvas id="grafico_ingresos" style="height:250px"></canvas>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Detalle de Atenciones -->
                        <div class="row">
                            <div class="col-md-12">
                                <div class="box box-solid bg-light-blue-gradient" style="background: #fff !important; color: #333 !important; border: 1px solid #ddd;">
                                    <div class="box-header">
                                        <i class="fa fa-list"></i>
                                        <h3 class="box-title">Detalle Cronológico</h3>
                                    </div>
                                    <div class="box-body">
                                        <div class="table-responsive">
                                            <table id="tbllistado" class="table table-striped table-bordered table-condensed table-hover">
                                              <thead>
                                                <tr>
                                                  <th>Fecha</th>
                                                  <th>Hora</th>
                                                  <th>Paciente</th>
                                                  <th>Médico</th>
                                                  <th>Especialidad</th>
                                                  <th>Servicio</th>
                                                  <th>Valor ($)</th>
                                                </tr>
                                              </thead>
                                              <tbody>                            
                                              </tbody>
                                              <tfoot>
                                                <tr>
                                                  <th colspan="6" style="text-align:right">TOTAL ACUMULADO:</th>
                                                  <th id="total_acumulado_tabla">$ 0.00</th>
                                                </tr>
                                              </tfoot>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Ranking de Médicos -->
                        <div class="row">
                            <div class="col-md-12">
                                <div class="box box-success">
                                    <div class="box-header with-border">
                                        <h3 class="box-title"><i class="fa fa-trophy"></i> Desempeño por Especialista</h3>
                                    </div>
                                    <div class="box-body">
                                        <div class="table-responsive">
                                            <table id="tblranking" class="table table-hover">
                                                <thead>
                                                    <tr>
                                                        <th>Médico</th>
                                                        <th>Especialidad</th>
                                                        <th>Atenciones</th>
                                                        <th>Ingresos</th>
                                                        <th>Promedio</th>
                                                        <th>Min/Max</th>
                                                    </tr>
                                                </thead>
                                                <tbody id="ranking_body">
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                    <!-- /.box-body -->
                </div><!-- /.box -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </section><!-- /.content -->

</div><!-- /.content-wrapper -->
<!--Fin-Contenido-->
<?php
    } else {
        require 'noacceso.php';
    }
    require 'footer.php';
?>
<script type="text/javascript" src="scripts/contabilidad.js"></script>
<?php 
}
ob_end_flush();
?>
