-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLA.gs
106 lines (88 loc) · 2.63 KB
/
GLA.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
100
101
102
103
104
105
106
function GLArequestEast() {
East.GLArequest()
}
function GLArequestWest() {
West.GLArequest()
}
function GLArequestSouth() {
South.GLArequest()
}
function GLArequestNorth() {
North.GLArequest()
}
function GLArequestSoutheast() {
Southeast.GLArequest()
}
function GLArequestSouthwest() {
Southwest.GLArequest()
}
function GLArequestNortheast() {
Northeast.GLArequest()
}
function GLArequestNorthwest() {
Northwest.GLArequest()
}
// ---------------------------------------------------------------
function GLArequestsort(reqval, GLArequests, div, sheet) {
// arrays to track failed GLA requests
var newheader = []
var newvalue = []
// array within an array because getValues
var arrayLength = reqval[0].length;
for (var i = 0; i < arrayLength; i++) {
// check for upper & lower case
var p = reqval[0][i].toUpperCase();
try{
var abbrev = new Abbrev(p)
}
catch(error){
SpreadsheetApp.getUi().alert('Oops! "' + error)
console.log(error)
}
var cell = GLAIteEmpty(abbrev.division)
if (cell !== null){
var id = abbrev.player + div
var value = reqval[1][i]
cell.setValues([[id],[value]])
// add onto sheet global tally
var range = sheet.getRange("AB2")
var GLAtally = range.getValue()
range.setValue(GLAtally+ +1)
} else {
newheader.push(p)
newvalue.push(reqval[1][i])
}
}
// fill up the lists to 4 values per array
while (newheader.length < 4){
newheader.push('')
newvalue.push('')
}
// print it back to request
var newlist = [newheader,newvalue]
GLArequests.setValues(newlist)
}
function GLAIteEmpty(division) {
var sheet = ss.getSheetByName(division)
if (sheet == null){
return null
}
var range = sheet.getRange("Z25:AC26").getValues()
var firstrow = range[0]
var secondrow = range[1]
// find next empty cell
if (firstrow[0] == "" && secondrow[0] == "") {
var cell = sheet.getRange("Z25:Z26")}
else if (firstrow[1] == "" && secondrow[1] == "") {
var cell = sheet.getRange("AA25:AA26")}
else if (firstrow[2] == "" && secondrow[2] == "") {
var cell = sheet.getRange("AB25:AB26")}
else if (firstrow[3] == "" && secondrow[3] == "") {
var cell = sheet.getRange("AC25:AC26")}
else {
SpreadsheetApp.getUi().alert('Uh oh! All full at '+ division+' division')
var cell = null
}
// return cell object to write into
return cell
}