scheduler-models 1.4.8 → 1.4.10

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.
@@ -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.push(new leave_1.Leave(l));
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.push(new leaverequest_1.LeaveRequest(r));
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
  }
@@ -157,6 +161,8 @@ class Employee {
157
161
  const result = new Employee(this);
158
162
  result.work = undefined;
159
163
  result.user = undefined;
164
+ result.leaves = undefined;
165
+ result.requests = undefined;
160
166
  return result;
161
167
  }
162
168
  purge(date) {
@@ -166,15 +172,19 @@ class Employee {
166
172
  this.variations.splice(v, 1);
167
173
  }
168
174
  }
169
- this.leaves.sort((a, b) => a.compareTo(b));
170
- for (let l = this.leaves.length - 1; l >= 0; l--) {
171
- if (this.leaves[l].leavedate.getTime() < date.getTime()) {
172
- this.leaves.splice(l, 1);
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
+ }
173
181
  }
174
182
  }
175
- for (let l = this.requests.length - 1; l >= 0; l--) {
176
- if (this.requests[l].enddate.getTime() < date.getTime()) {
177
- this.requests.splice(l, 1);
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
+ }
178
188
  }
179
189
  }
180
190
  this.balances.sort((a, b) => a.compareTo(b));
@@ -188,34 +198,36 @@ class Employee {
188
198
  return (last.endDate.getTime() < date.getTime());
189
199
  }
190
200
  removeLeaves(start, end, reqID = '', includeActuals = true) {
191
- this.leaves.sort((a, b) => a.compareTo(b));
192
- for (let l = this.leaves.length - 1; l >= 0; l--) {
193
- if (reqID === '' && includeActuals) {
194
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
195
- && this.leaves[l].leavedate.getTime() <= end.getTime()) {
196
- this.leaves.splice(l, 1);
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
+ }
197
209
  }
198
- }
199
- else if (reqID !== '' && includeActuals) {
200
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
201
- && this.leaves[l].leavedate.getTime() <= end.getTime()
202
- && this.leaves[l].requestid === reqID) {
203
- this.leaves.splice(l, 1);
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
+ }
204
216
  }
205
- }
206
- else if (reqID === '' && !includeActuals) {
207
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
208
- && this.leaves[l].leavedate.getTime() <= end.getTime()
209
- && this.leaves[l].status.toLowerCase() !== 'actual') {
210
- this.leaves.splice(l, 1);
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
+ }
211
223
  }
212
- }
213
- else if (reqID !== '' && !includeActuals) {
214
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
215
- && this.leaves[l].leavedate.getTime() <= end.getTime()
216
- && this.leaves[l].status.toLowerCase() !== 'actual'
217
- && this.leaves[l].requestid === reqID) {
218
- this.leaves.splice(l, 1);
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
+ }
219
231
  }
220
232
  }
221
233
  }
@@ -320,17 +332,19 @@ class Employee {
320
332
  wday.hours = work;
321
333
  return wday;
322
334
  }
323
- this.leaves.forEach(lv => {
324
- if (lv.useLeave(date)
325
- && (lv.hours > stdWorkday / 2 || lv.status.toLowerCase() === 'actual')) {
326
- wday = new workday_1.Workday({
327
- id: 0,
328
- workcenter: '',
329
- code: lv.code,
330
- hours: lv.hours
331
- });
332
- }
333
- });
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
+ }
334
348
  return wday;
335
349
  }
336
350
  getWorkdayActual(date, labor) {
@@ -357,7 +371,7 @@ class Employee {
357
371
  }
358
372
  });
359
373
  let bLeave = false;
360
- if (bPrimary || labor?.length === 0) {
374
+ if ((bPrimary || labor?.length === 0) && this.leaves) {
361
375
  this.leaves.forEach(lv => {
362
376
  if (lv.useLeave(date) && lv.status.toLowerCase() === 'actual') {
363
377
  if (!bLeave) {
@@ -419,19 +433,21 @@ class Employee {
419
433
  }
420
434
  return wday;
421
435
  }
422
- this.leaves.forEach(lv => {
423
- if (lv.useLeave(date)) {
424
- if (!wday || wday.hours < lv.hours) {
425
- wday = new workday_1.Workday({
426
- id: date.getDate(),
427
- workcenter: '',
428
- date: new Date(date),
429
- code: lv.code,
430
- hours: lv.hours
431
- });
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
+ }
432
448
  }
433
- }
434
- });
449
+ });
450
+ }
435
451
  return wday;
436
452
  }
