<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php echo form_open(current_url(), 'class="form-horizontal" name="editForm" id="editForm"'); ?>
<div class="form-group">
  <div class="col-sm-offset-3 col-sm-9">
    <div>
      <a href="<?php echo current_url(); ?>">Pengeditan lebih lanjut</a>
    </div>
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Server <span class="text-danger">*</span></label>
  <div class="col-sm-9">
    <select class="form-control input-sm" name="server">
      <option value="">-- Pilih --</option>
      <?php foreach ($daftar_server as $server) : ?>
        <option value="<?php echo $server->sv_id ?>" <?php echo set_select('server', $server->sv_id, $voucher->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 <span class="text-danger">*</span></label>
  <div class="col-sm-9">
    <input type="text" class="form-control" onkeyup="updateKodeTrx(value)" name="kode" value="<?php echo set_value('kode', $voucher->vo_kode); ?>" placeholder="<?php echo html_escape($voucher->vo_kode); ?>" maxlength="32" required="required" />
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Kode Trx <span class="text-danger">*</span></label>
  <div class="col-sm-9">
    <input type="text" class="form-control" id="kode_trx" name="kode_trx" value="<?php echo set_value('kode_trx', $voucher->vo_kode_trx); ?>" placeholder="<?php echo html_escape($voucher->vo_kode_trx); ?>" maxlength="32" required="required" />
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Nama <span class="text-danger">*</span></label>
  <div class="col-sm-9">
    <input type="text" class="form-control" name="nominal" value="<?php echo set_value('nominal', $voucher->vo_nominal); ?>" placeholder="<?php echo html_escape($voucher->vo_nominal); ?>" maxlength="120" required="required" />
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Keterangan</label>
  <div class="col-sm-9">
    <textarea class="form-control" name="deskripsi" rows="6"><?php echo set_value('deskripsi', $voucher->vo_description); ?></textarea>
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Harga Beli</label>
  <div class="col-sm-9">
    <input type="number" class="form-control" id="harga_beli" name="harga_beli" value="<?php echo set_value('harga_beli', $voucher->vo_harga_beli); ?>" placeholder="<?php echo $voucher->vo_harga_beli; ?>" />
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Harga Jual Umum <span class="text-danger">*</span></label>
  <div class="col-sm-9">
    <input type="number" class="form-control" id="harga" onkeyup="updateHargaReseller(value)" name="harga" value="<?php echo set_value('harga', $voucher->vo_harga); ?>" data-harga="<?php echo $voucher->vo_harga; ?>" placeholder="<?php echo $voucher->vo_harga; ?>" required="required" />
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Harga Jual Reseller <span class="text-danger">*</span></label>
  <div class="col-sm-9">
    <input type="number" class="form-control" id="harga_reseller" name="harga_reseller" value="<?php echo set_value('harga_reseller', ($voucher->vo_harga_reseller ? $voucher->vo_harga_reseller : $voucher->vo_harga)); ?>" data-harga="<?php echo $voucher->vo_harga_reseller ? $voucher->vo_harga_reseller : $voucher->vo_harga; ?>" placeholder="<?php echo $voucher->vo_harga_reseller ? $voucher->vo_harga_reseller : $voucher->vo_harga; ?>" />
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Produk Cek PPOB</label>
  <div class="col-sm-9">
    <select class="form-control" name="ppob_cek">
      <option value="0">-- Tidak ada --</option>
      <?php foreach ($vouchers as $vcr) : ?>
        <option value="<?php echo $vcr->vo_id; ?>" <?php echo ($voucher->vo_ppob_cek == $vcr->vo_id ? ' selected="selected"' : ''); ?>><?php echo html_escape($vcr->vo_nominal . ' (' . $vcr->vo_kode . ')'); ?></option>
      <?php endforeach; ?>
    </select>
  </div>
</div>
<div class="form-group">
  <label class="col-sm-3 control-label">Status <span class="text-danger">*</span></label>
  <div class="col-sm-9">
    <select class="form-control" name="status">
      <option value="1" <?php echo  set_select('status', '1', $voucher->vo_status ? true : false); ?>>Tersedia</option>
      <option value="0" <?php echo  set_select('status', '0', !$voucher->vo_status ? true : false); ?>>Tidak tersedia</option>
    </select>
  </div>
</div>
<div class="form-group" style="margin-bottom:0">
  <div class="col-sm-offset-3 col-sm-9">
    <button type="submit" class="btn btn-primary" name="save" value="advanced"><i class="fa fa-check"></i> Simpan</button>
    &nbsp;
    <a href="<?php echo site_url('admin/produk/browse/' . $voucher->op_produk . '/' . $voucher->op_slug . '/' . $this->uri->segment(5)); ?>" 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">
  function updateKodeTrx(val) {
    document.getElementById("kode_trx").value = val;
  }
  var umum = document.getElementById("harga");
  var reseller = document.getElementById("harga_reseller");
  var selisih = umum.getAttribute("data-harga") - reseller.getAttribute("data-harga");

  function updateHargaReseller(val) {
    reseller.value = val - selisih;
  }
</script>