Quellcode durchsuchen

Add total to the transactions table

Closes #2
master
Chris Smith vor 13 Jahren
Ursprung
Commit
1631bb6ecf
2 geänderte Dateien mit 20 neuen und 14 gelöschten Zeilen
  1. 18
    13
      analyser.js
  2. 2
    1
      index.html

+ 18
- 13
analyser.js Datei anzeigen

@@ -317,23 +317,24 @@ function showSelectedMonths(start, end, incoming, outgoing, categoryFilter, expa
317 317
 
318 318
  $('#historytable h3').text((categoryFilter ? categoryFilter + ' t' : 'T') + 'ransactions for ' + startDate.getRangeText(endDate));
319 319
 
320
- var table = $('#historytable table');
321
- var lastEntry = {};
322
- var id = 0;
323 320
  var included = getDataForRange(startDate, endDate);
324 321
  var filtered = $.grep(included, function(x) {
325 322
   var category = x.Category ? x.Category : 'Unsorted';
326 323
   return (incoming == x.Amount > 0) && (!categoryFilter || categoryFilter == category);
327 324
  });
328 325
 
326
+ var table = $('#historytable table');
327
+ var total = 0;
328
+ var lastEntry = {};
329
+ var id = 0;
329 330
  $.each(filtered, function() {
330
-  trans = this;
331
+  total += this.Amount;
331 332
 
332
-  var category = trans.Category ? trans.Category : 'Unsorted';
333
+  var category = this.Category ? this.Category : 'Unsorted';
333 334
 
334 335
   var tr = $('<tr/>').addClass('data').addClass('category' + category.replace(/[^a-zA-Z]*/g, '')).appendTo(table);
335 336
 
336
-  if (shouldMerge(lastEntry, trans)) {
337
+  if (shouldMerge(lastEntry, this)) {
337 338
    if (lastEntry.id) {
338 339
     var prefix = '(' + (expanded[lastEntry.id] ? '-' : '+');
339 340
     lastEntry.count++;
@@ -347,23 +348,27 @@ function showSelectedMonths(start, end, incoming, outgoing, categoryFilter, expa
347 348
     a.data('single', lastEntry.Amount);
348 349
    }
349 350
 
350
-   lastEntry.Amount = Math.round(100 * (lastEntry.Amount + trans.Amount)) / 100;
351
+   lastEntry.Amount = Math.round(100 * (lastEntry.Amount + this.Amount)) / 100;
351 352
    $('#collapseHandle' + lastEntry.id).data('total', lastEntry.Amount);
352 353
 
353 354
    !expanded[lastEntry.id] && tr.hide() && $('.amount', lastEntry.tr).text(lastEntry.Amount);
354 355
 
355 356
    tr.addClass('collapsed hidden' + lastEntry.id);
356 357
   } else {
357
-    lastEntry = $.extend({}, trans, {tr: tr});
358
+    lastEntry = $.extend({}, this, {tr: tr});
358 359
   }
359 360
 
360
-  $('<td/>').text(trans.Date.date.split(' ')[0]).appendTo(tr);
361
-  $('<td/>').text(trans.Type ? trans.Type : 'Other').appendTo(tr);
362
-  $('<td/>').text(trans.Category ? trans.Category : '').appendTo(tr);
363
-  $('<td/>').addClass('desc').text(trans.Description).appendTo(tr);
364
-  $('<td/>').addClass('amount').text(trans.Amount).appendTo(tr);
361
+  $('<td/>').text(this.Date.date.split(' ')[0]).appendTo(tr);
362
+  $('<td/>').text(this.Type ? this.Type : 'Other').appendTo(tr);
363
+  $('<td/>').text(this.Category ? this.Category : '').appendTo(tr);
364
+  $('<td/>').addClass('desc').text(this.Description).appendTo(tr);
365
+  $('<td/>').addClass('amount').text(this.Amount).appendTo(tr);
365 366
  });
366 367
 
368
+ var tr = $('<tr/>').addClass('data total').appendTo(table);
369
+ $('<th colspan="4" class="total">Total</th>').appendTo(tr);
370
+ $('<td class="amount"></td>').text(total).appendTo(tr);
371
+
367 372
  colourTableRows(table);
368 373
  drawCategoryPieChart(included, incoming);
369 374
 }

+ 2
- 1
index.html Datei anzeigen

@@ -22,10 +22,11 @@
22 22
    table { border-collapse: collapse; }
23 23
    tr.alt td { background-color: #ddd; }
24 24
    td { padding: 3px; }
25
-   th { text-align: left; }
25
+   th { text-align: left; padding: 5px; }
26 26
    .graph { margin-bottom: 40px; }
27 27
    .link { color: blue; text-decoration: underline; cursor: pointer; }
28 28
    #historytable tr.collapsed { opacity: 0.6; }
29
+   table tr.total td, table tr.total th { background-color: #666; color: #fff; }
29 30
   </style>
30 31
  </head>
31 32
  <body>

Laden…
Abbrechen
Speichern