Advertisement
jamboljack

hitungRatio

Jan 24th, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. function hitungRatio() {
  2.     var locale              = 'en';
  3.     var options             = {minimumFractionDigits: 3, maximumFractionDigits: 3};
  4.     var formatter           = new Intl.NumberFormat(locale, options);
  5.     var myForm              = document.formInput;
  6.     var Ratio               = myForm.ratio.value;
  7.     Ratio                   = Ratio.replace(/[,]/g, '');
  8.     Ratio                   = parseFloat(Ratio);
  9.     // Jumlah Value Ratio Item
  10.     var coating_ratio_id     = <?=$detailcoating->coating_ratio_id;?>;
  11.     var coating_ratio_value  = <?=$detailcoating->coating_ratio_value;?>;
  12.     $.ajax({
  13.         url:"<?=site_url('admin/color/jumlah_ratio/');?>"+coating_ratio_id,
  14.         type: "GET",
  15.         dataType: "JSON",
  16.         success: function(data) {
  17.             if (data.total_ratio===null) {
  18.                 var total = Ratio;
  19.                 console.log(total);
  20.             } else {
  21.                 var total = (data.total_ratio+Ratio);
  22.                 console.log(total);
  23.             }
  24.         },
  25.     });
  26.  
  27.     // console.log(total, coating_ratio_value, Ratio);
  28.     var Consumption              = ((Ratio*coating_ratio_value)/total);
  29.  
  30.     if (isNaN(Consumption)) {
  31.         myForm.consumption.value     = 0;    
  32.     } else {
  33.         myForm.consumption.value     = formatter.format(Consumption);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement