-
Notifications
You must be signed in to change notification settings - Fork 0
/
Away.gs
83 lines (71 loc) · 2.47 KB
/
Away.gs
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
function populateAwayDateData() {
var sheet = spreadsheet.getSheetByName('Away Dates');
var awayDateArray2 = sheet.getRange(1, 1, sheet.getLastRow(),sheet.getLastColumn()).getValues();
for (var column = 1; column < sheet.getLastColumn(); column++)
{
var memberCode = getMemberCodeFromName(awayDateArray2[0][column],awayDateArray2[1][column]);
for (var row = 2; row < sheet.getLastRow(); row++)
{
if (awayDateArray2[row][column] != '')
{
var awayDate = new Date(awayDateArray2[row][0]);
awayDateArray.push([memberCode,awayDate,awayDateArray2[row][column]]);
}
}
}
}
function populateConstraintsForAwayDates() {
//loop through the away dates and create contrainsts for each duty that that member does
for(var i = 0; i < awayDateArray.length; i++) {
//find the duties that the member does
var memberDuties = getDutiesByMemberCode(awayDateArray[i][0])
for (var j = 0; j < memberDuties.length; j++) {
var dutyToConstrain = getDutyForDutyCodeAndDate(memberDuties[j][1],awayDateArray[i][1]);
if (dutyToConstrain.length > 0) {
dutyConstraintArray.push([dutyToConstrain[0][0],memberDuties[j][0],'Away']);
}
}
}
}
function writeDutyConstraint(dutyNo,memberCode,reason) {
var sheet = spreadsheet.getSheetByName('Duty Constraint');
sheet.appendRow([dutyNo,memberCode,reason]);
}
function writeAwayDateSummary() {
var sheet = spreadsheet.getSheetByName('Away Date Summary');
sheet.clear();
var startDate = getFirstGivenDayOfWeekAfterDate(0,getStartDate()); //0 = Sunday
var endDate = getEndDate();
var awayDateSummaryArray = [];
while (startDate <= endDate) {
sheet.appendRow([startDate,getAwayDateSummaryForDate(startDate)]);
startDate = addDaysToDate(7,startDate);
}
writeArrayToSheet(awayDateSummaryArray,'Away Date Summary');
}
function getAwayDateSummaryForDate(date) {
var awayDatesOnDate = getAwayDatesByDate(date);
var summary = '';
for (var i = 0; i < awayDatesOnDate.length; i++) {
summary += ',' + awayDatesOnDate[i][0];
}
if (summary.length > 0) {
return summary.substr(1,summary.length - 1);
}
else {
return '';
}
}
function getAwayDatesByDate(date) {
return awayDateArray.filter(awayDatesByDateFilter(date));
}
function awayDatesByDateFilter(date) {
return function(element) {
if ((element[1].getTime() == date.getTime()) && element[2] == 'Away') {
return true;
}
else {
return false;
}
}
}