File tree 2 files changed +37
-9
lines changed
2 files changed +37
-9
lines changed Original file line number Diff line number Diff line change 1
1
module . exports = function ( eleventyConfig ) {
2
+ const _ = require ( "lodash" )
3
+
2
4
eleventyConfig . addLayoutAlias ( 'base' , 'layouts/base.njk' ) ;
3
5
4
6
eleventyConfig . addCollection ( "spendsOver500" , ( collection ) => {
@@ -29,15 +31,30 @@ module.exports = function (eleventyConfig) {
29
31
} , 0 ) ;
30
32
} ) ;
31
33
34
+ const GBPFormat = new Intl . NumberFormat ( 'en-GB' , {
35
+ style : 'currency' ,
36
+ currency : 'GBP' ,
37
+ } ) ;
38
+
39
+ function toCurrency ( value ) {
40
+ return GBPFormat . format ( value ) ;
41
+ }
42
+
32
43
eleventyConfig . addFilter ( "toCurrency" , function ( value ) {
33
- let GBPFormat = new Intl . NumberFormat ( 'en-GB' , {
34
- style : 'currency' ,
35
- currency : 'GBP' ,
36
- } ) ;
44
+ return toCurrency ( value ) ;
45
+ } )
37
46
38
- return GBPFormat . format ( value ) ;
47
+ eleventyConfig . addFilter ( "findTopSpender" , function ( value ) {
48
+ var maxSpend = _ ( value )
49
+ . groupBy ( "Directorate" )
50
+ . map ( ( directorate , total ) => ( {
51
+ directorate : total ,
52
+ total : _ . sumBy ( directorate , "Transaction Amount" )
53
+ } ) )
54
+ . maxBy ( "total" ) ;
55
+
56
+ return `${ maxSpend . directorate } (${ toCurrency ( maxSpend . total ) } )` ;
39
57
} )
40
58
41
59
eleventyConfig . addPassthroughCopy ( "CNAME" ) ;
42
-
43
60
} ;
Original file line number Diff line number Diff line change @@ -20,21 +20,32 @@ eleventyComputed:
20
20
<h1 >{{ title }} </h1 >
21
21
22
22
<div class =" row" >
23
- <div class =" col-lg-6 col-12" >
23
+ <div class =" col-lg-8 col-12" >
24
24
<table class =" table table-bordered" >
25
25
<thead >
26
26
<tr >
27
27
<th colspan =" 2" class =" text-center bg-light" >Spend profile</th >
28
28
</tr >
29
29
</thead >
30
+ {% set total_spend = spends .data | sum (" Transaction Amount" ) %}
31
+ {% set transaction_count = spends .data | length %}
32
+ {% set average_spend = total_spend / transaction_count %}
30
33
<tbody >
31
34
<tr >
32
35
<th class =" bg-light" >Total spend</th >
33
- <td >{{ spends . data | sum ( " Transaction Amount " ) | toCurrency }} </td >
36
+ <td >{{ total_spend | toCurrency }} </td >
34
37
</tr >
35
38
<tr >
36
39
<th class =" bg-light" >Transaction count</th >
37
- <td >{{ spends .data | length }} </td >
40
+ <td >{{ transaction_count }} </td >
41
+ </tr >
42
+ <tr >
43
+ <th class =" bg-light" >Average transaction spend</th >
44
+ <td >{{ average_spend | toCurrency }} </td >
45
+ </tr >
46
+ <tr >
47
+ <th class =" bg-light" >Top spender</th >
48
+ <td >{{ spends .data | findTopSpender }} </td >
38
49
</tr >
39
50
</tbody >
40
51
</table >
You can’t perform that action at this time.
0 commit comments