-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllCragFunctions.js
216 lines (154 loc) · 5.63 KB
/
AllCragFunctions.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// .addItem('Finalise Assignments', 'test')
// MarkAttended and Close
// https://woocommerce.github.io/woocommerce-rest-api-docs/#batch-update-orders
// Get all IDs
// SELECT order_id FROM wp_order_product_customer_lookup where product_id=$id AND status='wc-processing' AND cc_attendance='pending'
// Make on hold
function sendAllCragAssignments(tellme) {
const action = tellme
var sconn = Jdbc.getConnection(url, username, password);
var sstmt = sconn.createStatement();
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Sim-Dashboard');
var product_id = sheet.getRange('B5').getValues();
//var product_id = "3103";
var order_results = sstmt.executeQuery('SELECT distinct order_id from wp_order_product_customer_lookup where product_id="' + product_id + '" AND (cc_attendance_sim="pending" OR cc_attendance_sim IS NULL) LIMIT 99');
let active_user = Session.getActiveUser().getEmail();
let currentUnixTime = Date.now();
//var order_results = sstmt.executeQuery('select "3575"');
while (order_results.next()) {
scores_arr = [];
for (let col = 0; col < 1; col++) {
scores_arr.push(order_results.getString(col + 1));
}
console.log(scores_arr);
let order_id = scores_arr[0];
if (action === "close") {
var data = {
//"status": "completed",
"meta_data": [
{
"key": "cc_attendance_sim_set_by",
"value": active_user
},
{
"key": "cc_attendance_sim_set_at",
"value": currentUnixTime
},
{
"key": "cc_attendance_sim",
"value": "attended"
}
]
}
Logger.log(data);
pokeToWordPressOrders(data, order_id);
} else if (action === "location") {
var data = {
"id": order_id,
//"status": "on-hold",
"meta_data": [
{
"key": "cc_location_sim_signed_off_by",
"value": active_user
},
{
"key": "cc_location_sim_finalised_at",
"value": currentUnixTime
}
]
}
Logger.log(data);
pokeToWordPressOrders(data, order_id);
} else if (action === "reset") {
var data = {
"meta_data": [
{
"key": "cc_volunteer_attendance_sim",
"value": "pending"
},
{
"key": "cc_volunteer_sim",
"value": "none"
},
{
"key": "cc_location_sim",
"value": "none"
},
{
"key": "cc_location_sim_signed_off_by",
"value": ""
},
{
"key": "cc_location_sim_finalised_at",
"value": ""
},
{
"key": "cc_attendance_sim_set_by",
"value": ""
},
{
"key": "cc_attendance_sim",
"value": "pending"
}
]
}
Logger.log(data);
pokeToWordPressOrders(data, order_id);
} else {
console.log("All done")
}
//conn.close();
//console.log("done")
}
if (action === "close") {
/*
var data = {
"status": "private",
"meta_data": [
{
"key": "cc_post_set_private_set_by",
"value": active_user
},
{
"key": "cc_post_set_private_set_at",
"value": currentUnixTime
}
]
}
*/
console.log("data");
/*
pokeToWordPressProducts(data, product_id);
*/
} else {
console.log("All done")
}
}
//console.log(cell);
function markAttendedAndCloseEvent() {
if (Browser.msgBox("This will mark all those who haven't been cancelled as ATTENDED and will close the event", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("This should be done on Thursday evening", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("This cannot be undone", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("SIMULATOR: everyone was marked completed and the event was closed successfully", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("SIMULATOR: this also closed the event on the website for signup", Browser.Buttons.OK_CANCEL) == "ok") {
sendAllCragAssignments("close");
//markEventComplete;
/// Close the event
}}}}}
}
function finaliseCragLocations() {
if (Browser.msgBox("This will finalise the locations and email everyone their locations immediately", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("This should be done after 12:00 on Wed", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("After this, you cant change any locations", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("SIMULATOR: this completed successfully and everyone was emailed", Browser.Buttons.OK_CANCEL) == "ok") {
sendAllCragAssignments("location");
}}}}
}
function ResetSimulator() {
if (Browser.msgBox("This will reset the simulator", Browser.Buttons.OK_CANCEL) == "ok") {
if (Browser.msgBox("Any selections for this week will not be saved", Browser.Buttons.OK_CANCEL) == "ok") {
sendAllCragAssignments("reset");
readData();
}}
}