437
453
  getWorkdayWOLeaves(date, useWork) {
@@ -819,12 +835,14 @@ class Employee {
819
835
  this.work.sort((a, b) => a.compareTo(b));
820
836
  lastWorked = new Date(this.work[this.work.length - 1].dateworked);
821
837
  }
822
- this.leaves.sort((a, b) => a.compareTo(b));
823
- this.leaves.forEach(lv => {
824
- if (lv.status.toLowerCase() === 'actual' && lv.leavedate.getTime() > lastWorked.getTime()) {
825
- lastWorked = new Date(lv.leavedate);
826
- }
827
- });
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
+ }
828
846
  let current = new Date(start);
829
847
  while (current.getTime() <= end.getTime()) {
830
848
  if (current.getTime() > lastWorked.getTime()) {
@@ -930,12 +948,14 @@ class Employee {
930
948
  }
931
949
  else {
932
950
  let carry = lastAnnual + lastCarry;
933
- this.leaves.forEach(lv => {
934
- if (lv.leavedate.getFullYear() === year && lv.code.toLowerCase() === 'v'
935
- && lv.status.toLowerCase() === 'actual') {
936
- carry -= lv.hours;
937
- }
938
- });
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
+ }
939
959
  bal.carryover = carry;
940
960
  }
941
961
  this.balances.push(bal);
@@ -984,170 +1004,181 @@ class Employee {
984
1004
  let found = false;
985
1005
  let max = 0;
986
1006
  date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
987
- this.leaves.forEach((lv, l) => {
988
- if ((lv.useLeave(date) && lv.code.toLowerCase() === code.toLowerCase())
989
- || lv.id === id) {
990
- found = true;
991
- lv.status = status;
992
- lv.hours = hours;
993
- if (lv.requestid === '') {
994
- lv.requestid = 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
+ }
995
1023
  }
996
- if (holCode && holCode !== '') {
997
- lv.tagday = holCode;
1024
+ else if (lv.id > max) {
1025
+ max = lv.id;
998
1026
  }
999
- this.leaves[l] = lv;
1000
- }
1001
- else if (lv.id > max) {
1002
- max = lv.id;
1003
- }
1004
- });
1005
- if (!found) {
1006
- const lv = new leave_1.Leave({
1007
- id: max + 1,
1008
- leavedate: new Date(date),
1009
- code: code,
1010
- hours: hours,
1011
- status: status,
1012
- requestid: requestid,
1013
- used: false,
1014
- tagday: holCode
1015
1027
  });
1016
- this.leaves.push(lv);
1017
- this.leaves.sort((a, b) => a.compareTo(b));
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
+ }
1018
1042
  }
1019
1043
  }
1020
1044
  updateLeave(id, field, value) {
1021
1045
  let answer = undefined;
1022
- this.leaves.forEach((lv, l) => {
1023
- if (lv.id === id) {
1024
- switch (field.toLowerCase()) {
1025
- case "date":
1026
- const newdate = new Date(Date.parse(value));
1027
- lv.leavedate = newdate;
1028
- break;
1029
- case "code":
1030
- lv.code = value;
1031
- break;
1032
- case "hours":
1033
- lv.hours = Number(value);
1034
- break;
1035
- case 'status':
1036
- lv.status = value;
1037
- break;
1038
- case 'requestid':
1039
- lv.requestid = value;
1040
- break;
1041
- case 'tagday':
1042
- lv.tagday = value;
1043
- break;
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
+ }
1044
1070
  }
1045
- }
1046
- this.leaves[l] = lv;
1047
- this.leaves.sort((a, b) => a.compareTo(b));
1048
- answer = lv;
1049
- });
1071
+ if (this.leaves) {
1072
+ this.leaves[l] = lv;
1073
+ this.leaves.sort((a, b) => a.compareTo(b));
1074
+ }
1075
+ answer = lv;
1076
+ });
1077
+ }
1050
1078
  return answer;
