Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new tax calculation based on tax law, added capital tax.

  • Loading branch information...
commit 2363d82cf2a19d89606c40e1924394f6d2d247aa 1 parent 629d158
@kpii kpii authored
View
1  index.html
@@ -25,6 +25,7 @@
</div>
<p class="question">Your reported income for 2010 was: <span id="income"></span></p>
<div id="slider"></div>
+ <div><input id="capital" /></div>
<p>Annual taxes paid to the city of Zürich: <span id="taxes"></span>, this money lasted the city for <span id="duration"></span> seconds.</p>
<div class="chart"></div>
View
144 main.js
@@ -0,0 +1,144 @@
+"use strict";
+
+var taxDataIncome, taxDataCapital,
+ total = 0,
+ data = [
+ { key: "BEHÖRDEN UND ALLGEMEINE VERWALTUNG", value: 798532 },
+ { key: "RECHTSCHUTZ UND SICHERHEIT", value: 610601 },
+ { key: "BILDUNG", value: 897564 },
+ { key: "KULTUR UND FREIZEIT", value: 353979 },
+ { key: "GESUNDHEIT", value: 882751 },
+ { key: "SOZIALE WOHLFAHRT", value: 1358892 },
+ { key: "VERKEHR", value: 997827 },
+ { key: "UMWELT UND RAUMORDNUNG", value: 477265 },
+ { key: "VOLKSWIRTSCHAFT", value: 845404 },
+ { key: "FINANZEN UND STEUERN", value: 548101 }
+ ];
+
+function initData() {
+ var i;
+ data.sort(function (a, b) {
+ if (a.value == b.value) {
+ return 0;
+ }
+ return a.value > b.value ? -1 : 1;
+ });
+
+ for (i = 0; i < data.length; i++) {
+ total += data[i].value;
+ }
+}
+
+function getIncomeTaxes(income, married) {
+ if (taxDataIncome === undefined) {
+ $.ajax('taxrates_income.json', {
+ async: false,
+ dataType: 'json',
+ success: function (data) {
+ taxDataIncome = data;
+ }
+ });
+ }
+
+ var tax = 0;
+ var idx = married ? 2 : 1;
+
+ for(var i = 0 ; ; i++) {
+ var boundary = taxDataIncome[i][idx];
+ if (income < boundary || boundary == 0) {
+ tax += income * taxDataIncome[i][0];
+ break;
+ } else {
+ tax += boundary * taxDataIncome[i][0];
+ income -= boundary;
+ }
+ }
+
+ return tax;
+}
+
+function getCapitalTaxes(capital, married) {
+ if (taxDataCapital === undefined) {
+ $.ajax('taxrates_capital.json', {
+ async: false,
+ dataType: 'json',
+ success: function (data) {
+ taxDataCapital = data;
+ }
+ });
+ }
+
+ var tax = 0;
+ var idx = married ? 2 : 1;
+
+
+ for(var i = 0 ; ; i++) {
+ var boundary = taxDataCapital[i][idx];
+ if (capital < boundary || boundary == 0) {
+ tax += capital * taxDataCapital[i][0];
+ break;
+ } else {
+ tax += boundary * taxDataCapital[i][0];
+ capital -= boundary;
+ }
+ }
+
+ return tax;
+}
+
+function moneyFormat(value) {
+ value = value.toString();
+ if (value > 1000) {
+ return Math.floor(value / 1000) + "'" + "000".substr((value % 1000).toString().length) + (value % 1000);
+ }
+ return value;
+}
+
+function update() {
+ var i,
+ income = $('#slider').slider('value') * 1000,
+ capital = $('#capital').val(),
+ married = $('#married').is('.selected'),
+ taxes = getIncomeTaxes(income, married)
+ + getCapitalTaxes(capital, married),
+ duration = taxes / 1000 / total * 86400 * 365;
+
+ $('#income').text(moneyFormat(income) + ' CHF');
+ $('#taxes').text(moneyFormat(taxes) + ' CHF');
+ $('#duration').text(Math.round(duration));
+
+ $('.chart').html('');
+ var chart = d3.select(".chart").append("div").attr("class", "bar-chart");
+
+ chart.selectAll("div")
+ .data(data)
+ .enter()
+ .append("p")
+ .html(function (d) {
+ var spent = Math.round(taxes / total * d.value);
+ return '<span class="label">'+moneyFormat(spent)+' CHF</span>';
+ })
+ .append("div")
+ .style("width", function (d) {
+ return d.value / 2000 + "px";
+ })
+ .text(function (d) {
+ return d.key;
+ });
+}
+
+initData();
+
+$('#slider').slider({
+ min: 10,
+ max: 1249,
+ value: 50,
+}).bind('slidechange slide', function (e) {
+ update();
+}).trigger('slidechange');
+
+$('#married, #single').click(function (e) {
+ $('#married, #single').removeClass('selected');
+ $(this).addClass('selected');
+ update();
+});
View
9 taxrates_capital.json
@@ -0,0 +1,9 @@
+[
+[0.00,71000,142000],
+[0.0005,213000,213000],
+[0.001,356000,355000],
+[0.0015,567000,567000],
+[0.002,853000,853000],
+[0.0025,851000,852000],
+[0.003,0,0]
+]
View
15 taxrates_income.json
@@ -0,0 +1,15 @@
+[
+[0.00,6200,12400],
+[0.02,4300,5700],
+[0.03,4300,7100],
+[0.04,7000,8600],
+[0.05,8600,9900],
+[0.06,9900,12800],
+[0.07,11400,28400],
+[0.08,15600,28400],
+[0.09,29900,42700],
+[0.10,29700,51100],
+[0.11,47000,55400],
+[0.12,61000,63900],
+[0.13,0,0]
+]
Please sign in to comment.
Something went wrong with that request. Please try again.