<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Admin &gt; Riwayat Deposit</title>
    <?php include_once(VIEWPATH.'includes/head.php'); ?>
    <link id="bsdp-css" href="<?php echo base_url('assets/css/bootstrap-datepicker3.css');?>" rel="stylesheet"/>
    <style type="text/css">nav{float: right;margin-bottom: 15px;}</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 class="active"><span>Riwayat Deposit</span></li>
      </ul>
      <div class="row">
        <div class="col-sm-4 col-md-3">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><a class="pull-right" style="color: inherit;" href="#"><i class="fa fa-chevron-up"></i></a> <i class="fa fa-filter"></i> Filter</h3>
            </div>
            <div class="panel-body c">
              <form method="GET" action="<?php echo site_url('admin/riwayat-deposit');?>">
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon" data-toggle="tooltip" title="Username"><span style="width: 13px; display: block;"><i class="fa fa-user-o"></i></span></span>
                    <input type="text" class="form-control" name="username" value="<?php echo $username != 'all' ? html_escape($username) : '';?>" placeholder="Username" maxlength="16">
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon" data-toggle="tooltip" title="Dari tanggal"><i class="fa fa-calendar"></i></span>
                    <input type="text" class="form-control" name="from_date" id="from_date" value="<?php echo html_escape($from_date);?>" placeholder="HH-BB-TTTT" maxlength="10" autocomplete="off">
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon" data-toggle="tooltip" title="Ke tanggal"><i class="fa fa-calendar"></i></span>
                    <input type="text" class="form-control" name="to_date" id="to_date" value="<?php echo html_escape($to_date);?>" placeholder="HH-BB-TTTT" maxlength="10" autocomplete="off">
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon" data-toggle="tooltip" title="Pembayaran"><span style="width: 13px; display: block;"><i class="fa fa-credit-card"></i></span></span>
                    <select class="form-control" name="pembayaran">
                      <option value="all" <?php echo $pembayaran == 'all' ? 'selected="selected"' : '';?>>-- Semua --</option>
                      <?php foreach ($this->payment->get() as $payment): if ($payment->key == 'balance') continue; ?>
                      <option value="<?php echo $payment->key;?>" <?php echo $pembayaran == $payment->key ? 'selected="selected"' : '';?>><?php echo html_escape($payment->nama);?></option>
                      <?php endforeach;?>
                    </select>
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon" data-toggle="tooltip" title="Status"><span style="width: 13px; display: block;"><i class="fa fa-check-circle"></i></span></span>
                    <select class="form-control" name="status">
                      <option value="all" <?php echo $status == 'all' ? 'selected="selected"' : '';?>>-- Semua --</option>
                      <option value="pending" <?php echo $status == 'pending' ? 'selected="selected"' : '';?>>Menunggu Pembayaran</option>
                      <option value="waiting-confirm" <?php echo $status == 'waiting-confirm' ? 'selected="selected"' : '';?>>Menunggu Konfirmasi</option>
                      <option value="sukses" <?php echo $status == 'sukses' ? 'selected="selected"' : '';?>>Sukses</option>
                      <option value="expires" <?php echo $status == 'expires' ? 'selected="selected"' : '';?>>Tidak Berlaku</option>
                      <option value="refund" <?php echo $status == 'refund' ? 'selected="selected"' : '';?>>Refund</option>
                    </select>
                  </div>
                </div>
                <div>
                  <button type="submit" class="btn btn-primary btn-block">Tampilkan</button>
                </div>
              </form>
            </div>
          </div>
        </div>
        <div class="col-sm-8 col-md-9">
          <?php if (!$total):?>
          <div class="alert alert-warning">Tidak ada riwayat deposit.</div>
          <?php else:?>
          <?php echo form_open('admin/riwayat-deposit/hapus','id="form-confirm"');?>
          <div class="panel panel-default" id="history">
            <div class="panel-heading" style="white-space: nowrap; overflow: hidden;">
              <h3><i class="fa fa-credit-card"></i> Riwayat Deposit</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-hover">
                <thead>
                  <tr>
                    <th class="text-center" style="width: 40px;"><input type="checkbox" id="select-all"/></th>
                    <th>ID</th>
                    <th>User</th>
                    <th>Tanggal</th>
                    <th>Jumlah</th>
                    <th>Pembayaran</th>
                    <th>Status</th>
                  </tr>
                </thead>
                <tbody>
                  <?php foreach ($results as $res):?>
                  <tr id="deposit-<?php echo $res->de_id;?>">
                    <td class="text-center" style="vertical-align: middle;"><input type="checkbox" class="checkbox1" name="deposit[]" value="<?php echo $res->de_id;?>"/></td>
                    <td><a href="<?php echo site_url('admin/riwayat-deposit/view/'.$res->de_id);?>"><?php echo $res->de_id;?></a></td>
                    <td><a href="<?php echo site_url('admin/users/profil/'.$res->us_id);?>"><?php echo ($res->us_verified ? '<span class="text-success"><i class="fa fa-check-circle"></i></span> ' : '') . html_escape($res->us_name);?></a></td>
                    <td><?php echo format_tanggal($res->de_tanggal);?></td>
                    <td><?php echo format_uang2($res->de_amount, $res->de_rate, $this->payment->{$res->de_payment}->template, $this->payment->{$res->de_payment}->round);?></td>
                    <td><?php echo html_escape($this->payment->{$res->de_payment}->nama);?></td>
                    <td><?php echo deposit_status_label($res, $exp_time, false);?></td>
                  </tr>
                  <?php endforeach;?>
                </tbody>
              </table>
            </div>
          </div>
          <div class="row" style="margin-bottom: 5px;">
            <div class="col-xs-12 col-sm-4 col-md-3">
              <button class="btn btn-danger btn-block btn-sm" style="margin-bottom: 15px;" type="submit" name="delete" value="1"><i class="fa fa-trash"></i> Hapus yang ditandai</button>
            </div>
            <div class="col-xs-12 col-sm-8 col-md-9">
              <?php echo preg_replace('/\/([0-9]+)#history/','/$1?from_date='.urlencode($from_date).'&amp;to_date='.urlencode($to_date).'&amp;pembayaran='.$pembayaran.'&amp;status='.$status.'#history', pagination(site_url('admin/riwayat-deposit/index/'.$username),$start,$total,$this->system->set['list_per_page'],'/%d#history'));?>
            </div>
          </div>
          <?php echo form_close();?>
          <?php endif;?>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script src="<?php echo base_url('assets/js/bootstrap-datepicker.min.js');?>"></script>
    <script src="<?php echo base_url('assets/js/locales/bootstrap-datepicker.id.min.js');?>" charset="UTF-8"></script>
    <script type="text/javascript">
      $(".panel > .panel-heading > h3 > a").click(function () {
        var panelBody = $(this).parents(".panel").find(".c");
        if (panelBody.hasClass('hidden')) {
          panelBody.removeClass('hidden');
          $(this).html('<i class="fa fa-chevron-up"></i>');
        } else {
          panelBody.addClass('hidden');
          $(this).html('<i class="fa fa-chevron-down"></i>');
        }
        return false;
      });
      $('#select-all').click(function(event) {
        if (this.checked) {
          $('.checkbox1').each(function(){ this.checked = true; });
        } else {
          $('.checkbox1').each(function(){ this.checked = false; });
        }
      });
      $(document).on("submit","#form-confirm", function() {
      var formData = $(this).serialize();
      if (formData.indexOf('deposit') > 0){
        $("#myModal").modal("show");
        $.ajax({
          type: "POST",
          url: $(this).attr("action"),
          data: formData,
          success: function (data) {
            var csrf = $(data).find('[name="<?php echo $this->security->get_csrf_token_name();?>"]').val();
            $('#form-confirm [name="<?php echo $this->security->get_csrf_token_name();?>"]').val(csrf);
            $("#myModal .modal-content").html(data);
          },
          error: function() {
            alert("Terjadi kesalahan!");
          }
        });
      }
      return false;
    });
    <?php $tgl = explode(' ', format_tanggal(time()));?>
      $("#from_date").datepicker({format:"dd-mm-yyyy",endDate:"<?php echo str_replace('/', '-', $tgl[0]);?>",todayHighlight:true,autoclose:true,language:"id"});
      $("#to_date").datepicker({format:"dd-mm-yyyy",endDate:"<?php echo str_replace('/', '-', $tgl[0]);?>",todayHighlight:true,autoclose:true,language:"id"});
    </script>
  </body>
</html>