1051
1079
  }
1052
1080
  deleteLeave(id) {
1053
1081
  let found = -1;
1054
- this.leaves.forEach((lv, l) => {
1055
- if (lv.id === id) {
1056
- found = l;
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);
1057
1090
  }
1058
- });
1059
- if (found >= 0) {
1060
- this.leaves.splice(found, 1);
1061
1091
  }
1062
1092
  }
1063
1093
  getLeaveHours(start, end) {
1064
1094
  let answer = 0.0;
1065
- this.leaves.forEach(lv => {
1066
- if (lv.leavedate.getTime() >= start.getTime()
1067
- && end.getTime() >= lv.leavedate.getTime()
1068
- && lv.status.toLowerCase() === 'actual') {
1069
- answer += lv.hours;
1070
- }
1071
- });
1095
+ if (this.leaves) {
1096
+ }
1072
1097
  return answer;
1073
1098
  }
1074
1099
  getLeave(start) {
1075
1100
  const workday = new workday_1.Workday();
1076
- this.leaves.forEach(lv => {
1077
- if (lv.leavedate.getUTCFullYear() === start.getUTCFullYear()
1078
- && lv.leavedate.getUTCMonth() === start.getUTCMonth()
1079
- && lv.leavedate.getUTCDate() === start.getUTCDate()) {
1080
- if (workday.code === '') {
1081
- workday.code = lv.code;
1082
- workday.hours = lv.hours;
1083
- }
1084
- else {
1085
- 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 === '') {
1086
1107
  workday.code = lv.code;
1087
- workday.hours += lv.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
+ }
1088
1115
  }
1089
1116
  }
1090
- }
1091
- });
1117
+ });
1118
+ }
1092
1119
  return workday;
1093
1120
  }
1094
1121
  getPTOHours(start, end) {
1095
1122
  let answer = 0.0;
1096
- this.leaves.forEach(lv => {
1097
- if (lv.leavedate.getTime() >= start.getTime()
1098
- && end.getTime() >= lv.leavedate.getTime()
1099
- && lv.status.toLowerCase() === 'actual'
1100
- && lv.code.toLowerCase() === 'v') {
1101
- answer += lv.hours;
1102
- }
1103
- });
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
+ }
1104
1133
  return answer;
1105
1134
  }
1106
1135
  createLeaveRequest(start, end, code, comment) {
1107
1136
  start = new Date(Date.UTC(start.getFullYear(), start.getMonth(), start.getDate()));
1108
1137
  end = new Date(Date.UTC(end.getFullYear(), end.getMonth(), end.getDate()));
1109
1138
  let answer = undefined;
1110
- this.requests.forEach((req, r) => {
1111
- if (req.startdate.getTime() === start.getTime()
1112
- && req.enddate.getTime() === end.getTime()) {
1113
- if (comment) {
1114
- const cmt = new leaverequest_1.LeaveRequestComment({
1115
- commentdate: new Date(),
1116
- comment: comment
1117
- });
1118
- req.comments.push(cmt);
1119
- req.comments.sort((a, b) => a.compareTo(b));
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);
1120
1152
  }
1121
- answer = new leaverequest_1.LeaveRequest(req);
1122
- }
1123
- });
1124
- if (!answer) {
1125
- const id = (new Date()).getTime().toString();
1126
- answer = new leaverequest_1.LeaveRequest({
1127
- id: id,
1128
- employeeid: this.id,
1129
- requestDate: new Date(),
1130
- primarycode: code,
1131
- startdate: start,
1132
- enddate: end,
1133
- status: 'DRAFT',
1134
- approvalDate: new Date(0),
1135
- approvedby: '',
1136
- requesteddays: [],
1137
- comments: []
1138
1153
  });
1139
- answer.comments.push(new leaverequest_1.LeaveRequestComment({
1140
- commentdate: new Date(),
1141
- comment: 'Request Created'
1142
- }));
1143
- if (comment) {
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
+ });
1144
1169
  answer.comments.push(new leaverequest_1.LeaveRequestComment({
1145
1170
  commentdate: new Date(),
1146
- comment: comment
1171
+ comment: 'Request Created'
1147
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));
1148
1181
  }
