Explorar el Código

Group items in transaction history

master
Chris Smith hace 13 años
padre
commit
cc008aa7f5
Se han modificado 2 ficheros con 43 adiciones y 4 borrados
  1. 41
    4
      analyser.js
  2. 2
    0
      index.html

+ 41
- 4
analyser.js Ver fichero

@@ -48,6 +48,8 @@ function showSelectedMonths(start, end, incoming, outgoing) {
48 48
  var pieData = {};
49 49
  var table = $('#historytable table');
50 50
  var include = false;
51
+ var lastEntry = {};
52
+ var id = 0;
51 53
  $.each(data, function(month, monthData) {
52 54
   if (month == startKey) { include = true; }
53 55
 
@@ -56,14 +58,49 @@ function showSelectedMonths(start, end, incoming, outgoing) {
56 58
     if (incoming != trans.Amount > 0) { return; }
57 59
 
58 60
     var category = trans.Category ? trans.Category : 'Unsorted';
59
-
60 61
     var tr = $('<tr/>').addClass('data').addClass('category' + category.replace(/[^a-zA-Z]*/g, '')).appendTo(table);
61
- 
62
+
63
+    if (lastEntry.Description == trans.Description && lastEntry.Type == trans.Type && lastEntry.Category == lastEntry.Category) {
64
+     tr.hide();
65
+
66
+     if (lastEntry.id) {
67
+      lastEntry.count++;
68
+      $('span', lastEntry.tr).text('(+' + lastEntry.count + ')');
69
+     } else {
70
+      lastEntry.id = ++id;
71
+      lastEntry.count = 1;
72
+      var a = $('<span>').addClass('link').text('(+1)').appendTo($('td.desc', lastEntry.tr).append(' '));
73
+      a.data('otherAmount', lastEntry.Amount);
74
+      a.bind('click', { id: lastEntry.id, tr: lastEntry.tr }, function(event) {
75
+       $('.hidden' + event.data.id).toggle();
76
+
77
+       var text = $(this).text();
78
+       text = (text.substr(0, 2) == '(+' ? '(-' : '(+') + text.substr(2);
79
+       $(this).text(text);
80
+
81
+       var amount = $('.amount', event.data.tr);
82
+       var oldAmount = amount.text();
83
+       amount.text($(this).data('otherAmount'));
84
+       $(this).data('otherAmount', oldAmount);
85
+
86
+       colourTableRows($('#historytable'));
87
+      });
88
+     }
89
+
90
+     lastEntry.Amount = Math.round(100 * (lastEntry.Amount + trans.Amount)) / 100;
91
+     $('.amount', lastEntry.tr).text(lastEntry.Amount);
92
+
93
+     tr.addClass('collapsed hidden' + lastEntry.id);
94
+    } else {
95
+     lastEntry = trans;
96
+     lastEntry.tr = tr;
97
+    }
98
+
62 99
     $('<td/>').text(trans.Date.date.split(' ')[0]).appendTo(tr);
63 100
     $('<td/>').text(trans.Type ? trans.Type : 'Other').appendTo(tr);
64 101
     $('<td/>').text(trans.Category ? trans.Category : '').appendTo(tr);
65
-    $('<td/>').text(trans.Description).appendTo(tr);
66
-    $('<td/>').text(trans.Amount).appendTo(tr);
102
+    $('<td/>').addClass('desc').text(trans.Description).appendTo(tr);
103
+    $('<td/>').addClass('amount').text(trans.Amount).appendTo(tr);
67 104
  
68 105
     if (category != '(Ignored)') {
69 106
      if (!pieData[category]) { pieData[category] = 0; }

+ 2
- 0
index.html Ver fichero

@@ -24,6 +24,8 @@
24 24
    td { padding: 3px; }
25 25
    th { text-align: left; }
26 26
    .graph { margin-bottom: 40px; }
27
+   .link { color: blue; text-decoration: underline; cursor: pointer; }
28
+   #historytable tr.collapsed { opacity: 0.6; }
27 29
   </style>
28 30
  </head>
29 31
  <body>

Loading…
Cancelar
Guardar