-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteamReport.gs
186 lines (169 loc) · 7.03 KB
/
teamReport.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
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
// =========================================================================
// ADD TEAM REPORT - MENU ITEM FUNCTION
// =========================================================================
function generateTeamReport() {
var dialog1 = {
'title': 'Response Form',
'customTitle': false,
'subText': 'Would you like to generate a team report?'
};
var dialog2 = {
'title': 'Enter Time Tracking Response Link',
'subText': 'Please enter the response link to generate team report:'
};
reportDialog(dialog1, createTeamReport, dialog2);
}
// =========================================================================
// CREATE TEAM REPORT - DIALOG CALLS FUNCTION
// =========================================================================
function createTeamReport(report) {
if(!report.getSheetByName('Team Details')) {
report.insertSheet('Team Details', 2);
} else {
getTeamDetails(report).clear();
}
getTeamDetails(report).getRange('A:A').getCell(1, 1).setValue('Projects').setFontWeight('bold');
getTeamDetails(report).getRange('B:B').getCell(1, 1).setValue('Total Members').setFontWeight('bold');
getTeamDetails(report).getRange('C:C').getCell(1, 1).setValue('Total Percentage').setFontWeight('bold');
var values = getTeamValues(report);
var nR = 1, nC;
for(i in values) {
if(values[i].category != 'TimeOff' && values[i].category != 'New Project') {
nR++;
getTeamDetails(report).getRange('A:A').getCell(nR, 1).setValue(values[i].project);
getTeamDetails(report).getRange('B:B').getCell(nR, 1).setValue(values[i].total);
getTeamDetails(report).getRange('C:C').getCell(nR, 1).setValue(values[i].percentage);
for(var v = 0; v < values[i].total; v++) {
nC = getNextColumn(getTeamDetails(report), nR);
if(values[i].details[v].fullName) {
getTeamDetails(report).getRange(nR, nC).setValue(values[i].details[v].fullName);
} else {
getTeamDetails(report).getRange(nR, nC).setValue(values[i].details[v].employee);
}
var nCC = nC + 1;
getTeamDetails(report).getRange(nR, nCC).setValue(values[i].details[v].time);
}
} else if(values[i].category != 'TimeOff') {
nR++;
getTeamDetails(report).getRange('A:A').getCell(nR, 1).setValue(values[i].project).setFontColor('green');
getTeamDetails(report).getRange('B:B').getCell(nR, 1).setValue(values[i].total).setFontColor('green');
getTeamDetails(report).getRange('C:C').getCell(nR, 1).setValue(values[i].percentage).setFontColor('green');
for(var v = 0; v < values[i].total; v++) {
nC = getNextColumn(getTeamDetails(report), nR);
if(values[i].details[v].fullName) {
getTeamDetails(report).getRange(nR, nC).setValue(values[i].details[v].fullName).setFontColor('green');
} else {
getTeamDetails(report).getRange(nR, nC).setValue(values[i].details[v].employee).setFontColor('green');
}
var nCC = nC + 1;
getTeamDetails(report).getRange(nR, nCC).setValue(values[i].details[v].time).setFontColor('green');
}
} else {
nR++;
getTeamDetails(report).getRange('A:A').getCell(nR, 1).setValue(values[i].project).setFontColor('blue');
getTeamDetails(report).getRange('B:B').getCell(nR, 1).setValue(values[i].total).setFontColor('blue');
getTeamDetails(report).getRange('C:C').getCell(nR, 1).setValue(values[i].percentage).setFontColor('blue');
for(var v = 0; v < values[i].total; v++) {
nC = getNextColumn(getTeamDetails(report), nR);
if(values[i].details[v].fullName) {
getTeamDetails(report).getRange(nR, nC).setValue(values[i].details[v].fullName).setFontColor('blue');
} else {
getTeamDetails(report).getRange(nR, nC).setValue(values[i].details[v].employee).setFontColor('blue');
}
var nCC = nC + 1;
getTeamDetails(report).getRange(nR, nCC).setValue(values[i].details[v].time).setFontColor('blue');
}
}
}
createEnterpriseReport(report);
}
// =========================================================================
// GET TEAM REPORT VALUES
// =========================================================================
function getTeamValues(report) {
var projects = projectData();
var employeeTime = employeeTimeData(report);
addNewProjects(employeeTime, projects);
for(var i = 0; i < projects.length; i++) {
projects[i].details = [];
projects[i].total = 0;
projects[i].percentage = 0;
var t = 0;
while(t < employeeTime.length) {
var employeeProjects = employeeTime[t].projects;
employeeProjects.forEach(function (project, index) {
if(project.project == projects[i].project) {
projects[i].details[projects[i].total] = {
'employee': employeeTime[t].email,
'fullName': employeeTime[t].fullName,
'time': project.percentage
}
projects[i].total = projects[i].total + 1;
projects[i].percentage = projects[i].percentage + project.percentage;
}
});
t++;
}
}
addTimeOff(employeeTime, projects);
return projects;
}
function addNewProjects(employeeTime, projects) {
var t = 0, n = 0, newProjects = [];
while(t < employeeTime.length) {
var employeeProjects = employeeTime[t].projects;
employeeProjects.forEach(function (project, index) {
if(project.newProject) {
newProjects[n] = project.project;
n++;
}
});
t++;
}
newProjects = newProjects.filter(function(item, pos) {
return newProjects.indexOf(item) == pos;
});
var total = projects.length;
for(var i = 0; i < newProjects.length; i++) {
projects[total] = {
'project': newProjects[i],
'category': 'New Project',
'details': [],
'total': 0,
'percentage': 0
}
total++;
}
}
function addTimeOff(employeeTime, values) {
for(var i = 0; i < employeeTime.length; i++) {
if(employeeTime[i].timeOff.total > 0) {
var v = 0;
while(v < values.length) {
if(values[v].project == 'Personal and Vacation') {
if(employeeTime[i].timeOff.vacationPersonalTime > 0) {
values[v].details[values[v].total] = {
'employee': employeeTime[i].email,
'fullName': employeeTime[i].fullName,
'time': employeeTime[i].timeOff.vacationPersonalTime
}
values[v].total = values[v].total + 1;
values[v].percentage = values[v].percentage + employeeTime[i].timeOff.vacationPersonalTime;
}
}
if(values[v].project == 'National Holiday') {
if(employeeTime[i].timeOff.nationalHoliday > 0) {
values[v].details[values[v].total] = {
'employee': employeeTime[i].email,
'fullName': employeeTime[i].fullName,
'time': employeeTime[i].timeOff.nationalHoliday
}
values[v].total = values[v].total + 1;
values[v].percentage = values[v].percentage + employeeTime[i].timeOff.nationalHoliday;
}
}
v++;
}
}
};
}