<!DOCTYPE html>
<html lang="es">

<head>
  <%- include('../../../tools/head'); %>
  <!-- Custom styles for this page -->
  <link href="/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="https://cdn.datatables.net/datetime/1.1.2/css/dataTables.dateTime.min.css">
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.15/plugins/export/libs/FileSaver.js/FileSaver.min.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.15.6/xlsx.full.min.js"></script>
  <link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.dataTables.min.css">
</head>

<body id="page-top">
  <!-- Page Wrapper -->
  <div id="wrapper">

    <!-- Sidebar -->
    <%- include('../../../tools/sidebarProf'); %>
    <!-- End of Sidebar -->

    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">
      <!-- Main Content -->
      <div id="content">

        <!-- Topbar -->
        <%- include('../../../tools/topbar'); %>
        <!-- End of Topbar -->

        <!-- Begin Page Content -->
        <div class="container-fluid">

          <!-- DataTales -->
          <div class="card shadow mb-4">
            <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
              <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="/profesional/Consolidaciones/Ver">Consolidaciones</a></li>
                <li class="breadcrumb-item active" aria-current="page">Eventos de Salud Publica
                </li>
              </ol>
            </nav>

            <div class="card-body">
              <div class=" table-responsive">
                <div class="col">
                  <div class="row">
                    <div class="col-xl-10">
                      <table border="0" cellspacing="5" cellpadding="5">
                        <tbody>
                          <tr>
                            <td>Fecha Inicial:</td>
                            <td><input type="text" id="min" name="min"></td>
                          </tr>
                          <tr>
                            <td>Fecha Final:</td>
                            <td><input type="text" id="max" name="max"></td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                    <div class="col-xl-2">
                      <a id="button" href="/profesional/Consolidaciones/UpdateAcept/EvenSaludPubli" class="btn btn-primary btn-sm">Aceptar Consolidaciones</a>
                    </div>
                  </div>
                </div>
                <table class="table table-bordered table-hover display nowrap" id="dataTable" width="100%" cellspacing="0" style="font-size: 13px;  text-align: center !important;">
                  <thead>
                    <tr>
                      <th rowspan="2">Estado</th>
                      <th rowspan="2">Fecha_Enviado</th>
                      <th rowspan="2">Responsable</th>
                      <th rowspan="2">Mes</th>
                      <th rowspan="2">Provincia</th>
                      <th rowspan="2">Municipio</th>
                      <th colspan="2">Etas</th>
                      <th colspan="2">Intoxicaciones Por Sustancias Quimicas</th>
                      <th colspan="2">Agresiones</th>
                      <th colspan="2">Participación En Cove</th>
                      <th rowspan="2">Observaciones</th>
                      <th rowspan="2">Archivos</th>
                      <th rowspan="2">Acción</th>
                    </tr>
                    <tr>
                      <th>Etas Presentadas</th>
                      <th>Etas Atendidas</th>

                      <th>Intoxicaciones Presentadas</th>
                      <th>Intoxicaciones Atendidas</th>

                      <th>Agresiones Presentadas</th>
                      <th>Agresiones Atendidas</th>

                      <th>Si/No</th>
                      <th>Fecha Participación</th>
                    </tr>
                  </thead>
                  <tfoot>
                    <tr>
                      <th rowspan="2"><input type="text" placeholder="Busca por Estado" /></th>
                      <th rowspan="2"><input type="text" placeholder="Busca por Fecha_Enviado" /></th>
                      <th rowspan="2"><input type="text" placeholder="Busca por Responsable" /></th>
                      <th rowspan="2"><input type="text" placeholder="Busca por Mes" /></th>
                      <th rowspan="2"><input type="text" placeholder="Busca por Provincia" /></th>
                      <th rowspan="2"><input type="text" placeholder="Busca por Municipio" /></th>
                      <th><input type="text" placeholder="Busca por Etas Presentadas" /></th>
                      <th><input type="text" placeholder="Busca por Etas Atendidas" /></th>
                      <th><input type="text" placeholder="Busca por Intoxicaciones Presentadas" /></th>
                      <th><input type="text" placeholder="Busca por Intoxicaciones Atendidas" /></th>
                      <th><input type="text" placeholder="Busca por Agresiones Presentadas" /></th>
                      <th><input type="text" placeholder="Busca por Agresiones Atendidas" /></th>
                      <th><input type="text" placeholder="Busca por Si/No" /></th>
                      <th><input type="text" placeholder="Busca por Fecha Participación" /></th>
                      <th rowspan="2"><input type="text" placeholder="Busca por Observaciones" /></th>
                      <th rowspan="2">Archivos</th>
                      <th rowspan="2">Acción</th>
                    </tr>
                    <tr>
                      <th colspan="2">Etas</th>
                      <th colspan="2">Intoxicaciones Por Sustancias Quimicas</th>
                      <th colspan="2">Agresiones</th>
                      <th colspan="2">Participación En Cove</th>
                    </tr>
                  </tfoot>
                  <tbody>
                    <% if (allConso){ %>
                    <% allConso.forEach((allConso)=> { %>
                    <% if (allConso.consolidacion.EvenSaludPubli == "on"){ %>
                    <tr>
                      <td>
                        <% if(allConso.status=="Pendiente" ){ %>
                        <a href="/profesional/Consolidaciones/Validar/EventosSaludPublica/<%= allConso._id %>"><span class="badge badge-warning text-uppercase">Pendiente</span></a>
                        <% }else if(allConso.status=="Corregido" ){ %>
                        <a href="/profesional/Consolidaciones/Correccion/EventosSaludPublica/<%= allConso._id %>"><span class="badge badge-primary text-uppercase">Corregido</span></a>
                        <% }else if(allConso.status=="Rechazado" ){ %>
                        <span class="badge badge-danger text-uppercase">Rechazado</span>
                        <% }else if(allConso.status == "Enviado"){ %>
                        <span class="badge badge-info text-uppercase">Enviado</span>
                        <% }else if(allConso.status=="Aceptado" ){ %>
                        <span class="badge badge-success text-uppercase">Aceptado</span>
                        <% } %>
                      </td>
                      <td>
                        <%= moment(allConso.createdAt,"YYYY/MM/DD").format('YYYY-MM-DD'); %>
                      </td>
                      <td>
                        <%= allConso.responsable.userResponsable %>
                        <%= allConso.responsable.nombreResponsable %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.mes %>
                      </td>
                      <td>
                        <%= allConso.provincia %>
                      </td>
                      <td>
                        <%= allConso.municipio %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.presentEtas %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.atendEtas %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.presentIntox %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.atendIntox %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.presentAgre %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.atendAgre %>
                      </td>
                      <td>
                        <%= allConso.ForEvenSPublica.covePart %>
                      </td>
                      <td>
                        <%= moment(allConso.ForEvenSPublica.coveFech,"YYYY/MM/DD").add(1, 'days').format('DD-MM-YYYY'); %>
                      </td>
                      <td>
                        <%= allConso.observaciones %>
                      </td>
                      <td>
                        <a href="/profesional/evidencia/<%= allConso._id %>" target="_blank">target="_blank"><span class="badge badge-primary text-uppercase">Descargar</span></a>
                      </td>
                      <td>
                        <% if(allConso.SendNovAd == "off"){ %>
                        <a type="button" onclick='modalsEstablecimientos.eliminar_cons("<%= allConso._id %>")' data-target="#deleteModal" data-toggle="modal" class="btn btn-danger btn-circle btn-sm">
                          <i class="fas fa-trash"></i>
                        </a>
                        <% } %>
                      </td>
                    </tr>
                    <% } %>
                    <% }); %>
                    <% } %>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <!-- /.container-fluid -->

        </div>
        <!-- End of Main Content -->

        <!-- Footer -->
        <%- include('../../../tools/footer'); %>
        <!-- End of Footer -->

      </div>
      <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>

    <!-- Delete Modal-->
    <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">¡ATENCIÓN!</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">
            ¿Esta seguro de eliminar esta consolidación?
            <br>
            <b>RECUERDE QUE ESTA ACCIÓN ES IRREVERSIBLE</b>
          </div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">
              Cancelar
            </button>
            <a id="formDeleteCons" class="btn btn-primary">
              Eliminar
            </a>
          </div>
        </div>
      </div>
    </div>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Salida</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">Seleccione "Cerrar
            sesión" a continuación si está listo para
            finalizar su sesión actual.</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancelar</button>
            <a class="btn btn-primary" href="/profesional/logout">Cerrar Sesión</a>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="/vendor/jquery/jquery.min.js"></script>
    <script src="/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="/vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="/js/sb-admin-2.min.js"></script>

    <!-- Page level plugins -->
    <script src="/vendor/datatables/jquery.dataTables.min.js"></script>
    <script src="/vendor/datatables/dataTables.bootstrap4.min.js"></script>

    <!-- Page level custom scripts -->
    <script src="/js/demo/datatables-demo.js"></script>

    <!-- Excel -->
    <script src="https://cdn.datatables.net/buttons/2.2.3/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.html5.min.js"></script>

    <!-- Validation -->
    <script src="/js/Profesional/validaciones.js"></script>

    <!-- Search Advanced -->
    <script src="https://cdn.datatables.net/fixedcolumns/4.1.0/js/dataTables.fixedColumns.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.2/moment.min.js"></script>
    <script src="https://cdn.datatables.net/datetime/1.1.2/js/dataTables.dateTime.min.js"></script>

    <script>
      $(window).bind(' load', function() {
        var nav = document.getElementById('nav2');
        $('#navlink1').removeClass('collapsed');
        var nav3 = document.getElementById('collapseTwo');
        var nav4 = document.getElementById('show1');
        nav.className += "  active";
        nav3.className += "  show";
        nav4.className += "  active";
      });

      var table = $('#dataTable').DataTable({
        order: [
          [1, 'desc']
        ],
        scrollY: true,
        scrollX: true,
        scrollCollapse: true,
        language: {
          search: "Buscar:",
          info: "Mostrando _START_ elementos a _END_ de _TOTAL_ entradas",
          zeroRecords: "Sin Datos en esta Tabla",
          infoFiltered: " - filtrado desde _MAX_ entradas",
          lengthMenu: "Mostrando _MENU_ entradas",
          paginate: {
            previous: "Anterior",
            next: "Siguiente",
          },
        },
        dom: 'Bfrtlip',
        buttons: [{
          extend: 'excel',
          filename: 'EVESALUDPUBLICA_' + new Date().toJSON().substring(0, 10),
          autoFilter: true,
          sheetName: 'EVENTOS EN SALUD PUBLICA',
        }]
      });
      table.columns().every(function() {
        var that = this;
        $('input', this.footer()).on('keyup change', function() {
          that
            .search(this.value)
            .draw();
        });
      });

      var minDate, maxDate;

      $.fn.dataTable.ext.search.push(
        function(settings, data, dataIndex) {
          var min = minDate.val();
          var max = maxDate.val();
          var date = new Date(data[1]);

          if (
            (min === null && max === null) ||
            (min === null && date <= max) ||
            (min <= date && max === null) ||
            (min <= date && date <= max)
          ) {
            return true;
          }
          return false;
        }
      );

      $(document).ready(function() {
        minDate = new DateTime($('#min'), {
          format: 'YYYY-MM-DD'
        });
        maxDate = new DateTime($('#max'), {
          format: 'YYYY-MM-DD'
        });

        $('#min, #max').on('change', function() {
          table.draw();
        });
      });
    </script>

</body>

</html>