<?php
defined('BASEPATH') or exit('No direct script access allowed');
$payment_key = strtolower($this->router->fetch_class());
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Mutasi <?php echo $this->payment->{$payment_key}->nama;?></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><a href="<?php echo site_url('admin/payments');?>">Metode Pembayaran</a></li>
        <li><a href="<?php echo site_url('admin/payments/'.$payment_key);?>"><?php echo html_escape($this->payment->{$payment_key}->nama);?></a></li>
        <li class="active"><span>Mutasi</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/payments/'.$payment_key.'/mutasi');?>">
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon"><span style="width: 13px; display: block;"><i class="fa fa-calendar"></i></span></span>
                    <input type="text"  data-toggle="tooltip" data-placement="left" title="Tanggal" class="form-control" name="tanggal" value="<?php echo html_escape($tanggal);?>" placeholder="<?php echo date('Y/m/d', time() + (3600 * $this->system->get_set('zona_waktu')));?>" maxlength="10" />
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon"><span style="width: 13px; display: block;"><i class="fa fa-sticky-note-o"></i></span></span>
                    <input type="text" data-toggle="tooltip" data-placement="left" title="Keterangan" class="form-control" name="keterangan" value="<?php echo html_escape($keterangan);?>" placeholder="Keterangan" minlength="3" maxlength="32" />
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon"><span style="width: 13px; display: block;"><i class="fa fa-money"></i></span></span>
                    <input type="number" data-toggle="tooltip" data-placement="left" title="Jumlah" class="form-control" name="jumlah" value="<?php echo $jumlah;?>" placeholder="0" min="1" max="9999999999"/>
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon"><span style="width: 13px; display: block;"><i class="fa fa-exchange"></i></span></span>
                    <select class="form-control" name="type" data-toggle="tooltip" data-placement="left" title="Jenis">
                      <option value="" <?php echo $type == '' ? 'selected="selected"' : '';?>>Semua</option>
                      <option value="debet" <?php echo $type == 'debet' ? 'selected="selected"' : '';?>>Debet</option>
                      <option value="kredit" <?php echo $type == 'kredit' ? 'selected="selected"' : '';?>>Kredit</option>
                    </select>
                  </div>
                </div>
                <div>
                  <button type="submit" class="btn btn-primary btn-block">Tampilkan</button>
                </div>
              </form>
            </div>
          </div>
          <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-credit-card"></i> Total Mutasi</h3></div>
            <ul class="list-group c">
              <li class="list-group-item"><strong>Kredit</strong> <span class="badge"><?php echo format_uang2($total_kredit);?></span></li>
              <li class="list-group-item"><strong>Debet</strong> <span class="badge"><?php echo format_uang2($total_debet);?></span></li>
            </ul>
          </div>
        </div>
        <div class="col-sm-8 col-md-9">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-history"></i> Mutasi</h3>
            </div>
              <?php if (!$total): ?>
              <div class="alert alert-warning" style="margin: 15px;">
                Tidak ada riwayat mutasi.
              </div>
              <?php else: ?>
              <div class="table-responsive">
                <table class="table table-hover">
                  <thead>
                    <tr>
                      <th style="width: 100px;">Tanggal</th>
                      <th>Keterangan</th>
                      <th style="width: 100px;">Debet</th>
                      <th style="width: 100px;">Kredit</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php foreach ($results as $history):?>
                    <tr>
                      <?php if ($history->trx_id):?>
                      <td><a href="<?php echo site_url('admin/transaksi/view/'.$history->trx_id);?>"><?php echo html_escape($history->tgl);?></a></td>
                      <?php elseif ($history->dep_id):?>
                      <td><a href="<?php echo site_url('admin/riwayat-deposit/view/'.$history->dep_id);?>"><?php echo html_escape($history->tgl);?></a></td>
                      <?php else:?>
                      <td><?php echo html_escape($history->tgl);?></td>
                      <?php endif;?>
                      <td><?php echo ($keterangan ? preg_replace("#".str_replace("#","",$keterangan)."#i",'<span style="color:red;font-weight:bold">${0}</span>', html_escape($history->keterangan)) : html_escape($history->keterangan));?></td>
                      <td><?php echo format_uang($history->debet);?></td>
                      <td><?php echo format_uang($history->kredit);?></td>
                    </tr>
                    <?php endforeach;?>
                  </tbody>
                </table>
              </div>
              <?php endif; ?>
          </div>
          <?php echo preg_replace('/mutasi\/([0-9]+)/','mutasi/$1?tanggal='.urlencode($tanggal).'&amp;keterangan='.urlencode($keterangan).'&amp;jumlah='.$jumlah.'&amp;type='.$type,pagination(site_url('admin/payments/'.$payment_key.'/mutasi'),$start,$total,$this->system->set['list_per_page'],'/%d'));?>
        </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">
      <?php if ($this->payment->{$payment_key}->status == 'on'):?>
      $(document).on("submit",'form[action="<?php echo site_url('payment/'.$payment_key.'/deposit/0');?>"]', function(){
        document.getElementById("cekMutasi").innerHTML = '<i class="fa fa-spin fa-refresh"></i> Cek Mutasi</a>';
        $('button[data-dismiss="modal"]').trigger('click');
        $.post('<?php echo site_url('payment/'.$payment_key.'/deposit/0?format=json');?>', $(this).serialize()).done(function() {
          location.href = '<?php echo site_url('admin/payments/'.$payment_key.'/mutasi');?>';
        });
        return false;
      })
      $(".col-sm-4.col-md-3").prepend('<div style="margin-bottom: 20px;"><a class="btn btn-primary btn-block" href="<?php echo site_url('payment/'.$payment_key.'/deposit/0');?>" data-toggle="modal" data-target="#myModal" id="cekMutasi"><i class="fa fa-refresh"></i> Cek Mutasi</a></div>');
      <?php endif;?>
      $(".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;
      });
      $('input[name="tanggal"]').datepicker({format:"yyyy/mm/dd",endDate:"<?php echo str_replace('/', '-', date('Y/m/d'));?>",todayHighlight:true,autoclose:true,language:"id"});
    </script>
  </body>
</html>