<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Top Users</title>
    <?php include_once(VIEWPATH. 'includes/head.php'); ?>
    <link href="<?php echo base_url('assets/css/bootstrap-datepicker3.css');?>" rel="stylesheet"/>
    <style type="text/css">
    @media print {
    .panel,.panel-body{padding:0;border:0}
    .panel-heading,#back-to-top{display:none}
    .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{border:1px solid #ddd !important}
    }
    </style>
  </head>  
  <body>
    <?php include_once(VIEWPATH. 'admin/_navbar.php'); ?>
    <div class="container">
      <ul class="breadcrumb">
        <li><a href="<?php echo site_url();?>"><i class="fa fa-home"></i></a></li>
        <li><a href="<?php echo site_url('admin');?>">Admin Panel</a></li>
        <li><a href="<?php echo site_url('admin/transaksi');?>">Transaksi</a></li>
        <li class="active"><span>Top Users</span></li>
      </ul>
      <div class="row">
        <div class="col-sm-4 col-md-3 hidden-print">
          <?php
          $links = array(
            array('Hari ini',  site_url('admin/transaksi/top-users/hari-ini'), null, $waktu == 'hari-ini' ? true : false),
            array('Minggu ini',  site_url('admin/transaksi/top-users/minggu-ini'), null, $waktu == 'minggu-ini' ? true : false),
            array('Bulan ini',  site_url('admin/transaksi/top-users/bulan-ini'), null, $waktu == 'bulan-ini' ? true : false),
            array('Semua waktu',  site_url('admin/transaksi/top-users/semua-waktu'), null, $waktu == 'semua-waktu' ? true : false),
          );
          echo sidebar_menu(array(array('title' => 'Periode','icon' => 'fa fa-calendar','links' => $links)));
          ?>
        </div>
        <div class="col-sm-8 col-md-9">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-user-circle-o"></i> Top Users</h3>
            </div>
            <div class="panel-body">
              <form method="get" action="<?php echo site_url('admin/transaksi/top-users');?>" class="hidden-print">
                <div class="row">
                  <div class="col-sm-6 col-md-2 col-lg-3" style="margin-bottom: 15px;">
                    <div class="input-group">
                      <span class="input-group-addon"  data-toggle="tooltip" data-title="Jenis Prroduk"><i class="fa fa-tags"></i></span>
                      <select class="form-control" name="produk">
                        <option value="" <?php echo $produk == '' ? 'selected="selected"' : '';?>>-- Semua --</option>
                        <?php foreach ($this->system->produk as $pr_key => $pr_val):?>
                        <option value="<?php echo $pr_key;?>"  <?php echo $produk == $pr_key ? 'selected="selected"' : '';?>><?php echo $pr_val->nama;?></option>
                        <?php endforeach;?>
                      </select>
                    </div>
                  </div>
                  <div class="col-sm-6 col-md-3 col-lg-3" style="margin-bottom: 15px;">
                    <div class="input-group">
                      <span class="input-group-addon" data-toggle="tooltip" data-title="Dari tanggal"><i class="fa fa-calendar-o"></i></span>
                      <input type="text" class="form-control" id="dari_tanggal" name="dari_tanggal" value="<?php echo html_escape($dari_tanggal);?>" placeholder="HH-BB-TTTT" autocomplete="off"/>
                    </div>
                  </div>
                  <div class="col-sm-6 col-md-3 col-lg-3" style="margin-bottom: 15px;">
                    <div class="input-group">
                      <span class="input-group-addon" data-toggle="tooltip" data-title="Ke tanggal"><i class="fa fa-calendar-o"></i></span>
                      <input type="text" class="form-control" id="ke_tanggal" name="ke_tanggal" value="<?php echo html_escape($ke_tanggal);?>" placeholder="HH-BB-TTTT" autocomplete="off"/>
                    </div>
                  </div>
                  <div class="col-sm-6 col-md-2 col-lg-2" style="margin-bottom: 15px;">
                    <div class="input-group">
                      <span class="input-group-addon" data-toggle="tooltip" data-title="Jumlah Rows"><i class="fa fa-list-alt"></i></span>
                      <select class="form-control" name="rows">
                        <option value="5" <?php echo $rows == 5 ? 'selected="selected"' : '';?>>5</option>
                        <option value="10" <?php echo $rows == 10 ? 'selected="selected"' : '';?>>10</option>
                        <option value="20" <?php echo $rows == 20 ? 'selected="selected"' : '';?>>20</option>
                        <option value="30" <?php echo $rows == 30 ? 'selected="selected"' : '';?>>30</option>
                        <option value="50" <?php echo $rows == 50 ? 'selected="selected"' : '';?>>50</option>
                      </select>
                    </div>
                  </div>
                  <div class="col-sm-offset-6 col-sm-6 col-md-offset-0 col-md-2 col-md-offset-0 col-lg-1" style="margin-bottom: 15px;">
                    <button type="submit" class="btn btn-primary btn-block"><i class="fa fa-search"></i></button>
                  </div>
                </div>
              </form>
              <?php if (!$results):?>
              <div class="alert alert-warning">Tidak ada data</div>
              <?php else:?>
              <h5 class="visible-print text-center" style="margin-bottom: 20px;">
                Transaksi terbanyak <?php echo $this->system->get_domain();?><?php echo ($produk ? ' pada produk '.$this->system->produk->$produk->nama : '').($dari_tanggal ? ' dari tanggal '.html_escape($dari_tanggal).' s/d '.html_escape($ke_tanggal) : '');?>
              </h5>
              <div class="table-responsive">
                <table class="table table-bordered" style="margin-bottom: 0;">
                  <thead>
                    <tr>
                      <th style="width: 100px;">Peringkat</th>
                      <th>User</th>
                      <th>Total Trx</th>
                      <th class="pembayaran">Total Pembayaran <a href="#" class="hide-pembayaran hidden-print"><i class="fa fa-eye-slash"></i></a></th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php $i = 1; foreach ($results as $res):?>
                    <tr>
                      <td style="width: 100px;"><?php echo $i;?></td>
                      <td>
                        <span class="hidden-print"><?php echo ($res->us_name ? '<a href="'.site_url('admin/users/profil/'.$res->us_id).'">'.html_escape($res->us_name).'</a>' : '');?></span>
                        <span class="visible-print"><?php echo html_escape($res->us_name);?></span>
                      </td>
                      <td><?php echo $res->total_trx;?></td>
                      <td class="pembayaran"><span data-toggle="tooltip" data-title="Tidak termasuk harga unik"><?php echo format_uang2($res->total_payment);?></span></td>
                    </tr>
                    <?php ++$i; endforeach;?>
                  </tbody>
                </table>
              </div>
              <div class="hidden-print" style="margin-top: 15px;">
                <a class="btn btn-default" href="#" onclick="window.print();return false;"><i class="fa fa-print"></i> Print</a>
              </div>
              <?php endif;?>
            </div>
          </div>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script src="<?php echo base_url('assets/js/bootstrap-datepicker.min.js?aca');?>"></script>
    <script src="<?php echo base_url('assets/js/locales/bootstrap-datepicker.id.min.js');?>"></script>
    <script type="text/javascript">
      <?php $tgl = explode(' ', format_tanggal(time()));?>
      $("#dari_tanggal").datepicker({format:"dd-mm-yyyy",endDate:"<?php echo str_replace('/', '-', $tgl[0]);?>",todayHighlight:true,autoclose:true,language:"id"});
      $("#ke_tanggal").datepicker({format:"dd-mm-yyyy",endDate:"<?php echo str_replace('/', '-', $tgl[0]);?>",todayHighlight:true,autoclose:true,language:"id"});
      $(".hide-pembayaran").click(function(){$(".pembayaran").hide();return false});
    </script>
  </body>
</html>