/* js code */ // Credit calculator function elems_summ(arr) { var total = 0; for (var i=1; i < arr.length; i++) { total += arr[i]; } return total.toPrecision(7); } function calculate() { // datas for calculation var price = $("input#price").val(); var vznos = $("input#vznos").val(); var period = $("select#period").val(); var stavka = $("input#stavka").val(); var percents = new Array(); var m = ''; var html = ''; var price_glob = price; var credit_summ = price; if (vznos != 0) { price -= vznos; credit_summ = price; } var f1 = $("input#forma1:checked").val(); if (f1 == 1) { // anual credit var mounthly = price * (((stavka/100)/12)/(1-(Math.pow(1+((stavka/100)/12), -period)))); m = mounthly.toPrecision(7) for (var i=1; i <= period; i++) { var percent = (price * (stavka/12) / 100); percents[i] = percent; var body = m - percent; html += '<tr><td>'+i+'</td><td>'+parseFloat(price).toPrecision(7)+'</td><td>'+body.toPrecision(7)+'</td><td>'+percent.toPrecision(7)+'</td><td>'+m+'</td></tr>'; price -= body; } } else { // standart credit var body = price / period; var average_pay = 0; for (var i=1; i <= period; i++) { var percent = (price * (stavka/12) / 100); var mounthly = body + percent; average_pay += mounthly; percents[i] = percent; html += '<tr><td>'+i+'</td><td>'+parseFloat(price).toPrecision(7)+'</td><td>'+body.toPrecision(7)+'</td><td>'+percent.toPrecision(7)+'</td><td>'+mounthly.toPrecision(7)+'</td></tr>'; price -= body; } m = average_pay / period; } var percents_summ = elems_summ(percents); var full_summ = parseFloat(credit_summ) + parseFloat(percents_summ); $("div#result").html("<div id='estimate'>Цена автомобилÑ, USD: "+price_glob+ "<br />Сумма кредита, USD: "+credit_summ+ "<br />Сумма выплаченных процентов за веÑÑŒ Ñрок, USD: "+percents_summ+ "<br />СреднемеÑÑчный полный платеж, USD: "+m+ "<br />ÐŸÐ¾Ð»Ð½Ð°Ñ ÑтоимоÑÑ‚ÑŒ Ñ ÑƒÑ‡ÐµÑ‚Ð¾Ð¼ выплаченных процентов, USD: "+full_summ+"</div>") var tbl = $("input#table:checked").length; if (tbl) { $("div#estimate").after("<table border='1' id='est'><tr><td>МеÑÑц</td><td>ОÑтаток кредита</td><td>Тело кредита</td><td>ÐачиÑлено процентов</td><td>Ð’Ñего к оплате</td></tr>"+html+"</table>"); } $("#clean").click(function () { $("div#estimate").remove(); $("table#est").remove(); }) } /* template */ {% extends "base.html" %} {% load i18n %} {% block title %} {% trans "Credit calculator" %} {% endblock %} {% block scripts %} <script type="text/javascript" src="{{ MEDIA_URL }}js/credit.js"> </script> {% endblock %} {% block content %} <h2>{% trans "Credit calculator" %}</h2> <table width="300" cellspacing="0" cellpadding="3" border="0"> <tbody> <tr> <td nowrap="nowrap"> <strong>{% trans "Price of auto in USD" %}:</strong></td> <td nowrap="nowrap"> <input type="text" value="0" id="price" name="price" class="required" maxlength="6" /><strong>$</strong> <input type="hidden" value="" id="price" name="price"/> </td> </tr> <tr> <td><strong>{% trans "Start payment" %}<span id="vznos_proc"/>:</strong></td> <td nowrap="nowrap"> <input type="text" id="vznos" name="vznos" value="0" class="required" maxlength="6" /><strong>$</strong> </td> </tr> <tr> <td nowrap="nowrap"><strong>{% trans "Credit period" %}:</strong></td> <td> <select id="period" name="period" type="text" class="required"> <option value="12">{% trans "year" %}</option> <option value="24">{% trans "2 year" %}</option> <option value="36">{% trans "3 year" %}</option> <option value="48">{% trans "4 year" %}</option> <option selected="selected" value="60">{% trans "5 year" %}</option> <option value="84">{% trans "6 year" %}</option> </select> </td> </tr> <tr> <td> <strong>{% trans "Annual bank salary" %}:</strong></td> <td nowrap="nowrap"> <input type="text" id="stavka" name="stavka" value="12" style="width: 60px;" maxlength="6"/><strong>%</strong> </td> </tr> <tr> <td> <strong>{% trans "Form of credit repayment" %}:</strong></td> <td> </td> </tr> <tr> <td colspan="2"> <table> <tbody> <tr> <td> <input type="radio" value="1" id="forma1" name="forma" checked="checked"/> </td> <td> <label for="forma1">{% trans "Annua" %} ({% trans "equal parts" %})</label> </td> <td> <input type="radio" value="2" id="forma2" name="forma"/> </td> <td> <label for="forma2">{% trans "standart" %}</label> </td> </tr> </tbody> </table> </td> </tr> <tr> <td colspan="2"> <input type="checkbox" align="absmiddle" value="yes" id="table" name="table" />{% trans "calculate monthly instalments" %} </td> </tr> <tr> <td colspan="2"><br/> <input type="button" value="{% trans 'Clean' %}" id="clean" /> <input type="button" value="{% trans 'Calculate' %}" id="countb" name="" onclick="calculate()" /> </td> </tr> </tbody> </table> <div id="result"> </div> {% endblock %}