1149
- answer.setLeaveDays(this, true);
1150
- this.requests.push(new leaverequest_1.LeaveRequest(answer));
1151
1182
  }
1152
1183
  return answer;
1153
1184
  }
@@ -1157,377 +1188,395 @@ class Employee {
1157
1188
  leaverequest: undefined,
1158
1189
  error: undefined
1159
1190
  };
1160
- this.requests.forEach((req, r) => {
1161
- if (req.useRequest(id)) {
1162
- switch (field.toLowerCase()) {
1163
- case "approve":
1164
- this.approveLeaveRequest(id, value);
1165
- break;
1166
- case "startdate":
1167
- case "start":
1168
- let sdate = new Date(Date.parse(value));
1169
- sdate = new Date(Date.UTC(sdate.getFullYear(), sdate.getMonth(), sdate.getDate()));
1170
- if (sdate.getTime() < req.startdate.getTime()
1171
- || sdate.getTime() > req.enddate.getTime()) {
1172
- if (req.status.toLowerCase() === 'approved') {
1173
- this.leaves.sort((a, b) => a.compareTo(b));
1174
- let count = 0;
1175
- let startpos = -1;
1176
- this.leaves.forEach((lv, l) => {
1177
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
1178
- if (startpos < 0) {
1179
- startpos = l;
1180
- count++;
1181
- }
1182
- else {
1183
- count++;
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);
1184
1222
  }
1185
1223
  }
1186
- });
1187
- if (startpos >= 0) {
1188
- this.leaves.splice(startpos, count);
1189
- }
1190
- }
1191
- req.status = 'DRAFT';
1192
- req.approvalDate = new Date(0);
1193
- req.approvedby = '';
1194
- answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
1195
- + `(${req.startdate.toLocaleDateString('en-US')}-`
1196
- + `${req.enddate.toLocaleDateString('en-US')}) start date was changed to `
1197
- + `before original date. This converted the leave request back to draft `
1198
- + `for resubmittal.`;
1199
- }
1200
- else {
1201
- if (req.status.toLowerCase() === 'approved') {
1202
- this.leaves.sort((a, b) => a.compareTo(b));
1203
- let count = 0;
1204
- let startpos = -1;
1205
- this.leaves.forEach((lv, l) => {
1206
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1207
- && lv.leavedate.getTime() < sdate.getTime()) {
1208
- if (startpos < 0) {
1209
- startpos = l;
1210
- count++;
1211
- }
1212
- else {
1213
- count++;
1214
- }
1215
- }
1216
- });
1217
- if (startpos >= 0 && count > 0) {
1218
- this.leaves.splice(startpos, count);
1219
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.`;
1220
1233
  }
1221
- answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
1222
- + `(${req.startdate.toLocaleDateString('en-US')}-`
1223
- + `${req.enddate.toLocaleDateString('en-US')}) start date was changed `
1224
- + `within the original dates. Approved Leave days were updated in the database `
1225
- + 'as approved.';
1226
- }
1227
- req.startdate = new Date(sdate);
1228
- req.setLeaveDays(this);
1229
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1230
- commentdate: new Date(),
1231
- comment: `Start date for request was changed to ${sdate.toDateString()}`
1232
- }));
1233
- req.comments.sort((a, b) => a.compareTo(b));
1234
- break;
1235
- case "enddate":
1236
- case "end":
1237
- let edate = new Date(Date.parse(value));
1238
- edate = new Date(Date.UTC(edate.getFullYear(), edate.getMonth(), edate.getDate()));
1239
- if (edate.getTime() < req.startdate.getTime()
1240
- || edate.getTime() > req.enddate.getTime()) {
1241
- if (req.status.toLowerCase() === 'approved') {
1242
- this.leaves.sort((a, b) => a.compareTo(b));
1243
- let count = 0;
1244
- let startpos = -1;
1245
- this.leaves.forEach((lv, l) => {
1246
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
1247
- if (startpos < 0) {
1248
- startpos = l;
1249
- count++;
1250
- }
1251
- else {
1252
- 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);
1253
1254
  }
1254
1255
  }
1255
- });
1256
- if (startpos >= 0) {
1257
- this.leaves.splice(startpos, count);
1258
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.';
1259
1262
  }
1260
- req.status = 'DRAFT';
1261
- req.approvalDate = new Date(0);
1262
- req.approvedby = '';
1263
- answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
1264
- + `(${req.startdate.toLocaleDateString('en-US')}-`
1265
- + `${req.enddate.toLocaleDateString('en-US')}) ending date was changed to `
1266
- + `after original date. This converted the leave request back to draft `
1267
- + `for resubmittal.`;
1268
- }
1269
- else {
1270
- if (req.status.toLowerCase() === 'approved') {
1271
- this.leaves.sort((a, b) => a.compareTo(b));
1272
- let count = 0;
1273
- let startpos = -1;
1274
- this.leaves.forEach((lv, l) => {
1275
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1276
- && lv.leavedate.getTime() > edate.getTime()) {
1277
- if (startpos < 0) {
1278
- startpos = l;
1279
- count++;
1280
- }
1281
- else {
1282
- 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);
1283
1295
  }
1284
1296
  }
1285
- });
1286
- if (startpos >= 0 && count > 0) {
1287
- this.leaves.splice(startpos, count);
1288
1297
  }
1298
+ req.status = 'DRAFT';
1299
+ req.approvalDate = new Date(0);
1300
+ req.approvedby = '';
1289
1301
  answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
1290
1302
  + `(${req.startdate.toLocaleDateString('en-US')}-`
1291
- + `${req.enddate.toLocaleDateString('en-US')}) start date was changed `
1292
- + `within the original dates. Approved leave dates were updated in the`
1293
- + 'database as approved';
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.`;
1294
1306
  }
1295
- }
1296
- req.enddate = new Date(edate);
1297
- req.setLeaveDays(this);
1298
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1299
- commentdate: new Date(),
1300
- comment: `End date for request was changed to ${edate.toDateString()}`
1301
- }));
1302
- req.comments.sort((a, b) => a.compareTo(b));
1303
- break;
1304
- case 'dates':
1305
- const values = value.split('|');
1306
- let newstart = new Date(Date.parse(values[0]));
1307
- newstart = new Date(Date.UTC(newstart.getFullYear(), newstart.getMonth(), newstart.getDate()));
1308
- let newend = new Date(Date.parse(values[1]));
1309
- newend = new Date(Date.UTC(newend.getFullYear(), newend.getMonth(), newend.getDate()));
1310
- if (newstart.getTime() < req.startdate.getTime()
1311
- || newstart.getTime() > req.enddate.getTime()
1312
- || newend.getTime() < req.startdate.getTime()
1313
- || newend.getTime() > req.enddate.getTime()) {
1314
- if (req.status.toLowerCase() === 'approved') {
1315
- this.leaves.sort((a, b) => a.compareTo(b));
1316
- let count = 0;
1317
- let startpos = -1;
1318
- this.leaves.forEach((lv, l) => {
1319
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
1320
- if (startpos < 0) {
1321
- startpos = l;
1322
- count++;
1323
- }
1324
- else {
1325
- 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);
1326
1327
  }
1327
1328
  }
1328
- });
1329
- if (startpos >= 0) {
1330
- this.leaves.splice(startpos, count);
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';
1331
1334
  }
