Ledger Nano X - The secure hardware wallet
SHARE
TWEET

perhitungan.js

MarsCelebrity May 20th, 2020 857 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var list_package    = [];
  2. var list_harga      = [];
  3. $('#G-Game').on('change',function(){
  4.     val = $(this).val();
  5.     if(val == 'ff'){
  6.         list_package    = ff_package;
  7.         list_harga      = ff_harga;
  8.     }else if(val == 'pubg'){
  9.         list_package    = pubg_package;
  10.         list_harga      = pubg_harga;
  11.     }else if(val == 'ml'){
  12.         list_package    = ml_package;
  13.         list_harga      = ml_harga;
  14.     }else{
  15.         list_package    = [];
  16.         list_harga      = [];
  17.     }
  18.     reset_value('Game');
  19.  
  20.     item    = '';
  21.     item2   = '';
  22.     for (var i = 0; i < list_package.length; i++) {
  23.         item += '<option class="dt" value="'+i+'">'+list_package[i]+'</option>';
  24.         if(i != 0){
  25.             item2 += '<option class="dt" value="'+i+'">'+list_package[i]+'</option>';
  26.         }
  27.     }
  28.     $('#G-From').append(item);
  29.     $('#G-To').append(item2);
  30.  
  31. });
  32.  
  33. $('#G-From').on('change',function(){
  34.     sum_total();
  35. });
  36. $('#G-To').on('change',function(){
  37.     sum_total();
  38. });
  39. $('#G-Fee-Type').on('change',function(){
  40.     sum_total();
  41. });
  42. $('#G-Reseller').change(function () {
  43.     sum_total();
  44.  });
  45.  
  46. function sum_total(){
  47.     from        = $('#G-From option:selected').val();
  48.     to          = $('#G-To option:selected').val();
  49.     fee_type    = $('#G-Fee-Type option:selected').val();
  50.     reseller    = $('#G-Reseller:checked').val();
  51.  
  52.     status_perhitungan = true;
  53.     if(from == 'none' || to == 'none' || to<from){
  54.         status_perhitungan = false;
  55.         reset_value('From');
  56.     }
  57.  
  58.     if(status_perhitungan){
  59.         index_no = to-from;
  60.         val = list_harga[from][index_no];
  61.         val = val.replace(/,/g,'');
  62.         val = parseFloat(val);
  63.  
  64.         val_fee = 0;
  65.         if(fee_pembayaran[fee_type]){
  66.             val_fee_temp = fee_pembayaran[fee_type];
  67.             val_fee_temp = val_fee_temp.split('-');
  68.             if(val_fee_temp[0] == '%'){
  69.                 val_fee_temp = val_fee_temp[1];
  70.                 val_fee      = parseFloat(val_fee_temp);
  71.                 val_fee      = PersenttoRp(val,val_fee);
  72.             }else{
  73.                 val_fee = val_fee_temp[0];
  74.                 val_fee = val_fee.replace(/,/g,'');
  75.                 val_fee = parseFloat(val_fee);
  76.             }
  77.         }
  78.  
  79.         val_reseller = 0;
  80.         if(reseller == 1){
  81.             status_reseller     = false;
  82.             val_reseller_temp   = '0';
  83.             $.each(key_diskon_reseller,function(k,v){
  84.                 if(val>=v){
  85.                     status_reseller     = true;
  86.                     val_reseller_temp   = diskon_reseller[''+v];
  87.                     return false;
  88.                 }
  89.             });
  90.             if(status_reseller){
  91.                 val_reseller_temp = val_reseller_temp.split('-');
  92.                 if(val_reseller_temp[0] == '%'){
  93.                     val_reseller_temp = val_reseller_temp[1];
  94.                     val_reseller      = parseFloat(val_reseller_temp);
  95.                     val_reseller     = PersenttoRp(val,val_reseller);
  96.                 }else{
  97.                     val_reseller = val_reseller_temp[0];
  98.                     val_reseller = val_reseller.replace(/,/g,'');
  99.                     val_reseller = parseFloat(val_reseller);
  100.                 }
  101.             }
  102.         }
  103.  
  104.  
  105.         $('#G-Fee-Package').val(formatRupiah(''+val,'IDR '));
  106.         $('#G-Fee-Via').val(formatRupiah(''+val_fee,'IDR '));
  107.         if(val_reseller>0){
  108.             $('#G-Fee-Reseller').val(formatRupiah(''+val_reseller,'IDR -'))
  109.         }else{
  110.             $('#G-Fee-Reseller').val('IDR 0');
  111.         }
  112.         total = (val+val_fee)-val_reseller;
  113.         $('#TotalPrice').text(formatRupiah(''+total,'IDR '));
  114.     }
  115. }
  116.  
  117. function show_console(p1){
  118.     console.log(p1);
  119. }
  120.  
  121. function reset_value(p1){
  122.     if(p1 == 'Game'){
  123.         $('#G-From .dt').remove();
  124.         $('#G-To .dt').remove();
  125.         $('#G-Fee-Package').val(formatRupiah(''+0,'IDR '));
  126.         $('#G-Fee-Via').val(formatRupiah(''+0,'IDR '));
  127.         $('#G-Fee-Reseller').val(formatRupiah(''+0,'IDR '));
  128.         $('#TotalPrice').val(formatRupiah(''+0,'IDR '));
  129.     }
  130.     if(p1 == 'From' || p1 == 'To'){
  131.         $('#G-Fee-Package').val(formatRupiah(''+0,'IDR '));
  132.         $('#G-Fee-Via').val(formatRupiah(''+0,'IDR '));
  133.         $('#G-Fee-Reseller').val(formatRupiah(''+0,'IDR '));
  134.         $('#TotalPrice').text(formatRupiah(''+0,'IDR '));
  135.     }
  136. }
  137.  
  138. function formatRupiah(angka, prefix){
  139.     var number_string = angka.replace(/[^,\d]/g, '').toString(),
  140.     split           = number_string.split(','),
  141.     sisa            = split[0].length % 3,
  142.     rupiah          = split[0].substr(0, sisa),
  143.     ribuan          = split[0].substr(sisa).match(/\d{3}/gi);
  144.  
  145.     // tambahkan titik jika yang di input sudah menjadi angka ribuan
  146.     if(ribuan){
  147.         separator = sisa ? ',' : '';
  148.         rupiah += separator + ribuan.join(',');
  149.     }
  150.  
  151.     rupiah = split[1] != undefined ? rupiah + '.' + split[1] : rupiah;
  152.     return prefix == undefined ? rupiah : (rupiah ? prefix+'' + rupiah : '');
  153. }
  154.  
  155. function PersenttoRp(total,persen){
  156.   total  = parseFloat(total);
  157.   persen = parseFloat(persen);
  158.   hasil = (persen/100)*total;
  159.   return hasil;
  160. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top