<?php //print_r($usertype);exit; ?>
    <section class="content-header">
      <h1>
        Best Customers Revenue
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">List</li>
      </ol>
    </section>

    <section class="content">
      <div class="row">
        <?php echo $this->utility->showMsg();?>
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Management</h3>
              </div>
               
              <div></div>
            <!-- /.box-header -->
            <div class="box-body">
            <form action="" id="search_frm" method="post" style="margin-bottom: 5%;">
              <select class="form-contrl" name="year" style="width: 25%; float: right;height: 34px">
                <option value="">--Select Year--</option>
                <option value="all" <?php if($this->input->post('year')=='all'){ echo 'selected'; }?>>Select All Years</option>
                <?php for($i=2014; $i<=date('Y');$i++){ ?>
                  <option value="<?php echo $i; ?>" <?php if($this->input->post('year')==$i){ echo 'selected'; }?>><?php echo $i; ?></option>
                <?php } ?>
              </select>
              <input type="submit" class="btn btn-primary" value="Search" style="float: right;">
            </form>
            <div class="table-responsive">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th style="display: none;">#</th>
                  <th>Pseudonym</th>
                  <th>Membership Total</th>
                  <th>Booking Total</th>
                  <?php if($this->input->post('year')){ 
                          if($this->input->post('year')=='all'){
                            for($i=2014; $i<=date('Y');$i++){
                              echo '<th>'.$i.'</th>'; 
                            }
                          } else {
                            echo '<th>'.$this->input->post('year').'</th>'; 
                          }
                        } else { 
                          echo '<th>'.date('Y').'</th>'; 
                        }
                  ?>
                  
                  <th>Checkin Total</th>
                  <th>Selected Year</th>
                  <th>Total Participated</th>
                  <th>Total</th>
                </tr>
                </thead>
                 <?php if(count($resultBest)>0)
                {?>
                <tbody>
               <?php
                $i=1;
                foreach ($resultBest as $key=>$data) 
                {
                  $total = 0;
                  $year = 0;
                  if($this->input->post('year')){ 
                    $year = $this->input->post('year'); 
                  } else { 
                    $year = date('Y'); 
                  }
                  $total = $data['order_total']+$data['booking_total'];
                  if(file_exists(FCPATH.'assets/userfiles/'.$data['path'].'/'.$data['filename'].'.'.$data['extension'])){
                    $imageFile = base_url().'assets/userfiles/'.$data['path'].'/'.$data['filename'].'.'.$data['extension'];
                  } else {
                    $imageFile = base_url().'assets/images/default-avatar.jpg';
                  }
                ?>
                <tr>
                    <td style="display: none;"><?php echo $key+1; ?></td>
                    <td class="best_customer_pic"><a target="_blank" href="<?php echo  base_url().'admin/users/edit/'.base64_encode($data['user_id']);?>"><img class="direct-chat-img" src="<?php echo $imageFile; ?>" title="" style="margin: 10px;"><?php echo $data['username']; ?></a></td>
                    <td><?php echo number_format($data['order_total']/100, 2,',', '.'); ?> &euro;</td>
                    <td><?php echo number_format($data['booking_total']/100, 2,',', '.'); ?> &euro;</td>
                    <?php if($this->input->post('year')){ 
                            if($this->input->post('year')=='all'){
                              $total_part = 0;
                              foreach ($data['years'] as $kyear => $vyear) { ?>
                                  <td>
                                      <?php 
                                            if(in_array(1, $vyear['months']) || in_array(2, $vyear['months']) || in_array(3, $vyear['months'])) {
                                              $total_part = $total_part + 1; 
                                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') < 3) { 
                                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') > 3) { 
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } else {
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } 
                                      ?>

                                      <?php if(in_array(4, $vyear['months']) || in_array(5, $vyear['months']) || in_array(6, $vyear['months'])) { 
                                              $total_part = $total_part + 1; 
                                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') < 6) { 
                                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') > 6) { 
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } else {
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } 
                                      ?>

                                      <?php if(in_array(7, $vyear['months']) || in_array(8, $vyear['months']) || in_array(9, $vyear['months'])) { 
                                              $total_part = $total_part + 1; 
                                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') < 9) { 
                                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') > 9) { 
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } else {
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } 
                                      ?>

                                      <?php if(in_array(10, $vyear['months']) || in_array(11, $vyear['months']) || in_array(12, $vyear['months'])) { 
                                              $total_part = $total_part + 1; 
                                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') < 11) { 
                                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                                            } elseif(date('Y') == $kyear && date('m') > 11) { 
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } else {
                                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                                            } 
                                      ?>
                                        
                                  </td>
                    <?php   }  } else { ?>

                          <td>
                      <?php $total_part = 0;
                            if(in_array(1, $data['months']) || in_array(2, $data['months']) || in_array(3, $data['months'])) {
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 3) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 3) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>

                      <?php if(in_array(4, $data['months']) || in_array(5, $data['months']) || in_array(6, $data['months'])) { 
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 6) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 6) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>

                      <?php if(in_array(7, $data['months']) || in_array(8, $data['months']) || in_array(9, $data['months'])) { 
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 9) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 9) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>

                      <?php if(in_array(10, $data['months']) || in_array(11, $data['months']) || in_array(12, $data['months'])) { 
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 11) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 11) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>
                        
                    </td>
                    <?php  } } else { ?>
                    <td>
                      <?php $total_part = 0;
                            if(in_array(1, $data['months']) || in_array(2, $data['months']) || in_array(3, $data['months'])) {
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 3) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 3) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>

                      <?php if(in_array(4, $data['months']) || in_array(5, $data['months']) || in_array(6, $data['months'])) { 
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 6) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 6) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>

                      <?php if(in_array(7, $data['months']) || in_array(8, $data['months']) || in_array(9, $data['months'])) { 
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 9) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 9) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>

                      <?php if(in_array(10, $data['months']) || in_array(11, $data['months']) || in_array(12, $data['months'])) { 
                              $total_part = $total_part + 1; 
                              echo '<i class="fa fa-circle" style="color:green"></i>'; 
                            } elseif(date('Y') == $year && date('m') < 11) { 
                              echo '<i class="fa fa-circle" style="color:#fff"></i>'; 
                            } elseif(date('Y') == $year && date('m') > 11) { 
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } else {
                              echo '<i class="fa fa-circle" style="color:#f00"></i>'; 
                            } 
                      ?>
                        
                    </td>
                      <?php } ?>
                    <td><?php echo number_format($data['checkin_sum'], 2,',', '.'); ?> &euro;</td>
                    <td><?php echo $data['count_book']; ?></td>
                    <td><?php echo $total_part; ?> </td>
                    <td><?php echo number_format($total/100, 2,',', '.'); ?> &euro;</td>
                </tr>

               <?php $i++; } ?>

                </tbody>
                <?php } ?>
                <tfoot>
               
                </tfoot>
              </table>
              </div>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    

    
<script>
  $(function () {
    $("#example1").DataTable();
  });
</script>