-
Notifications
You must be signed in to change notification settings - Fork 1
/
WriteReports.gs
99 lines (89 loc) · 2.3 KB
/
WriteReports.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Validates and processes the ledger, retrieves the currenct crypto prices, and writes the reports.
* Uses the error handler to handle any ValidatioError, CryptoAccountError, or ApiError .
* Updates the data validation on the ledger currency and wallet columns.
* Displays toast on success.
*/
CryptoTracker.prototype.writeReports = function () {
let ledgerRecords;
try {
ledgerRecords = this.getLedgerRecords();
this.validateLedgerRecords(ledgerRecords);
}
catch (error) {
if (error instanceof ValidationError) {
this.handleError('validation', error.message, error.rowIndex, error.columnName);
return;
}
else {
throw error;
}
}
try {
this.processLedger(ledgerRecords);
}
catch (error) {
if (error instanceof CryptoAccountError) {
this.handleError('cryptoAccount', error.message, error.rowIndex, 'debitAmount');
return;
}
else {
throw error;
}
}
let apiError;
try {
this.exRatesSheet();
}
catch (error) {
if (error instanceof ApiError) {
//handle the error later
apiError = error;
}
else {
throw error;
}
}
this.fiatAccountsSheet();
this.openPositionsReport();
this.closedPositionsReport();
this.donationsReport();
this.incomeReport();
this.openSummaryReport();
this.closedSummaryReport();
this.incomeSummaryReport();
this.donationsSummaryReport();
this.cryptoWalletsReport();
this.fiatWalletsReport();
this.exRatesTable();
this.updateLedger();
if (apiError) {
this.handleError('api', apiError.message);
}
else {
SpreadsheetApp.getActive().toast('Reports complete', 'Finished', 10);
}
};
/**
* Deletes all the output sheets.
* Not intended for use by the end user.
* Useful in development and testing.
*/
CryptoTracker.prototype.deleteReports = function () {
let sheetNames = [
this.openPositionsReportName,
this.closedPositionsReportName,
this.donationsReportName,
this.incomeReportName,
this.openSummaryReportName,
this.closedSummaryReportName,
this.incomeSummaryReportName,
this.donationsSummaryReportName,
this.cryptoWalletsReportName,
this.fiatWalletsReportName,
this.exRatesTableSheetName,
this.exRatesSheetName,
this.fiatAccountsSheetName
];
this.deleteSheets(sheetNames);
};