<?php
$expired = time() - (3600 * $this->system->set['jam_pembayaran']);
$opsi = $trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array();
echo form_open(current_url(), 'class="form-horizontal"');
?>
  <div class="form-group">
    <label class="col-sm-3 control-label">Server</label>
    <div class="col-sm-8 col-md-9">
      <select class="form-control" name="server">
        <?php foreach ($daftar_server as $server):?>
        <option value="<?php echo $server->sv_id?>" <?php echo set_select('server', $server->sv_id, $trx->sv_id == $server->sv_id ? true : false);?>><?php echo html_escape($server->sv_nama)?></option>
        <?php endforeach;?>
      </select>
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-3 control-label">Kode Server</label>
    <div class="col-sm-8 col-md-9">
      <input type="text" class="form-control" name="kode" value="<?php echo set_value('kode', $trx->vo_kode);?>" placeholder="<?php echo $trx->vo_kode;?>"/>
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-3 control-label">Nomor HP</label>
    <div class="col-sm-8 col-md-9">
      <input type="text" class="form-control" name="no_hp" value="<?php echo set_value('no_hp', $trx->tr_no_hp);?>" placeholder="<?php echo $trx->tr_no_hp;?>"/>
    </div>
  </div>
  <?php if ($trx->tr_id_plgn):?>
  <div class="form-group">
    <label class="col-sm-3 control-label">ID Pelanggan</label>
    <div class="col-sm-8 col-md-9">
      <input type="text" class="form-control" name="id_plgn" value="<?php echo set_value('id_plgn', $trx->tr_id_plgn);?>" placeholder="<?php echo $trx->tr_id_plgn;?>"/>
    </div>
  </div>
  <?php endif;?>
  <div class="form-group">
    <label class="col-sm-3 control-label">Status Pembayaran</label>
    <div class="col-sm-8 col-md-9">
      <select class="form-control" name="status_pembayaran" onchange="leaveChange()" id="payment_status">
        <option value="sukses"<?php echo ($trx->tr_status_pembayaran == 'Xrefund' ? 'disabled="disabled"' : ($trx->tr_status_pembayaran == 'sukses' ? ' selected="selected"' : ''));?>>Sukses</option>
        <option value="pending"<?php echo ($trx->tr_status_pembayaran == 'Xrefund' || $trx->tr_pembayaran == 'Xbalance'  ? 'disabled="disabled"' : ($trx->tr_status_pembayaran == 'pending' ? ' selected="selected"' : ''));?>>Pending</option>
        <option value="refund"<?php echo ($trx->tr_status_pembayaran == 'refund' ? ' selected="selected"' : '');?>>Refund</option>
      </select>
      <?php if ($trx->tr_pembayaran == 'balance'):?>
      <div id="refund_payment_checkbox" class="checkbox" style="display: none;">
        <label><input type="checkbox" name="refund_payment" id="refund_payment" value="1"/> Refund saldo ke akun user</label>
      </div>
      <?php endif;?>
    </div>
  </div>
  <?php if (isset($opsi['shipping'])):?>
  <div class="form-group">
    <label class="col-sm-3 control-label">Nomor Resi / AWB</label>
    <div class="col-sm-8 col-md-9">
      <input type="text" class="form-control" name="awb_number" value="<?php echo set_value('awb_number', $opsi['shipping']['awb_number']);?>" placeholder="<?php echo $opsi['shipping']['awb_number'];?>" maxlength="32"/>
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-3 control-label">Status Pengiriman</label>
    <div class="col-sm-8 col-md-9">
      <select class="form-control" name="status_pengiriman">
        <option value="belum_dikirim" <?php echo set_select('status_pengiriman', 'belum_dikirim', $opsi['shipping']['delivery_status'] == 'belum_dikirim'); ?>>Belum dikirim</option>
        <option value="sedang_dikirim" <?php echo set_select('status_pengiriman', 'sedang_dikirim', $opsi['shipping']['delivery_status'] == 'sedang_dikirim'); ?>>Sedang dikirim</option>
        <option value="sudah_diterima" <?php echo set_select('status_pengiriman', 'sudah_diterima', $opsi['shipping']['delivery_status'] == 'sudah_diterima'); ?>>Sudah diterima</option>
        <option value="gagal" <?php echo set_select('status_pengiriman', 'gagal', $opsi['shipping']['delivery_status'] == 'gagal'); ?>>Gagal</option>
      </select>
    </div>
  </div>
  <?php else:?>
  <div class="form-group">
    <label class="col-sm-3 control-label">Status Pengisian</label>
    <div class="col-sm-8 col-md-9">
      <select class="form-control" name="status_pengisian" id="status">
        <option value=""></option>
        <option value="sukses"<?php echo ($trx->tr_status_pembayaran == 'Xrefund' ? 'disabled="disabled"' : ($trx->tr_status == 'sukses' ? ' selected="selected"' : ''));?>>Sukses</option>
        <option value="pending"<?php echo ($trx->tr_status_pembayaran == 'Xrefund' ? 'disabled="disabled"' : ($trx->tr_status == 'pending' ? ' selected="selected"' : ''));?>>Pending</option>
        <option value="gagal"<?php echo ($trx->tr_status == 'gagal' ? ' selected="selected"' : '');?>>Gagal</option>
      </select>
      <p class="help-block">Status yang tersimpan di database: <?php echo $trx->tr_status;?></p>
    </div>
  </div>
  <?php endif;?>
  <div class="form-group">
    <label class="col-sm-3 control-label">Pendapatan Bersih</label>
    <div class="col-sm-8 col-md-9">
      <div class="input-group">
        <span class="input-group-addon">Rp</span>
        <input type="number" class="form-control" name="income" value="<?php echo set_value('income', $trx->tr_income);?>"  placeholder="<?php echo $trx->tr_income;?>"/>
      </div>
    </div>
  </div>
  <div class="form-group" id="sn_form">
    <label class="col-sm-3 control-label">SN/Ref</label>
    <div class="col-sm-8 col-md-9">
      <input type="text" class="form-control" name="sn" value="<?php echo set_value('sn', isset($opsi['sn']) ? $opsi['sn'] : '');?>"  placeholder="<?php echo html_escape(isset($opsi['sn']) ? $opsi['sn'] : '');?>" maxlength="64"/>
    </div>
  </div>
  <div class="form-group" style="margin-bottom:0">
    <div class="col-sm-offset-3 col-sm-9">
      <button type="submit" name="submit" class="btn btn-primary" value="save"><i class="fa fa-check"></i> Simpan </button>
      &nbsp;
      <a href="<?php echo site_url('admin/transaksi/view/' . $trx->tr_id);?>" class="btn btn-default" data-dismiss="modal"><i class="fa fa-remove"></i> Batal</a>
    </div>
  </div>
<?php echo form_close();?>
<script type="text/javascript">
  <?php if ($trx->tr_pembayaran == 'balance'):?>
  function leaveChange() {
    var e = document.getElementById("payment_status");
    var payment_status = e.options[e.selectedIndex].value;
    if (payment_status == 'refund') {
      document.getElementById("refund_payment_checkbox").style.display = "block";
    } else {
      document.getElementById("refund_payment_checkbox").style.display = "none";
      document.getElementById("refund_payment").checked = false;
    }
  }
  <?php endif;?>
</script>