-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIncomeReport.gs
84 lines (62 loc) · 2 KB
/
IncomeReport.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Creates the income report if it doesn't already exist.
* Updates the sheet with the current income data.
* Trims the sheet to fit the data.
*/
CryptoTracker.prototype.incomeReport = function () {
const sheetName = this.incomeReportName;
let ss = SpreadsheetApp.getActive();
let sheet = ss.getSheetByName(sheetName);
if (!sheet) {
sheet = ss.insertSheet(sheetName);
let headers = [
[
'Date Time',
'Currency',
'Ex Rate',
'Amount',
'Wallet',
'Income Value'
]
];
sheet.getRange('A1:F1').setValues(headers).setFontWeight('bold').setHorizontalAlignment("center");
sheet.setFrozenRows(1);
sheet.getRange('A2:A').setNumberFormat('yyyy-mm-dd hh:mm:ss');
sheet.getRange('B2:B').setNumberFormat('@');
sheet.getRange('C2:C').setNumberFormat('#,##0.00000;(#,##0.00000);');
sheet.getRange('D2:D').setNumberFormat('#,##0.00000000;(#,##0.00000000)');
sheet.getRange('E2:E').setNumberFormat('@');
sheet.getRange('F2:F').setNumberFormat('#,##0.00;(#,##0.00)');
const formulas = [[
`IF(ISBLANK(A2),,ArrayFormula(FILTER(D2:D*C2:C, LEN(A2:A))))`
]];
sheet.getRange('F2:F2').setFormulas(formulas);
let protection = sheet.protect().setDescription('Essential Data Sheet');
protection.setWarningOnly(true);
}
let dataTable = this.getIncomeTable();
this.writeTable(ss, sheet, dataTable, this.incomeRangeName, 1, 5, 1);
};
/**
* Returns a table of the current income data.
* The income data is collected when the ledger is processed.
* @return {Array<Array>} The current income data.
*/
CryptoTracker.prototype.getIncomeTable = function () {
let table = [];
for (let lot of this.incomeLots) {
let date = lot.date;
let currency = lot.debitCurrency;
let exRate = lot.debitExRate;
let amount = lot.debitAmount;
let wallet = lot.walletName;
table.push([
date,
currency,
exRate,
amount,
wallet
]);
}
return this.sortTable(table, 0);
};