<?php
    //OBTENEMOS LA HORA EXACTA SETEANDO LA VARIABLE DATE_DEFAULT_TIMEZONE_SET
    date_default_timezone_set("America/Mexico_City"); 
?>
      <div class="row row-offcanvas row-offcanvas-right">

        <div class="col-xs-18 col-sm-12"><!--col-xs-12 col-sm-9 ESTOS DATOS SE UTILIZAN CUANDO PONEMOS EL MENU LATERAL, PARA QUE EL RESTO DEL CONTENIDO SEA DE ACUERDO A LA PANTALLA-->
          <!--<p class="pull-right visible-xs">
            <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle nav</button>
          </p>-->
          <div class="jumbotron" style="background-color:#FCFBFB">
            <img src="<?= base_url().'dist/images/grupo.jpg' ?>" alt="Logo" class="img-thumbnail" style="float:right">
            <h1>Bienvenido!</h1>
            <p>Usuario: <?= get_instance()->session->userdata('nombre') ?></p>

            <?php //echo print_r(get_instance()->session->all_userdata()); ?>

            <?php if(get_instance()->session->userdata("fk_cat_tipo_usuario") != 1){ ?>
            <ul id="myTabs" class="nav nav-tabs" role="tablist">
              <li role="presentation" class='nav-item'><a href="#act-pend" id="act-pend-tab" role="tab" data-toggle="tab" aria-controls="act-pend" class='nav-link active'>Actividades <span class='badge'><?= count($actividades) ?></span></a></li>
              <li role="presentation" class='nav-item'><a href="#status-vta" role="tab" id="status-vta-tab" data-toggle="tab" aria-controls="status-vta" class='nav-link'>Status de Venta</a></li>
              <!-- <li role="presentation"><a href="#vta" role="tab" id="vta-tab" data-toggle="tab" aria-controls="vta">Ventas</a></li>
              <li role="presentation"><a href="#prospectos" role="tab" id="prospectos-tab" data-toggle="tab" aria-controls="prospectos">Prospectos</a></li> -->
              
            </ul>
            <div id="myTabContent" class="tab-content">

              <div role="tabpanel" class="tab-pane fade show active" id="act-pend" aria-labelledBy="act-pend-tab">
                <p>
                  <?php 
                        //No such function exists. You always need to first map the values you would like to count (and those values must be string or integer)
                        //$map = function($v) {return $v->status;};
                        //$status = array_count_values(array_map($map, $actividades));

                        $array_pend_status = array();
                        $array_atra_status = array();
                        $array_pend_act = array();
                        $array_atra_act = array();
                        for($i = 0; $i < count($actividades); $i++){
                          if(stripos($actividades[$i]["dif"], '-') === FALSE){
                            $index_status = $actividades[$i]["fk_cat_status_seguimiento"]."-".$actividades[$i]["status"];
                            $index_actividad = $actividades[$i]["fk_cat_actividad_status_seguimiento"]."-".$actividades[$i]["actividad"];
                            //status
                            if(array_key_exists($index_status, $array_pend_status))
                              $array_pend_status[$index_status]++;
                            else
                              $array_pend_status[$index_status] = 1;
                            //actividades
                            if(array_key_exists($index_actividad, $array_pend_act))
                              $array_pend_act[$index_actividad]++;
                            else
                              $array_pend_act[$index_actividad] = 1;
                          }
                          else{
                            $index_status = $actividades[$i]["fk_cat_status_seguimiento"]."-".$actividades[$i]["status"];
                            $index_actividad = $actividades[$i]["fk_cat_actividad_status_seguimiento"]."-".$actividades[$i]["actividad"];
                            //status
                            if(array_key_exists($index_status, $array_atra_status))
                              $array_atra_status[$index_status]++;
                            else
                              $array_atra_status[$index_status] = 1;
                            //actividades
                            if(array_key_exists($index_actividad, $array_atra_act))
                              $array_atra_act[$index_actividad]++;
                            else
                              $array_atra_act[$index_actividad] = 1;
                          }
                        }
                        //print_r($array_atra_act);
                  ?>

                  <table class="table table-condensed">
                    <thead>
                      <tr>
                        <th colspan='2'>Pendientes</th>
                        <th colspan='2'>Atrasadas</th>
                      </tr>
                    </thead>
                    <tr>
                      <td width='23%'>
                        <table class="table table-bordered table-hover table-condensed">
                          <thead>
                            <tr>
                              <th>Por Status</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php foreach ($array_pend_status as $key => $value):
                              $key = explode("-", $key);
                            ?>
                            <tr class="table-warning">
                              <td><?= anchor('#','<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-square-fill" viewBox="0 0 16 16">
  <path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2zm8.93 4.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM8 5.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/>
</svg> '.$key[1],'onclick="loading_small(\'div_modal\');xajax_ver(\'pendiente\',\'status\',\''.$key[0].'\');return false;" data-toggle=\'modal\' data-target=\'#myModal\'') ?> <span class='badge'><?= $value ?></span></td>
                            </tr>
                            <?php 
                                  endforeach;
                            ?>
                          </tbody>
                        </table>
                      </td>
                      <td width='27%'>
                        <table class="table table-bordered table-hover table-condensed">
                          <thead>
                            <tr>
                              <th>Por Actividad</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php foreach ($array_pend_act as $key => $value):
                              $key = explode("-", $key);
                            ?>
                            <tr class="table-warning">
                              <td><?= anchor('#','<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-square-fill" viewBox="0 0 16 16">
  <path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2zm8.93 4.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM8 5.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/>
</svg> '.$key[1],'onclick="loading_small(\'div_modal\');xajax_ver(\'pendiente\',\'actividad\',\''.$key[0].'\');return false;" data-toggle=\'modal\' data-target=\'#myModal\'') ?> <span class='badge'><?= $value ?></span></span></td>
                            </tr>
                            <?php 
                                  endforeach;
                            ?>
                          </tbody>
                        </table>
                      </td>
                      <td width='23%'>
                        <table class="table table-bordered table-hover table-condensed">
                          <thead>
                            <tr>
                              <th>Por Status</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php foreach ($array_atra_status as $key => $value):
                              $key = explode("-", $key);
                            ?>
                            <tr class="table-danger">
                              <td><?= anchor('#','<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-square-fill" viewBox="0 0 16 16">
  <path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2zm8.93 4.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM8 5.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/>
</svg> '.$key[1],'onclick="loading_small(\'div_modal\');xajax_ver(\'atrasada\',\'status\',\''.$key[0].'\');return false;" data-toggle=\'modal\' data-target=\'#myModal\'') ?> <span class='badge'><?= $value ?></span></td>
                            </tr>
                            <?php 
                                  endforeach;
                            ?>
                          </tbody>
                        </table>
                      </td>
                      <td width='27%'>
                        <table class="table table-bordered table-hover table-condensed">
                          <thead>
                            <tr>
                              <th>Por Actividad</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php foreach ($array_atra_act as $key => $value):
                              $key = explode("-", $key);
                            ?>
                            <tr class="table-danger">
                              <td><?= anchor('#','<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-square-fill" viewBox="0 0 16 16">
  <path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2zm8.93 4.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM8 5.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/>
</svg> '.$key[1],'onclick="loading_small(\'div_modal\');xajax_ver(\'atrasada\',\'actividad\',\''.$key[0].'\');return false;" data-toggle=\'modal\' data-target=\'#myModal\'') ?> <span class='badge'><?= $value ?></span></span></td>
                            </tr>
                            <?php 
                                  endforeach;
                            ?>
                          </tbody>
                        </table>
                      </td>
                    </tr>
                  </table>
                </p>
              </div>
              <div role="tabpanel" class="tab-pane fade" id="status-vta" aria-labelledBy="status-vta-tab">
                <?php 
                      //empezamos a obtener la cantidad y porcentajes
                      $tot_prospectos = $frias[0]->tot + $tibias + $calientes + $cerradas;
                      $frias_p = (!empty($frias[0]->tot)) ? ($frias[0]->tot / $tot_prospectos) * 100 : 0;
                      $tibias_p = (!empty($tibias) != 0) ? ($tibias / $tot_prospectos) * 100 : 0;
                      $calientes_p = (!empty($calientes)) ? ($calientes / $tot_prospectos) * 100 : 0;
                      $cerradas_p = (!empty($cerradas)) ? ($cerradas / $tot_prospectos) * 100 : 0;
                ?>
                <p>
                  <center><b>TOTAL DE PROSPECTOS: <?= $tot_prospectos; ?></b></center><br />
                  <div class="progress">
                    <div class="progress-bar bg-info" role="progressbar" style="width: <?= number_format($frias_p,0) ?>%" aria-valuenow="<?= number_format($frias_p,0) ?>" aria-valuemin="0" aria-valuemax="100">
                      <?= "<b>".number_format($frias_p,0)."%</b>" ?>
                    </div>
                    <div class="progress-bar bg-warning" role="progressbar" style="width: <?= number_format($tibias_p,0) ?>%" aria-valuenow="<?= number_format($tibias_p,0) ?>" aria-valuemin="0" aria-valuemax="100">
                      <?= "<b>".number_format($tibias_p,0)."%</b>" ?>
                    </div>
                    <div class="progress-bar bg-danger" role="progressbar" style="width: <?= number_format($calientes_p,0) ?>%" aria-valuenow="<?= number_format($calientes_p,0) ?>" aria-valuemin="0" aria-valuemax="100">
                      <?= "<b>".number_format($calientes_p,0)."%</b>" ?>
                    </div>
                    <div class="progress-bar bg-success" role="progressbar" style="width: <?= number_format($cerradas_p,0) ?>%" aria-valuenow="<?= number_format($cerradas_p,0) ?>" aria-valuemin="0" aria-valuemax="100">
                      <?= "<b>".number_format($cerradas_p,0)."%</b>" ?>
                    </div>
                  </div>
                  <b>Nomenclatura:</b><br /><br />
                  <div class='Progress'>
                    <div class="progress-bar bg-info" style="width: 5%">
                      <span class="sr-only"></span>&nbsp;
                    </div>
                    &nbsp;&nbsp;Frío Cantidad = <b><?= $frias[0]->tot; ?></b>
                  </div>
                  <br />
                  <div class='Progress'>
                    <div class="progress-bar bg-warning" style="width: 5%">
                      <span class="sr-only"></span>&nbsp;
                    </div>
                    &nbsp;&nbsp;Tibio Cantidad = <b><?= $tibias; ?></b>
                  </div>
                  <br />
                  <div class='Progress'>
                    <div class="progress-bar bg-danger" style="width: 5%">
                      <span class="sr-only"></span>&nbsp;
                    </div>
                    &nbsp;&nbsp;Caliente Cantidad = <b><?= $calientes; ?></b>
                  </div>
                  <br />
                  <div class='Progress'>
                    <div class="progress-bar bg-success" style="width: 5%">
                      <span class="sr-only"></span>&nbsp;
                    </div>
                    &nbsp;&nbsp;Cerrada Cantidad = <b><?= $cerradas; ?></b>
                  </div>
                </p>
              </div>
              <div role="tabpanel" class="tab-pane fade" id="vta" aria-labelledBy="vta-tab">
                <p>
                  TOT VENTAS
                </p>
              </div>
              <div role="tabpanel" class="tab-pane fade" id="prospectos" aria-labelledBy="prospectos-tab">
                <p>
                  TOT PROSPECTOS
                </p>
              </div>
              
            </div>
            <?php } ?>

          </div>
        </div>
      </div><!--/row-->
      <?= show_modal() ?>