-
Notifications
You must be signed in to change notification settings - Fork 1
/
FiatAccountsSheet.gs
66 lines (45 loc) · 1.62 KB
/
FiatAccountsSheet.gs
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
/**
* Creates the fiat accounts sheet if it doesn't already exist.
* Updates the sheet with the current fiat accounts data.
* Trims the sheet to fit the data.
*/
CryptoTracker.prototype.fiatAccountsSheet = function () {
const sheetName = this.fiatAccountsSheetName;
let ss = SpreadsheetApp.getActive();
let sheet = ss.getSheetByName(sheetName);
if (!sheet) {
sheet = ss.insertSheet(sheetName);
let headers = [['Wallet', 'Currency', 'Balance']];
sheet.getRange('A1:C1').setValues(headers).setFontWeight('bold').setHorizontalAlignment("center");
sheet.setFrozenRows(1);
sheet.getRange('A2:A').setNumberFormat('@');
sheet.getRange('B2:B').setNumberFormat('@');
sheet.getRange('C2:C').setNumberFormat('#,##0.00;(#,##0.00)');
sheet.hideSheet();
let protection = sheet.protect().setDescription('Essential Data Sheet');
protection.setWarningOnly(true);
}
let dataTable = this.getFiatTable();
this.writeTable(ss, sheet, dataTable, this.fiatAccountsRangeName, 1, 3);
};
/**
* Returns a table of the current fiat accounts data.
* The fiat accounts data is collected when the ledger is processed.
* @return {Array<Array>} The current fiat accounts data.
*/
CryptoTracker.prototype.getFiatTable = function () {
let table = [];
for (let wallet of this.wallets) {
for (let fiatAccount of wallet.fiatAccounts) {
table.push([wallet.name, fiatAccount.ticker, fiatAccount.balance]);
}
}
table.sort(function (a, b) {
return a[0] > b[0] ? 1 :
b[0] > a[0] ? -1 :
a[1] > b[1] ? 1 :
b[1] > a[1] ? -1 :
0;
});
return table;
};