-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnapshotValues.js
35 lines (30 loc) · 1018 Bytes
/
snapshotValues.js
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
function onOpen() {
setSnapshotValues();
}
/**
* Sets the portfolio values from snapshots according to recent entry
*/
function setSnapshotValues() {
var SUM_COLUMN = 'B';
var SUM_ROW_START = 17;
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var allocationSheet = spreadsheet.getSheetByName('Allocation');
var snapshotsSheet = spreadsheet.getSheetByName('Snapshots');
var lastColumn = snapshotsSheet.getLastColumn() - 2;
var sumTypes = {
'Cash Bank': 0,
'Crypto': 0,
'Numismatic': 0
};
for (var i = 3, type; (type = snapshotsSheet.getRange('B' + i).getValue()); i++) {
if (sumTypes.hasOwnProperty(type)) {
var val = snapshotsSheet.getRange(i, lastColumn).getValue();
val = val ? val : 0;
sumTypes[type] += parseFloat(val);
}
}
for (var type in sumTypes) {
allocationSheet.getRange(SUM_COLUMN + SUM_ROW_START).setValue(sumTypes[type]);
SUM_ROW_START++;
}
}