-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatCommand.js
More file actions
201 lines (144 loc) · 5 KB
/
Copy pathchatCommand.js
File metadata and controls
201 lines (144 loc) · 5 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
function listCommand(){
sendB(
`Commands:
1. <a href="#" onclick="">balance (tb)</a>
2. <a href="#" onclick="cmdinputadd('tin')" >income (tin)</a>
3. <a href="#" onclick="cmdinputadd('te')" >expense (te) </a>
4. <a href="#" onclick="cmdinputadd('te from education')" >expense from category</a>
5. <a href="#" onclick="cmdinputadd('income from example 2025-01-01 to 2026-01-01 sum')" > income from source from-date to to-date sum </a>
6. <a href="#" onclick="cmdinputadd('income from example 2025-01-01 to 2026-01-01 sum chart bar')" > income from source from-date to to-date sum chart bar</a>
7. <a href="#" onclick="cmdinputadd('ls src')" >ls src </a>
8. <a href="#" onclick="cmdinputadd('ls expense category')" > ls expense category </a>
9. <a href="#" onclick="cmdinputadd('not chng')" > not chng </a>
10. <a href="#" onclick="cmdinputadd('not off')" > not off </a>
11. <a href="#" onclick="cmdinputadd('ieb')" > ieb </a>
12. <a href="#" onclick="cmdinputadd('ieb chart pie')" > ieb chart pie/bar/line </a>
13. <a href="#" onclick="cmdinputadd('lend tot')" > lend tot </a>
14. <a href="#" onclick="cmdinputadd('lend sum')" > lend sum </a>
15. <a href="#" onclick="cmdinputadd('ls lend')" > ls lend </a>
15. <a href="#" onclick="cmdinputadd('lend name person_name')" >lend name person_name</a>
15. <a href="#" onclick="cmdinputadd('ls lend name')" > ls lend name</a>
15. <a href="#" onclick="cmdinputadd('lend sum chart pie')" > lend chart bar/pie</a>
`
);
}
function totalLendByType(x) {
let borrowTotal = 0;
let receivableTotal = 0;
lenddata.forEach(item => {
if (item.type === "B") {
borrowTotal += item.amount;
} else if (item.type === "R") {
receivableTotal += item.amount;
}
});
if(x === "bar" || x=== "pie"){
showLendChart(["Total","Recivable","Borrow"],borrowTotal+receivableTotal,receivableTotal,borrowTotal,x);
}else{
sendB(` Lend \n borrow : ${borrowTotal} \n recivable : ${receivableTotal} \n\n Total : ${borrowTotal+receivableTotal}`);
}
}
function lendByName(targetName) {
let borrow = 0;
let receivable = 0;
const nameKey = targetName.trim().toLowerCase();
lenddata.forEach(item => {
if (item.name.trim().toLowerCase() === nameKey) {
if (item.type === "B") {
borrow += Number(item.amount);
} else if (item.type === "R") {
receivable += Number(item.amount);
}
}
});
sendB(` name : ${targetName} \n Borrow : ${borrow} \n Recivable : ${receivable}`);
}
function listLend(){
Object.values(lenddata).forEach((v, i) => {
sendB(`${i}.
<span style="color:red;font-weight:bold">name :</span> ${v.name}
<span style="color:lightgreen;font-weight:bold">${v.type === "R" ? "Recivable" : "Borrow"} :</span> ${v.amount}
<span style="color:skyblue;font-weight:bold">date :</span> ${v.date}
<span style="color:brown;font-weight:bold">details :</span> ${v.description}
`);
});
}
function lendNames() {
const names = [...new Set(lenddata.map(x => x.name.trim()))];
let out = "Lend \n\n";
names.forEach((name, i) => {
out += `<a href="#" onclick="cmdinputadd('lend name ${name}')">${i + 1}. ${name}</a><br>`;
});
sendB(out);
}
function lendsummary() {
const map = {};
lenddata.forEach(item => {
const name = item.name.trim();
if (!map[name]) {
map[name] = { borrow: 0, receivable: 0 };
}
if (item.type === "B") {
map[name].borrow += Number(item.amount);
} else if (item.type === "R") {
map[name].receivable += Number(item.amount);
}
});
let html = `
<table style="width:100%;border-collapse:collapse;font-family:monospace">
<thead>
<tr style="background:#222;color:#fff">
<th style="border:1px solid #555;padding:6px">Name</th>
<th style="border:1px solid #555;padding:6px;color:#ff6b6b">Borrow</th>
<th style="border:1px solid #555;padding:6px;color:#6bff95">Receivable</th>
</tr>
</thead>
<tbody>
`;
Object.keys(map).forEach(name => {
html += `
<tr>
<td style="border:1px solid #555;padding:2px">${name}</td>
<td style="border:1px solid #555;padding:2px;">${map[name].borrow}</td>
<td style="border:1px solid #555;padding:2px;">${map[name].receivable}</td>
</tr>
`;
});
html += `
</tbody>
</table>
`;
sendB(html);
}
function listSource(){
const s = [...new Set(data.map(x => x.from).filter(Boolean))];
sendB(s.join("\n") || "No sources");
}
function cmdinputadd(x){
document.getElementById("chat-i").value=x;
}
function listExpenseCategory(){
const cats = [
...new Set(
data.flatMap(x =>
x.transactions?.map(tr => tr.category).filter(Boolean)
)
)
];
sendB(cats.join("\n") || "No caloriers found");
}
function expenseFrom(cat){
let sum = 0;
data.forEach(x => {
x.transactions?.forEach(tr => {
if (tr.category?.toLowerCase() === cat) {
sum += tr.amount || 0;
}
});
});
sendB(
sum
? `Total expense for "${cat}": ${sum}`
: `No expenses found for "${cat}"`
);
}