-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSocial Matrix.js
139 lines (116 loc) · 5.12 KB
/
Social Matrix.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
const scriptProperties = PropertiesService.getScriptProperties();
const server = scriptProperties.getProperty('cred_server');
const port = parseInt(scriptProperties.getProperty('cred_port'), 10);
const dbName = scriptProperties.getProperty('cred_dbName');
const username = scriptProperties.getProperty('cred_username');
const password = scriptProperties.getProperty('cred_password');
const url = `jdbc:mysql://${server}:${port}/${dbName}`;
const apidomain = scriptProperties.getProperty('cred_apidomain');
const apiusername = scriptProperties.getProperty('cred_apiusername');
const apipassword = scriptProperties.getProperty('cred_apipassword');
function readData() {
var conn = Jdbc.getConnection(url, username, password);
var stmt = conn.createStatement();
//Diet
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Dashboard');
var cell = sheet.getRange('B4').getValues();
var results = stmt.executeQuery('select distinct db.`first_name` "First Name",`nickname` "Facebook Name",`social-menu-choice-one` Starter,`social-menu-choice-two` "Main",`social-menu-choice-three` "Desert", `admin-dietary-requirements` "Dietary Requirements", `admin-diet-allergies-health-extra-info` "Extra Diet Info", `admin-social-requests-notes` "Notes" , order_id from wp_member_db db LEFT JOIN wp_order_product_customer_lookup pd on pd.user_id = db.id where product_id=' + cell + ' AND pd.status="wc-processing" order by db.`first_name` ASC');
//console.log(results);
var metaData=results.getMetaData();
var numCols = metaData.getColumnCount();
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Diet');
sheet.clearContents();
var arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(metaData.getColumnName(col + 1));
}
sheet.appendRow(arr);
while (results.next()) {
arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(results.getString(col + 1));
}
sheet.appendRow(arr);
}
sheet.autoResizeColumns(1, numCols+1);
//Transport
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Dashboard');
var cell = sheet.getRange('B4').getValues();
var results = stmt.executeQuery('select db.`first_name`,`nickname` fbname, `transport-need-lift`, `transport-will-you-give-lift`, `transport-leaving-location`, `transport-depature-time` from wp_member_db db LEFT JOIN wp_order_product_customer_lookup pd on pd.user_id = db.id where product_id=' + cell + ' AND status="wc-processing" order by `transport-need-lift` ASC');
//console.log(results);
var metaData=results.getMetaData();
var numCols = metaData.getColumnCount();
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Transport');
sheet.clearContents();
var arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(metaData.getColumnName(col + 1));
}
sheet.appendRow(arr);
while (results.next()) {
arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(results.getString(col + 1));
}
sheet.appendRow(arr);
}
sheet.autoResizeColumns(1, numCols+1);
//Volunteering
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Dashboard');
var cell = sheet.getRange('B4').getValues();
var results = stmt.executeQuery('select db.`first_name`,`nickname` fbname, `admin-can-you-help-social` from wp_member_db db LEFT JOIN wp_order_product_customer_lookup pd on pd.user_id = db.id where product_id=' + cell + ' AND status="wc-processing" order by `transport-need-lift` ASC');
//console.log(results);
var metaData=results.getMetaData();
var numCols = metaData.getColumnCount();
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Volunteering');
sheet.clearContents();
var arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(metaData.getColumnName(col + 1));
}
sheet.appendRow(arr);
while (results.next()) {
arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(results.getString(col + 1));
}
sheet.appendRow(arr);
}
sheet.autoResizeColumns(1, numCols+1);
//Buddy
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Dashboard');
var cell = sheet.getRange('B4').getValues();
var results = stmt.executeQuery('select distinct db.`first_name`,`nickname` fbname, `admin-first-timer-question`, `_order_count` from wp_member_db db LEFT JOIN wp_order_product_customer_lookup pd on pd.user_id = db.id where product_id=' + cell + ' AND status="wc-processing" order by `_order_count` ASC');
//console.log(results);
var metaData=results.getMetaData();
var numCols = metaData.getColumnCount();
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Buddy');
sheet.clearContents();
var arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(metaData.getColumnName(col + 1));
}
sheet.appendRow(arr);
while (results.next()) {
arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(results.getString(col + 1));
}
sheet.appendRow(arr);
}
results.close();
stmt.close();
sheet.autoResizeColumns(1, numCols+1);
}
//ScriptApp.newTrigger('readData')
//.timeBased()
//.everyMinutes(30)
//.create();