1332
1335
  }
1333
- req.status = 'DRAFT';
1334
- req.approvalDate = new Date(0);
1335
- req.approvedby = '';
1336
- answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
1337
- + `(${req.startdate.toLocaleDateString('en-US')}-`
1338
- + `${req.enddate.toLocaleDateString('en-US')}) start date was changed to `
1339
- + `outside the original dates. This converted the leave request back to draft `
1340
- + `for resubmittal.`;
1341
- }
1342
- else {
1343
- if (req.status.toLowerCase() === 'approved') {
1344
- this.leaves.sort((a, b) => a.compareTo(b));
1345
- let startcount = 0;
1346
- let startpos = -1;
1347
- let endcount = 0;
1348
- let endpos = -1;
1349
- this.leaves.forEach((lv, l) => {
1350
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1351
- && lv.leavedate.getTime() < newstart.getTime()) {
1352
- if (startpos < 0) {
1353
- startpos = l;
1354
- startcount++;
1355
- }
1356
- else {
1357
- startcount++;
1358
- }
1359
- }
1360
- else if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1361
- && lv.leavedate.getTime() > newend.getTime()) {
1362
- if (endpos < 0) {
1363
- endpos = l;
1364
- endcount++;
1365
- }
1366
- else {
1367
- endcount++;
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);
1368
1372
  }
1369
1373
  }
1370
- });
1371
- if (startpos >= 0 && endcount > 0) {
1372
- this.leaves.splice(startpos, startcount);
1373
- }
1374
- if (endpos >= 0 && endcount > 0) {
1375
- this.leaves.splice(endpos, endcount);
1376
1374
  }
