|
@@ -8,178 +8,7 @@
|
8
|
8
|
<script src="externals/flot/jquery.flot.selection.js" type="text/javascript"></script>
|
9
|
9
|
<script src="externals/jquery.history/jquery.history.js" type="text/javascript"></script>
|
10
|
10
|
<script src="data.php" type="text/javascript"></script>
|
11
|
|
- <script type="text/javascript">
|
12
|
|
- var previousPoint = null;
|
13
|
|
- var plots = {};
|
14
|
|
- var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
15
|
|
-
|
16
|
|
- function showTooltip(x, y, contents) {
|
17
|
|
- $('<div id="tooltip">' + contents + '</div>').css( {
|
18
|
|
- position: 'absolute',
|
19
|
|
- display: 'none',
|
20
|
|
- top: y + 5,
|
21
|
|
- left: x + 5,
|
22
|
|
- border: '1px solid #fdd',
|
23
|
|
- padding: '2px',
|
24
|
|
- 'background-color': '#fee',
|
25
|
|
- }).appendTo("body").fadeIn(200);
|
26
|
|
- }
|
27
|
|
-
|
28
|
|
- function getDateKey(date) {
|
29
|
|
- return date.getFullYear() + '-' + (date.getMonth() < 9 ? '0' : '') + (date.getMonth() + 1);
|
30
|
|
- }
|
31
|
|
-
|
32
|
|
- function showSelectedMonths(start, end, incoming, outgoing) {
|
33
|
|
- $('#historytable tr.data').remove();
|
34
|
|
- $('#historytable').show();
|
35
|
|
-
|
36
|
|
- var startDate = new Date(start), endDate = new Date(end);
|
37
|
|
-
|
38
|
|
- if (startDate.getDate() > 1) {
|
39
|
|
- startDate.setDate(1);
|
40
|
|
- startDate.getMonth() == 11 && startDate.setYear(startDate.getFullYear() + 1);
|
41
|
|
- startDate.setMonth(startDate.getMonth() == 11 ? 0 : startDate.getMonth() + 1);
|
42
|
|
- }
|
43
|
|
-
|
44
|
|
- var startKey = getDateKey(startDate), endKey = getDateKey(endDate);
|
45
|
|
-
|
46
|
|
- if (startKey == endKey) {
|
47
|
|
- $('#historytable h3').text('Transactions for ' + months[startDate.getMonth()] + ' ' + startDate.getFullYear());
|
48
|
|
- } else if (startDate.getFullYear() == endDate.getFullYear()) {
|
49
|
|
- $('#historytable h3').text('Transactions for ' + months[startDate.getMonth()] + '-' + months[endDate.getMonth()] + ' ' + startDate.getFullYear());
|
50
|
|
- } else {
|
51
|
|
- $('#historytable h3').text('Transactions for ' + months[startDate.getMonth()] + ' ' + startDate.getFullYear() + ' - ' + months[endDate.getMonth()] + ' ' + endDate.getFullYear());
|
52
|
|
- }
|
53
|
|
-
|
54
|
|
- var pieData = {};
|
55
|
|
- var table = $('#historytable table');
|
56
|
|
- var include = false;
|
57
|
|
- $.each(data, function(month, monthData) {
|
58
|
|
- if (month == startKey) { include = true; }
|
59
|
|
-
|
60
|
|
- if (include) {
|
61
|
|
- $.each(monthData, function(index, trans) {
|
62
|
|
- if (incoming != trans.Amount > 0) { return; }
|
63
|
|
-
|
64
|
|
- var category = trans.Category ? trans.Category : 'Unsorted';
|
65
|
|
-
|
66
|
|
- var tr = $('<tr/>').addClass('data').addClass('category' + category.replace(/[^a-zA-Z]*/g, '')).appendTo(table);
|
67
|
|
-
|
68
|
|
- $('<td/>').text(trans.Date.date.split(' ')[0]).appendTo(tr);
|
69
|
|
- $('<td/>').text(trans.Type ? trans.Type : 'Other').appendTo(tr);
|
70
|
|
- $('<td/>').text(trans.Category ? trans.Category : '').appendTo(tr);
|
71
|
|
- $('<td/>').text(trans.Description).appendTo(tr);
|
72
|
|
- $('<td/>').text(trans.Amount).appendTo(tr);
|
73
|
|
-
|
74
|
|
- if (category != '(Ignored)') {
|
75
|
|
- if (!pieData[category]) { pieData[category] = 0; }
|
76
|
|
- pieData[category] += Math.abs(trans.Amount);
|
77
|
|
- }
|
78
|
|
- });
|
79
|
|
- }
|
80
|
|
-
|
81
|
|
- if (month == endKey) { include = false; }
|
82
|
|
- });
|
83
|
|
-
|
84
|
|
- var seriesData = [];
|
85
|
|
- $.each(pieData, function(category, amount) {
|
86
|
|
- seriesData.push({ label: category + ' (' + Math.round(amount) + ')', data: amount });
|
87
|
|
- });
|
88
|
|
-
|
89
|
|
- seriesData.sort(function(a, b) { return b.data - a.data; });
|
90
|
|
-
|
91
|
|
- plots.expense = $.plot($('#expense'), seriesData, {
|
92
|
|
- series: { pie: { show: true, innerRadius: 0.5, highlight: { opacity: 0.5 } } },
|
93
|
|
- grid: { clickable: true }
|
94
|
|
- });
|
95
|
|
- }
|
96
|
|
-
|
97
|
|
- $(function() {
|
98
|
|
- var transData = [{label: 'Income', data: []}, {label: 'Expense', data: []}, {label: 'Difference', data: []}];
|
99
|
|
- var min = new Date().getTime(), max = 0;
|
100
|
|
-
|
101
|
|
- $.each(data, function(month, entries) {
|
102
|
|
- var split = month.split('-');
|
103
|
|
- var timestamp = new Date(split[0], split[1] - 1).getTime();
|
104
|
|
- var sum = [0, 0];
|
105
|
|
-
|
106
|
|
- $.each(entries, function() {
|
107
|
|
- if (this.Category == '(Ignored)') { return; }
|
108
|
|
-
|
109
|
|
- sum[this.Amount < 0 ? 1 : 0] += this.Amount;
|
110
|
|
- });
|
111
|
|
-
|
112
|
|
- transData[0].data.push([timestamp, sum[0]]);
|
113
|
|
- transData[1].data.push([timestamp, sum[1]]);
|
114
|
|
- transData[2].data.push([timestamp, sum[0] + sum[1]]);
|
115
|
|
- min = Math.min(min, timestamp);
|
116
|
|
- max = Math.max(max, timestamp);
|
117
|
|
- });
|
118
|
|
-
|
119
|
|
- plots.history = $.plot($('#history'), transData, {
|
120
|
|
- xaxis: { mode: 'time', timeformat: '%y/%m'},
|
121
|
|
- series: {
|
122
|
|
- lines: { show: true, fill: true },
|
123
|
|
- points: { show: true }
|
124
|
|
- },
|
125
|
|
- grid: {
|
126
|
|
- hoverable: true,
|
127
|
|
- clickable: true,
|
128
|
|
- markings: [{ color: '#000', lineWidth: 1, xaxis: { from: min, to: max }, yaxis: { from: 0, to: 0 } }]
|
129
|
|
- },
|
130
|
|
- selection: { mode : "x" }
|
131
|
|
- });
|
132
|
|
-
|
133
|
|
- $("#history").bind("plothover", function (event, pos, item) {
|
134
|
|
- if (item) {
|
135
|
|
- var id = {dataIndex: item.dataIndex, seriesIndex: item.seriesIndex};
|
136
|
|
-
|
137
|
|
- if (previousPoint == null || previousPoint.dataIndex != id.dataIndex || previousPoint.seriesIndex != id.seriesIndex) {
|
138
|
|
- previousPoint = id;
|
139
|
|
-
|
140
|
|
- $("#tooltip").remove();
|
141
|
|
- var x = item.datapoint[0],
|
142
|
|
- y = item.datapoint[1].toFixed(2);
|
143
|
|
-
|
144
|
|
- var date = new Date(x);
|
145
|
|
-
|
146
|
|
- var seriesTitles = ["Money in", "Money out", "Balance change"];
|
147
|
|
- showTooltip(item.pageX, item.pageY, (seriesTitles[item.seriesIndex]) + " during " + months[date.getMonth()] + " " + date.getFullYear() + " = " + y);
|
148
|
|
- }
|
149
|
|
- } else {
|
150
|
|
- $("#tooltip").remove();
|
151
|
|
- previousPoint = null;
|
152
|
|
- }
|
153
|
|
- });
|
154
|
|
-
|
155
|
|
- $('#history').bind('plotselected', function(event, ranges) {
|
156
|
|
- var startDate = parseInt(ranges.xaxis.from.toFixed());
|
157
|
|
- var endDate = parseInt(ranges.xaxis.to.toFixed());
|
158
|
|
-
|
159
|
|
- $.history.load('start:' + startDate + ';end:' + endDate + ';type:expenses');
|
160
|
|
- });
|
161
|
|
-
|
162
|
|
- $('#history').bind('plotclick', function(event, pos, item) {
|
163
|
|
- if (item) {
|
164
|
|
- $.history.load('start:' + item.datapoint[0] + ';end:' + item.datapoint[0] + ';type:' + (item.seriesIndex == 0 ? 'income' : 'expenses'));
|
165
|
|
- }
|
166
|
|
- });
|
167
|
|
-
|
168
|
|
- $('#expense').bind('plotclick', function(event, pos, item) {
|
169
|
|
- $('#historytable .data').hide();
|
170
|
|
- $('#historytable .category' + item.series.label.replace(/[^a-zA-Z]*/g, '')).show();
|
171
|
|
- });
|
172
|
|
-
|
173
|
|
- $.history.init(function(hash) {
|
174
|
|
- var match = /start:([0-9]+);end:([0-9]+);type:(income|expenses)/.exec(hash);
|
175
|
|
-
|
176
|
|
- if (match != null) {
|
177
|
|
- showSelectedMonths(parseInt(match[1]), parseInt(match[2]), match[3] == 'income', match[3] == 'expenses');
|
178
|
|
- plots.history.setSelection({ xaxis: { from: parseInt(match[1]), to: parseInt(match[2]) }});
|
179
|
|
- }
|
180
|
|
- });
|
181
|
|
- });
|
182
|
|
- </script>
|
|
11
|
+ <script src="analyser.js" type="text/javascript"></script>
|
183
|
12
|
<style type="text/css">
|
184
|
13
|
.categoryIgnored td { color: gray; }
|
185
|
14
|
.left { width: 45%; padding: 20px; float: left; }
|
|
@@ -189,6 +18,10 @@
|
189
|
18
|
#header h1 { color: white; margin: 0; font-size: 60px; position: absolute; top: 42px; left: 20px; z-index: 2; }
|
190
|
19
|
#headershadow { font-size: 60px; position: absolute; top: 42px; left: 25px; font-weight: bold; z-index: 1; }
|
191
|
20
|
h2 { margin-top: 0; }
|
|
21
|
+ table { border-collapse: collapse; }
|
|
22
|
+ tr.alt td { background-color: #ddd; }
|
|
23
|
+ td { padding: 3px; }
|
|
24
|
+ th { text-align: left; }
|
192
|
25
|
</style>
|
193
|
26
|
</head>
|
194
|
27
|
<body>
|