-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectTrackingRoughmill.js
203 lines (163 loc) · 6.7 KB
/
ProjectTrackingRoughmill.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
//Globals
var projectTracking = ""; //Put project tracking sheet ID here
var projectTrackingComplete = ""; //Put completed project tracking sheet ID here
function moveCompletedRoughmill() {
var ss = SpreadsheetApp.openById(projectTracking);
var ssComplete = SpreadsheetApp.openById(projectTrackingComplete);
var sheet = ss.getSheetByName("Rough Mill");
var cncSheet = ss.getSheetByName("CNC");
var lastRowCNC = cncSheet.getLastRow();
var lastColumnCNC = cncSheet.getLastColumn();
var rangeCNC = cncSheet.getRange(3, 1, lastRowCNC, lastColumnCNC);
var completedSheet = ssComplete.getSheetByName("Rough Mill Completed");
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastColumnComplete = completedSheet.getLastColumn();
var range = sheet.getRange(3, 1, lastRow-3, lastColumn);
var rowNum = 0;
var row = 0;
var destination = 0;
var today = Utilities.formatDate(new Date(), "GMT-4", "MM/dd/YYYY");
rowNum = completedSheet.getLastRow();
for(var i = 1; i <= lastRow-3; i++) {
if (range.getCell(i, 11).getValue() == "Complete"){
for(var k = 1; k <= lastRowCNC - 2; k++){
if (rangeCNC.getCell(k, 1).getValue() == range.getCell(i, 1).getValue() | rangeCNC.getCell(k, 2).getValue() == range.getCell(i, 2).getValue()){
rangeCNC.getCell(k, lastColumnCNC).setValue("Material Received");
}
}
completedSheet.insertRowBefore(rowNum);
completedSheet.getRange(rowNum+1, 1, 1, lastColumnComplete).copyTo(completedSheet.getRange(rowNum, 1, 1, lastColumnComplete));
row = completedSheet.getRange(rowNum, 1, 1, lastColumnComplete);
row.getCell(1, 7).setValue(today);
row.getCell(1,1).setValue(range.getCell(i,1).getValue());
row.getCell(1,2).setValue(range.getCell(i,2).getValue());
row.getCell(1,3).setValue(range.getCell(i,3).getFormula());
row.getCell(1,4).setValue(range.getCell(i,4).getValue());
row.getCell(1,5).setValue(range.getCell(i,6).getValue());
row.getCell(1,6).setValue(range.getCell(i,7).getValue());
row.getCell(1,8).setValue(range.getCell(i,10).getValue());
sendEmail(range, i);
range.getCell(i,11).setValue("Complete & CNC Notified");
}
}
}
function sendEmail(range, i) {
var emailContact = range.getCell(i,4).getValue();
var emailOperator = range.getCell(i,5).getValue();
if (emailContact == "") { //Programmer contact name here
emailContact = "" //Programmer email address here
}
else if (emailContact == "") { //Programmer contact name here
emailContact = "" //Programmer email address here
}
else if (emailContact == "") { //Programmer contact name here
emailContact = "" //Programmer email address here
}
else if (emailContact == "") { //Programmer contact name here
emailContact = "" //Programmer email address here
}
else if (emailContact == "") { //Programmer contact name here
emailContact = "" //Programmer email address here
}
else if (emailContact == "") { //Programmer contact name here
emailContact = "" //Programmer email address here
}
else if (emailContact == "") { //Programmer contact name here
emailContact = "" //Programmer email address here
}
if (emailOperator == "") { //Operator contact name here
emailOperator = "" //Operator email address here
}
else if (emailOperator == "") { //Operator contact name here
emailOperator = "" //Operator email address here
}
else if (emailOperator == "") { //Operator contact name here
emailOperator = "" //Operator email address here
}
else if (emailOperator == "") { //Operator contact name here
emailOperator = "" //Operator email address here
}
else if (emailOperator == "") { //Operator contact name here
emailOperator = "" //Operator email address here
}
else if (emailOperator == "") { //Operator contact name here
emailOperator = "" //Operator email address here
}
else if (emailOperator == "") { //Operator contact name here
emailOperator = "" //Operator email address here
}
var email = emailContact;
if (emailOperator != "") {
email = email + "," + emailOperator
}
var subject = range.getCell(i,1).getValue() + " Milling Completed";
var location = range.getCell(i,8).getValue();
var notes = range.getCell(i,9).getValue();
var link = range.getCell(i,3).getFormula();
MailApp.sendEmail({
to: email,
subject: subject,
htmlBody: "<b>" + "Location: " + "</b>" + location + "<br>" + "<b>" + "Notes: "+ "</b>" + notes + "<font color = white>" + link + "</font>",
});
}
function dueTwoWeeks(){
var dateNeeded = 7
var ss = SpreadsheetApp.openById(projectTracking);
var sheet = ss.getSheetByName("Rough Mill");
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(3, dateNeeded, lastRow -1, 1);
var data = range.getValues();
var today = new Date();
var twoWeeks = addDays(today,14);
var row = 0;
for(var i = 0; i <= lastRow-4; i++){
if (data[i][0] <= twoWeeks){
row = sheet.getRange(i+3, 1, 1, lastColumn-1);
row.setBackground("#9fc5e8");
}
else {
row = sheet.getRange(i+3, 1, 1, lastColumn-1);
row.setBackground("#f3f3f3");
}
}
}
function addDays(theDate, days) {
return new Date(theDate.getTime() + days*24*60*60*1000);
}
function searchTwoWeeks() {
var dateNeeded = 7
var ss = SpreadsheetApp.openById(projectTracking);
var sheet = ss.getSheetByName("Rough Mill");
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(3, dateNeeded, lastRow -1, 1);
var data = range.getValues();
var today = new Date();
var twoWeeks = addDays(today,14);
var row = 0;
var twoWeeksFormat = Utilities.formatDate(twoWeeks, "GMT-4", "MM/dd/YYYY");
var dateFormat = 0;
Logger.log(twoWeeksFormat);
for(var i = 0; i <= lastRow-4; i++){
dateFormat = Utilities.formatDate(data[i][0], "GMT-4", "MM/dd/YYYY");
if (dateFormat == twoWeeksFormat){
row = sheet.getRange(i+3, 1, 1, lastColumn-1);
emailTwoWeeks(row);
}
}
}
function emailTwoWeeks(row) {
var email = ""; //Add email addresses here
var subject = "DUE TO CNC IN TWO WEEKS: " + row.getCell(1,1).getValue();
var link = row.getCell(1,3).getFormula();
var dateRequested = Utilities.formatDate(row.getCell(1,6).getValue(), "GMT-4", "MM/dd/YYYY");
var dateNeeded = Utilities.formatDate(row.getCell(1,7).getValue(), "GMT-4", "MM/dd/YYYY");
var body = "<b>" + "Date Requested: " + "</b>" + dateRequested + "<br>" + "<b>" + "Due to CNC: " + "</b>" + dateNeeded + "<br>" + "<font color = white>" + link + "</font>";
MailApp.sendEmail({
to: email,
subject: subject,
htmlBody: body,
});
}