1375
+ req.status = 'DRAFT';
1376
+ req.approvalDate = new Date(0);
1377
+ req.approvedby = '';
1377
1378
  answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
1378
1379
  + `(${req.startdate.toLocaleDateString('en-US')}-`
1379
- + `${req.enddate.toLocaleDateString('en-US')}) both dates were changed to `
1380
- + `within the original dates. All approved leave dates were updated in `
1381
- + 'the database.';
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.`;
1382
1383
  }
1383
- }
1384
- req.startdate = new Date(newstart);
1385
- req.enddate = new Date(newend);
1386
- req.setLeaveDays(this);
1387
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1388
- commentdate: new Date(),
1389
- comment: `Request dates for request were changed to `
1390
- + `${newstart.toDateString()} - ${newend.toDateString()}`
1391
- }));
1392
- req.comments.sort((a, b) => a.compareTo(b));
1393
- break;
1394
- case "code":
1395
- case "primarycode":
1396
- req.primarycode = value;
1397
- req.setLeaveDays(this, true);
1398
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1399
- commentdate: new Date(),
1400
- comment: `Primary Code for request was changed to ${value}`
1401
- }));
1402
- req.comments.sort((a, b) => a.compareTo(b));
1403
- break;
1404
- case "requested":
1405
- req.status = 'REQUESTED';
1406
- req.requesteddays.forEach((lv, l) => {
1407
- if (lv.code !== '') {
1408
- lv.status = 'REQUESTED';
1409
- req.requesteddays[l] = lv;
1410
- }
1411
- });
1412
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1413
- commentdate: new Date(),
1414
- comment: 'Leave request was submitted for approval.'
1415
- }));
1416
- req.comments.sort((a, b) => a.compareTo(b));
1417
- answer.message = `Leave Request from ${this.user?.getLastFirst()} `
1418
- + `submitted for approval. Requested leave dates: `
1419
- + `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
1420
- break;
1421
- case "unapprove":
1422
- req.approvedby = '';
1423
- req.approvalDate = new Date(0);
1424
- req.status = 'DRAFT';
1425
- req.requesteddays.forEach((lv, l) => {
1426
- if (lv.code !== '') {
1427
- lv.status = 'REQUESTED';
1428
- req.requesteddays[l] = lv;
1429
- }
1430
- });
1431
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1432
- commentdate: new Date(),
1433
- comment: `Request was declined by approver: ${value}`
1434
- }));
1435
- req.comments.sort((a, b) => a.compareTo(b));
1436
- answer.message = `Leave Request: ${this.user?.getFirstLast()} leave request `
1437
- + `(${req.startdate.toLocaleDateString('en-US')}-`
1438
- + `${req.enddate.toLocaleDateString('en-US')}) was declined by approver.`;
1439
- break;
1440
- case 'day':
1441
- case 'requestday':
1442
- const bApproved = req.status.toLowerCase() === 'approved';
1443
- let found = false;
1444
- let max = 0;
1445
- const svalues = value.split('|');
1446
- let lvDate = new Date(Number(svalues[0]));
1447
- let code = svalues[1];
1448
- let hours = Number(svalues[2]);
1449
- let tagday = svalues[3];
1450
- let status = '';
1451
- let workcenter = '';
1452
- if (svalues.length > 3) {
1453
- workcenter = svalues[3];
1454
- }
1455
- req.requesteddays.forEach((lv, l) => {
1456
- if (lv.useLeave(lvDate)) {
1457
- found = true;
1458
- lv.code = code;
1459
- if (status == '') {
1460
- status = lv.status;
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);
1416
+ }
1417
+ if (endpos >= 0 && endcount > 0) {
1418
+ this.leaves.splice(endpos, endcount);
1419
+ }
1420
+ }
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.';
1461
1426
  }
