scheduler-models 1.4.7 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -40,8 +40,8 @@ class Employee {
|
|
|
40
40
|
}
|
|
41
41
|
this.team = (emp) ? emp.team : '';
|
|
42
42
|
this.site = (emp) ? emp.site : '';
|
|
43
|
-
this.email = (emp) ? emp.email :
|
|
44
|
-
this.name = (emp) ? new employeename_1.EmployeeName(emp.name) :
|
|
43
|
+
this.email = (emp && emp.email) ? emp.email : undefined;
|
|
44
|
+
this.name = (emp && emp.name) ? new employeename_1.EmployeeName(emp.name) : undefined;
|
|
45
45
|
this.companyinfo = (emp) ? emp.companyinfo : { company: '', employeeid: '' };
|
|
46
46
|
this.assignments = [];
|
|
47
47
|
if (emp && emp.assignments && emp.assignments.length > 0) {
|
|
@@ -64,17 +64,21 @@ class Employee {
|
|
|
64
64
|
});
|
|
65
65
|
this.balances.sort((a, b) => a.compareTo(b));
|
|
66
66
|
}
|
|
67
|
-
this.leaves = [];
|
|
68
67
|
if (emp && emp.leaves && emp.leaves.length > 0) {
|
|
68
|
+
this.leaves = [];
|
|
69
69
|
emp.leaves.forEach(l => {
|
|
70
|
-
this.leaves
|
|
70
|
+
if (this.leaves) {
|
|
71
|
+
this.leaves.push(new leave_1.Leave(l));
|
|
72
|
+
}
|
|
71
73
|
});
|
|
72
74
|
this.leaves.sort((a, b) => a.compareTo(b));
|
|
73
75
|
}
|
|
74
|
-
this.requests = [];
|
|
75
76
|
if (emp && emp.requests && emp.requests.length > 0) {
|
|
77
|
+
this.requests = [];
|
|
76
78
|
emp.requests.forEach(r => {
|
|
77
|
-
this.requests
|
|
79
|
+
if (this.requests) {
|
|
80
|
+
this.requests.push(new leaverequest_1.LeaveRequest(r));
|
|
81
|
+
}
|
|
78
82
|
});
|
|
79
83
|
this.requests.sort((a, b) => a.compareTo(b));
|
|
80
84
|
}
|
|
@@ -99,10 +103,12 @@ class Employee {
|
|
|
99
103
|
});
|
|
100
104
|
this.specialties.sort((a, b) => a.compareTo(b));
|
|
101
105
|
}
|
|
102
|
-
this.emails = [];
|
|
103
106
|
if (emp && emp.emails && emp.emails.length > 0) {
|
|
107
|
+
this.emails = [];
|
|
104
108
|
emp.emails.forEach(e => {
|
|
105
|
-
this.emails
|
|
109
|
+
if (this.emails) {
|
|
110
|
+
this.emails.push(e);
|
|
111
|
+
}
|
|
106
112
|
});
|
|
107
113
|
this.emails.sort((a, b) => (a < b) ? -1 : 1);
|
|
108
114
|
}
|
|
@@ -125,21 +131,29 @@ class Employee {
|
|
|
125
131
|
}
|
|
126
132
|
compareTo(other) {
|
|
127
133
|
if (other) {
|
|
128
|
-
if (this.
|
|
129
|
-
if (this.
|
|
130
|
-
if (this.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
if (this.user && other.user) {
|
|
135
|
+
if (this.user.lastName === other.user.lastName) {
|
|
136
|
+
if (this.user.firstName === other.user.firstName) {
|
|
137
|
+
if (this.user.middleName && other.user.middleName) {
|
|
138
|
+
return (this.user.middleName < other.user.middleName) ? -1 : 1;
|
|
139
|
+
}
|
|
140
|
+
else if (this.user.middleName) {
|
|
141
|
+
return -1;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
138
146
|
}
|
|
147
|
+
return (this.user.firstName < other.user.firstName) ? -1 : 1;
|
|
139
148
|
}
|
|
140
|
-
return (this.
|
|
149
|
+
return (this.user.lastName < other.user.lastName) ? -1 : 1;
|
|
150
|
+
}
|
|
151
|
+
if (!this.user) {
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return -1;
|
|
141
156
|
}
|
|
142
|
-
return (this.name.lastname < other.name.lastname) ? -1 : 1;
|
|
143
157
|
}
|
|
144
158
|
return -1;
|
|
145
159
|
}
|
|
@@ -147,6 +161,8 @@ class Employee {
|
|
|
147
161
|
const result = new Employee(this);
|
|
148
162
|
result.work = undefined;
|
|
149
163
|
result.user = undefined;
|
|
164
|
+
result.leaves = undefined;
|
|
165
|
+
result.requests = undefined;
|
|
150
166
|
return result;
|
|
151
167
|
}
|
|
152
168
|
purge(date) {
|
|
@@ -156,15 +172,19 @@ class Employee {
|
|
|
156
172
|
this.variations.splice(v, 1);
|
|
157
173
|
}
|
|
158
174
|
}
|
|
159
|
-
this.leaves
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.leaves.
|
|
175
|
+
if (this.leaves) {
|
|
176
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
177
|
+
for (let l = this.leaves.length - 1; l >= 0; l--) {
|
|
178
|
+
if (this.leaves[l].leavedate.getTime() < date.getTime()) {
|
|
179
|
+
this.leaves.splice(l, 1);
|
|
180
|
+
}
|
|
163
181
|
}
|
|
164
182
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.requests.
|
|
183
|
+
if (this.requests) {
|
|
184
|
+
for (let l = this.requests.length - 1; l >= 0; l--) {
|
|
185
|
+
if (this.requests[l].enddate.getTime() < date.getTime()) {
|
|
186
|
+
this.requests.splice(l, 1);
|
|
187
|
+
}
|
|
168
188
|
}
|
|
169
189
|
}
|
|
170
190
|
this.balances.sort((a, b) => a.compareTo(b));
|
|
@@ -178,34 +198,36 @@ class Employee {
|
|
|
178
198
|
return (last.endDate.getTime() < date.getTime());
|
|
179
199
|
}
|
|
180
200
|
removeLeaves(start, end, reqID = '', includeActuals = true) {
|
|
181
|
-
this.leaves
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
201
|
+
if (this.leaves) {
|
|
202
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
203
|
+
for (let l = this.leaves.length - 1; l >= 0; l--) {
|
|
204
|
+
if (reqID === '' && includeActuals) {
|
|
205
|
+
if (this.leaves[l].leavedate.getTime() >= start.getTime()
|
|
206
|
+
&& this.leaves[l].leavedate.getTime() <= end.getTime()) {
|
|
207
|
+
this.leaves.splice(l, 1);
|
|
208
|
+
}
|
|
187
209
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
210
|
+
else if (reqID !== '' && includeActuals) {
|
|
211
|
+
if (this.leaves[l].leavedate.getTime() >= start.getTime()
|
|
212
|
+
&& this.leaves[l].leavedate.getTime() <= end.getTime()
|
|
213
|
+
&& this.leaves[l].requestid === reqID) {
|
|
214
|
+
this.leaves.splice(l, 1);
|
|
215
|
+
}
|
|
194
216
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
217
|
+
else if (reqID === '' && !includeActuals) {
|
|
218
|
+
if (this.leaves[l].leavedate.getTime() >= start.getTime()
|
|
219
|
+
&& this.leaves[l].leavedate.getTime() <= end.getTime()
|
|
220
|
+
&& this.leaves[l].status.toLowerCase() !== 'actual') {
|
|
221
|
+
this.leaves.splice(l, 1);
|
|
222
|
+
}
|
|
201
223
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
224
|
+
else if (reqID !== '' && !includeActuals) {
|
|
225
|
+
if (this.leaves[l].leavedate.getTime() >= start.getTime()
|
|
226
|
+
&& this.leaves[l].leavedate.getTime() <= end.getTime()
|
|
227
|
+
&& this.leaves[l].status.toLowerCase() !== 'actual'
|
|
228
|
+
&& this.leaves[l].requestid === reqID) {
|
|
229
|
+
this.leaves.splice(l, 1);
|
|
230
|
+
}
|
|
209
231
|
}
|
|
210
232
|
}
|
|
211
233
|
}
|
|
@@ -310,17 +332,19 @@ class Employee {
|
|
|
310
332
|
wday.hours = work;
|
|
311
333
|
return wday;
|
|
312
334
|
}
|
|
313
|
-
this.leaves
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
335
|
+
if (this.leaves) {
|
|
336
|
+
this.leaves.forEach(lv => {
|
|
337
|
+
if (lv.useLeave(date)
|
|
338
|
+
&& (lv.hours > stdWorkday / 2 || lv.status.toLowerCase() === 'actual')) {
|
|
339
|
+
wday = new workday_1.Workday({
|
|
340
|
+
id: 0,
|
|
341
|
+
workcenter: '',
|
|
342
|
+
code: lv.code,
|
|
343
|
+
hours: lv.hours
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
324
348
|
return wday;
|
|
325
349
|
}
|
|
326
350
|
getWorkdayActual(date, labor) {
|
|
@@ -347,7 +371,7 @@ class Employee {
|
|
|
347
371
|
}
|
|
348
372
|
});
|
|
349
373
|
let bLeave = false;
|
|
350
|
-
if (bPrimary || labor?.length === 0) {
|
|
374
|
+
if ((bPrimary || labor?.length === 0) && this.leaves) {
|
|
351
375
|
this.leaves.forEach(lv => {
|
|
352
376
|
if (lv.useLeave(date) && lv.status.toLowerCase() === 'actual') {
|
|
353
377
|
if (!bLeave) {
|
|
@@ -409,19 +433,21 @@ class Employee {
|
|
|
409
433
|
}
|
|
410
434
|
return wday;
|
|
411
435
|
}
|
|
412
|
-
this.leaves
|
|
413
|
-
|
|
414
|
-
if (
|
|
415
|
-
wday
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
436
|
+
if (this.leaves) {
|
|
437
|
+
this.leaves.forEach(lv => {
|
|
438
|
+
if (lv.useLeave(date)) {
|
|
439
|
+
if (!wday || wday.hours < lv.hours) {
|
|
440
|
+
wday = new workday_1.Workday({
|
|
441
|
+
id: date.getDate(),
|
|
442
|
+
workcenter: '',
|
|
443
|
+
date: new Date(date),
|
|
444
|
+
code: lv.code,
|
|
445
|
+
hours: lv.hours
|
|
446
|
+
});
|
|
447
|
+
}
|
|
422
448
|
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
449
|
+
});
|
|
450
|
+
}
|
|
425
451
|
return wday;
|
|
426
452
|
}
|
|
427
453
|
getWorkdayWOLeaves(date, useWork) {
|
|
@@ -809,12 +835,14 @@ class Employee {
|
|
|
809
835
|
this.work.sort((a, b) => a.compareTo(b));
|
|
810
836
|
lastWorked = new Date(this.work[this.work.length - 1].dateworked);
|
|
811
837
|
}
|
|
812
|
-
this.leaves
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
838
|
+
if (this.leaves) {
|
|
839
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
840
|
+
this.leaves.forEach(lv => {
|
|
841
|
+
if (lv.status.toLowerCase() === 'actual' && lv.leavedate.getTime() > lastWorked.getTime()) {
|
|
842
|
+
lastWorked = new Date(lv.leavedate);
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
}
|
|
818
846
|
let current = new Date(start);
|
|
819
847
|
while (current.getTime() <= end.getTime()) {
|
|
820
848
|
if (current.getTime() > lastWorked.getTime()) {
|
|
@@ -920,12 +948,14 @@ class Employee {
|
|
|
920
948
|
}
|
|
921
949
|
else {
|
|
922
950
|
let carry = lastAnnual + lastCarry;
|
|
923
|
-
this.leaves
|
|
924
|
-
|
|
925
|
-
&& lv.
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
951
|
+
if (this.leaves) {
|
|
952
|
+
this.leaves.forEach(lv => {
|
|
953
|
+
if (lv.leavedate.getFullYear() === year && lv.code.toLowerCase() === 'v'
|
|
954
|
+
&& lv.status.toLowerCase() === 'actual') {
|
|
955
|
+
carry -= lv.hours;
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
}
|
|
929
959
|
bal.carryover = carry;
|
|
930
960
|
}
|
|
931
961
|
this.balances.push(bal);
|
|
@@ -974,170 +1004,181 @@ class Employee {
|
|
|
974
1004
|
let found = false;
|
|
975
1005
|
let max = 0;
|
|
976
1006
|
date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
977
|
-
this.leaves
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
lv.requestid
|
|
1007
|
+
if (this.leaves) {
|
|
1008
|
+
this.leaves.forEach((lv, l) => {
|
|
1009
|
+
if ((lv.useLeave(date) && lv.code.toLowerCase() === code.toLowerCase())
|
|
1010
|
+
|| lv.id === id) {
|
|
1011
|
+
found = true;
|
|
1012
|
+
lv.status = status;
|
|
1013
|
+
lv.hours = hours;
|
|
1014
|
+
if (lv.requestid === '') {
|
|
1015
|
+
lv.requestid = requestid;
|
|
1016
|
+
}
|
|
1017
|
+
if (holCode && holCode !== '') {
|
|
1018
|
+
lv.tagday = holCode;
|
|
1019
|
+
}
|
|
1020
|
+
if (this.leaves) {
|
|
1021
|
+
this.leaves[l] = lv;
|
|
1022
|
+
}
|
|
985
1023
|
}
|
|
986
|
-
if (
|
|
987
|
-
|
|
1024
|
+
else if (lv.id > max) {
|
|
1025
|
+
max = lv.id;
|
|
988
1026
|
}
|
|
989
|
-
this.leaves[l] = lv;
|
|
990
|
-
}
|
|
991
|
-
else if (lv.id > max) {
|
|
992
|
-
max = lv.id;
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
if (!found) {
|
|
996
|
-
const lv = new leave_1.Leave({
|
|
997
|
-
id: max + 1,
|
|
998
|
-
leavedate: new Date(date),
|
|
999
|
-
code: code,
|
|
1000
|
-
hours: hours,
|
|
1001
|
-
status: status,
|
|
1002
|
-
requestid: requestid,
|
|
1003
|
-
used: false,
|
|
1004
|
-
tagday: holCode
|
|
1005
1027
|
});
|
|
1006
|
-
|
|
1007
|
-
|
|
1028
|
+
if (!found) {
|
|
1029
|
+
const lv = new leave_1.Leave({
|
|
1030
|
+
id: max + 1,
|
|
1031
|
+
leavedate: new Date(date),
|
|
1032
|
+
code: code,
|
|
1033
|
+
hours: hours,
|
|
1034
|
+
status: status,
|
|
1035
|
+
requestid: requestid,
|
|
1036
|
+
used: false,
|
|
1037
|
+
tagday: holCode
|
|
1038
|
+
});
|
|
1039
|
+
this.leaves.push(lv);
|
|
1040
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1041
|
+
}
|
|
1008
1042
|
}
|
|
1009
1043
|
}
|
|
1010
1044
|
updateLeave(id, field, value) {
|
|
1011
1045
|
let answer = undefined;
|
|
1012
|
-
this.leaves
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1046
|
+
if (this.leaves) {
|
|
1047
|
+
this.leaves.forEach((lv, l) => {
|
|
1048
|
+
if (lv.id === id) {
|
|
1049
|
+
switch (field.toLowerCase()) {
|
|
1050
|
+
case "date":
|
|
1051
|
+
const newdate = new Date(Date.parse(value));
|
|
1052
|
+
lv.leavedate = newdate;
|
|
1053
|
+
break;
|
|
1054
|
+
case "code":
|
|
1055
|
+
lv.code = value;
|
|
1056
|
+
break;
|
|
1057
|
+
case "hours":
|
|
1058
|
+
lv.hours = Number(value);
|
|
1059
|
+
break;
|
|
1060
|
+
case 'status':
|
|
1061
|
+
lv.status = value;
|
|
1062
|
+
break;
|
|
1063
|
+
case 'requestid':
|
|
1064
|
+
lv.requestid = value;
|
|
1065
|
+
break;
|
|
1066
|
+
case 'tagday':
|
|
1067
|
+
lv.tagday = value;
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1034
1070
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1071
|
+
if (this.leaves) {
|
|
1072
|
+
this.leaves[l] = lv;
|
|
1073
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1074
|
+
}
|
|
1075
|
+
answer = lv;
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1040
1078
|
return answer;
|
|
1041
1079
|
}
|
|
1042
1080
|
deleteLeave(id) {
|
|
1043
1081
|
let found = -1;
|
|
1044
|
-
this.leaves
|
|
1045
|
-
|
|
1046
|
-
|
|
1082
|
+
if (this.leaves) {
|
|
1083
|
+
this.leaves.forEach((lv, l) => {
|
|
1084
|
+
if (lv.id === id) {
|
|
1085
|
+
found = l;
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
if (found >= 0) {
|
|
1089
|
+
this.leaves.splice(found, 1);
|
|
1047
1090
|
}
|
|
1048
|
-
});
|
|
1049
|
-
if (found >= 0) {
|
|
1050
|
-
this.leaves.splice(found, 1);
|
|
1051
1091
|
}
|
|
1052
1092
|
}
|
|
1053
1093
|
getLeaveHours(start, end) {
|
|
1054
1094
|
let answer = 0.0;
|
|
1055
|
-
this.leaves
|
|
1056
|
-
|
|
1057
|
-
&& end.getTime() >= lv.leavedate.getTime()
|
|
1058
|
-
&& lv.status.toLowerCase() === 'actual') {
|
|
1059
|
-
answer += lv.hours;
|
|
1060
|
-
}
|
|
1061
|
-
});
|
|
1095
|
+
if (this.leaves) {
|
|
1096
|
+
}
|
|
1062
1097
|
return answer;
|
|
1063
1098
|
}
|
|
1064
1099
|
getLeave(start) {
|
|
1065
1100
|
const workday = new workday_1.Workday();
|
|
1066
|
-
this.leaves
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
workday.code
|
|
1072
|
-
workday.hours = lv.hours;
|
|
1073
|
-
}
|
|
1074
|
-
else {
|
|
1075
|
-
if (workday.hours < lv.hours) {
|
|
1101
|
+
if (this.leaves) {
|
|
1102
|
+
this.leaves.forEach(lv => {
|
|
1103
|
+
if (lv.leavedate.getUTCFullYear() === start.getUTCFullYear()
|
|
1104
|
+
&& lv.leavedate.getUTCMonth() === start.getUTCMonth()
|
|
1105
|
+
&& lv.leavedate.getUTCDate() === start.getUTCDate()) {
|
|
1106
|
+
if (workday.code === '') {
|
|
1076
1107
|
workday.code = lv.code;
|
|
1077
|
-
workday.hours
|
|
1108
|
+
workday.hours = lv.hours;
|
|
1109
|
+
}
|
|
1110
|
+
else {
|
|
1111
|
+
if (workday.hours < lv.hours) {
|
|
1112
|
+
workday.code = lv.code;
|
|
1113
|
+
workday.hours += lv.hours;
|
|
1114
|
+
}
|
|
1078
1115
|
}
|
|
1079
1116
|
}
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1082
1119
|
return workday;
|
|
1083
1120
|
}
|
|
1084
1121
|
getPTOHours(start, end) {
|
|
1085
1122
|
let answer = 0.0;
|
|
1086
|
-
this.leaves
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1123
|
+
if (this.leaves) {
|
|
1124
|
+
this.leaves.forEach(lv => {
|
|
1125
|
+
if (lv.leavedate.getTime() >= start.getTime()
|
|
1126
|
+
&& end.getTime() >= lv.leavedate.getTime()
|
|
1127
|
+
&& lv.status.toLowerCase() === 'actual'
|
|
1128
|
+
&& lv.code.toLowerCase() === 'v') {
|
|
1129
|
+
answer += lv.hours;
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1094
1133
|
return answer;
|
|
1095
1134
|
}
|
|
1096
1135
|
createLeaveRequest(start, end, code, comment) {
|
|
1097
1136
|
start = new Date(Date.UTC(start.getFullYear(), start.getMonth(), start.getDate()));
|
|
1098
1137
|
end = new Date(Date.UTC(end.getFullYear(), end.getMonth(), end.getDate()));
|
|
1099
1138
|
let answer = undefined;
|
|
1100
|
-
this.requests
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1139
|
+
if (this.requests) {
|
|
1140
|
+
this.requests.forEach((req, r) => {
|
|
1141
|
+
if (req.startdate.getTime() === start.getTime()
|
|
1142
|
+
&& req.enddate.getTime() === end.getTime()) {
|
|
1143
|
+
if (comment) {
|
|
1144
|
+
const cmt = new leaverequest_1.LeaveRequestComment({
|
|
1145
|
+
commentdate: new Date(),
|
|
1146
|
+
comment: comment
|
|
1147
|
+
});
|
|
1148
|
+
req.comments.push(cmt);
|
|
1149
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1150
|
+
}
|
|
1151
|
+
answer = new leaverequest_1.LeaveRequest(req);
|
|
1110
1152
|
}
|
|
1111
|
-
answer = new leaverequest_1.LeaveRequest(req);
|
|
1112
|
-
}
|
|
1113
|
-
});
|
|
1114
|
-
if (!answer) {
|
|
1115
|
-
const id = (new Date()).getTime().toString();
|
|
1116
|
-
answer = new leaverequest_1.LeaveRequest({
|
|
1117
|
-
id: id,
|
|
1118
|
-
employeeid: this.id,
|
|
1119
|
-
requestDate: new Date(),
|
|
1120
|
-
primarycode: code,
|
|
1121
|
-
startdate: start,
|
|
1122
|
-
enddate: end,
|
|
1123
|
-
status: 'DRAFT',
|
|
1124
|
-
approvalDate: new Date(0),
|
|
1125
|
-
approvedby: '',
|
|
1126
|
-
requesteddays: [],
|
|
1127
|
-
comments: []
|
|
1128
1153
|
});
|
|
1129
|
-
answer
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1154
|
+
if (!answer) {
|
|
1155
|
+
const id = (new Date()).getTime().toString();
|
|
1156
|
+
answer = new leaverequest_1.LeaveRequest({
|
|
1157
|
+
id: id,
|
|
1158
|
+
employeeid: this.id,
|
|
1159
|
+
requestDate: new Date(),
|
|
1160
|
+
primarycode: code,
|
|
1161
|
+
startdate: start,
|
|
1162
|
+
enddate: end,
|
|
1163
|
+
status: 'DRAFT',
|
|
1164
|
+
approvalDate: new Date(0),
|
|
1165
|
+
approvedby: '',
|
|
1166
|
+
requesteddays: [],
|
|
1167
|
+
comments: []
|
|
1168
|
+
});
|
|
1134
1169
|
answer.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1135
1170
|
commentdate: new Date(),
|
|
1136
|
-
comment:
|
|
1171
|
+
comment: 'Request Created'
|
|
1137
1172
|
}));
|
|
1173
|
+
if (comment) {
|
|
1174
|
+
answer.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1175
|
+
commentdate: new Date(),
|
|
1176
|
+
comment: comment
|
|
1177
|
+
}));
|
|
1178
|
+
}
|
|
1179
|
+
answer.setLeaveDays(this, true);
|
|
1180
|
+
this.requests.push(new leaverequest_1.LeaveRequest(answer));
|
|
1138
1181
|
}
|
|
1139
|
-
answer.setLeaveDays(this, true);
|
|
1140
|
-
this.requests.push(new leaverequest_1.LeaveRequest(answer));
|
|
1141
1182
|
}
|
|
1142
1183
|
return answer;
|
|
1143
1184
|
}
|
|
@@ -1147,377 +1188,395 @@ class Employee {
|
|
|
1147
1188
|
leaverequest: undefined,
|
|
1148
1189
|
error: undefined
|
|
1149
1190
|
};
|
|
1150
|
-
this.requests
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1191
|
+
if (this.requests) {
|
|
1192
|
+
this.requests.forEach((req, r) => {
|
|
1193
|
+
if (req.useRequest(id)) {
|
|
1194
|
+
switch (field.toLowerCase()) {
|
|
1195
|
+
case "approve":
|
|
1196
|
+
this.approveLeaveRequest(id, value);
|
|
1197
|
+
break;
|
|
1198
|
+
case "startdate":
|
|
1199
|
+
case "start":
|
|
1200
|
+
let sdate = new Date(Date.parse(value));
|
|
1201
|
+
sdate = new Date(Date.UTC(sdate.getFullYear(), sdate.getMonth(), sdate.getDate()));
|
|
1202
|
+
if (sdate.getTime() < req.startdate.getTime()
|
|
1203
|
+
|| sdate.getTime() > req.enddate.getTime()) {
|
|
1204
|
+
if (req.status.toLowerCase() === 'approved') {
|
|
1205
|
+
if (this.leaves) {
|
|
1206
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1207
|
+
let count = 0;
|
|
1208
|
+
let startpos = -1;
|
|
1209
|
+
this.leaves.forEach((lv, l) => {
|
|
1210
|
+
if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
|
|
1211
|
+
if (startpos < 0) {
|
|
1212
|
+
startpos = l;
|
|
1213
|
+
count++;
|
|
1214
|
+
}
|
|
1215
|
+
else {
|
|
1216
|
+
count++;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
if (startpos >= 0) {
|
|
1221
|
+
this.leaves.splice(startpos, count);
|
|
1174
1222
|
}
|
|
1175
1223
|
}
|
|
1176
|
-
});
|
|
1177
|
-
if (startpos >= 0) {
|
|
1178
|
-
this.leaves.splice(startpos, count);
|
|
1179
1224
|
}
|
|
1225
|
+
req.status = 'DRAFT';
|
|
1226
|
+
req.approvalDate = new Date(0);
|
|
1227
|
+
req.approvedby = '';
|
|
1228
|
+
answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
|
|
1229
|
+
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1230
|
+
+ `${req.enddate.toLocaleDateString('en-US')}) start date was changed to `
|
|
1231
|
+
+ `before original date. This converted the leave request back to draft `
|
|
1232
|
+
+ `for resubmittal.`;
|
|
1180
1233
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
count
|
|
1201
|
-
}
|
|
1202
|
-
else {
|
|
1203
|
-
count++;
|
|
1234
|
+
else {
|
|
1235
|
+
if (req.status.toLowerCase() === 'approved') {
|
|
1236
|
+
if (this.leaves) {
|
|
1237
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1238
|
+
let count = 0;
|
|
1239
|
+
let startpos = -1;
|
|
1240
|
+
this.leaves.forEach((lv, l) => {
|
|
1241
|
+
if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
|
|
1242
|
+
&& lv.leavedate.getTime() < sdate.getTime()) {
|
|
1243
|
+
if (startpos < 0) {
|
|
1244
|
+
startpos = l;
|
|
1245
|
+
count++;
|
|
1246
|
+
}
|
|
1247
|
+
else {
|
|
1248
|
+
count++;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
if (startpos >= 0 && count > 0) {
|
|
1253
|
+
this.leaves.splice(startpos, count);
|
|
1204
1254
|
}
|
|
1205
1255
|
}
|
|
1206
|
-
});
|
|
1207
|
-
if (startpos >= 0 && count > 0) {
|
|
1208
|
-
this.leaves.splice(startpos, count);
|
|
1209
1256
|
}
|
|
1257
|
+
answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
|
|
1258
|
+
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1259
|
+
+ `${req.enddate.toLocaleDateString('en-US')}) start date was changed `
|
|
1260
|
+
+ `within the original dates. Approved Leave days were updated in the database `
|
|
1261
|
+
+ 'as approved.';
|
|
1210
1262
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
count
|
|
1263
|
+
req.startdate = new Date(sdate);
|
|
1264
|
+
req.setLeaveDays(this);
|
|
1265
|
+
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1266
|
+
commentdate: new Date(),
|
|
1267
|
+
comment: `Start date for request was changed to ${sdate.toDateString()}`
|
|
1268
|
+
}));
|
|
1269
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1270
|
+
break;
|
|
1271
|
+
case "enddate":
|
|
1272
|
+
case "end":
|
|
1273
|
+
let edate = new Date(Date.parse(value));
|
|
1274
|
+
edate = new Date(Date.UTC(edate.getFullYear(), edate.getMonth(), edate.getDate()));
|
|
1275
|
+
if (edate.getTime() < req.startdate.getTime()
|
|
1276
|
+
|| edate.getTime() > req.enddate.getTime()) {
|
|
1277
|
+
if (req.status.toLowerCase() === 'approved') {
|
|
1278
|
+
if (this.leaves) {
|
|
1279
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1280
|
+
let count = 0;
|
|
1281
|
+
let startpos = -1;
|
|
1282
|
+
this.leaves.forEach((lv, l) => {
|
|
1283
|
+
if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
|
|
1284
|
+
if (startpos < 0) {
|
|
1285
|
+
startpos = l;
|
|
1286
|
+
count++;
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
count++;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
if (startpos >= 0) {
|
|
1294
|
+
this.leaves.splice(startpos, count);
|
|
1243
1295
|
}
|
|
1244
1296
|
}
|
|
1245
|
-
});
|
|
1246
|
-
if (startpos >= 0) {
|
|
1247
|
-
this.leaves.splice(startpos, count);
|
|
1248
1297
|
}
|
|
1298
|
+
req.status = 'DRAFT';
|
|
1299
|
+
req.approvalDate = new Date(0);
|
|
1300
|
+
req.approvedby = '';
|
|
1301
|
+
answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
|
|
1302
|
+
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1303
|
+
+ `${req.enddate.toLocaleDateString('en-US')}) ending date was changed to `
|
|
1304
|
+
+ `after original date. This converted the leave request back to draft `
|
|
1305
|
+
+ `for resubmittal.`;
|
|
1249
1306
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
count
|
|
1270
|
-
}
|
|
1271
|
-
else {
|
|
1272
|
-
count++;
|
|
1307
|
+
else {
|
|
1308
|
+
if (req.status.toLowerCase() === 'approved') {
|
|
1309
|
+
if (this.leaves) {
|
|
1310
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1311
|
+
let count = 0;
|
|
1312
|
+
let startpos = -1;
|
|
1313
|
+
this.leaves.forEach((lv, l) => {
|
|
1314
|
+
if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
|
|
1315
|
+
&& lv.leavedate.getTime() > edate.getTime()) {
|
|
1316
|
+
if (startpos < 0) {
|
|
1317
|
+
startpos = l;
|
|
1318
|
+
count++;
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
count++;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
if (startpos >= 0 && count > 0) {
|
|
1326
|
+
this.leaves.splice(startpos, count);
|
|
1273
1327
|
}
|
|
1274
1328
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1329
|
+
answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
|
|
1330
|
+
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1331
|
+
+ `${req.enddate.toLocaleDateString('en-US')}) start date was changed `
|
|
1332
|
+
+ `within the original dates. Approved leave dates were updated in the`
|
|
1333
|
+
+ 'database as approved';
|
|
1278
1334
|
}
|
|
1279
|
-
answer.message = `Leave Request: ${this.name.getFirstLast()} leave request `
|
|
1280
|
-
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1281
|
-
+ `${req.enddate.toLocaleDateString('en-US')}) start date was changed `
|
|
1282
|
-
+ `within the original dates. Approved leave dates were updated in the`
|
|
1283
|
-
+ 'database as approved';
|
|
1284
1335
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1336
|
+
req.enddate = new Date(edate);
|
|
1337
|
+
req.setLeaveDays(this);
|
|
1338
|
+
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1339
|
+
commentdate: new Date(),
|
|
1340
|
+
comment: `End date for request was changed to ${edate.toDateString()}`
|
|
1341
|
+
}));
|
|
1342
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1343
|
+
break;
|
|
1344
|
+
case 'dates':
|
|
1345
|
+
const values = value.split('|');
|
|
1346
|
+
let newstart = new Date(Date.parse(values[0]));
|
|
1347
|
+
newstart = new Date(Date.UTC(newstart.getFullYear(), newstart.getMonth(), newstart.getDate()));
|
|
1348
|
+
let newend = new Date(Date.parse(values[1]));
|
|
1349
|
+
newend = new Date(Date.UTC(newend.getFullYear(), newend.getMonth(), newend.getDate()));
|
|
1350
|
+
if (newstart.getTime() < req.startdate.getTime()
|
|
1351
|
+
|| newstart.getTime() > req.enddate.getTime()
|
|
1352
|
+
|| newend.getTime() < req.startdate.getTime()
|
|
1353
|
+
|| newend.getTime() > req.enddate.getTime()) {
|
|
1354
|
+
if (req.status.toLowerCase() === 'approved') {
|
|
1355
|
+
if (this.leaves) {
|
|
1356
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1357
|
+
let count = 0;
|
|
1358
|
+
let startpos = -1;
|
|
1359
|
+
this.leaves.forEach((lv, l) => {
|
|
1360
|
+
if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
|
|
1361
|
+
if (startpos < 0) {
|
|
1362
|
+
startpos = l;
|
|
1363
|
+
count++;
|
|
1364
|
+
}
|
|
1365
|
+
else {
|
|
1366
|
+
count++;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
if (startpos >= 0) {
|
|
1371
|
+
this.leaves.splice(startpos, count);
|
|
1316
1372
|
}
|
|
1317
1373
|
}
|
|
1318
|
-
});
|
|
1319
|
-
if (startpos >= 0) {
|
|
1320
|
-
this.leaves.splice(startpos, count);
|
|
1321
1374
|
}
|
|
1375
|
+
req.status = 'DRAFT';
|
|
1376
|
+
req.approvalDate = new Date(0);
|
|
1377
|
+
req.approvedby = '';
|
|
1378
|
+
answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
|
|
1379
|
+
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1380
|
+
+ `${req.enddate.toLocaleDateString('en-US')}) start date was changed to `
|
|
1381
|
+
+ `outside the original dates. This converted the leave request back to draft `
|
|
1382
|
+
+ `for resubmittal.`;
|
|
1322
1383
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1384
|
+
else {
|
|
1385
|
+
if (req.status.toLowerCase() === 'approved') {
|
|
1386
|
+
if (this.leaves) {
|
|
1387
|
+
this.leaves.sort((a, b) => a.compareTo(b));
|
|
1388
|
+
let startcount = 0;
|
|
1389
|
+
let startpos = -1;
|
|
1390
|
+
let endcount = 0;
|
|
1391
|
+
let endpos = -1;
|
|
1392
|
+
this.leaves.forEach((lv, l) => {
|
|
1393
|
+
if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
|
|
1394
|
+
&& lv.leavedate.getTime() < newstart.getTime()) {
|
|
1395
|
+
if (startpos < 0) {
|
|
1396
|
+
startpos = l;
|
|
1397
|
+
startcount++;
|
|
1398
|
+
}
|
|
1399
|
+
else {
|
|
1400
|
+
startcount++;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
else if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
|
|
1404
|
+
&& lv.leavedate.getTime() > newend.getTime()) {
|
|
1405
|
+
if (endpos < 0) {
|
|
1406
|
+
endpos = l;
|
|
1407
|
+
endcount++;
|
|
1408
|
+
}
|
|
1409
|
+
else {
|
|
1410
|
+
endcount++;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
if (startpos >= 0 && endcount > 0) {
|
|
1415
|
+
this.leaves.splice(startpos, startcount);
|
|
1355
1416
|
}
|
|
1356
|
-
|
|
1357
|
-
endcount
|
|
1417
|
+
if (endpos >= 0 && endcount > 0) {
|
|
1418
|
+
this.leaves.splice(endpos, endcount);
|
|
1358
1419
|
}
|
|
1359
1420
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
this.leaves.splice(endpos, endcount);
|
|
1421
|
+
answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
|
|
1422
|
+
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1423
|
+
+ `${req.enddate.toLocaleDateString('en-US')}) both dates were changed to `
|
|
1424
|
+
+ `within the original dates. All approved leave dates were updated in `
|
|
1425
|
+
+ 'the database.';
|
|
1366
1426
|
}
|
|
1367
|
-
answer.message = `Leave Request: ${this.name.getFirstLast()} leave request `
|
|
1368
|
-
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1369
|
-
+ `${req.enddate.toLocaleDateString('en-US')}) both dates were changed to `
|
|
1370
|
-
+ `within the original dates. All approved leave dates were updated in `
|
|
1371
|
-
+ 'the database.';
|
|
1372
1427
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
req.requesteddays[l] = lv;
|
|
1400
|
-
}
|
|
1401
|
-
});
|
|
1402
|
-
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1403
|
-
commentdate: new Date(),
|
|
1404
|
-
comment: 'Leave request was submitted for approval.'
|
|
1405
|
-
}));
|
|
1406
|
-
req.comments.sort((a, b) => a.compareTo(b));
|
|
1407
|
-
answer.message = `Leave Request from ${this.name.getLastFirst()} `
|
|
1408
|
-
+ `submitted for approval. Requested leave dates: `
|
|
1409
|
-
+ `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
|
|
1410
|
-
break;
|
|
1411
|
-
case "unapprove":
|
|
1412
|
-
req.approvedby = '';
|
|
1413
|
-
req.approvalDate = new Date(0);
|
|
1414
|
-
req.status = 'DRAFT';
|
|
1415
|
-
req.requesteddays.forEach((lv, l) => {
|
|
1416
|
-
if (lv.code !== '') {
|
|
1417
|
-
lv.status = 'REQUESTED';
|
|
1418
|
-
req.requesteddays[l] = lv;
|
|
1419
|
-
}
|
|
1420
|
-
});
|
|
1421
|
-
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1422
|
-
commentdate: new Date(),
|
|
1423
|
-
comment: `Request was declined by approver: ${value}`
|
|
1424
|
-
}));
|
|
1425
|
-
req.comments.sort((a, b) => a.compareTo(b));
|
|
1426
|
-
answer.message = `Leave Request: ${this.name.getFirstLast()} leave request `
|
|
1427
|
-
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1428
|
-
+ `${req.enddate.toLocaleDateString('en-US')}) was declined by approver.`;
|
|
1429
|
-
break;
|
|
1430
|
-
case 'day':
|
|
1431
|
-
case 'requestday':
|
|
1432
|
-
const bApproved = req.status.toLowerCase() === 'approved';
|
|
1433
|
-
let found = false;
|
|
1434
|
-
let max = 0;
|
|
1435
|
-
const svalues = value.split('|');
|
|
1436
|
-
let lvDate = new Date(Number(svalues[0]));
|
|
1437
|
-
let code = svalues[1];
|
|
1438
|
-
let hours = Number(svalues[2]);
|
|
1439
|
-
let tagday = svalues[3];
|
|
1440
|
-
let status = '';
|
|
1441
|
-
let workcenter = '';
|
|
1442
|
-
if (svalues.length > 3) {
|
|
1443
|
-
workcenter = svalues[3];
|
|
1444
|
-
}
|
|
1445
|
-
req.requesteddays.forEach((lv, l) => {
|
|
1446
|
-
if (lv.useLeave(lvDate)) {
|
|
1447
|
-
found = true;
|
|
1448
|
-
lv.code = code;
|
|
1449
|
-
if (status == '') {
|
|
1450
|
-
status = lv.status;
|
|
1451
|
-
}
|
|
1452
|
-
lv.status = workcenter;
|
|
1453
|
-
if (code == '') {
|
|
1454
|
-
lv.hours = 0.0;
|
|
1428
|
+
req.startdate = new Date(newstart);
|
|
1429
|
+
req.enddate = new Date(newend);
|
|
1430
|
+
req.setLeaveDays(this);
|
|
1431
|
+
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1432
|
+
commentdate: new Date(),
|
|
1433
|
+
comment: `Request dates for request were changed to `
|
|
1434
|
+
+ `${newstart.toDateString()} - ${newend.toDateString()}`
|
|
1435
|
+
}));
|
|
1436
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1437
|
+
break;
|
|
1438
|
+
case "code":
|
|
1439
|
+
case "primarycode":
|
|
1440
|
+
req.primarycode = value;
|
|
1441
|
+
req.setLeaveDays(this, true);
|
|
1442
|
+
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1443
|
+
commentdate: new Date(),
|
|
1444
|
+
comment: `Primary Code for request was changed to ${value}`
|
|
1445
|
+
}));
|
|
1446
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1447
|
+
break;
|
|
1448
|
+
case "requested":
|
|
1449
|
+
req.status = 'REQUESTED';
|
|
1450
|
+
req.requesteddays.forEach((lv, l) => {
|
|
1451
|
+
if (lv.code !== '') {
|
|
1452
|
+
lv.status = 'REQUESTED';
|
|
1453
|
+
req.requesteddays[l] = lv;
|
|
1455
1454
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1455
|
+
});
|
|
1456
|
+
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1457
|
+
commentdate: new Date(),
|
|
1458
|
+
comment: 'Leave request was submitted for approval.'
|
|
1459
|
+
}));
|
|
1460
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1461
|
+
answer.message = `Leave Request from ${this.user?.getLastFirst()} `
|
|
1462
|
+
+ `submitted for approval. Requested leave dates: `
|
|
1463
|
+
+ `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
|
|
1464
|
+
break;
|
|
1465
|
+
case "unapprove":
|
|
1466
|
+
req.approvedby = '';
|
|
1467
|
+
req.approvalDate = new Date(0);
|
|
1468
|
+
req.status = 'DRAFT';
|
|
1469
|
+
req.requesteddays.forEach((lv, l) => {
|
|
1470
|
+
if (lv.code !== '') {
|
|
1471
|
+
lv.status = 'REQUESTED';
|
|
1472
|
+
req.requesteddays[l] = lv;
|
|
1458
1473
|
}
|
|
1459
|
-
lv.tagday = tagday;
|
|
1460
|
-
req.requesteddays[l] = lv;
|
|
1461
|
-
}
|
|
1462
|
-
if (max < lv.id) {
|
|
1463
|
-
max = lv.id;
|
|
1464
|
-
}
|
|
1465
|
-
});
|
|
1466
|
-
if (!found) {
|
|
1467
|
-
const lv = new leave_1.Leave({
|
|
1468
|
-
id: max + 1,
|
|
1469
|
-
leavedate: new Date(lvDate),
|
|
1470
|
-
code: code,
|
|
1471
|
-
hours: hours,
|
|
1472
|
-
tagday: tagday,
|
|
1473
|
-
status: status,
|
|
1474
|
-
requestid: req.id,
|
|
1475
|
-
used: false
|
|
1476
1474
|
});
|
|
1477
|
-
req.
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
this.
|
|
1475
|
+
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1476
|
+
commentdate: new Date(),
|
|
1477
|
+
comment: `Request was declined by approver: ${value}`
|
|
1478
|
+
}));
|
|
1479
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1480
|
+
answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
|
|
1481
|
+
+ `(${req.startdate.toLocaleDateString('en-US')}-`
|
|
1482
|
+
+ `${req.enddate.toLocaleDateString('en-US')}) was declined by approver.`;
|
|
1483
|
+
break;
|
|
1484
|
+
case 'day':
|
|
1485
|
+
case 'requestday':
|
|
1486
|
+
const bApproved = req.status.toLowerCase() === 'approved';
|
|
1487
|
+
let found = false;
|
|
1488
|
+
let max = 0;
|
|
1489
|
+
const svalues = value.split('|');
|
|
1490
|
+
let lvDate = new Date(Number(svalues[0]));
|
|
1491
|
+
let code = svalues[1];
|
|
1492
|
+
let hours = Number(svalues[2]);
|
|
1493
|
+
let tagday = svalues[3];
|
|
1494
|
+
let status = '';
|
|
1495
|
+
let workcenter = '';
|
|
1496
|
+
if (svalues.length > 3) {
|
|
1497
|
+
workcenter = svalues[3];
|
|
1498
|
+
}
|
|
1499
|
+
req.requesteddays.forEach((lv, l) => {
|
|
1483
1500
|
if (lv.useLeave(lvDate)) {
|
|
1484
1501
|
found = true;
|
|
1485
1502
|
lv.code = code;
|
|
1486
|
-
if (
|
|
1503
|
+
if (status == '') {
|
|
1504
|
+
status = lv.status;
|
|
1505
|
+
}
|
|
1506
|
+
lv.status = workcenter;
|
|
1507
|
+
if (code == '') {
|
|
1487
1508
|
lv.hours = 0.0;
|
|
1488
1509
|
}
|
|
1489
1510
|
else {
|
|
1490
1511
|
lv.hours = hours;
|
|
1491
1512
|
}
|
|
1492
|
-
|
|
1513
|
+
lv.tagday = tagday;
|
|
1514
|
+
req.requesteddays[l] = lv;
|
|
1515
|
+
}
|
|
1516
|
+
if (max < lv.id) {
|
|
1517
|
+
max = lv.id;
|
|
1493
1518
|
}
|
|
1494
1519
|
});
|
|
1495
|
-
if (!found
|
|
1496
|
-
|
|
1520
|
+
if (!found) {
|
|
1521
|
+
const lv = new leave_1.Leave({
|
|
1497
1522
|
id: max + 1,
|
|
1498
1523
|
leavedate: new Date(lvDate),
|
|
1499
1524
|
code: code,
|
|
1500
1525
|
hours: hours,
|
|
1501
1526
|
tagday: tagday,
|
|
1502
|
-
status:
|
|
1527
|
+
status: status,
|
|
1503
1528
|
requestid: req.id,
|
|
1504
1529
|
used: false
|
|
1505
|
-
})
|
|
1530
|
+
});
|
|
1531
|
+
req.requesteddays.push(lv);
|
|
1532
|
+
req.requesteddays.sort((a, b) => a.compareTo(b));
|
|
1506
1533
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1534
|
+
if (bApproved) {
|
|
1535
|
+
found = false;
|
|
1536
|
+
if (this.leaves) {
|
|
1537
|
+
this.leaves.forEach((lv, l) => {
|
|
1538
|
+
if (lv.useLeave(lvDate)) {
|
|
1539
|
+
found = true;
|
|
1540
|
+
lv.code = code;
|
|
1541
|
+
if (code === '') {
|
|
1542
|
+
lv.hours = 0.0;
|
|
1543
|
+
}
|
|
1544
|
+
else {
|
|
1545
|
+
lv.hours = hours;
|
|
1546
|
+
}
|
|
1547
|
+
if (this.leaves) {
|
|
1548
|
+
this.leaves[l] = lv;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
});
|
|
1552
|
+
if (!found && code !== '') {
|
|
1553
|
+
this.leaves.push(new leave_1.Leave({
|
|
1554
|
+
id: max + 1,
|
|
1555
|
+
leavedate: new Date(lvDate),
|
|
1556
|
+
code: code,
|
|
1557
|
+
hours: hours,
|
|
1558
|
+
tagday: tagday,
|
|
1559
|
+
status: req.status,
|
|
1560
|
+
requestid: req.id,
|
|
1561
|
+
used: false
|
|
1562
|
+
}));
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
break;
|
|
1567
|
+
case "comment":
|
|
1568
|
+
case "addcomment":
|
|
1569
|
+
req.comments.push(new leaverequest_1.LeaveRequestComment({
|
|
1570
|
+
commentdate: new Date(),
|
|
1571
|
+
comment: value
|
|
1572
|
+
}));
|
|
1573
|
+
req.comments.sort((a, b) => a.compareTo(b));
|
|
1574
|
+
break;
|
|
1575
|
+
}
|
|
1576
|
+
answer.leaverequest = req;
|
|
1517
1577
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
});
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1521
1580
|
return answer;
|
|
1522
1581
|
}
|
|
1523
1582
|
approveLeaveRequest(id, approver) {
|
|
@@ -1526,115 +1585,125 @@ class Employee {
|
|
|
1526
1585
|
leaverequest: undefined,
|
|
1527
1586
|
error: undefined
|
|
1528
1587
|
};
|
|
1529
|
-
this.requests
|
|
1530
|
-
|
|
1531
|
-
req.
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
if (
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
day.status = 'Approved';
|
|
1546
|
-
req.requesteddays[d] = day;
|
|
1547
|
-
this.leaves.push(new leave_1.Leave({
|
|
1548
|
-
id: max,
|
|
1549
|
-
leavedate: new Date(day.leavedate),
|
|
1550
|
-
code: day.code,
|
|
1551
|
-
hours: day.hours,
|
|
1552
|
-
status: day.status,
|
|
1553
|
-
requestid: req.id,
|
|
1554
|
-
used: false
|
|
1555
|
-
}));
|
|
1556
|
-
}
|
|
1557
|
-
});
|
|
1558
|
-
answer.message = `Leave Request was approved for period of `
|
|
1559
|
-
+ `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
|
|
1560
|
-
answer.leaverequest = req;
|
|
1561
|
-
}
|
|
1562
|
-
else {
|
|
1563
|
-
let found = false;
|
|
1564
|
-
this.variations.forEach((vari, v) => {
|
|
1565
|
-
if (vari.startdate.getTime() === req.startdate.getTime()
|
|
1566
|
-
&& vari.enddate.getTime() === req.enddate.getTime()
|
|
1567
|
-
&& vari.mod) {
|
|
1568
|
-
found = true;
|
|
1569
|
-
let start = new Date(req.startdate);
|
|
1570
|
-
while (start.getDay() !== 0) {
|
|
1571
|
-
start = new Date(start.getTime() - (24 * 3600000));
|
|
1572
|
-
}
|
|
1573
|
-
vari.setScheduleDays();
|
|
1574
|
-
let lastcode = '';
|
|
1575
|
-
let workcenter = '';
|
|
1576
|
-
req.requesteddays.forEach(day => {
|
|
1588
|
+
if (this.requests) {
|
|
1589
|
+
this.requests.forEach((req, r) => {
|
|
1590
|
+
if (req.id === id) {
|
|
1591
|
+
req.approvalDate = new Date();
|
|
1592
|
+
req.approvedby = approver;
|
|
1593
|
+
req.status = 'Approved';
|
|
1594
|
+
let max = 0;
|
|
1595
|
+
if (req.primarycode.toLowerCase() !== 'mod') {
|
|
1596
|
+
this.removeLeaves(req.startdate, req.enddate, req.id, false);
|
|
1597
|
+
if (this.leaves) {
|
|
1598
|
+
this.leaves.forEach(lv => {
|
|
1599
|
+
if (max < lv.id) {
|
|
1600
|
+
max = lv.id;
|
|
1601
|
+
}
|
|
1602
|
+
});
|
|
1603
|
+
req.requesteddays.forEach((day, d) => {
|
|
1577
1604
|
if (day.code !== '') {
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1605
|
+
max++;
|
|
1606
|
+
day.status = 'Approved';
|
|
1607
|
+
req.requesteddays[d] = day;
|
|
1608
|
+
if (this.leaves) {
|
|
1609
|
+
this.leaves.push(new leave_1.Leave({
|
|
1610
|
+
id: max,
|
|
1611
|
+
leavedate: new Date(day.leavedate),
|
|
1612
|
+
code: day.code,
|
|
1613
|
+
hours: day.hours,
|
|
1614
|
+
status: day.status,
|
|
1615
|
+
requestid: req.id,
|
|
1616
|
+
used: false
|
|
1617
|
+
}));
|
|
1581
1618
|
}
|
|
1582
1619
|
}
|
|
1583
|
-
const dos = Math.floor((day.leavedate.getTime() - start.getTime())
|
|
1584
|
-
/ (24 * 3600000));
|
|
1585
|
-
vari.schedule.workdays[dos].code = lastcode;
|
|
1586
|
-
vari.schedule.workdays[dos].hours = day.hours;
|
|
1587
|
-
vari.schedule.workdays[dos].workcenter = workcenter;
|
|
1588
1620
|
});
|
|
1589
1621
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1622
|
+
answer.message = `Leave Request was approved for period of `
|
|
1623
|
+
+ `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
|
|
1624
|
+
answer.leaverequest = req;
|
|
1625
|
+
}
|
|
1626
|
+
else {
|
|
1627
|
+
let found = false;
|
|
1628
|
+
this.variations.forEach((vari, v) => {
|
|
1629
|
+
if (vari.startdate.getTime() === req.startdate.getTime()
|
|
1630
|
+
&& vari.enddate.getTime() === req.enddate.getTime()
|
|
1631
|
+
&& vari.mod) {
|
|
1632
|
+
found = true;
|
|
1633
|
+
let start = new Date(req.startdate);
|
|
1634
|
+
while (start.getDay() !== 0) {
|
|
1635
|
+
start = new Date(start.getTime() - (24 * 3600000));
|
|
1636
|
+
}
|
|
1637
|
+
vari.setScheduleDays();
|
|
1638
|
+
let lastcode = '';
|
|
1639
|
+
let workcenter = '';
|
|
1640
|
+
req.requesteddays.forEach(day => {
|
|
1641
|
+
if (day.code !== '') {
|
|
1642
|
+
lastcode = day.code;
|
|
1643
|
+
if (day.tagday) {
|
|
1644
|
+
workcenter = day.tagday;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
const dos = Math.floor((day.leavedate.getTime() - start.getTime())
|
|
1648
|
+
/ (24 * 3600000));
|
|
1649
|
+
vari.schedule.workdays[dos].code = lastcode;
|
|
1650
|
+
vari.schedule.workdays[dos].hours = day.hours;
|
|
1651
|
+
vari.schedule.workdays[dos].workcenter = workcenter;
|
|
1652
|
+
});
|
|
1596
1653
|
}
|
|
1597
1654
|
});
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1655
|
+
if (!found) {
|
|
1656
|
+
let max = 0;
|
|
1657
|
+
this.variations.forEach(vari => {
|
|
1658
|
+
if (max < vari.id) {
|
|
1659
|
+
max = vari.id;
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
const vari = new variation_1.Variation({
|
|
1663
|
+
id: max + 1,
|
|
1664
|
+
mids: false,
|
|
1665
|
+
mod: true,
|
|
1666
|
+
startdate: new Date(req.startdate),
|
|
1667
|
+
enddate: new Date(req.enddate),
|
|
1668
|
+
site: this.site,
|
|
1669
|
+
schedule: new workday_1.Schedule()
|
|
1670
|
+
});
|
|
1671
|
+
vari.setScheduleDays();
|
|
1672
|
+
vari.schedule.showdates = true;
|
|
1673
|
+
req.requesteddays.forEach(day => {
|
|
1674
|
+
vari.updateWorkdayByDate;
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1612
1677
|
}
|
|
1613
1678
|
}
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1616
1681
|
return answer;
|
|
1617
1682
|
}
|
|
1618
1683
|
deleteLeaveRequest(id) {
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
if (req
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
if (
|
|
1631
|
-
this.variations.
|
|
1684
|
+
if (this.requests) {
|
|
1685
|
+
let req = this.requests.find(r => r.id === id);
|
|
1686
|
+
if (req) {
|
|
1687
|
+
if (req.status.toLowerCase() === 'approved') {
|
|
1688
|
+
if (this.leaves) {
|
|
1689
|
+
let pos = this.leaves.findIndex(l => l.requestid === id);
|
|
1690
|
+
while (pos >= 0) {
|
|
1691
|
+
this.leaves.splice(pos, 1);
|
|
1692
|
+
pos = this.leaves.findIndex(l => l.requestid === id);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
if (req.primarycode.toLowerCase() === 'mod') {
|
|
1696
|
+
let pos = this.variations.findIndex(v => (v.mod && v.startdate.getTime() === req.startdate.getTime()
|
|
1697
|
+
&& v.enddate.getTime() === req.enddate.getTime()));
|
|
1698
|
+
if (pos >= 0) {
|
|
1699
|
+
this.variations.splice(pos, 1);
|
|
1700
|
+
}
|
|
1632
1701
|
}
|
|
1633
1702
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1703
|
+
let pos = this.requests.findIndex(r => r.id === id);
|
|
1704
|
+
if (pos >= 0) {
|
|
1705
|
+
this.requests.splice(pos, 1);
|
|
1706
|
+
}
|
|
1638
1707
|
}
|
|
1639
1708
|
}
|
|
1640
1709
|
}
|