/
reports.tt
124 lines (113 loc) · 4.39 KB
/
reports.tt
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
117
118
119
120
121
122
123
124
<h1>Reports</h1>
<h2>Transactions by size</h2>
<div id="litres_per_txn" style="width:450px;height:300px"></div>
<div>
<input type="button" class="btn" id="litres_per_txn_day" value="Today">
<input type="button" class="btn" id="litres_per_txn_week" value="Last Week" />
<input type="button" class="btn" id="litres_per_txn_month" value="Last Month" />
<input type="button" class="btn" id="litres_per_txn_year" value="Last Year" />
<input type="button" class="btn" id="litres_per_txn_alltime" value="All Time" />
</div>
<h2>Litres sold per day of week</h2>
<div id="litres_per_day" style="width:450px;height:300px"></div>
<div>
<input type="button" class="btn" id="litres_per_day_week" value="Last Week" />
<input type="button" class="btn" id="litres_per_day_month" value="Last Month" />
<input type="button" class="btn" id="litres_per_day_year" value="Last Year" />
<input type="button" class="btn" id="litres_per_day_alltime" value="All Time" />
</div>
<h2>Cumulative membership</h2>
<div id="cumulative_members" style="width:452px;height:300px"></div>
<h2>Cumulative litres sold</h2>
<div id="cumulative_litres" style="width:452px;height:300px"></div>
<script src="/javascripts/libs/jquery.flot.js"></script>
<script type="text/javascript">
$(function () {
var litres_per_txn_config = {
bars: { show: true, barWidth: 10 },
options: {
xaxis: { tickFormatter:
function suffixFormatter (val, axis) {
return val.toFixed(axis.tickDecimals) + "L";
},
tickSize: 10
},
yaxis: { tickFormatter:
function suffixFormatter (val, axis) {
return val.toFixed(axis.tickDecimals) + " Txns";
},
tickDecimals: 0
}
}
};
var litres_per_day_config = {
bars: { show: true, barWidth: 1 },
options: {
xaxis: { tickFormatter:
function suffixFormatter (val, axis) {
return val.toFixed(axis.tickDecimals) + "L";
},
ticks: [[0,"Sun"], [1, "Mon"], [2, "Tue"], [3, "Wed"], [4, "Thu"], [5, "Fri"], [6, "Sat"]],
},
yaxis: { tickFormatter:
function suffixFormatter (val, axis) {
return val.toFixed(axis.tickDecimals) + "L";
},
tickDecimals: 0
}
}
};
$.plot($("#litres_per_txn"), [ {
data: [% stats.litres_per_txn %],
bars: litres_per_txn_config.bars
}],
litres_per_txn_config.options
);
$.plot($("#litres_per_day"), [ {
data: [% stats.litres_per_day %],
bars: litres_per_day_config.bars
}],
litres_per_day_config.options
);
$.plot($("#cumulative_members"), [ {
data: [% stats.cumulative_members %],
}],
{ xaxis: { mode: "time" }}
);
$.plot($("#cumulative_litres"), [ {
data: [% stats.cumulative_litres %],
}],
{ xaxis: { mode: "time" }}
);
function litres_per_txn_onDataReceived(series) {
var bars = litres_per_txn_config.bars;
var options = litres_per_txn_config.options;
$.plot($("#litres_per_txn"), [{data:series, bars:bars}], options);
}
function litres_per_day_onDataReceived(series) {
var bars = litres_per_day_config.bars;
var options = litres_per_day_config.options;
$.plot($("#litres_per_day"), [{data:series, bars:bars}], options);
}
var reports = ["litres_per_txn", "litres_per_day"];
var times = ["day", "week", "month", "year", "alltime"];
function getClickFunction (report, time) {
var url = "reports/" + report + "/" + time;
return function () {
$.ajax({
url: url,
method: 'GET',
dataType: 'json',
success: eval (report + "_onDataReceived")
});
}
}
for (var i = 0; i < reports.length; i++) {
for (var j = 0; j < times.length; j++) {
var clickFunction = getClickFunction(reports[i], times[j])
var button = $("#" + reports[i] + "_" + times[j]);
if (button.length) button.click(clickFunction);
}
}
});
</script>