Login

Credit calculator(ua-ru)

Author:
fordexa
Posted:
September 20, 2008
Language:
JavaScript
Version:
Not specified
Score:
-3 (after 3 ratings)

Simple jquery creditcalculator

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* 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:&nbsp;"+price_glob+
						 "<br />Сумма кредита, USD:&nbsp;"+credit_summ+
						 "<br />Сумма выплаченных процентов за весь срок, USD:&nbsp;"+percents_summ+
						 "<br />Среднемесячный полный платеж, USD:&nbsp;"+m+
						 "<br />Полная стоимость с учетом выплаченных процентов, USD:&nbsp;"+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>&nbsp;<strong>{% trans "Form of credit repayment" %}:</strong></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td colspan="2">
				<table>
					<tbody>
						<tr>
							<td>&nbsp;
								<input type="radio" value="1" id="forma1" name="forma" checked="checked"/>
							</td>
							<td>&nbsp;
								<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" />&nbsp;
				<input type="button" value="{% trans 'Calculate' %}" id="countb" name="" onclick="calculate()" />
			</td>
		</tr>
		</tbody>
	</table>
	<div id="result"> </div>
{% endblock %}

More like this

  1. Django Collapsed Stacked Inlines by applecat 1 year, 9 months ago
  2. Django Collapsed Stacked Inlines by mkarajohn 3 years, 10 months ago
  3. Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 6 months ago
  4. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 7 months ago
  5. Django admin inline ordering - javascript only implementation by ojhilt 11 years, 11 months ago

Comments

aarond10ster (on September 21, 2008):

Looks like a clean implementation but not really a snippet right? The only django here is the use of i18n {% trans %} tags.

#

Please login first before commenting.