-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspendover500.njk
116 lines (108 loc) · 3.88 KB
/
spendover500.njk
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
---
pagination:
data: collections.spendsOver500
size: 1
alias: spends
layout: base
permalink: "spends/{{ spends.title | slugify }}/"
layout: base
eleventyComputed:
title: "Spends over £500 - {{ spends.displayTitle }}"
description: "Transactions with spend over £500 for {{spends.displayTitle}}"
---
{% set json_link = "/spends/" + spends.title + ".json" %}
<link rel="alternate" type="application/json" title="JSON version of {{description}}" href="{{json_link}}">
<script id="spend-data" type="application/json">
{{spends.data | jsonify | safe }}
</script>
<nav>
<ul class="pagination">
{% if pagination.href.previous != null %}
<li class="page-item">
<a class="page-link" href="{{pagination.href.previous}}">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous month</span>
</a>
</li>
{% endif %}
<li class="page-item">
<a class="page-link" href="/">Home</a>
</li>
{% if pagination.href.next != null %}
<li class="page-item">
<a class="page-link" href="{{pagination.href.next}}">
<span class="sr-only">Next month</span>
<span aria-hidden="true">»</span>
</a>
</li>
{% endif %}
</ul>
</nav>
<h1>{{title}}</h1>
<div class="row">
<div class="col-lg-8 col-12">
<table class="table table-bordered">
<thead>
<tr>
<th colspan="2" class="text-center bg-light">Spend profile</th>
</tr>
</thead>
{% set total_spend = spends.data | sum("Transaction Amount") %}
{% set transaction_count = spends.data | length %}
{% set average_spend = total_spend / transaction_count %}
<tbody>
<tr>
<th class="bg-light">Total spend</th>
<td>{{total_spend | toCurrency }}</td>
</tr>
<tr>
<th class="bg-light">Transaction count</th>
<td>{{transaction_count }}</td>
</tr>
<tr>
<th class="bg-light">Average transaction spend</th>
<td>{{ average_spend | toCurrency }}</td>
</tr>
<tr>
<th class="bg-light">Top spender</th>
<td>{{ spends.data | findTopSpender }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="btn-group" role="group">
<a href="{{json_link}}" target="_blank" class="btn btn-primary">JSON</a>
</div>
<div id="chart-spend-by-directorate" style="width:100%; height:600px;"></div>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Directorate</th>
<th>Merchant name</th>
<th>Merchant category name</th>
<th>Transaction date</th>
<th>Transaction amount</th>
<th>Expense description</th>
</tr>
</thead>
<tbody>
{% for row in spends.data %}
<tr>
<td>{{row["Directorate"]}}</td>
<td>{{row["Merchant Name"]}}</td>
<td>{{row["Merchant Category Name"]}}</td>
<td>{{row["Transaction Date"]}}</td>
<td>{{row["Transaction Amount"] | fixed }}</td>
<td>{{row["Expense Description"]}}</td>
</tr>
{%endfor%}
</tbody>
</table>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
charts.spendByDirectorate("spend-data", "chart-spend-by-directorate");
});
</script>