<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Akun <?php echo html_escape($server->sv_nama);?> | <?php echo $javah2h ? 'Java H2H' : 'Portal Pulsa';?></title>
    <?php include_once(VIEWPATH.'includes/head.php'); ?>
  </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/modules/portalpulsa');?>"><?php echo $javah2h ? 'Java H2H' : 'Portal Pulsa';?></a></li>
        <li class="active"><span><?php echo html_escape($server->sv_nama);?></span></li>
      </ul>
      <div class="row">
        <div class="col-sm-8">
          <div class="row">
            <div class="col-xs-6 col-sm-4 col-lg-3">
              <a class="btn btn-default btn-block" href="<?php echo site_url('admin/modules/portalpulsa/produk/'.$server->sv_id);?>" style="margin-bottom: 15px;"><i class="fa fa-tags"></i> Produk</a>
            </div>
            <div class="col-xs-6 col-sm-offset-4 col-sm-4 col-lg-offset-6 col-lg-3">
              <a <?php echo !$total_vouchers ? 'class="btn btn-default btn-block disabled"' : 'class="btn btn-default btn-block" id="btn-sinkronisasi"';?> href="<?php echo site_url('admin/modules/portalpulsa/sinkronisasi/'.$server->sv_id);?>" title="Perbarui harga dan status produk yang sudah tersimpan di database" style="margin-bottom: 15px;"><i class="fa fa-refresh"></i> Sinkronkan</a>
            </div>
          </div>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-user"></i> Info Akun</h3>
            </div>
            <div class="list-group">
              <div class="list-group-item">
                <h6 class="list-group-item-heading" style="font-weight: bold;">API Server</h6>
                <p class="list-group-item-text"><?php echo $data['server'] == 'javah2h' ? 'Java H2H' : 'Portal Pulsa';?></p>
              </div>
              <div class="list-group-item">
                <h6 class="list-group-item-heading" style="font-weight: bold;">User ID</h6>
                <p class="list-group-item-text"><?php echo $data['userid'];?></p>
              </div>
              <div class="list-group-item">
                <h6 class="list-group-item-heading" style="font-weight: bold;">Saldo</h6>
                <p class="list-group-item-text"><span id="saldo"><i class="fa fa-refresh fa-spin"></i></span></p>
              </div>
              <div class="list-group-item">
                <h6 class="list-group-item-heading" style="font-weight: bold;">Key</h6>
                <p class="list-group-item-text"><?php echo $data['key'];?></p>
              </div>
              <div class="list-group-item">
                <h6 class="list-group-item-heading" style="font-weight: bold;">Secret</h6>
                <p class="list-group-item-text"><?php echo $data['secret'];?></p>
              </div>
              <div class="list-group-item">
                <h6 class="list-group-item-heading" style="font-weight: bold;">Callback URL</h6>
                <p class="list-group-item-text"><?php echo site_url('api/portalpulsa-callback/index/'.$data['callback']);?></p>
              </div>
              <div class="list-group-item">
                <h6 class="list-group-item-heading" style="font-weight: bold;">Jumlah Voucher</h6>
                <p class="list-group-item-text"><?php echo @$total_vouchers;?></p>
              </div>
            </div>
          </div>
        </div>
        <div class="col-sm-4">
          <div class="panel panel-default" id="deposit" style="max-height: 468px;overflow: hidden;">
            <div class="panel-heading">
              <h3><a class="pull-right btn-deposit" href="#" data-toggle="tooltip" title="Kirim tiket deposit"><i class="fa fa-plus"></i></a><i class="fa fa-money"></i> Deposit</h3>
            </div>
            <div class="panel-body form-deposit" style="display: none;">
              <?php echo form_open('admin/modules/portalpulsa/deposit/'.$server->sv_id,'id="depositForm"');?>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon">Rp</span>
                    <input type="text" class="form-control" name="jumlah" value="" placeholder="100000" required="required" />
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-bank"></i></span>
                    <select class="form-control" name="bank" required="required">
                      <option value="">-- Pilih Bank --</option>
                      <option value="bca">BCA</option>
                      <option value="bni">BNI</option>
                      <option value="bri">BRI</option>
                      <option value="mandiri">Mandiri</option>
                      <option value="muamalat">Muamalat</option>
                    </select>
                  </div>
                </div>
                <div><button type="submit" class="btn btn-primary btn-block">Kirim tiket deposit</button></div>
              <?php echo form_close();?>
            </div>
             <div class="list-group" style="max-height: 426px;overflow-x: hidden; overflow-y: scroll;" id="lists">
              <?php if ($riwayat_deposit):?>
              <?php for ($i = 0; $i < count($riwayat_deposit); $i++):?>
              <div class="list-group-item" id="riwayat-<?php echo $i;?>">
                <h6 class="list-group-item-heading" style="font-weight: bold;"><a data-toggle="tooltip" data-placement="left" title="Hapus riwayat" class="pull-right hapus-riwayat text-danger" href="<?php echo site_url('admin/modules/portalpulsa/deposit/'.$server->sv_id.'/hapus/'.$i);?>" data-id="<?php echo $i;?>" class="hapus-riwayat"><i class="fa fa-times"></i></a><?php echo $riwayat_deposit[$i]['tanggal'];?></h6>
                <p class="list-group-item-text"><?php echo html_escape($riwayat_deposit[$i]['info']);?></p>
              </div>
              <?php endfor;?>
              <?php else:?>
              <div class="list-group-item list-group-item-warning"><p class="list-group-item-text">Belum ada riwayat deposit yang tersimpan</p></div>
              <?php endif;?>
            </div>
          </div>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script type="text/javascript">
    $("#btn-sinkronisasi").click(function(){var btn=$(this);btn.attr("disabled","disabled").html('<i class="fa fa-refresh fa-spin"></i> Menyinkronkan');$.get($(this).attr('href'),function(data){if(data.updated>0){$.notify(data.updated+" produk berhasil diperbarui.","success");}else{$.notify("Tidak ada produk yang diperbarui","info");}}).fail(function(){$.notify("Terjadi kesalahan ketika menyinkronkan produk.","error");}).done(function(data){btn.removeAttr("disabled").html('<i class="fa fa-refresh"></i> Sinkronisasi');$.notify("Sinkronisasi selesai","success");});return false;});
    $(document).ready(function(){var saldo=sessionStorage.getItem('saldo');if(saldo!=null){$("#saldo").text(saldo);}else{$.get("<?php echo site_url('admin/modules/portalpulsa/akun/'.$server->sv_id.'/saldo');?>",function(data){if(data.result=='success'){$("#saldo").text(data.balance);sessionStorage.setItem('saldo',data.balance);}else{$("#saldo").text(data.message);}});}});
    $(".btn-deposit").click(function(){$('.form-deposit').slideToggle();return false;});
    $(document).on("submit","#depositForm",function(){var btn=$("#depositForm button.btn");btn.addClass('disabled');btn.html('<i class="fa fa-refresh fa-spin"></i> Memproses');$.ajax({type:"POST",url:$(this).attr('action'),data:$(this).serialize(),success:function(data){btn.removeClass('disabled');btn.html('Kirim tiket deposit');if(typeof data==='object'){$('[name="<?php echo $this->security->get_csrf_token_name();?>"]').val(data.token);if(data.result=='success'){$('[name="jumlah"]').val('');var lists='';var i;for(i=0;i<data.riwayat.length;i++){lists+='<div class="list-group-item '+(i == 0 ? 'list-group-item-success' : '')+'" id="riwayat-'+i+'"><h6 class="list-group-item-heading" style="font-weight: bold;">'+(i != 0 ? '<a data-toggle="tooltip" data-placement="left" title="Hapus riwayat" class="pull-right hapus-riwayat text-danger" href="<?php echo site_url('admin/modules/portalpulsa/deposit/'.$server->sv_id.'/hapus');?>/'+i+'" data-id="'+i+'" class="hapus-riwayat"><i class="fa fa-times"></i></a>' : '')+data.riwayat[i].tanggal+'</h6><p class="list-group-item-text">'+data.riwayat[i].info+'</p></div>';}var mlists=$("#lists");mlists.html(lists);mlists.show();$('#riwayat-0').notify("Terkirim",{position:"top",className:"success"});}else{$.notify(data.message,"error");}}else{btn.removeClass('disabled');btn.html('Kirim tiket deposit');$.notify("Terjadi kesalahan ketika memproses permintaan,","error");}},error:function(){btn.removeClass('disabled');btn.html('Kirim tiket deposit');$.notify("Terjadi kesalahan ketika memproses permintaan,","error");}});return false;});
    $(document).on("click",".hapus-riwayat",function(){var id=$(this).data('id');var list=$("#riwayat-"+id);list.hide('fast');$.get($(this).attr('href'),function(data){list.remove();$.notify("Riwayat dihapus","success");}).fail(function(){list.show("fast");$.notify("Riwayat gagal dihapus","error");});return false;});
    </script>
  </body>
</html>