-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-1.html
More file actions
124 lines (110 loc) · 3.32 KB
/
index-1.html
File metadata and controls
124 lines (110 loc) · 3.32 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Elijah's日常消费记录</title>
<script src="https://code.jquery.com/jquery-3.7.0.min.js" ></script>
<script src="https://momentjs.com/downloads/moment.min.js" ></script>
<script src="./data.js"></script>
<script>
$.when( $.ready ).then(function() {
var html = "<table border='1'>"
html +="<tr>";
for (key in dailyColumns) {
html +="<td>";
html += dailyColumns[key];
html +="</td>";
}
html +="</tr>";
for (index in dailyDatas) {
//console.log(dailyDatas[index]);
html +="<tr>";
for (key in dailyColumns) {
html +="<td>";
html += dailyDatas[index][dailyColumns[key]];
html +="</td>";
}
html +="</tr>";
}
html += "</table>";
$("#dailyTable").html(html);
$("#statisticTable").html("<tr><td>统计(Only Elijah&Jing):"+cal(dailyDatas)+"</td></tr>");
var filterByDateData = filterByDate(dailyDatas);
for(key1 in filterByDateData){
var html = $("#statisticTable").html()
var child = "<tr><td>月份"+key1+" :"+cal(filterByDateData[key1])+"<br/>明细分类统计:<br/><ul>";
var categoryData = filterByCategory(filterByDateData[key1])
//console.log("categoryData"+JSON.stringify(categoryData));
for(category in categoryData){
child +="<li>"+category+" :"+cal(categoryData[category])+"</li>"
}
child += "</ul></td></tr>";
$("#statisticTable").html(html+child);
}
});
function filterByDate(dailyDatas){
var data = {};
for (const index in dailyDatas) {
var key = moment(new Date(dailyDatas[index].date)).format('YYYY-MM');
if(data[key] == undefined){
data[key] = [];
}
data[key].push(dailyDatas[index]);
}
return data;
}
function filterByCategory(dateGroupedDataList){
var data = {};
for (const index in dateGroupedDataList) {
var key = dateGroupedDataList[index].subCategory;
//console.log("分类:"+key);
if(data[key] == undefined){
data[key] = [];
}
data[key].push(dateGroupedDataList[index]);
}
return data;
}
function cal(dailyDatas){
var currencyAmount = {};
for (index in dailyDatas) {
var drcr = dailyDatas[index].drcr;
if("D" != drcr && 'C' != drcr){
continue;
}
var currency = dailyDatas[index].currency+"("+(drcr=='D'?"支出":"收入")+")";
if(currencyAmount[currency] == undefined){
currencyAmount[currency] = {amount: 0};
}
currencyAmount[currency].amount += parseFloat(dailyDatas[index].amount)*(drcr=='D'?-1:1);
}
var statisticValue = "";
var totalCNY = 0;
for (key in currencyAmount) {
var amount = currencyAmount[key].amount;
if(key.indexOf('AED') >= 0){
var cny = Math.round( amount*1.95 * 10 ) / 10 ;
statisticValue += key +":" + amount + "*1.95=CNY:" + (cny) + ","
totalCNY += cny;
}else if(key.indexOf('CNY') >= 0){
statisticValue += key +":"+amount+","
totalCNY += amount;
}else{
console.log(key+" 币种不支持");
}
}
return statisticValue+";<label style='color:red'>总计(CNY):"+totalCNY.toFixed(2)+"</label>";
}
</script>
</head>
<body>
<table>
<tr>
<td><div id = "dailyTable" ></div></td>
<td valign="top">
<table id="statisticTable" border="1"></table>
</td>
</tr>
</table>
</body>
</html>