<?php
defined('BASEPATH') or exit('No direct script access allowed');
$opsi_continues = array('sn','shipping','shipping_last_check','original_amount','weight','quantity');
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Transaksi #<?php echo $trx->tr_id;?></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/transaksi');?>">Transaksi</a></li>
        <li class="active"><span>Detail</span></li>
      </ul>
      <div class="row">
        <div class="col-sm-6 col-md-8">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-list-alt"></i> Transaksi #<?php echo $trx->tr_id;?></h3>
            </div>
            <?php
            if (file_exists(dirname(__FILE__).'/'.$trx->op_produk.'.php'))
              include (dirname(__FILE__).'/'.$trx->op_produk.'.php');
            else
              include (dirname(__FILE__).'/undefined.php');
            ?>
            <div class="panel-footer hidden-print">
              <a class="btn btn-danger pull-right" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/transaksi/hapus/' . $trx->tr_id);?>"><i class="fa fa-remove"></i> Hapus</a>
              <a class="btn btn-default" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/transaksi/edit/' . $trx->tr_id);?>"><i class="fa fa-edit"></i> Edit</a>
            </div>
          </div>
        </div>
        <div class="col-sm-6 col-md-4 hidden-print">
          <?php if ($trx->us_username):?>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-user"></i> User</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-hover" style="margin-bottom: 0;">
                <tbody>
                  <tr><td>Nama Lengkap</td><td><a href="<?php echo site_url('admin/users/profil/'.$trx->us_id);?>"><?php echo ($trx->us_verified ? '<span class="text-success"><i class="fa fa-check-circle"></i></span> ' : '') . html_escape($trx->us_name);?></a></td></tr>
                  <tr><td>Saldo</td><td><?php echo format_uang2($trx->us_balance, 0);?></td></tr>
                  <tr><td>Total Transaksi</td><td><?php echo $trx->us_total_order;?> sukses</td></tr>
                  <tr><td>Masuk Terakhir</td><td><?php echo format_tanggal($trx->us_lastdate);?></td></tr>
                </tbody>
              </table>
            </div>
          </div>
          <?php endif;?>
          <?php if ($opsi):?>
          <?php if (isset($opsi['shipping'])):?>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-truck"></i> Pengiriman</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-hover">
                <tbody>
                  <tr><td>Dikirim Dari</td><td><?php echo html_escape($opsi['shipping']['from']['city'].' - '.$opsi['shipping']['from']['province']);?></td></tr>
                  <tr><td>Harga Barang</td><td><?php echo @$opsi['quantity'];?> x <?php echo format_uang2($opsi['original_amount']);?></td></tr>
                  <tr><td>Berat Barang</td><td><?php echo @$opsi['weight'];?></td></tr>
                  <tr><td>Jasa Pengiriman</td><td><?php echo html_escape($opsi['shipping']['courier']['name']);?></td></tr>
                  <tr><td>Biaya Kirim</td><td><?php echo format_uang2($opsi['shipping']['courier']['cost']);?></td></tr>
                  <tr><td>Nomor Resi</td><td><?php echo html_escape($opsi['shipping']['awb_number']);?></td></tr>
                  <tr><td>Status Pengiriman</td><td><?php if ($opsi['shipping']['delivery_status'] == 'belum_dikirim'):?><?php echo ucwords(str_replace("_", " ", @$opsi['shipping']['delivery_status']));?><?php else:?><a data-toggle="modal" data-target="#myModal" href="<?php echo site_url('status-pengiriman/trx/'.$trx->tr_id.'/'.@$opsi['shipping']['awb_number']);?>"><?php echo ucwords(str_replace("_", " ", @$opsi['shipping']['delivery_status']));?> <i class="fa fa-external-link"></i></a><?php endif;?></td></tr>
                </tbody>
              </table>
            </div>
          </div>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-user"></i> Penerima</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-hover">
                <tbody>
                  <tr><td>Nama</td><td><?php echo html_escape($opsi['shipping']['to']['name']);?></td></tr>
                  <tr><td>No. Telepon</td><td><?php echo html_escape($opsi['shipping']['to']['phone']);?></td></tr>
                  <tr><td>Provinsi</td><td><?php echo html_escape($opsi['shipping']['to']['province']);?></td></tr>
                  <tr><td>Kota</td><td><?php echo html_escape($opsi['shipping']['to']['city']);?></td></tr>
                  <tr><td>Kode POS</td><td><?php echo html_escape($opsi['shipping']['to']['postal_code']);?></td></tr>
                  <tr><td>Alamat</td><td><?php echo html_escape($opsi['shipping']['to']['address']);?></td></tr>
                </tbody>
              </table>
            </div>
          </div>
          <?php endif;?>
          <?php endif;?>
          <?php if ($trx->tr_pembayaran =='balance'):?>
          <div class="alert alert-success">
            <h3>Sukses</h3>Pembayaran sudah diselesaikan dengan menggunakan saldo akun.
          </div>
          <?php else:?>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-money"></i> Bayar dengan <?php echo $this->payment->{$trx->tr_pembayaran}->nama;?></h3>
            </div>
            <?php if ($trx->tr_status_pembayaran == 'pending' && $trx->tr_tanggal < $exp_time):?>
              <div class="alert alert-danger" style="margin: 15px;">
                <h3>Tidak Berlaku</h3>Pembayaran belum diselesaikan dan pesanan sudah tidak berlaku lagi.
              </div>
            <?php elseif ($trx->tr_status_pembayaran == 'pending'):?>
              <div class="alert alert-info" style="margin: 15px;">
                <h3>Menunggu Pembayaran</h3>Pembayaran belum diselesaikan dan masih berlaku sampai <?php echo format_tanggal($trx->tr_tanggal + (3600 * $this->system->set['jam_pembayaran']));?>.
              </div>
            <?php elseif ($trx->tr_status_pembayaran == 'refund'):?>
              <div class="alert alert-danger" style="margin: 15px;">
                <h3>Refund</h3>Pembayaran dikembalikan.
              </div>
            <?php elseif ($trx->tr_status_pembayaran == 'sukses' && $trx->tr_status == 'manual'):?>
              <div class="alert alert-warning" style="margin: 15px;">
                <h3>Dalam Proses</h3>Pembayaran sudah diselesaikan dan sedang menunggu konfirmasi Administartor.
              </div>
            <?php else:?>
              <div class="alert alert-success" style="margin: 15px;">
                <h3>Lunas</h3>Pembayaran berhasil diselesaikan. <a class="alert-link" href="<?php echo site_url('admin/payments/'.$trx->tr_pembayaran.'/mutasi');?>">Lihat mutasi &raquo;</a>
              </div>
              <?php endif;?>
              <?php if ($trx->keterangan): ?>
              <div class="table-responsive">
                <table class="table table-hover">
                  <tbody>
                    <tr><td>Tanggal</td><td><?php echo format_tanggal($trx->tanggal);?></td></tr>
                    <tr><td>Keterangan</td><td><?php echo nl2br(html_escape($trx->keterangan));?></td></tr>
                    <tr><td>Kredit</td><td><?php echo $trx->kredit;?></td></tr>
                  </tbody>
                </table>
              </div>
              <?php endif;?>
              <?php if ($trx->tr_status_pembayaran == 'sukses' && $trx->tr_status == 'manual'):?>
              <div class="row" id="confirm">
                <div class="col-sm-6">
                  <a class="btn btn-primary btn-block" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/payments/'.$trx->tr_pembayaran.'/confirm_trx/'.$trx->tr_id);?>"><i class="fa fa-check"></i> Confirm</a>
                </div>
                <div class="col-sm-6">
                  <a class="btn btn-danger btn-block" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/payments/'.$trx->tr_pembayaran.'/reject_trx/'.$trx->tr_id);?>"><i class="fa fa-remove"></i> Reject</a>
                </div>
              </div>
            <?php endif;?>
          </div>
          <?php endif;?>
          <?php if ($opsi):?>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-info-circle"></i> Opsi Transaksi</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-hover">
                <tbody>
                  <?php foreach ($opsi as $info_key=>$info_val): if(in_array($info_key, $opsi_continues)) continue;?>
                  <tr><td><?php echo html_escape($info_key);?></td><td><?php echo html_escape(is_array($info_val) ? json_encode($info_val) : $info_val);?></td></tr>
                  <?php endforeach;?>
                </tbody>
              </table>
            </div>
          </div>
          <?php endif;?>
          <?php if ($trx->in_trx_id):?>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-envelope"></i> Balasan Server</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-hover" style="margin-bottom: 0;">
                <tbody>
                  <tr><td>Pengirim</td><td><a data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/sms/kirim?phone=' . $trx->in_from);?>"><?php echo html_escape($trx->in_from);?></a></td></tr>
                  <tr><td>Pesan</td><td><?php echo nl2br(html_escape($trx->in_message));?></td></tr>
                  <tr><td>Tanggal</td><td><?php echo format_tanggal($trx->in_timestamp);?></td></tr>
                </tbody>
              </table>
            </div>
          </div>
          <?php endif;?>
          <?php if ($testimonial = $this->trx_model->get_testimonial($trx->tr_id)): ?>
          <div class="panel panel-default" id="testimonial">
            <div class="panel-heading">
              <h3><i class="fa fa-comments-o"></i> Testimonial</h3>
            </div>
            <div class="panel-body">
              <div>
                <span class="text-muted pull-right"><small><i class="fa fa-clock-o"></i> <?php echo format_tanggal($testimonial->tanggal);?></small></span>
                <a href="<?php echo site_url('admin/users/profil/'.$testimonial->us_id);?>"><strong><i class="fa fa-user"></i> <?php echo html_escape($testimonial->nama);?></a></strong>&nbsp;
              </div>
              <div>
                <p style="margin-bottom: 0;"><?php echo nl2br(html_escape($testimonial->pesan)) . (!$testimonial->moderasi && $this->user->is_admin() ? '&nbsp;<a href="'.site_url('admin/testimonial/delete/'.$testimonial->id).'" data-toggle="modal" data-target="#myModal">[Hapus]</a>' : '');?></p>
                <?php if ($testimonial->moderasi):?>
                <div class="row" style="margin-top: 10px;">
                  <div class="col-xs-6">
                    <a class="btn btn-primary btn-sm btn-block" href="<?php echo site_url('admin/testimonial/confirm/'.$testimonial->id);?>" data-toggle="modal" data-target="#myModal"><i class="fa fa-check"></i> Konfirmasi</a>
                  </div>
                  <div class="col-xs-6">
                    <a class="btn btn-danger btn-sm btn-block" href="<?php echo site_url('admin/testimonial/delete/'.$testimonial->id);?>" data-toggle="modal" data-target="#myModal"><i class="fa fa-trash"></i> Hapus</a>
                  </div>
                </div>
                <?php endif;?>
              </div>
            </div>
          </div>
          <?php endif;?>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
  </body>
</html>