Created
September 4, 2014 06:45
-
-
Save VorontsovIE/b947eaf85f0bcebc4ab3 to your computer and use it in GitHub Desktop.
JS calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var emcntnt = '' + | |
'<h2 id = "osemi-header">Рассчитать стоимость услуг</h2>' + | |
'<div class = "emi-form"><table class = "table table-bordered">' + | |
'<tr class = "outstanamount">' + | |
'<td>Количество документов в месяц:</td> ' + | |
'<td>' + | |
'<div> <input type = "text" placeholder = "0.00" id = "outstanding_principle" value = "0" onchange = "calculateEMI();"></div>' + | |
'<div id = "osp_range"></div>' + | |
'</td>' + | |
'</tr>' + | |
'<tr class = "intrate">' + | |
'<td>Количество работников:</td>' + | |
'<td>' + | |
'<input type = "text" placeholder = "0.00" id = "interest_rate" value = "0" onchange = "calculateEMI();">' + | |
'<div id = "osir_range"></div>' + | |
'</td>' + | |
'</tr>' + | |
'<tr>' + | |
'<td>Ваша система налогообложения:</td>' + | |
'<td>' + | |
'<div class = "osemi-term">' + | |
'<input type = "text" placeholder = "0.00" id = "tenure" value = "42" onchange = "calculateEMI(); disabled = "disabled">' + | |
'</div>' + | |
'<div class = "osemi-tenurechoice">' + | |
'<div id = "osemi-lyear">' + | |
'<input name = "osemi-loantenure" class = "osemiloanperiod" id = "osemi-loanyears" value = "osemi-loanyears" type = "radio" checked = "checked">' + | |
'<label id = "osemi-loanyearslabel" for = "osemi-loanyears">Основной</label>' + | |
'</div>' + | |
'<div id = "osemi-lmths">' + | |
'<input name = "osemi-loantenure" class = "osemiloanperiod" id = "osemi-loanmonths" value = "osemi-loanmonths" type = "radio">' + | |
'<label id = "osemi-loanmonthslabel" for = "osemi-loanmonths">Упрощенный 6%</label>' + | |
'</div>' + | |
'<div id = "osemi-lyear">' + | |
'<input name = "osemi-loantenure" class = "osemiloanperiod" id = "osemi-loandays" value = "osemi-loandays" type = "radio">' + | |
'<label id = "osemi-loandayslabel" for = "osemi-loandays">Упрощенный 15%</label>' + | |
'</div>' + | |
'</div>' + | |
'</td>' + | |
'</table></div>' + | |
'<div id = "osemi-summary"><div id = "osemi-totalamount">' + | |
'<span clas = "itog">Приблизительная стоимость:</span><p>руб./мес. <span id = "totpay"></span></p>' + | |
'</div></div>' + | |
'<div class = "clear-style"></div>' + | |
'<div id = "container"></div>'; | |
$.noConflict(); | |
jQuery( document ).ready(function( $ ) { | |
function calculate_value_by_slider(val) { | |
if (val >=1 && val <= 20) { | |
return val * 350; | |
} else if (val >= 21 && val <= 50) { | |
return 350 * 20 + 300 * (val - 20); | |
} | |
} | |
function calculateEMI(obj) { | |
var op = $("#outstanding_principle").val(), | |
ir = $("#interest_rate").val(), | |
ten = $("#tenure").val(), | |
// ipp = pap = tp = ip = '', | |
// em = $('#emi'), | |
// tipay = $('#tipay'), | |
totpay = $('#totpay'); | |
// isNaN(isNotaNumber): Check whether the value is Number or Not | |
// if ((!isNaN(op) && op !== 0) && (!isNaN(ir) && ir !== 0) && (!isNaN(ten) && ten !== 0)) { | |
if (!isNaN(op) && !isNaN(ir) && !isNaN(ten)) { | |
// var emi = 0, P = 0, n = 1, r = 0; | |
// parseFloat: This function parses a string and returns a floating point number | |
var op_value, ir_value, ten_value; | |
op_value = parseFloat(op); | |
ir_value = parseFloat(ir); | |
ten_value = parseFloat(ten); | |
totpay.text(CommaFormatted(op_value + ir_value + ten_value)); | |
} | |
} | |
/*code to format currency*/ | |
function CommaFormatted(amount) { | |
var numberStr = amount.toString(); | |
var thousandsMatcher = /(\d+)(\d{3})$/; | |
var thousandsAndRest = thousandsMatcher.exec(numberStr); | |
if (!thousandsAndRest) return numberStr; | |
return thousandsAndRest[1].replace(/\B(?=(\d{2})+(?!\d))/g, ",") + "," + thousandsAndRest[2]; | |
} | |
$('.emi-container').html(emcntnt); | |
$('.osemiloanperiod').click(function(){ | |
if($(this).is(':checked')){ | |
var cd = $(this).val(), | |
tp = $('#tenure'); | |
if(cd == 'osemi-loanyears') { | |
tp.val(42); | |
} else if (cd == 'osemi-loanmonths') { | |
tp.val(12); | |
} else if (cd == 'osemi-loandays') { | |
tp.val(99); | |
} | |
} | |
calculateEMI(); | |
}); | |
calculateEMI(); | |
$( "#osp_range" ).slider({ | |
range: "min", | |
value: 0, | |
min: 0, | |
max: 50, | |
slide: function( event, ui ) { | |
$( "#outstanding_principle" ).val( calculate_value_by_slider(ui.value) ); | |
calculateEMI(); | |
} | |
}); | |
$( "#osir_range" ).slider({ | |
range: "min", | |
value: 0, | |
min: 0, | |
max: 50, | |
slide: function( event, ui ) { | |
$( "#interest_rate" ).val( calculate_value_by_slider(ui.value) ); | |
calculateEMI(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment