
<div class='row'>
    <div class="col-lg-11 col-md-11 col-sm-11">
      <h2> Payment Credit </h2>
      <br>
      <table class='table table-striped'>
        <tr>
          <td> Payment Reference
          </td>
          <td><input type='text' id='reference'/></td>
        </tr>
        <tr>
          <td> Remark
          </td>
          <td><input type="text" id='remark'/></td>
        </tr>
        <tr>
          <td> Payment Method
          </td>
          <td>
              <button class='btn btn-primary payment-type' data-id='cash' id='cash'>CASH</button>
              <button class='btn btn-primary payment-type' data-id='mpu' id='mpu'>MPU</button>
              <button class='btn btn-primary payment-type' data-id='visa' id='visa'>VISA</button>
              <button class='btn btn-primary payment-type' data-id='jcb' id='jcb'>JCB</button>
          </td>
        </tr>
        <tr>
          <td> Reference Number
          </td>
          <td><input type='text' id='payment_method_reference'/></td>
        </tr>
        <tr>
          <td> Amount
          </td>
          <td><input type='text' id='amount'/></td>
        </tr>
      </table>
    </div>
    <div class="col-lg-1 col-md-1 col-sm-1">
      <button type="button" class="btn btn-primary btn-block" id='back'> Back </button>
      <button type="button" class="btn btn-primary btn-block" id='cash_in'> Cash In </button>
    </div>
</div>

<script>
var payment_method = "";
$('.payment-type').on('click',function(){
  $('.payment-type').css("background-color","#7a62d3")
  $(this).css("background-color","green");
  var type = $(this).attr('data-id')
  if(type == 'cash'){
    payment_method = 'cash';
  }else if(type == 'mpu'){
    payment_method = "mpu";
  }else if(type == 'visa'){
    payment_method = "visa";
  }else if(type == 'jcb'){
    payment_method = "jcb";
  }
})
$('#cash_in').on('click',function(){
  var reference = $('#reference').val();
  var remark = $('#remark').val();
  var amount = $('#amount').val();
  var payment_method_reference = $('#payment_method_reference').val();
  $.ajax({type: "POST",
    url: "<%= origami_cash_ins_path %>",
    data: "reference="+ reference + "&remark=" + remark + "&amount="+ amount + "&payment_method="+payment_method + "&payment_method_reference="+ payment_method_reference,
    success:function(result){
      window.location.href = '/origami';
    }
  });
})
$('#back').on('click',function(){
   window.location.href = '/origami';
})
</script>