1462
- lv.status = workcenter;
1463
- if (code == '') {
1464
- lv.hours = 0.0;
1427
+ }
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;
1465
1454
  }
1466
- else {
1467
- lv.hours = hours;
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;
1468
1473
  }
1469
- lv.tagday = tagday;
1470
- req.requesteddays[l] = lv;
1471
- }
1472
- if (max < lv.id) {
1473
- max = lv.id;
1474
- }
1475
- });
1476
- if (!found) {
1477
- const lv = new leave_1.Leave({
1478
- id: max + 1,
1479
- leavedate: new Date(lvDate),
1480
- code: code,
1481
- hours: hours,
1482
- tagday: tagday,
1483
- status: status,
1484
- requestid: req.id,
1485
- used: false
1486
1474
  });
1487
- req.requesteddays.push(lv);
1488
- req.requesteddays.sort((a, b) => a.compareTo(b));
1489
- }
1490
- if (bApproved) {
1491
- found = false;
1492
- this.leaves.forEach((lv, l) => {
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) => {
1493
1500
  if (lv.useLeave(lvDate)) {
1494
1501
  found = true;
1495
1502
  lv.code = code;
1496
- if (code === '') {
1503
+ if (status == '') {
1504
+ status = lv.status;
1505
+ }
1506
+ lv.status = workcenter;
1507
+ if (code == '') {
1497
1508
  lv.hours = 0.0;
1498
1509
  }
1499
1510
  else {
1500
1511
  lv.hours = hours;
1501
1512
  }
1502
- this.leaves[l] = lv;
1513
+ lv.tagday = tagday;
1514
+ req.requesteddays[l] = lv;
1515
+ }
1516
+ if (max < lv.id) {
1517
+ max = lv.id;
1503
1518
  }
1504
1519
  });
1505
- if (!found && code !== '') {
1506
- this.leaves.push(new leave_1.Leave({
1520
+ if (!found) {
1521
+ const lv = new leave_1.Leave({
1507
1522
  id: max + 1,
1508
1523
  leavedate: new Date(lvDate),
1509
1524
  code: code,
1510
1525
  hours: hours,
1511
1526
  tagday: tagday,
1512
- status: req.status,
1527
+ status: status,
1513
1528
  requestid: req.id,
1514
1529
  used: false
1515
- }));
1530
+ });
1531
+ req.requesteddays.push(lv);
1532
+ req.requesteddays.sort((a, b) => a.compareTo(b));
1516
1533
  }
1517
- }
1518
- break;
1519
- case "comment":
1520
- case "addcomment":
1521
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1522
- commentdate: new Date(),
1523
- comment: value
1524
- }));
1525
- req.comments.sort((a, b) => a.compareTo(b));
1526
- break;
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;
1527
1577
  }
1528
- answer.leaverequest = req;
1529
- }
1530
- });
1578
+ });
1579
+ }
1531
1580
  return answer;
1532
1581
  }
