-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiAdditions.gs
73 lines (54 loc) · 2.15 KB
/
uiAdditions.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
function onOpenAddUI() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('AC system')
.addItem('User paid', 'userPaidFunctionUI')
.addToUi();
}
function userPaidFunctionUI(){
var ui = SpreadsheetApp.getUi(); // Same variations.
var result = ui.prompt(
'Enter information about payment',
'Please user id, amount paid, and currency (CZK or EUR); all separated with ";".\n E.g.: "9510234298;CZK;2000"',
ui.ButtonSet.OK);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
if (button == ui.Button.CLOSE || text == null || text == '') {
return;
}
var matches = text.match(/^([0-9]{10});((CZK)|(EUR));([0-9]+)$/);
if(matches == null || matches.length != 6){
ui.alert("Incorrect format :(.");
return;
}
var varSymbol = matches[1];
var transactionObj = {
'currency' : matches[2],
'amount' : matches[5],
'variableSymbol' : varSymbol,
}
runtimeLog(varSymbol);
runtimeLog(transactionObj);
updateBankInfoWithTransactionObj(varSymbol, transactionObj);
}
function updateBankInfoWithTransactionObj(varSymbol, transactionObj){
var sheetName = 'money info';
var varSymbolIndex = 2;
var searchValue = varSymbol;
var rowInfo = findRowIndexAndRangeInSheet(sheetName, searchValue, varSymbolIndex); runtimeLog(rowInfo);
if(rowInfo == null) {return;}
writeDownInfoAboutDirectPayment(rowInfo, transactionObj);
writeDownTransactionToBankInfo(transactionObj, rowInfo.range, rowInfo.indexInRange);
}
function writeDownInfoAboutDirectPayment(rowInfo, transactionObj){
var otherNotesIndex = 15;
var indexInRange = rowInfo.indexInRange;
var currRange = rowInfo.range;
var currUserEmail = Session.getActiveUser().getEmail();
var newEntry = currUserEmail + ": " + transactionObj.amount + ' ' + transactionObj.currency;
var cellValue = currRange.getValues()[indexInRange][otherNotesIndex];
if(cellValue != null || cellValue != undefined) { cellValue += '\n'; }
else {cellValue = '';}
cellValue += newEntry;
currRange.getSheet().getRange(indexInRange + 1, otherNotesIndex + 1).setValue(cellValue);
}