<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Admin Panel</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 class="active"><span>Admin Panel</span></li>
      </ul>
      <div class="row">
        <div class="col-sm-3">
          <div class="row">
            <div class="col-xs-12">
              <div class="alert alert-<?php echo ($this->system->set['smsg_aktif'] > (time() - 300) ? 'success' : 'warning');?>" data-toggle="tooltip" data-title="SMS Gateway terakhir terhubung">
                <strong><i class="fa fa-signal"></i> <?php echo format_tanggal($this->system->set['smsg_aktif']);?></strong>
              </div>
            </div>
          </div>
          <?php
          $params = array(
            array(
              'title' => 'Penanda',
              'icon' => 'fa fa-book',
              'links' => array(
                array('Produk', site_url('admin/produk')),
                array('Transaksi', site_url('admin/transaksi')),
                array('Member', site_url('admin/users'), null, false, '<span class="badge">'.$total_users.'</span>'),
                array('Riwayat Deposit', site_url('admin/riwayat-deposit'.($deposit_pending ? '/index/waiting-confirm' : '')), null, false, ($deposit_pending ? '<span class="badge badge-danger">'.$deposit_pending.'</span>' : '')),
                array('SMS', site_url('admin/sms')),
                array('Testimonial', site_url('admin/testimonial'), null, false, ($testimonial_pending ? ' <span class="badge badge-danger">' . $testimonial_pending . '</span>' : '')),
                array('Umpan Balik', site_url('admin/feedback'), null, false, ($feedback_unread ? ' <span class="badge badge-danger">' . $feedback_unread . '</span>' : '')),
                array('F.A.Q', site_url('admin/faq')),
                array('Sistem', site_url('admin/sistem'), null, false, '<span class="badge">v'.$this->system->get_version()->versi.'</span>'),
              ),
            ),
            array(
              'title' => 'Modul',
              'icon' => 'fa fa-cubes',
              'links' => array(),
            ),
            array(
              'title' => 'Pengaturan',
              'icon' => 'fa fa-cogs',
              'links' => array(
                array('Umum',  site_url('admin/pengaturan')),
                array('Server Pulsa', site_url('admin/pengaturan/server')),
                array('Payments', site_url('admin/payments')),
                array('Transaksi', site_url('admin/pengaturan/transaksi')),
                array('Deposit', site_url('admin/pengaturan/deposit')),
                array('Reseller', site_url('admin/pengaturan/reseller')),
                array('Perijinan &amp; Lainnya', site_url('admin/pengaturan/perijinan-lainnya')),
              ),
            ),
          );
          foreach ($adm_links->bookmarks as $link_key=>$link_val) {
            $params[0]['links'][] = array($link_val, site_url('admin/'.str_replace('_','-',$link_key)));
          }
          foreach ($adm_links->modules as $link_key=>$link_val) {
            $params[1]['links'][] = array($link_val, site_url('admin/modules/'.str_replace('_','-',$link_key)));
          }
          $fm = $this->config->item('file_manager');
          if ($fm['active'])
            $params[1]['links'][] = array('File Manager', site_url('admin/modules/file-manager'));
          
          echo sidebar_menu($params, true, 'ADMIN MENU');
          ?>
        </div>
        <div class="col-sm-9">
          <div style="">
            <div class="row">
              <div class="col-md-3 col-sm-6">
                <div class="panel panel-default">
                  <div class="panel-body" style="height: 85px;overflow: hidden;">
                    <div class="row">
                      <div class="col-xs-8">
                        <h3 class="text-left" style="color: #888;white-space: nowrap;"><?php echo $trx_sukses;?></h3>
                        <p style="color: #888;white-space: nowrap;">Transaksi Sukses</p>
                      </div>
                      <div class="col-xs-4" style="overflow: hidden;">
                        <div><i class="fa fa-pie-chart" style="color: rgba(0, 0, 0, 0.05);font-size: 60px;line-height: 65px;"></i>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="panel-footer">
                    <a class="details" href="<?php echo site_url('admin/transaksi?status_pembayaran=sukses&status_pengisian=sukses');?>"><span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>Details</a>
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-6">
                <div class="panel panel-default">
                  <div class="panel-body" style="height: 85px;overflow: hidden;">
                    <div class="row">
                      <div class="col-xs-8">
                        <h3 class="text-left" style="color: #888;white-space: nowrap;"><?php echo $total_users;?></h3>
                        <p style="color: #888;white-space: nowrap;">User Terdaftar</p>
                      </div>
                      <div class="col-xs-4" style="overflow: hidden;">
                        <div><i class="fa fa-group" style="color: rgba(0, 0, 0, 0.05);font-size: 60px;line-height: 65px;"></i></div>
                      </div>
                    </div>
                  </div>
                  <div class="panel-footer">
                    <a class="details" href="<?php echo site_url('admin/users');?>"><span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>Details</a>
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-6">
                <div class="panel panel-default">
                  <div class="panel-body" style="height: 85px;overflow: hidden;">
                    <div class="row">
                      <div class="col-xs-8">
                        <h3 class="text-left" style="color: #888;white-space: nowrap;"><?php echo format_uang2($total_saldo);?></h3>
                        <p style="color: #888;white-space: nowrap;">Saldo User</p>
                      </div>
                      <div class="col-xs-4" style="overflow: hidden;">
                        <div><i class="fa fa-credit-card" style="color: rgba(0, 0, 0, 0.05);font-size: 60px;line-height: 65px;"></i></div>
                      </div>
                    </div>
                  </div>
                  <div class="panel-footer">
                    <a class="details" href="<?php echo site_url('admin/users?filter=balance&data=0-');?>"><span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>Details</a>
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-6">
                <div class="panel panel-default">
                  <div class="panel-body" style="height: 85px;overflow: hidden;">
                    <div class="row">
                      <div class="col-xs-8">
                        <h3 class="text-left" style="color: #888;white-space: nowrap;"><?php echo ($pendapatan_kotor ? format_uang2($pendapatan_kotor) : '0');?></h3>
                        <p style="color: #888;white-space: nowrap;">Pendapatan Kotor</p>
                      </div>
                      <div class="col-xs-4" style="overflow: hidden;">
                        <div><i class="fa fa-money" style="color: rgba(0, 0, 0, 0.05);font-size: 60px;line-height: 65px;"></i>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="panel-footer">
                    <a class="details" href="<?php echo site_url('admin/rekap-trx');?>"><span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>Details</a>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-server"></i> Server Pulsa</h3>
            </div>
            <?php if (!$servers):?>
              <div class="alert alert-warning" style="margin: 15px;">Belum ada server.</div>
            <?php else:?>
              <div class="table-responsive">
                <table class="table table-bordered" style="margin-bottom: 0;">
                  <thead>
                    <tr>
                      <th>Nama Server</th>
                      <th>Saldo</th>
                      <th>SMS Center</th>
                      <th>Jabber Center</th>
                      <th>Jalur Transaksi</th>
                      <th>Voucher</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php foreach ($servers as $server):?>
                    <tr>
                      <td><a href="<?php echo site_url('admin/pengaturan/server/edit/'.$server->sv_id);?>"><?php echo $server->sv_nama;?></a></td>
                      <td><?php echo format_uang2($server->sv_saldo);?></td>
                      <td><?php echo $server->sv_sms_center;?></td>
                      <td><?php echo html_escape($server->sv_jabber_center);?></td>
                      <td><?php echo $this->server_model->gateway_label($server->sv_gateway);?></td>
                      <td><?php echo $this->server_model->count_vouchers($server->sv_id);?></td>
                    </tr>
                    <?php endforeach;?>
                  </tbody>
                </table>
              </div>
            <?php endif;?>
            <div class="panel-footer text-center">
              <a id="l_servers" class="btn btn-default btn-sm" href="<?php echo site_url('admin/pengaturan/server');?>">Kelola Server &raquo;</a>
            </div>
          </div>
          <div class="panel panel-default" id="produk">  
            <div class="panel-heading">
              <h3><i class="fa fa-book"></i> Produk</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-bordered" style="margin-bottom: 0;">
                <thead>
                  <tr>
                    <th>Nama Produk</th>
                    <th>Provider</th>
                    <th>Voucher</th>
                    <th>Trx Sukses</th>
                    <th>Pendapatan Kotor</th>
                    <th class="text-center" style="width: 120px;">Status</th>
                  </tr>
                </thead>
                <tbody>
                  <?php foreach ($this->system->produk as $pr_key => $pr_data): $produk_total = $this->produk_model->count($pr_key); ?>
                  <tr>
                    <td><a href="<?php echo site_url('admin/produk/browse/'.$pr_key);?>"><?php echo $pr_data->nama;?></a></td>
                    <td><?php echo $produk_total['providers'];?></td>
                    <td><?php echo $produk_total['vouchers'];?></td>
                    <td><?php echo $produk_total['trx'];?></td>
                    <td><?php echo format_uang($produk_total['gross_income']);?></td>
                    <td class="text-center" style="width: 120px;"><?php echo ($pr_data->status == 'on' ? '<span class="badge badge-success">Aktif</span>' : '<span class="badge">Tidak aktif</span>');?></td>
                    <?php endforeach;?>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="panel-footer text-center">
              <a id="l_produk" class="btn btn-default btn-sm" href="<?php echo site_url('admin/produk');?>">Kelola Produk &raquo;</a>
            </div>
          </div>
          <div class="panel panel-default" id="payments">  
            <div class="panel-heading">
              <h3><i class="fa fa-credit-card"></i> Payments</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-bordered" style="margin-bottom: 0;">
                <thead>
                  <tr>
                    <th>Nama</th>
                    <th>Saldo</th>
                    <th>Total Mutasi</th>
                    <th>Pembayaran Diterima</th>
                    <th class="text-center" style="width: 120px;">Status</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                    foreach ($this->payment->get() as $payment) {
                        if ($payment->key == 'balance')
                          continue;
                  ?>
                  <tr>
                    <td><a id="payment_<?php echo $payment->key;?>" href="<?php echo site_url('admin/payments/' . $payment->key);?>"><?php echo $payment->nama;?></a></td>
                    <td><?php echo !$payment->rate ? format_uang2($payment->saldo) : '$ '.$payment->saldo.' USD';?></td>
                    <td><a href="<?php echo site_url('admin/payments/'.$payment->key.'/mutasi');?>"><?php echo $this->db->query("SELECT COUNT(*) AS total FROM mutasi WHERE bank = '$payment->key'")->row()->total;?></a></td>
                    <td><?php echo format_uang2($this->db->query("SELECT SUM(tr_harga2) AS harga FROM transaksi WHERE tr_pembayaran = '$payment->key' AND tr_status_pembayaran = 'sukses'")->row()->harga); ?></td>
                    <td class="text-center" style="width: 120px;"><?php echo $payment->status == 'on' ? '<span class="badge badge-success">Aktif</span>' : '<span class="badge">Tidak aktif</span>';?></td>
                  </tr>
                  <?php } ;?>
                </tbody>
              </table>
            </div>
            <div class="panel-footer text-center">
              <a id="l_payments" class="btn btn-default btn-sm" href="<?php echo site_url('admin/payments');?>">Kelola Payments &raquo;</a>
            </div>
          </div>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
  </body>
</html>