1533
1582
  approveLeaveRequest(id, approver) {
@@ -1536,115 +1585,125 @@ class Employee {
1536
1585
  leaverequest: undefined,
1537
1586
  error: undefined
1538
1587
  };
1539
- this.requests.forEach((req, r) => {
1540
- if (req.id === id) {
1541
- req.approvalDate = new Date();
1542
- req.approvedby = approver;
1543
- req.status = 'Approved';
1544
- let max = 0;
1545
- if (req.primarycode.toLowerCase() !== 'mod') {
1546
- this.removeLeaves(req.startdate, req.enddate, req.id, false);
1547
- this.leaves.forEach(lv => {
1548
- if (max < lv.id) {
1549
- max = lv.id;
1550
- }
1551
- });
1552
- req.requesteddays.forEach((day, d) => {
1553
- if (day.code !== '') {
1554
- max++;
1555
- day.status = 'Approved';
1556
- req.requesteddays[d] = day;
1557
- this.leaves.push(new leave_1.Leave({
1558
- id: max,
1559
- leavedate: new Date(day.leavedate),
1560
- code: day.code,
1561
- hours: day.hours,
1562
- status: day.status,
1563
- requestid: req.id,
1564
- used: false
1565
- }));
1566
- }
1567
- });
1568
- answer.message = `Leave Request was approved for period of `
1569
- + `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
1570
- answer.leaverequest = req;
1571
- }
1572
- else {
1573
- let found = false;
1574
- this.variations.forEach((vari, v) => {
1575
- if (vari.startdate.getTime() === req.startdate.getTime()
1576
- && vari.enddate.getTime() === req.enddate.getTime()
1577
- && vari.mod) {
1578
- found = true;
1579
- let start = new Date(req.startdate);
1580
- while (start.getDay() !== 0) {
1581
- start = new Date(start.getTime() - (24 * 3600000));
1582
- }
1583
- vari.setScheduleDays();
1584
- let lastcode = '';
1585
- let workcenter = '';
1586
- 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) => {
1587
1604
  if (day.code !== '') {
1588
- lastcode = day.code;
1589
- if (day.tagday) {
1590
- workcenter = day.tagday;
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
+ }));
1591
1618
  }
1592
1619
  }
1593
- const dos = Math.floor((day.leavedate.getTime() - start.getTime())
1594
- / (24 * 3600000));
1595
- vari.schedule.workdays[dos].code = lastcode;
1596
- vari.schedule.workdays[dos].hours = day.hours;
1597
- vari.schedule.workdays[dos].workcenter = workcenter;
1598
1620
  });
1599
1621
  }
1600
- });
1601
- if (!found) {
1602
- let max = 0;
1603
- this.variations.forEach(vari => {
1604
- if (max < vari.id) {
1605
- max = vari.id;
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
+ });
1606
1653
  }
1607
1654
  });
1608
- const vari = new variation_1.Variation({
1609
- id: max + 1,
1610
- mids: false,
1611
- mod: true,
1612
- startdate: new Date(req.startdate),
1613
- enddate: new Date(req.enddate),
1614
- site: this.site,
1615
- schedule: new workday_1.Schedule()
1616
- });
1617
- vari.setScheduleDays();
1618
- vari.schedule.showdates = true;
1619
- req.requesteddays.forEach(day => {
1620
- vari.updateWorkdayByDate;
1621
- });
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
+ }
1622
1677
  }
1623
1678
  }
1624
- }
1625
- });
1679
+ });
1680
+ }
1626
1681
  return answer;
1627
1682
  }
1628
1683
  deleteLeaveRequest(id) {
1629
- let req = this.requests.find(r => r.id === id);
1630
- if (req) {
1631
- if (req.status.toLowerCase() === 'approved') {
1632
- let pos = this.leaves.findIndex(l => l.requestid === id);
1633
- while (pos >= 0) {
1634
- this.leaves.splice(pos, 1);
1635
- pos = this.leaves.findIndex(l => l.requestid === id);
1636
- }
1637
- if (req.primarycode.toLowerCase() === 'mod') {
1638
- pos = this.variations.findIndex(v => (v.mod && v.startdate.getTime() === req.startdate.getTime()
1639
- && v.enddate.getTime() === req.enddate.getTime()));
1640
- if (pos >= 0) {
1641
- this.variations.splice(pos, 1);
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
+ }
1642
1701
  }
1643
1702
  }
1644
- }
1645
- let pos = this.requests.findIndex(r => r.id === id);
1646
- if (pos >= 0) {
1647
- this.requests.splice(pos, 1);
1703
+ let pos = this.requests.findIndex(r => r.id === id);
1704
+ if (pos >= 0) {
1705
+ this.requests.splice(pos, 1);
1706
+ }
1648
1707
  }
1649
1708
  }
1650
1709
  }