-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportBadges.js
67 lines (62 loc) · 2.62 KB
/
reportBadges.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
function readBadgesNeeded(stmt) {
makeReport(stmt, {
sheetName: "Badges",
query: `
SELECT
"Given Badge" AS "Given Badge",
db.\`first_name\` AS "First Name",
db.\`nickname\` AS "Facebook Name",
db.stats_volunteer_for_numerator_cached AS "Volunteered For",
db.id AS "Clan ID"
FROM wp_member_db db
JOIN wp_order_product_customer_lookup pd ON pd.user_id = db.id
WHERE product_id=${cell}
AND \`cc_location\`="${cc_location}"
AND status IN ("wc-processing", "wc-onhold", "wc-on-hold")
AND ((db.\`stats_volunteer_for_numerator_cached\`>=3) OR (db.\`stats_volunteer_for_numerator_cached\`=2 AND pd.cc_volunteer<>"none"))
AND ((db.milestones_3_badge IS NULL) OR (db.milestones_3_badge ="due"))
ORDER BY db.\`first_name\`, CAST(db.stats_volunteer_for_numerator_cached AS UNSIGNED INTEGER) DESC
`,
formatting: [
{ type: 'color', column: "Given Badge", search: "", color: colors.lightGreen },
{ type: 'numberFormat', column: "Volunteered For", format: "0" },
{ type: 'columnWidth', column: "Facebook Name", width: 150 },
{ type: 'columnWidth', column: "Clan ID", width: 100 },
],
title: "People who need badges"
});
// Add checkboxes to column A from row 2 downwards
let sheet = SpreadsheetApp.getActive().getSheetByName("Badges");
let lastRow = sheet.getLastRow();
if (lastRow > 1) {
let range = sheet.getRange(2, 1, lastRow - 1, 1);
range.insertCheckboxes();
}
}
function readBadgesGiven(stmt) {
makeReport(stmt, {
sheetName: "Badges Given",
query: `
SELECT
"Given Badge" AS "Given Badge",
db.\`first_name\` AS "First Name",
db.\`nickname\` AS "Facebook Name",
db.milestones_3_badge_marked_given_by AS "Given by",
FROM_UNIXTIME((db.milestones_3_badge_marked_given_at)/1000, "%d %M %Y") AS "Given on"
FROM wp_member_db db
JOIN wp_order_product_customer_lookup pd ON pd.user_id = db.id
WHERE product_id=${cell}
AND \`cc_location\`="${cc_location}"
AND status IN ("wc-processing", "wc-onhold", "wc-on-hold")
AND db.milestones_3_badge="given"
ORDER BY db.\`first_name\`, CAST(db.stats_volunteer_for_numerator_cached AS UNSIGNED INTEGER) DESC
`,
formatting: [
{ type: 'color', column: "Given Badge", search: "", color: colors.lightYellow },
{ type: 'columnWidth', column: "Facebook Name", width: 150 },
{ type: 'columnWidth', column: "Given by", width: 150 },
{ type: 'columnWidth', column: "Given on", width: 120 },
],
title: "People who have been given badges"
});
}