-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEveryoneFunctions.js
172 lines (157 loc) · 4.08 KB
/
EveryoneFunctions.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
function sendAllCragAssignments(action) {
try {
let data;
const sconn = Jdbc.getConnection(url, username, password);
const sstmt = sconn.createStatement();
const product_id = setupCell("Dashboard", "B49");
const active_user = Session.getActiveUser().getEmail();
const currentUnixTime = Date.now();
const order_results = sstmt.executeQuery(
`SELECT distinct order_id from jtl_order_product_customer_lookup where product_id="${product_id}" AND status="wc-processing" AND cc_attendance="pending" LIMIT 99`,
);
while (order_results.next()) {
const order_id = order_results.getString(1);
console.log(order_id);
if (action === "close") {
data = {
status: "completed",
meta_data: [
{
key: "cc_attendance_set_by",
value: active_user,
},
{
key: "cc_attendance_set_at",
value: currentUnixTime,
},
{
key: "cc_attendance",
value: "attended",
},
],
};
Logger.log(data);
pokeToWordPressOrders(data, order_id);
updateOrderStatus(order_id, "Attended");
}
}
if (action === "close") {
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);
}
sstmt.close();
sconn.close();
} catch (error) {
showError(error.message);
}
}
function markAttendedAndCloseEvent() {
if (
Browser.msgBox(
"This will mark all those who haven't been cancelled as ATTENDED, close the event, and set it to private",
Browser.Buttons.OK_CANCEL,
) === "ok"
) {
if (
Browser.msgBox(
"This should be done after caving",
Browser.Buttons.OK_CANCEL,
) === "ok"
) {
if (
Browser.msgBox("This cannot be undone", Browser.Buttons.OK_CANCEL) ===
"ok"
) {
sendAllCragAssignments("close");
readData(); // Refresh the data after closing the event
refreshUpcomingEvents(); // Update upcoming events list
}
}
}
}
function cancelWholeEvent() {
if (
Browser.msgBox(
"Are you sure you want to cancel the whole event?",
Browser.Buttons.OK_CANCEL,
) === "ok"
) {
if (
Browser.msgBox(
"This will mark all attendees as 'clan_cancelled' and set the event to private. This action cannot be undone.",
Browser.Buttons.OK_CANCEL,
) === "ok"
) {
const product_id = setupCell("Dashboard", "B49");
const active_user = Session.getActiveUser().getEmail();
const currentUnixTime = Date.now();
const sconn = Jdbc.getConnection(url, username, password);
const sstmt = sconn.createStatement();
const order_results = sstmt.executeQuery(
`SELECT distinct order_id from jtl_order_product_customer_lookup where product_id="${product_id}" AND status="wc-processing" AND cc_attendance="pending" LIMIT 99`,
);
while (order_results.next()) {
const order_id = order_results.getString(1);
const data = {
status: "cancelled",
meta_data: [
{
key: "cc_attendance_set_by",
value: active_user,
},
{
key: "cc_attendance_set_at",
value: currentUnixTime,
},
{
key: "cc_attendance",
value: "clan_cancelled",
},
],
};
pokeToWordPressOrders(data, order_id);
updateOrderStatus(order_id, "Cancelled");
}
// Add calendar cleanup
try {
deleteCalendarEventForProduct(product_id);
} catch (e) {
console.warn("Failed to delete calendar event:", e);
}
// Set event to private
const eventData = {
status: "private",
meta_data: [
{
key: "cc_post_set_private_set_by",
value: active_user,
},
{
key: "cc_post_set_private_set_at",
value: currentUnixTime,
},
],
};
pokeToWordPressProducts(eventData, product_id);
sstmt.close();
sconn.close();
Browser.msgBox(
"Event cancelled successfully. All attendees marked as 'clan_cancelled' and event set to private.",
);
readData(); // Refresh the data after cancelling the event
}
}
}