scheduler-node-models 1.0.75 → 1.0.79

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.
Files changed (145) hide show
  1. package/package.json +21 -6
  2. package/.npmignore +0 -1
  3. package/general/emailer.d.ts +0 -1
  4. package/general/emailer.js +0 -31
  5. package/general/general.d.ts +0 -12
  6. package/general/general.js +0 -2
  7. package/general/index.d.ts +0 -4
  8. package/general/index.js +0 -20
  9. package/general/report.d.ts +0 -12
  10. package/general/report.js +0 -70
  11. package/general/reportStyle.d.ts +0 -0
  12. package/general/reportStyle.js +0 -1
  13. package/general/viewstate.d.ts +0 -5
  14. package/general/viewstate.js +0 -9
  15. package/index.d.ts +0 -0
  16. package/metrics/images.d.ts +0 -22
  17. package/metrics/images.js +0 -33
  18. package/metrics/index.d.ts +0 -5
  19. package/metrics/index.js +0 -21
  20. package/metrics/mission.d.ts +0 -47
  21. package/metrics/mission.js +0 -81
  22. package/metrics/missionSensorOutage.d.ts +0 -11
  23. package/metrics/missionSensorOutage.js +0 -14
  24. package/metrics/missionsensor.d.ts +0 -67
  25. package/metrics/missionsensor.js +0 -128
  26. package/metrics/outage.d.ts +0 -43
  27. package/metrics/outage.js +0 -55
  28. package/metrics/reports/drawSummary.d.ts +0 -24
  29. package/metrics/reports/drawSummary.js +0 -311
  30. package/metrics/reports/index.d.ts +0 -5
  31. package/metrics/reports/index.js +0 -21
  32. package/metrics/reports/missionDay.d.ts +0 -8
  33. package/metrics/reports/missionDay.js +0 -23
  34. package/metrics/reports/missionSummary.d.ts +0 -25
  35. package/metrics/reports/missionSummary.js +0 -421
  36. package/metrics/reports/missionType.d.ts +0 -20
  37. package/metrics/reports/missionType.js +0 -314
  38. package/metrics/reports/outageDay.d.ts +0 -8
  39. package/metrics/reports/outageDay.js +0 -23
  40. package/metrics/systemdata/classifications.d.ts +0 -18
  41. package/metrics/systemdata/classifications.js +0 -23
  42. package/metrics/systemdata/communications.d.ts +0 -21
  43. package/metrics/systemdata/communications.js +0 -40
  44. package/metrics/systemdata/dcgs.d.ts +0 -19
  45. package/metrics/systemdata/dcgs.js +0 -29
  46. package/metrics/systemdata/exploitations.d.ts +0 -18
  47. package/metrics/systemdata/exploitations.js +0 -23
  48. package/metrics/systemdata/groundSystems.d.ts +0 -86
  49. package/metrics/systemdata/groundSystems.js +0 -143
  50. package/metrics/systemdata/index.d.ts +0 -7
  51. package/metrics/systemdata/index.js +0 -23
  52. package/metrics/systemdata/platform.d.ts +0 -124
  53. package/metrics/systemdata/platform.js +0 -176
  54. package/metrics/systemdata/systeminfo.d.ts +0 -28
  55. package/metrics/systemdata/systeminfo.js +0 -64
  56. package/scheduler/employees/assignment.d.ts +0 -139
  57. package/scheduler/employees/assignment.js +0 -304
  58. package/scheduler/employees/balance.d.ts +0 -35
  59. package/scheduler/employees/balance.js +0 -39
  60. package/scheduler/employees/companyinfo.d.ts +0 -16
  61. package/scheduler/employees/companyinfo.js +0 -6
  62. package/scheduler/employees/contact.d.ts +0 -36
  63. package/scheduler/employees/contact.js +0 -40
  64. package/scheduler/employees/employee.d.ts +0 -420
  65. package/scheduler/employees/employee.js +0 -1862
  66. package/scheduler/employees/employeename.d.ts +0 -48
  67. package/scheduler/employees/employeename.js +0 -97
  68. package/scheduler/employees/index.d.ts +0 -14
  69. package/scheduler/employees/index.js +0 -30
  70. package/scheduler/employees/labor.d.ts +0 -31
  71. package/scheduler/employees/labor.js +0 -39
  72. package/scheduler/employees/leave.d.ts +0 -58
  73. package/scheduler/employees/leave.js +0 -73
  74. package/scheduler/employees/leaverequest.d.ts +0 -105
  75. package/scheduler/employees/leaverequest.js +0 -226
  76. package/scheduler/employees/specialty.d.ts +0 -35
  77. package/scheduler/employees/specialty.js +0 -40
  78. package/scheduler/employees/variation.d.ts +0 -80
  79. package/scheduler/employees/variation.js +0 -132
  80. package/scheduler/employees/web.d.ts +0 -6
  81. package/scheduler/employees/web.js +0 -2
  82. package/scheduler/employees/work.d.ts +0 -96
  83. package/scheduler/employees/work.js +0 -133
  84. package/scheduler/employees/workday.d.ts +0 -91
  85. package/scheduler/employees/workday.js +0 -170
  86. package/scheduler/labor/index.d.ts +0 -2
  87. package/scheduler/labor/index.js +0 -18
  88. package/scheduler/labor/laborcode.d.ts +0 -33
  89. package/scheduler/labor/laborcode.js +0 -55
  90. package/scheduler/labor/workcode.d.ts +0 -28
  91. package/scheduler/labor/workcode.js +0 -35
  92. package/scheduler/reports/chargeStatus.d.ts +0 -66
  93. package/scheduler/reports/chargeStatus.js +0 -702
  94. package/scheduler/reports/cofsReports.d.ts +0 -11
  95. package/scheduler/reports/cofsReports.js +0 -36
  96. package/scheduler/reports/enterpriseSchedule.d.ts +0 -18
  97. package/scheduler/reports/enterpriseSchedule.js +0 -159
  98. package/scheduler/reports/index.d.ts +0 -4
  99. package/scheduler/reports/index.js +0 -20
  100. package/scheduler/reports/scheduleReport.d.ts +0 -17
  101. package/scheduler/reports/scheduleReport.js +0 -311
  102. package/scheduler/sites/index.d.ts +0 -1
  103. package/scheduler/sites/index.js +0 -17
  104. package/scheduler/sites/reports/cofsReport.d.ts +0 -41
  105. package/scheduler/sites/reports/cofsReport.js +0 -104
  106. package/scheduler/sites/reports/forecast.d.ts +0 -57
  107. package/scheduler/sites/reports/forecast.js +0 -205
  108. package/scheduler/sites/reports/index.d.ts +0 -4
  109. package/scheduler/sites/reports/index.js +0 -20
  110. package/scheduler/sites/reports/period.d.ts +0 -11
  111. package/scheduler/sites/reports/period.js +0 -27
  112. package/scheduler/sites/reports/section.d.ts +0 -63
  113. package/scheduler/sites/reports/section.js +0 -174
  114. package/scheduler/sites/site.d.ts +0 -39
  115. package/scheduler/sites/site.js +0 -61
  116. package/scheduler/sites/workcenters/index.d.ts +0 -3
  117. package/scheduler/sites/workcenters/index.js +0 -19
  118. package/scheduler/sites/workcenters/position.d.ts +0 -27
  119. package/scheduler/sites/workcenters/position.js +0 -36
  120. package/scheduler/sites/workcenters/shift.d.ts +0 -32
  121. package/scheduler/sites/workcenters/shift.js +0 -47
  122. package/scheduler/sites/workcenters/workcenter.d.ts +0 -43
  123. package/scheduler/sites/workcenters/workcenter.js +0 -123
  124. package/scheduler/teams/company/company.d.ts +0 -99
  125. package/scheduler/teams/company/company.js +0 -256
  126. package/scheduler/teams/company/holiday.d.ts +0 -55
  127. package/scheduler/teams/company/holiday.js +0 -108
  128. package/scheduler/teams/company/index.d.ts +0 -3
  129. package/scheduler/teams/company/index.js +0 -19
  130. package/scheduler/teams/company/modperiod.d.ts +0 -21
  131. package/scheduler/teams/company/modperiod.js +0 -24
  132. package/scheduler/teams/contact.d.ts +0 -18
  133. package/scheduler/teams/contact.js +0 -23
  134. package/scheduler/teams/index.d.ts +0 -3
  135. package/scheduler/teams/index.js +0 -19
  136. package/scheduler/teams/specialty.d.ts +0 -18
  137. package/scheduler/teams/specialty.js +0 -23
  138. package/scheduler/teams/team.d.ts +0 -95
  139. package/scheduler/teams/team.js +0 -351
  140. package/users/index.d.ts +0 -2
  141. package/users/index.js +0 -18
  142. package/users/user.d.ts +0 -130
  143. package/users/user.js +0 -254
  144. package/users/web.d.ts +0 -22
  145. package/users/web.js +0 -2
@@ -1,1862 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Employee = void 0;
4
- const mongodb_1 = require("mongodb");
5
- const employeename_1 = require("./employeename");
6
- const assignment_1 = require("./assignment");
7
- const variation_1 = require("./variation");
8
- const leaverequest_1 = require("./leaverequest");
9
- const labor_1 = require("./labor");
10
- const work_1 = require("./work");
11
- const users_1 = require("../../users");
12
- const contact_1 = require("./contact");
13
- const specialty_1 = require("./specialty");
14
- const leave_1 = require("./leave");
15
- const workday_1 = require("./workday");
16
- const balance_1 = require("./balance");
17
- class Employee {
18
- id;
19
- team;
20
- site;
21
- email;
22
- name;
23
- companyinfo;
24
- assignments;
25
- variations;
26
- balance;
27
- leaves;
28
- requests;
29
- laborCodes;
30
- work;
31
- user;
32
- contactinfo;
33
- specialties;
34
- emails;
35
- constructor(emp) {
36
- this.id = (emp && emp.id) ? emp.id : '';
37
- if (this.id === '') {
38
- this.id = (emp && emp._id) ? emp._id.toString() : '';
39
- }
40
- this.team = (emp) ? emp.team : '';
41
- this.site = (emp) ? emp.site : '';
42
- this.email = (emp) ? emp.email : '';
43
- this.name = (emp) ? new employeename_1.EmployeeName(emp.name) : new employeename_1.EmployeeName();
44
- this.companyinfo = (emp) ? emp.companyinfo : { company: '', employeeid: '' };
45
- this.assignments = [];
46
- if (emp && emp.assignments && emp.assignments.length > 0) {
47
- emp.assignments.forEach(a => {
48
- this.assignments.push(new assignment_1.Assignment(a));
49
- });
50
- this.assignments.sort((a, b) => a.compareTo(b));
51
- }
52
- this.variations = [];
53
- if (emp && emp.variations && emp.variations.length > 0) {
54
- emp.variations.forEach(v => {
55
- this.variations.push(new variation_1.Variation(v));
56
- });
57
- this.variations.sort((a, b) => a.compareTo(b));
58
- }
59
- this.balance = [];
60
- if (emp && emp.balance && emp.balance.length > 0) {
61
- emp.balance.forEach(b => {
62
- this.balance.push(new balance_1.AnnualLeave(b));
63
- });
64
- this.balance.sort((a, b) => a.compareTo(b));
65
- }
66
- this.leaves = [];
67
- if (emp && emp.leaves && emp.leaves.length > 0) {
68
- emp.leaves.forEach(l => {
69
- this.leaves.push(new leave_1.Leave(l));
70
- });
71
- this.leaves.sort((a, b) => a.compareTo(b));
72
- }
73
- this.requests = [];
74
- if (emp && emp.requests && emp.requests.length > 0) {
75
- emp.requests.forEach(r => {
76
- this.requests.push(new leaverequest_1.LeaveRequest(r));
77
- });
78
- this.requests.sort((a, b) => a.compareTo(b));
79
- }
80
- this.laborCodes = [];
81
- if (emp && emp.laborCodes && emp.laborCodes.length > 0) {
82
- emp.laborCodes.forEach(l => {
83
- this.laborCodes.push(new labor_1.EmployeeLaborCode(l));
84
- });
85
- this.laborCodes.sort((a, b) => a.compareTo(b));
86
- }
87
- this.contactinfo = [];
88
- if (emp && emp.contactinfo && emp.contactinfo.length > 0) {
89
- emp.contactinfo.forEach(c => {
90
- this.contactinfo.push(new contact_1.Contact(c));
91
- });
92
- this.contactinfo.sort((a, b) => a.compareTo(b));
93
- }
94
- this.specialties = [];
95
- if (emp && emp.specialties && emp.specialties.length > 0) {
96
- emp.specialties.forEach(sp => {
97
- this.specialties.push(new specialty_1.Specialty(sp));
98
- });
99
- this.specialties.sort((a, b) => a.compareTo(b));
100
- }
101
- this.emails = [];
102
- if (emp && emp.emails && emp.emails.length > 0) {
103
- emp.emails.forEach(e => {
104
- this.emails.push(e);
105
- });
106
- this.emails.sort((a, b) => (a < b) ? -1 : 1);
107
- }
108
- if (emp && emp.work && emp.work.length > 0) {
109
- this.work = [];
110
- emp.work.forEach(w => {
111
- this.work.push(new work_1.Work(w));
112
- });
113
- this.work.sort((a, b) => a.compareTo(b));
114
- }
115
- else {
116
- this.work = undefined;
117
- }
118
- if (emp && emp.user) {
119
- this.user = new users_1.User(emp.user);
120
- }
121
- else {
122
- this.user = undefined;
123
- }
124
- }
125
- compareTo(other) {
126
- if (other) {
127
- if (this.name.lastname === other.name.lastname) {
128
- if (this.name.firstname === other.name.firstname) {
129
- if (this.name.middlename && other.name.middlename) {
130
- return (this.name.middlename < other.name.middlename) ? -1 : 1;
131
- }
132
- else if (this.name.middlename) {
133
- return -1;
134
- }
135
- else {
136
- return 1;
137
- }
138
- }
139
- return (this.name.firstname < other.name.firstname) ? -1 : 1;
140
- }
141
- return (this.name.lastname < other.name.lastname) ? -1 : 1;
142
- }
143
- return -1;
144
- }
145
- /**
146
- * This function will clone this object, but remove all the work and user objects
147
- * so they aren't saved in the database. They are saved in other collections.
148
- * @returns An employee object for saving to the database
149
- */
150
- cloneForSave() {
151
- const result = new Employee(this);
152
- result.work = undefined;
153
- result.user = undefined;
154
- return result;
155
- }
156
- /**
157
- * This function is designed to remove old data from this employee object. It will
158
- * remove old variations, leaves, leave requests, and leave balances, if they are
159
- * older than the date given.
160
- * @param date This date value is used for comparison, for anything before this date.
161
- * @returns A boolean value to indicate to the calling function whether or not to
162
- * remove this employee.
163
- */
164
- purge(date) {
165
- // purge old variations
166
- this.variations.sort((a, b) => a.compareTo(b));
167
- for (let v = this.variations.length - 1; v >= 0; v--) {
168
- if (this.variations[v].enddate.getTime() < date.getTime()) {
169
- this.variations.splice(v, 1);
170
- }
171
- }
172
- // purge old leaves and leave requests(based on request's end date)
173
- this.leaves.sort((a, b) => a.compareTo(b));
174
- for (let l = this.leaves.length - 1; l >= 0; l--) {
175
- if (this.leaves[l].leavedate.getTime() < date.getTime()) {
176
- this.leaves.splice(l, 1);
177
- }
178
- }
179
- for (let l = this.requests.length - 1; l >= 0; l--) {
180
- if (this.requests[l].enddate.getTime() < date.getTime()) {
181
- this.requests.splice(l, 1);
182
- }
183
- }
184
- // purge old leave balances
185
- this.balance.sort((a, b) => a.compareTo(b));
186
- for (let b = this.balance.length - 1; b >= 0; b--) {
187
- if (this.balance[b].year < date.getUTCFullYear()) {
188
- this.balance.splice(b, 1);
189
- }
190
- }
191
- // return as to whether the employee quit before date
192
- this.assignments.sort((a, b) => a.compareTo(b));
193
- const last = this.assignments[this.assignments.length - 1];
194
- return (last.endDate.getTime() < date.getTime());
195
- }
196
- /**********************************************************************************
197
- * This is the assignments section for modifying the assignment list.
198
- **********************************************************************************/
199
- /**
200
- * Remove Leaves between and including dates.
201
- * @param start The date for the start of the removal
202
- * @param end The date for the end of the removal
203
- * @param reqID (Optional) the string value for a possible request identifier
204
- * @param includeActuals (Optional) the boolean value to delete actuals
205
- */
206
- removeLeaves(start, end, reqID = '', includeActuals = true) {
207
- this.leaves.sort((a, b) => a.compareTo(b));
208
- for (let l = this.leaves.length - 1; l >= 0; l--) {
209
- if (reqID === '' && includeActuals) {
210
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
211
- && this.leaves[l].leavedate.getTime() <= end.getTime()) {
212
- this.leaves.splice(l, 1);
213
- }
214
- }
215
- else if (reqID !== '' && includeActuals) {
216
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
217
- && this.leaves[l].leavedate.getTime() <= end.getTime()
218
- && this.leaves[l].requestid === reqID) {
219
- this.leaves.splice(l, 1);
220
- }
221
- }
222
- else if (reqID === '' && !includeActuals) {
223
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
224
- && this.leaves[l].leavedate.getTime() <= end.getTime()
225
- && this.leaves[l].status.toLowerCase() !== 'actual') {
226
- this.leaves.splice(l, 1);
227
- }
228
- }
229
- else if (reqID !== '' && !includeActuals) {
230
- if (this.leaves[l].leavedate.getTime() >= start.getTime()
231
- && this.leaves[l].leavedate.getTime() <= end.getTime()
232
- && this.leaves[l].status.toLowerCase() !== 'actual'
233
- && this.leaves[l].requestid === reqID) {
234
- this.leaves.splice(l, 1);
235
- }
236
- }
237
- }
238
- }
239
- /**
240
- * This function is used to determine if the employee is active on the date given.
241
- * @param date The date object used to determine whether or not the employee was active
242
- * on this date.
243
- * @returns A boolean value for whether or not the employee was active.
244
- */
245
- isActive(date) {
246
- let result = false;
247
- this.assignments.forEach(a => {
248
- if (a.useSiteAssignment(this.site, date)) {
249
- result = true;
250
- }
251
- });
252
- return result;
253
- }
254
- /**
255
- * This function is used to determine if the employee is active during a particular
256
- * period of time at a site and workcenter.
257
- * @param site The string value to designate the site.
258
- * @param wkctr The string value to designate the workcenter.
259
- * @param start The date object for the start of the requested period.
260
- * @param end The date object for the end of the requested period.
261
- * @returns The boolean value to indicate the employee was working at the site and
262
- * workcenter during the period.
263
- */
264
- isAssigned(site, wkctr, start, end) {
265
- let result = false;
266
- this.assignments.forEach(a => {
267
- if (a.site.toLowerCase() === site.toLowerCase()
268
- && a.workcenter.toLowerCase() === wkctr.toLowerCase()
269
- && ((start.getTime() < a.startDate.getTime()
270
- && end.getTime() > a.endDate.getTime())
271
- || (end.getTime() > a.startDate.getTime()
272
- && end.getTime() < a.endDate.getTime())
273
- || (start.getTime() > a.startDate.getTime()
274
- && end.getTime() < a.endDate.getTime()))) {
275
- result = true;
276
- }
277
- });
278
- return result;
279
- }
280
- /**
281
- * This function is used to determine if the employee is active at a site during a
282
- * period of time.
283
- * @param site The string value to designate the site.
284
- * @param start The date object for the start of the requested period.
285
- * @param end The date object for the end of the requested period.
286
- * @returns The boolean value to indicate the employee was working at the site during
287
- * the period.
288
- */
289
- atSite(site, start, end) {
290
- let result = false;
291
- this.assignments.forEach(a => {
292
- if (a.site.toLowerCase() === site.toLowerCase()
293
- && ((start.getTime() < a.startDate.getTime()
294
- && end.getTime() > a.endDate.getTime())
295
- || (end.getTime() > a.startDate.getTime()
296
- && end.getTime() < a.endDate.getTime())
297
- || (start.getTime() > a.startDate.getTime()
298
- && end.getTime() < a.endDate.getTime()))) {
299
- result = true;
300
- }
301
- });
302
- return result;
303
- }
304
- /**
305
- * This general function is used to get the employee's workday for a date. There are
306
- * three possible types of request: general, actuals, and without leave. It will
307
- * provide the workday, if the employee will work or was working on the date.
308
- * @param date The date object representing the date to check against.
309
- * @param type The string value for the type of request to conduct: general, actuals
310
- * or noleaves.
311
- * @param labor An array of Employee Labor Codes to compare against in the "actuals"
312
- * type request.
313
- * @returns A workday object for the work to be or was performed. Will return undefined
314
- * for a day not working or on leave.
315
- */
316
- getWorkday(date, type = 'general', labor) {
317
- // calls one of three child functions (private) to provide the data
318
- switch (type.toLowerCase()) {
319
- case "actuals":
320
- return this.getWorkdayActual(date, labor);
321
- break;
322
- case "noleaves":
323
- return this.getWorkdayWOLeaves(date);
324
- break;
325
- default:
326
- return this.getWorkdayGeneral(date);
327
- }
328
- }
329
- /**
330
- * This private function will provide the employee's workday based on assignment, then
331
- * variation and lastly leaves. Actual work hours are used for dates where they are
332
- * before or on the date of the newest work record.
333
- * @param date The date object used for comparison
334
- * @returns A workday object or undefined for the employee's workday on the date.
335
- */
336
- getWorkdayGeneral(date) {
337
- let wday;
338
- let stdWorkday = 8.0;
339
- let work = 0.0;
340
- let siteid = '';
341
- let lastWorked = new Date(0);
342
- // first get the standard workday hours;
343
- this.assignments.forEach(asgmt => {
344
- if (asgmt.useSiteAssignment(this.site, date)) {
345
- stdWorkday = asgmt.getStandardWorkHours();
346
- }
347
- });
348
- // check work records for work hours
349
- if (this.work) {
350
- this.work.forEach(wk => {
351
- if (wk.useWork(date) && wk.modtime) {
352
- work += wk.hours;
353
- }
354
- if (wk.dateworked.getTime() > lastWorked.getTime()) {
355
- lastWorked = new Date(wk.dateworked);
356
- }
357
- });
358
- }
359
- // now get the normal workday based on assignment
360
- this.assignments.forEach(asgmt => {
361
- if (asgmt.useAssignment(date)) {
362
- wday = asgmt.getWorkday(date);
363
- siteid = asgmt.site;
364
- }
365
- });
366
- // next, check for variation on date
367
- this.variations.forEach(vari => {
368
- if (vari.useVariation(date)) {
369
- wday = vari.getWorkday(date);
370
- }
371
- });
372
- if (work > 0.0) {
373
- while (!wday || (wday && wday.code === '')) {
374
- date = new Date(date.getTime() - (24 * 3600000));
375
- this.assignments.forEach(asgmt => {
376
- if (asgmt.useAssignment(date)) {
377
- wday = asgmt.getWorkday(date);
378
- }
379
- });
380
- }
381
- wday.hours = work;
382
- return wday;
383
- }
384
- if (date.getTime() <= lastWorked.getTime()) {
385
- wday = undefined;
386
- }
387
- // lastly check leave list
388
- this.leaves.forEach(lv => {
389
- if (lv.useLeave(date)
390
- && (lv.hours > stdWorkday / 2 || lv.status.toLowerCase() === 'actual')) {
391
- wday = new workday_1.Workday({
392
- id: 0,
393
- workcenter: '',
394
- code: lv.code,
395
- hours: lv.hours
396
- });
397
- }
398
- });
399
- return wday;
400
- }
401
- /**
402
- * This private function provides the employee's workday for a particular date, but
403
- * only provides leaves if the labor codes provided is a primary code for the
404
- * employee.
405
- * @param date The date object to compare for the workday.
406
- * @param labor The charge number and extension array for comparison against the
407
- * employee's labor codes to determine if it is a primary code.
408
- * @returns A workday object or undefined for the employee's workday on the date.
409
- */
410
- getWorkdayActual(date, labor) {
411
- let wday;
412
- let siteid = '';
413
- let bPrimary = false;
414
- this.assignments.forEach(asgmt => {
415
- if (asgmt.useAssignment(date)) {
416
- siteid = asgmt.site;
417
- wday = asgmt.getWorkday(date);
418
- labor?.forEach(lc => {
419
- asgmt.laborcodes.forEach(alc => {
420
- if (lc.chargeNumber.toLowerCase() === alc.chargeNumber.toLowerCase()
421
- && lc.extension.toLowerCase() === alc.extension.toLowerCase()) {
422
- bPrimary = true;
423
- }
424
- });
425
- });
426
- }
427
- });
428
- this.variations.forEach(vari => {
429
- if (vari.useVariation(date)) {
430
- wday = vari.getWorkday(date);
431
- }
432
- });
433
- let bLeave = false;
434
- if (bPrimary || labor?.length === 0) {
435
- this.leaves.forEach(lv => {
436
- if (lv.useLeave(date) && lv.status.toLowerCase() === 'actual') {
437
- if (!bLeave) {
438
- wday = new workday_1.Workday({
439
- id: 0,
440
- workcenter: '',
441
- code: lv.code,
442
- hours: lv.hours
443
- });
444
- }
445
- else {
446
- if (wday) {
447
- if (lv.hours <= wday.hours) {
448
- wday.hours += lv.hours;
449
- }
450
- else {
451
- wday.hours += lv.hours;
452
- wday.code = lv.code;
453
- }
454
- }
455
- }
456
- }
457
- });
458
- }
459
- return wday;
460
- }
461
- /**
462
- * This private function provides the employee's workday without leaves in consideration.
463
- * @param date The date object used for comparison
464
- * @returns A workday object or undefined for the employee's workday on the date.
465
- */
466
- getWorkdayWOLeaves(date) {
467
- let wday;
468
- let stdWorkday = 8.0;
469
- let work = 0.0;
470
- let siteid = '';
471
- let lastWorked = new Date(0);
472
- // first get the standard workday hours;
473
- this.assignments.forEach(asgmt => {
474
- if (asgmt.useSiteAssignment(this.site, date)) {
475
- stdWorkday = asgmt.getStandardWorkHours();
476
- }
477
- });
478
- // check work records for work hours
479
- if (this.work) {
480
- this.work.forEach(wk => {
481
- if (wk.useWork(date) && wk.modtime) {
482
- work += wk.hours;
483
- }
484
- if (wk.dateworked.getTime() > lastWorked.getTime()) {
485
- lastWorked = new Date(wk.dateworked);
486
- }
487
- });
488
- }
489
- // now get the normal workday based on assignment
490
- this.assignments.forEach(asgmt => {
491
- if (asgmt.useAssignment(date)) {
492
- wday = asgmt.getWorkday(date);
493
- siteid = asgmt.site;
494
- }
495
- });
496
- // next, check for variation on date
497
- this.variations.forEach(vari => {
498
- if (vari.useVariation(date)) {
499
- wday = vari.getWorkday(date);
500
- }
501
- });
502
- if (work > 0.0) {
503
- while (!wday || (wday && wday.code === '')) {
504
- date = new Date(date.getTime() - (24 * 3600000));
505
- this.assignments.forEach(asgmt => {
506
- if (asgmt.useAssignment(date)) {
507
- wday = asgmt.getWorkday(date);
508
- }
509
- });
510
- }
511
- wday.hours = work;
512
- return wday;
513
- }
514
- if (date.getTime() <= lastWorked.getTime()) {
515
- wday = undefined;
516
- }
517
- return wday;
518
- }
519
- /**
520
- * This function provides the employee's standard workday hours, which is based on a
521
- * 40-hour work week divided by number of days worked in the work week.
522
- * @param date The date object used to determine the assignment to use.
523
- * @returns The float number value for the number of hours normal for each day's work.
524
- */
525
- getStandardWorkday(date) {
526
- let answer = 8.0;
527
- this.assignments.forEach(asgmt => {
528
- if (asgmt.useAssignment(date)) {
529
- answer = asgmt.getStandardWorkHours();
530
- }
531
- });
532
- return answer;
533
- }
534
- /**
535
- * This function will add a new work assignment to the employee's assignment list. It
536
- * will assign the employee to a site and workcenter on a particular date. It is
537
- * assumed that this is the last assignment in the list, the end date is set to
538
- * 12/31/9999. It also sets the previous assignment to the end date of the start date
539
- * value minus one day.
540
- * @param site The string value for the site to assign the employee to.
541
- * @param wkctr The string value for the workcenter to assign the employee to.
542
- * @param start The date object used to mark the start of the assignment
543
- */
544
- addAssignment(site, wkctr, start) {
545
- let max = -1;
546
- this.assignments.sort((a, b) => a.compareTo(b));
547
- this.assignments.forEach(asgmt => {
548
- if (asgmt.id > max) {
549
- max = asgmt.id;
550
- }
551
- });
552
- const lastAsgmt = this.assignments[this.assignments.length - 1];
553
- lastAsgmt.endDate = new Date(start.getTime() - (24 * 3600000));
554
- this.assignments[this.assignments.length - 1] = lastAsgmt;
555
- // create new assignment
556
- const newAsgmt = new assignment_1.Assignment({
557
- id: max + 1,
558
- site: site,
559
- workcenter: wkctr,
560
- startDate: new Date(start),
561
- endDate: new Date(Date.UTC(9999, 11, 31)),
562
- schedules: []
563
- });
564
- // add a new work schedule of seven days with the employee working days (M-F).
565
- newAsgmt.addSchedule(7);
566
- for (let d = 1; d < 6; d++) {
567
- newAsgmt.changeWorkday(0, d, wkctr, 'D', 8.0);
568
- }
569
- this.assignments.push(newAsgmt);
570
- }
571
- /**
572
- * The function will remove a particular assignment from the assignment list
573
- * @param id The numeric identifier for the assignment to remove.
574
- */
575
- removeAssignment(id) {
576
- this.assignments.sort((a, b) => a.compareTo(b));
577
- let pos = -1;
578
- for (let a = 0; a < this.assignments.length && pos < 0; a++) {
579
- if (this.assignments[a].id === id) {
580
- pos = a;
581
- }
582
- }
583
- if (pos === 0) {
584
- const asgmt = this.assignments[pos];
585
- const nextAsgmt = this.assignments[pos + 1];
586
- nextAsgmt.startDate = new Date(asgmt.startDate);
587
- this.assignments[pos + 1] = nextAsgmt;
588
- this.assignments.splice(pos, 1);
589
- }
590
- else if (pos === this.assignments.length - 1) {
591
- if (pos > 0) {
592
- this.assignments[pos - 1].endDate = new Date(Date.UTC(9999, 11, 31));
593
- this.assignments.pop();
594
- }
595
- }
596
- else {
597
- this.assignments[pos - 1].endDate
598
- = new Date(this.assignments[pos + 1].startDate.getTime() - (24 * 3600000));
599
- this.assignments.splice(pos, 1);
600
- }
601
- }
602
- /**
603
- * This function will determine if a labor code (charge number and extension) is the
604
- * employee's primary code for the date given.
605
- * @param date The date object used for comparison.
606
- * @param labor The labor code object to provide the charge number/extension for
607
- * comparison.
608
- * @returns A boolean value for whether or not the labor code is a primary one used
609
- * by the employee.
610
- */
611
- isPrimaryCode(date, labor) {
612
- let answer = false;
613
- this.assignments.forEach(asgmt => {
614
- if (asgmt.useAssignment(date)) {
615
- asgmt.laborcodes.forEach(lc => {
616
- if (labor.chargeNumber.toLowerCase() === lc.chargeNumber.toLowerCase()
617
- && labor.extension.toLowerCase() === lc.extension.toLowerCase()) {
618
- answer = true;
619
- }
620
- });
621
- }
622
- });
623
- return answer;
624
- }
625
- /**
626
- * This function will find out if the employee is assigned a particular labor code
627
- * @param chargeNumber The string value for the charge number to check for
628
- * @param extension The string value for the extension to check for.
629
- * @returns The boolean value for assignment of the charge number/extension.
630
- */
631
- hasLaborCode(chargeNumber, extension) {
632
- let found = false;
633
- this.assignments.forEach(asgmt => {
634
- asgmt.laborcodes.forEach(lc => {
635
- if (lc.chargeNumber.toLowerCase() === chargeNumber.toLowerCase()
636
- && lc.extension.toLowerCase() === extension.toLowerCase()) {
637
- found = true;
638
- }
639
- });
640
- });
641
- return found;
642
- }
643
- /**
644
- * This function will check if the employee is assigned a particular charge number/
645
- * extension on a particular date.
646
- * @param date The date object used for the date to check.
647
- * @param chgNo The string value for the charge number to check for
648
- * @param extension The string value for the extension to check for.
649
- * @returns The boolean value for assignment of the charge number/extension.
650
- */
651
- hasLaborCodeOnDate(date, chgNo, ext) {
652
- let found = false;
653
- this.assignments.forEach(asgmt => {
654
- if (asgmt.useAssignment(date)) {
655
- asgmt.laborcodes.forEach(lc => {
656
- if (lc.chargeNumber.toLowerCase() === chgNo.toLowerCase()
657
- && lc.extension.toLowerCase() === ext.toLowerCase()) {
658
- found = true;
659
- }
660
- });
661
- }
662
- });
663
- return found;
664
- }
665
- /**
666
- * This function is used to determine a workcenter and shift code for work during a
667
- * period of time.
668
- * @param start The date object for the start of the period.
669
- * @param end The date object for the end of the period.
670
- * @returns A workday object containing the workcenter and shift code to use for the
671
- * period.
672
- */
673
- getAssignmentForPeriod(start, end) {
674
- const assigned = new Map();
675
- start = new Date(Date.UTC(start.getFullYear(), start.getMonth(), start.getDate()));
676
- end = new Date(Date.UTC(end.getFullYear(), end.getMonth(), end.getDate()));
677
- while (start.getTime() <= end.getTime()) {
678
- const wd = this.getWorkdayWOLeaves(start);
679
- if (wd) {
680
- const label = `${wd.workcenter}-${wd.code}`;
681
- if (label !== '-') {
682
- if (assigned.has(label)) {
683
- let num = assigned.get(label);
684
- if (num) {
685
- num++;
686
- assigned.set(label, num);
687
- }
688
- else {
689
- assigned.set(label, 1);
690
- }
691
- }
692
- else {
693
- assigned.set(label, 1);
694
- }
695
- }
696
- }
697
- start = new Date(start.getTime() + (24 * 3600000));
698
- }
699
- let max = 0;
700
- let label = '';
701
- const keys = Array.from(assigned.keys());
702
- keys.forEach(key => {
703
- const num = assigned.get(key);
704
- if (num && num > max) {
705
- max = num;
706
- label = key;
707
- }
708
- });
709
- const work = label.split('-');
710
- return new workday_1.Workday({
711
- id: 0,
712
- workcenter: work[0],
713
- code: work[1],
714
- hours: 0.0
715
- });
716
- }
717
- /**
718
- * This function will retrieve and provide the number of forecasted hours from this
719
- * employee for a time period and labor code.
720
- * @param labor The company labor code object for the labor codes to check against
721
- * @param start The date object for the start of the period
722
- * @param end The date object for the end of the period
723
- * @param codes A list of compare code objects used for verifying correct codes and
724
- * whether or not they are leave codes.
725
- * @returns A numeric (float) value for the number of hours the employee is forecast.
726
- */
727
- getForecastHours(labor, start, end, codes) {
728
- let answer = 0.0;
729
- start = new Date(Date.UTC(start.getFullYear(), start.getMonth(), start.getDate()));
730
- end = new Date(Date.UTC(end.getFullYear(), end.getMonth(), end.getDate()));
731
- // Check for assignment during period
732
- let found = false;
733
- this.assignments.forEach(asgmt => {
734
- if (asgmt.useAssignment(start, end, labor)) {
735
- found = true;
736
- }
737
- });
738
- if (!found) {
739
- return 0.0;
740
- }
741
- // check if labor code is applicable during period
742
- if (!labor.startDate || !labor.endDate
743
- || labor.endDate.getTime() < start.getTime()
744
- || labor.startDate.getTime() > end.getTime()) {
745
- return 0.0;
746
- }
747
- // determine last worked day from work records
748
- let lastWorked = new Date(0);
749
- if (this.work && this.work.length > 0) {
750
- this.work.sort((a, b) => a.compareTo(b));
751
- lastWorked = new Date(this.work[this.work.length - 1].dateworked);
752
- }
753
- // check leaves for a date greater than lastworked
754
- this.leaves.sort((a, b) => a.compareTo(b));
755
- this.leaves.forEach(lv => {
756
- if (lv.status.toLowerCase() === 'actual' && lv.leavedate.getTime() > lastWorked.getTime()) {
757
- lastWorked = new Date(lv.leavedate);
758
- }
759
- });
760
- // now step through the days of the period to:
761
- // 1) see if they had worked any charge numbers during
762
- // the period, if working add 0 hours
763
- // 2) see if they were supposed to be working on this
764
- // date, compare workday code to workcodes to ensure
765
- // they weren't on leave. If not on leave, add
766
- // standard work day.
767
- let current = new Date(start);
768
- while (current.getTime() <= end.getTime()) {
769
- if (current.getTime() > lastWorked.getTime()) {
770
- const nextday = new Date(current.getTime() + (24 * 3600000));
771
- let hours = this.getWorkedHours(current, nextday);
772
- if (hours === 0.0) {
773
- if (current.getTime() >= labor.startDate.getTime()
774
- && current.getTime() <= labor.endDate.getTime()) {
775
- const wd = this.getWorkday(current);
776
- if (wd && wd.code !== '') {
777
- codes.forEach(code => {
778
- if (code.code.toLowerCase() === wd.code.toLowerCase() && !code.isLeave) {
779
- const std = this.getStandardWorkday(current);
780
- this.assignments.forEach(asgmt => {
781
- if (asgmt.useAssignment(current, nextday, labor)) {
782
- answer += std;
783
- }
784
- });
785
- }
786
- });
787
- }
788
- }
789
- }
790
- }
791
- }
792
- return answer;
793
- }
794
- /**************************************************************************************
795
- * Work Records section
796
- **************************************************************************************/
797
- /**
798
- * This function will provide the total number of hours of actual work for the period
799
- * given
800
- * @param start The date object for the start of the period
801
- * @param end The date object for the end of the period
802
- * @param chgno (Optional) The string value for the charge number
803
- * @param ext (Optional) The string value for the charge number extension
804
- * @returns The numeric value for the total hours of actual work
805
- */
806
- getWorkedHours(start, end, chgno, ext) {
807
- let answer = 0.0;
808
- if (this.work) {
809
- this.work.forEach(wk => {
810
- if (wk.dateworked.getTime() >= start.getTime()
811
- && wk.dateworked.getTime() <= end.getTime()
812
- && !wk.modtime) {
813
- if (!chgno) {
814
- answer += wk.hours;
815
- }
816
- else if (chgno && ext) {
817
- if (chgno.toLowerCase() === wk.chargenumber.toLowerCase()
818
- && ext.toLowerCase() === wk.extension.toLowerCase()) {
819
- answer += wk.hours;
820
- }
821
- }
822
- }
823
- });
824
- }
825
- return answer;
826
- }
827
- /**
828
- * This function will provide the date for the last work record in the object
829
- * @returns A date object for the last worked day.
830
- */
831
- getLastWorkday() {
832
- let answer = new Date(0);
833
- if (this.work && this.work.length > 0) {
834
- this.work.sort((a, b) => a.compareTo(b));
835
- const last = this.work[this.work.length - 1];
836
- answer = new Date(last.dateworked);
837
- }
838
- return answer;
839
- }
840
- /**
841
- * This function will provide the number of modified time hours for a period of time.
842
- * @param start The date object for the start of the period.
843
- * @param end The date object for the end of the period.
844
- * @returns The numeric (float) value for the number of hours of modified time.
845
- */
846
- getModTime(start, end) {
847
- let answer = 0.0;
848
- this.work?.forEach(wk => {
849
- if (wk.dateworked.getTime() >= start.getTime()
850
- && wk.dateworked.getTime() <= end.getTime()
851
- && wk.modtime) {
852
- answer += wk.hours;
853
- }
854
- });
855
- return answer;
856
- }
857
- hasModTime(start, end) {
858
- let answer = false;
859
- this.work?.forEach(wk => {
860
- if (wk.dateworked.getTime() >= start.getTime()
861
- && wk.dateworked.getTime() <= end.getTime()
862
- && wk.modtime) {
863
- answer = true;
864
- }
865
- });
866
- return answer;
867
- }
868
- /**************************************************************************************
869
- * Leave Balance Section - it provides the employee's starting leave balance and the
870
- * number of hours provided for the year.
871
- **************************************************************************************/
872
- /**
873
- * This function will add a new leave balance object to the leave balance list. It will
874
- * only add a new leave balance object if the object for the year doesn't already exist.
875
- * @param year The numeric (int) value for the year the balances are for.
876
- */
877
- createLeaveBalance(year) {
878
- let found = false;
879
- let lastAnnual = 0.0;
880
- let lastCarry = 0.0;
881
- this.balance.forEach(bal => {
882
- if (bal.year === year) {
883
- found = true;
884
- }
885
- if (bal.year === year - 1) {
886
- lastAnnual = bal.annual;
887
- lastCarry = bal.carryover;
888
- }
889
- });
890
- if (!found) {
891
- const bal = new balance_1.AnnualLeave({
892
- year: year,
893
- annual: lastAnnual,
894
- carryover: lastCarry
895
- });
896
- if (lastAnnual === 0.0) {
897
- bal.annual = 100;
898
- }
899
- else {
900
- let carry = lastAnnual + lastCarry;
901
- this.leaves.forEach(lv => {
902
- if (lv.leavedate.getFullYear() === year && lv.code.toLowerCase() === 'v'
903
- && lv.status.toLowerCase() === 'actual') {
904
- carry -= lv.hours;
905
- }
906
- });
907
- bal.carryover = carry;
908
- }
909
- this.balance.push(bal);
910
- this.balance.sort((a, b) => a.compareTo(b));
911
- }
912
- }
913
- /**
914
- * This function is used to update a leave balance object with a new annual year and
915
- * carry over amount.
916
- * @param year The numeric value for the year used as a key value
917
- * @param annual The numeric value for the employee's annual leave amount in hours.
918
- * @param carry The numeric value for the number of hours the employee brings forward
919
- * to this year.
920
- */
921
- updateLeaveBalance(year, annual, carry) {
922
- let found = false;
923
- for (let lb = 0; lb < this.balance.length && !found; lb++) {
924
- if (this.balance[lb].year === year) {
925
- this.balance[lb].annual = annual;
926
- this.balance[lb].carryover = carry;
927
- }
928
- }
929
- if (!found) {
930
- const lb = new balance_1.AnnualLeave({
931
- year: year,
932
- annual: annual,
933
- carryover: carry
934
- });
935
- this.balance.push(lb);
936
- }
937
- this.balance.sort((a, b) => a.compareTo(b));
938
- }
939
- /**
940
- * This function will remove a leave balance from the employee's leave balance list.
941
- * @param year The numeric value for the year of the leave balance (primary key).
942
- */
943
- deleteLeaveBalance(year) {
944
- let found = -1;
945
- this.balance.forEach((bal, i) => {
946
- if (bal.year === year) {
947
- found = i;
948
- }
949
- });
950
- if (found >= 0) {
951
- this.balance.splice(found, 1);
952
- }
953
- }
954
- /**
955
- * This is the employee leave section.
956
- */
957
- /**
958
- * This function will add a new leave day to the employee's leave list. It first checks
959
- * for a leave on the date and code given and will modify leave's other data. If not
960
- * found in the list, it will add the leave to the list, then sort the leaves.
961
- * @param id The numeric value for the leave, normally zero for new leave
962
- * @param date The date object to give the date the leave
963
- * @param code The string value representing the work/leave code for this leave
964
- * @param status The string value for the status of this leave.
965
- * @param hours The numeric value for the number of hours (float)
966
- * @param requestid The string value for the associated request reference, may be an
967
- * empty string.
968
- * @param holCode (Optional) A reference string for the holiday the leave is associated
969
- * with.
970
- */
971
- addLeave(id, date, code, status, hours, requestid, holCode) {
972
- let found = false;
973
- let max = 0;
974
- date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
975
- this.leaves.forEach((lv, l) => {
976
- if ((lv.useLeave(date) && lv.code.toLowerCase() === code.toLowerCase())
977
- || lv.id === id) {
978
- found = true;
979
- lv.status = status;
980
- lv.hours = hours;
981
- if (lv.requestid === '') {
982
- lv.requestid = requestid;
983
- }
984
- if (holCode && holCode !== '') {
985
- lv.tagday = holCode;
986
- }
987
- this.leaves[l] = lv;
988
- }
989
- else if (lv.id > max) {
990
- max = lv.id;
991
- }
992
- });
993
- if (!found) {
994
- const lv = new leave_1.Leave({
995
- id: max + 1,
996
- leavedate: new Date(date),
997
- code: code,
998
- hours: hours,
999
- status: status,
1000
- requestid: requestid,
1001
- used: false,
1002
- tagday: holCode
1003
- });
1004
- this.leaves.push(lv);
1005
- this.leaves.sort((a, b) => a.compareTo(b));
1006
- }
1007
- }
1008
- /**
1009
- * This function will update a single field within the leave, based on leave's identifier.
1010
- * @param id The numeric value for the leave.
1011
- * @param field The string value for the associated data member to update
1012
- * @param value The string value for the updated value.
1013
- * @returns The updated leave object.
1014
- */
1015
- updateLeave(id, field, value) {
1016
- let answer = undefined;
1017
- this.leaves.forEach((lv, l) => {
1018
- if (lv.id === id) {
1019
- switch (field.toLowerCase()) {
1020
- case "date":
1021
- const newdate = new Date(Date.parse(value));
1022
- lv.leavedate = newdate;
1023
- break;
1024
- case "code":
1025
- lv.code = value;
1026
- break;
1027
- case "hours":
1028
- lv.hours = Number(value);
1029
- break;
1030
- case 'status':
1031
- lv.status = value;
1032
- break;
1033
- case 'requestid':
1034
- lv.requestid = value;
1035
- break;
1036
- case 'tagday':
1037
- lv.tagday = value;
1038
- break;
1039
- }
1040
- }
1041
- this.leaves[l] = lv;
1042
- this.leaves.sort((a, b) => a.compareTo(b));
1043
- answer = lv;
1044
- });
1045
- return answer;
1046
- }
1047
- /**
1048
- * This function will remove a leave day from the employee's leave list, base on
1049
- * numeric identifier.
1050
- * @param id numeric value for the identifier.
1051
- */
1052
- deleteLeave(id) {
1053
- let found = -1;
1054
- this.leaves.forEach((lv, l) => {
1055
- if (lv.id === id) {
1056
- found = l;
1057
- }
1058
- });
1059
- if (found >= 0) {
1060
- this.leaves.splice(found, 1);
1061
- }
1062
- }
1063
- /**
1064
- * This function will provide a total number of leave hours for a particular period of
1065
- * time (Actual Leave Only)
1066
- * @param start The date object for the start of the time period
1067
- * @param end The date object for the end of the time period
1068
- * @returns numeric (float) value for the total leave hours for the period
1069
- */
1070
- getLeaveHours(start, end) {
1071
- let answer = 0.0;
1072
- this.leaves.forEach(lv => {
1073
- if (lv.leavedate.getTime() >= start.getTime()
1074
- && end.getTime() >= lv.leavedate.getTime()
1075
- && lv.status.toLowerCase() === 'actual') {
1076
- answer += lv.hours;
1077
- }
1078
- });
1079
- return answer;
1080
- }
1081
- /**
1082
- * This function will provide a total number of vacation/PTO leave hours for a
1083
- * particular period of time (Actual Leave Only)
1084
- * @param start The date object for the start of the time period
1085
- * @param end The date object for the end of the time period
1086
- * @returns numeric (float) value for the total leave hours for the period
1087
- */
1088
- getPTOHours(start, end) {
1089
- let answer = 0.0;
1090
- this.leaves.forEach(lv => {
1091
- if (lv.leavedate.getTime() >= start.getTime()
1092
- && end.getTime() >= lv.leavedate.getTime()
1093
- && lv.status.toLowerCase() === 'actual'
1094
- && lv.code.toLowerCase() === 'v') {
1095
- answer += lv.hours;
1096
- }
1097
- });
1098
- return answer;
1099
- }
1100
- /**
1101
- * This will be the Leave Request section
1102
- */
1103
- /**
1104
- * This function will create a new leave request for the employee
1105
- * @param start The date object for the start of the leave request period
1106
- * @param end The date object for the end of the leave request period
1107
- * @param code the string value for the code to the primary leave type to use
1108
- * @param comment The string vlue for any comment to use
1109
- * @returns The new leave request object or undefined if not created.
1110
- */
1111
- createLeaveRequest(start, end, code, comment) {
1112
- start = new Date(Date.UTC(start.getFullYear(), start.getMonth(), start.getDate()));
1113
- end = new Date(Date.UTC(end.getFullYear(), end.getMonth(), end.getDate()));
1114
- // first check to see if the period is covered by a current leave request and return
1115
- // this object. if The comment is not empty, add it to the request.
1116
- let answer = undefined;
1117
- this.requests.forEach((req, r) => {
1118
- if (req.startdate.getTime() === start.getTime()
1119
- && req.enddate.getTime() === end.getTime()) {
1120
- if (comment !== '') {
1121
- const cmt = new leaverequest_1.LeaveRequestComment({
1122
- commentdate: new Date(),
1123
- comment: comment
1124
- });
1125
- req.comments.push(cmt);
1126
- req.comments.sort((a, b) => a.compareTo(b));
1127
- }
1128
- answer = new leaverequest_1.LeaveRequest(req);
1129
- }
1130
- });
1131
- // if not found, create a new leave request
1132
- if (!answer) {
1133
- const id = new mongodb_1.ObjectId().toString();
1134
- answer = new leaverequest_1.LeaveRequest({
1135
- id: id,
1136
- employeeid: this.id,
1137
- requestdate: new Date(),
1138
- primarycode: code,
1139
- startdate: start,
1140
- enddate: end,
1141
- status: 'DRAFT',
1142
- approvalDate: new Date(0),
1143
- approvedby: '',
1144
- requesteddays: [],
1145
- comments: []
1146
- });
1147
- answer.comments.push(new leaverequest_1.LeaveRequestComment({
1148
- commentdate: new Date(),
1149
- comment: 'Request Created'
1150
- }));
1151
- if (comment !== '') {
1152
- answer.comments.push(new leaverequest_1.LeaveRequestComment({
1153
- commentdate: new Date(),
1154
- comment: comment
1155
- }));
1156
- }
1157
- answer.setLeaveDays(this);
1158
- this.requests.push(new leaverequest_1.LeaveRequest(answer));
1159
- }
1160
- return answer;
1161
- }
1162
- /**
1163
- * This function is used to update a leave request of the employee, by identifier,
1164
- * field to update and the value to update to.
1165
- * @param id The string value representing the identifier
1166
- * @param field The string value for the field to update.
1167
- * @param value The string value to use in the update.
1168
- * @returns An interface of the consisting of a email message, leave request, and an
1169
- * error message.
1170
- */
1171
- updateLeaveRequest(id, field, value) {
1172
- const answer = {
1173
- message: '',
1174
- leaverequest: undefined,
1175
- error: undefined
1176
- };
1177
- this.requests.forEach((req, r) => {
1178
- if (req.useRequest(id)) {
1179
- switch (field.toLowerCase()) {
1180
- case "startdate":
1181
- case "start":
1182
- // parse the value to make a date object, then make sure the date is a UTC
1183
- // value
1184
- let date = new Date(Date.parse(value));
1185
- date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
1186
- // check to see if the dates are outside the original start and end dates,
1187
- // which invalidates the leave request and places back in the draft status
1188
- // and removes any current approved leaves to be removed.
1189
- if (date.getTime() < req.startdate.getTime()
1190
- || date.getTime() > req.enddate.getTime()) {
1191
- if (req.status.toLowerCase() === 'approved') {
1192
- // remove the approved leaves from the leaves list.
1193
- this.leaves.sort((a, b) => a.compareTo(b));
1194
- let count = 0;
1195
- let startpos = -1;
1196
- this.leaves.forEach((lv, l) => {
1197
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
1198
- if (startpos < 0) {
1199
- startpos = l;
1200
- count++;
1201
- }
1202
- else {
1203
- count++;
1204
- }
1205
- }
1206
- });
1207
- if (startpos >= 0) {
1208
- this.leaves.splice(startpos, count);
1209
- }
1210
- }
1211
- req.status = 'DRAFT';
1212
- req.approvalDate = new Date(0);
1213
- req.approvedby = '';
1214
- }
1215
- else {
1216
- if (req.status.toLowerCase() === 'approved') {
1217
- // remove approved leaves from before the new date that have the
1218
- // request identifier
1219
- this.leaves.sort((a, b) => a.compareTo(b));
1220
- let count = 0;
1221
- let startpos = -1;
1222
- this.leaves.forEach((lv, l) => {
1223
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1224
- && lv.leavedate.getTime() < date.getTime()) {
1225
- if (startpos < 0) {
1226
- startpos = l;
1227
- count++;
1228
- }
1229
- else {
1230
- count++;
1231
- }
1232
- }
1233
- });
1234
- if (startpos >= 0 && count > 0) {
1235
- this.leaves.splice(startpos, count);
1236
- }
1237
- }
1238
- }
1239
- req.startdate = new Date(date);
1240
- req.setLeaveDays(this);
1241
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1242
- commentdate: new Date(),
1243
- comment: `Start date for request was changed to ${date.toDateString()}`
1244
- }));
1245
- req.comments.sort((a, b) => a.compareTo(b));
1246
- break;
1247
- case "enddate":
1248
- case "end":
1249
- // parse the value to make a date object, then make sure the date is a UTC
1250
- // value
1251
- date = new Date(Date.parse(value));
1252
- date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
1253
- // check to see if the dates are outside the original start and end dates,
1254
- // which invalidates the leave request and places back in the draft status
1255
- // and removes any current approved leaves to be removed.
1256
- if (date.getTime() < req.startdate.getTime()
1257
- || date.getTime() > req.enddate.getTime()) {
1258
- if (req.status.toLowerCase() === 'approved') {
1259
- // remove the approved leaves from the leaves list.
1260
- this.leaves.sort((a, b) => a.compareTo(b));
1261
- let count = 0;
1262
- let startpos = -1;
1263
- this.leaves.forEach((lv, l) => {
1264
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
1265
- if (startpos < 0) {
1266
- startpos = l;
1267
- count++;
1268
- }
1269
- else {
1270
- count++;
1271
- }
1272
- }
1273
- });
1274
- if (startpos >= 0) {
1275
- this.leaves.splice(startpos, count);
1276
- }
1277
- }
1278
- req.status = 'DRAFT';
1279
- req.approvalDate = new Date(0);
1280
- req.approvedby = '';
1281
- }
1282
- else {
1283
- if (req.status.toLowerCase() === 'approved') {
1284
- // remove approved leaves from before the new date that have the
1285
- // request identifier
1286
- this.leaves.sort((a, b) => a.compareTo(b));
1287
- let count = 0;
1288
- let startpos = -1;
1289
- this.leaves.forEach((lv, l) => {
1290
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1291
- && lv.leavedate.getTime() > date.getTime()) {
1292
- if (startpos < 0) {
1293
- startpos = l;
1294
- count++;
1295
- }
1296
- else {
1297
- count++;
1298
- }
1299
- }
1300
- });
1301
- if (startpos >= 0 && count > 0) {
1302
- this.leaves.splice(startpos, count);
1303
- }
1304
- }
1305
- }
1306
- req.enddate = new Date(date);
1307
- req.setLeaveDays(this);
1308
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1309
- commentdate: new Date(),
1310
- comment: `End date for request was changed to ${date.toDateString()}`
1311
- }));
1312
- req.comments.sort((a, b) => a.compareTo(b));
1313
- break;
1314
- case 'dates':
1315
- const values = value.split('|');
1316
- // parse the value to make a date object, then make sure the date is a UTC
1317
- // value
1318
- let newstart = new Date(Date.parse(values[0]));
1319
- newstart = new Date(Date.UTC(newstart.getFullYear(), newstart.getMonth(), newstart.getDate()));
1320
- let newend = new Date(Date.parse(values[1]));
1321
- newend = new Date(Date.UTC(newend.getFullYear(), newend.getMonth(), newend.getDate()));
1322
- // check to see if the dates are outside the original start and end dates,
1323
- // which invalidates the leave request and places back in the draft status
1324
- // and removes any current approved leaves to be removed.
1325
- if (newstart.getTime() < req.startdate.getTime()
1326
- || newstart.getTime() > req.enddate.getTime()
1327
- || newend.getTime() < req.startdate.getTime()
1328
- || newend.getTime() > req.enddate.getTime()) {
1329
- if (req.status.toLowerCase() === 'approved') {
1330
- // remove the approved leaves from the leaves list.
1331
- this.leaves.sort((a, b) => a.compareTo(b));
1332
- let count = 0;
1333
- let startpos = -1;
1334
- this.leaves.forEach((lv, l) => {
1335
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual') {
1336
- if (startpos < 0) {
1337
- startpos = l;
1338
- count++;
1339
- }
1340
- else {
1341
- count++;
1342
- }
1343
- }
1344
- });
1345
- if (startpos >= 0) {
1346
- this.leaves.splice(startpos, count);
1347
- }
1348
- }
1349
- req.status = 'DRAFT';
1350
- req.approvalDate = new Date(0);
1351
- req.approvedby = '';
1352
- }
1353
- else {
1354
- if (req.status.toLowerCase() === 'approved') {
1355
- // remove approved leaves from before the new date that have the
1356
- // request identifier
1357
- this.leaves.sort((a, b) => a.compareTo(b));
1358
- let startcount = 0;
1359
- let startpos = -1;
1360
- let endcount = 0;
1361
- let endpos = -1;
1362
- this.leaves.forEach((lv, l) => {
1363
- if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1364
- && lv.leavedate.getTime() < newstart.getTime()) {
1365
- if (startpos < 0) {
1366
- startpos = l;
1367
- startcount++;
1368
- }
1369
- else {
1370
- startcount++;
1371
- }
1372
- }
1373
- else if (lv.requestid === id && lv.status.toLowerCase() !== 'actual'
1374
- && lv.leavedate.getTime() > newend.getTime()) {
1375
- if (endpos < 0) {
1376
- endpos = l;
1377
- endcount++;
1378
- }
1379
- else {
1380
- endcount++;
1381
- }
1382
- }
1383
- });
1384
- if (startpos >= 0 && endcount > 0) {
1385
- this.leaves.splice(startpos, startcount);
1386
- }
1387
- if (endpos >= 0 && endcount > 0) {
1388
- this.leaves.splice(endpos, endcount);
1389
- }
1390
- }
1391
- }
1392
- req.startdate = new Date(newstart);
1393
- req.enddate = new Date(newend);
1394
- req.setLeaveDays(this);
1395
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1396
- commentdate: new Date(),
1397
- comment: `Request dates for request were changed to `
1398
- + `${newstart.toDateString()} - ${newend.toDateString()}`
1399
- }));
1400
- req.comments.sort((a, b) => a.compareTo(b));
1401
- break;
1402
- case "code":
1403
- case "primarycode":
1404
- req.primarycode = value;
1405
- req.setLeaveDays(this, true);
1406
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1407
- commentdate: new Date(),
1408
- comment: `Primary Code for request was changed to ${value}`
1409
- }));
1410
- req.comments.sort((a, b) => a.compareTo(b));
1411
- break;
1412
- case "requested":
1413
- req.status = 'REQUESTED';
1414
- req.requesteddays.forEach((lv, l) => {
1415
- if (lv.code !== '') {
1416
- lv.status = 'REQUESTED';
1417
- req.requesteddays[l] = lv;
1418
- }
1419
- });
1420
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1421
- commentdate: new Date(),
1422
- comment: 'Leave request was submitted for approval.'
1423
- }));
1424
- req.comments.sort((a, b) => a.compareTo(b));
1425
- answer.message = `Leave Request from ${this.name.getLastFirst()} `
1426
- + `submitted for approval. Requested leave dates: `
1427
- + `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
1428
- break;
1429
- case "unapprove":
1430
- req.approvedby = '';
1431
- req.approvalDate = new Date(0);
1432
- req.status = 'DRAFT';
1433
- req.requesteddays.forEach((lv, l) => {
1434
- if (lv.code !== '') {
1435
- lv.status = 'REQUESTED';
1436
- req.requesteddays[l] = lv;
1437
- }
1438
- });
1439
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1440
- commentdate: new Date(),
1441
- comment: value
1442
- }));
1443
- req.comments.sort((a, b) => a.compareTo(b));
1444
- break;
1445
- case 'day':
1446
- case 'requestday':
1447
- const bApproved = req.status.toLowerCase() === 'approved';
1448
- let found = false;
1449
- let max = 0;
1450
- const svalues = value.split('|');
1451
- let lvDate = new Date(Date.parse(svalues[0]));
1452
- let code = svalues[1];
1453
- let hours = Number(svalues[2]);
1454
- let status = '';
1455
- let workcenter = '';
1456
- if (svalues.length > 3) {
1457
- workcenter = svalues[3];
1458
- }
1459
- req.requesteddays.forEach((lv, l) => {
1460
- if (lv.useLeave(lvDate)) {
1461
- found = true;
1462
- lv.code = code;
1463
- if (status == '') {
1464
- status = lv.status;
1465
- }
1466
- lv.status = workcenter;
1467
- if (code == '') {
1468
- lv.hours = 0.0;
1469
- }
1470
- else {
1471
- lv.hours = hours;
1472
- }
1473
- req.requesteddays[l] = lv;
1474
- }
1475
- if (max < lv.id) {
1476
- max = lv.id;
1477
- }
1478
- });
1479
- if (!found) {
1480
- const lv = new leave_1.Leave({
1481
- id: max + 1,
1482
- leavedate: new Date(lvDate),
1483
- code: code,
1484
- hours: hours,
1485
- status: status,
1486
- requestid: req.id,
1487
- used: false
1488
- });
1489
- req.requesteddays.push(lv);
1490
- req.requesteddays.sort((a, b) => a.compareTo(b));
1491
- }
1492
- if (bApproved) {
1493
- found = false;
1494
- this.leaves.forEach((lv, l) => {
1495
- if (lv.useLeave(lvDate)) {
1496
- found = true;
1497
- lv.code = code;
1498
- if (code === '') {
1499
- lv.hours = 0.0;
1500
- }
1501
- else {
1502
- lv.hours = hours;
1503
- }
1504
- this.leaves[l] = lv;
1505
- }
1506
- });
1507
- if (!found && code !== '') {
1508
- this.leaves.push(new leave_1.Leave({
1509
- id: max + 1,
1510
- leavedate: new Date(lvDate),
1511
- code: code,
1512
- hours: hours,
1513
- status: req.status,
1514
- requestid: req.id,
1515
- used: false
1516
- }));
1517
- }
1518
- }
1519
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1520
- commentdate: new Date(),
1521
- comment: `Requested Days Updated: ${lvDate.toDateString()} to Code: ${code}, `
1522
- + `hours: ${hours}`
1523
- }));
1524
- case "comment":
1525
- case "addcomment":
1526
- req.comments.push(new leaverequest_1.LeaveRequestComment({
1527
- commentdate: new Date(),
1528
- comment: value
1529
- }));
1530
- req.comments.sort((a, b) => a.compareTo(b));
1531
- break;
1532
- }
1533
- answer.leaverequest = req;
1534
- }
1535
- });
1536
- return answer;
1537
- }
1538
- /**
1539
- * This function is used to approve a requested leave request. When approved it updates
1540
- * the leave list of the employee, plus if the request is a mod time request, it creates
1541
- * the variation for the mod time.
1542
- * @param id The string value for the identifier for the leave request.
1543
- * @param approver The string value for the identifier for the employee who approved
1544
- * this request.
1545
- * @param leavecodes A list of workcode associated with types of leaves.
1546
- * @returns A change leave request response containing any message to email and this
1547
- * leave request.
1548
- */
1549
- approveLeaveRequest(id, approver, leavecodes) {
1550
- const answer = {
1551
- message: '',
1552
- leaverequest: undefined,
1553
- error: undefined
1554
- };
1555
- this.requests.forEach((req, r) => {
1556
- if (req.id === id) {
1557
- req.approvalDate = new Date();
1558
- req.approvedby = approver;
1559
- req.status = 'Approved';
1560
- let max = 0;
1561
- this.removeLeaves(req.startdate, req.enddate, req.id, false);
1562
- this.leaves.forEach(lv => {
1563
- if (max < lv.id) {
1564
- max = lv.id;
1565
- }
1566
- });
1567
- if (req.primarycode.toLowerCase() !== 'mod') {
1568
- req.requesteddays.forEach((day, d) => {
1569
- if (day.code !== '') {
1570
- max++;
1571
- day.status = 'Approved';
1572
- req.requesteddays[d] = day;
1573
- this.leaves.push(new leave_1.Leave({
1574
- id: max,
1575
- leavedate: new Date(day.leavedate),
1576
- code: day.code,
1577
- hours: day.hours,
1578
- status: day.status,
1579
- requestid: req.id,
1580
- used: false
1581
- }));
1582
- }
1583
- });
1584
- answer.message = `Leave Request was approved for period of `
1585
- + `${req.startdate.toDateString()} - ${req.enddate.toDateString()}.`;
1586
- answer.leaverequest = req;
1587
- }
1588
- else {
1589
- // a mod time request will create a variation rather than leave objects
1590
- // check if there is a variation for this period first and modify it
1591
- let found = false;
1592
- this.variations.forEach((vari, v) => {
1593
- if (vari.startdate.getTime() === req.startdate.getTime()
1594
- && vari.enddate.getTime() === req.enddate.getTime()
1595
- && vari.mod) {
1596
- found = true;
1597
- let start = new Date(req.startdate);
1598
- while (start.getDay() !== 0) {
1599
- start = new Date(start.getTime() - (24 * 3600000));
1600
- }
1601
- vari.setScheduleDays();
1602
- let lastcode = '';
1603
- let workcenter = '';
1604
- req.requesteddays.forEach(day => {
1605
- let isLeave = false;
1606
- leavecodes.forEach(wc => {
1607
- if (wc.id.toLowerCase() === day.code.toLowerCase() && wc.isLeave) {
1608
- isLeave = true;
1609
- }
1610
- });
1611
- if (isLeave) {
1612
- max++;
1613
- this.leaves.push(new leave_1.Leave({
1614
- id: max,
1615
- leavedate: new Date(day.leavedate),
1616
- code: day.code,
1617
- hours: day.hours,
1618
- status: 'APPROVED',
1619
- requestid: req.id,
1620
- used: false
1621
- }));
1622
- this.leaves.sort((a, b) => a.compareTo(b));
1623
- }
1624
- else {
1625
- lastcode = day.code;
1626
- workcenter = day.status;
1627
- }
1628
- const dos = Math.floor((day.leavedate.getTime() - start.getTime())
1629
- / (24 * 3600000));
1630
- vari.schedule.workdays[dos].code = lastcode;
1631
- vari.schedule.workdays[dos].hours = day.hours;
1632
- vari.schedule.workdays[dos].workcenter = workcenter;
1633
- });
1634
- }
1635
- });
1636
- // if no variation, add a new one.
1637
- if (!found) {
1638
- let max = 0;
1639
- this.variations.forEach(vari => {
1640
- if (max < vari.id) {
1641
- max = vari.id;
1642
- }
1643
- });
1644
- const vari = new variation_1.Variation({
1645
- id: max + 1,
1646
- mids: false,
1647
- mod: true,
1648
- startdate: new Date(req.startdate),
1649
- enddate: new Date(req.enddate),
1650
- site: this.site,
1651
- schedule: new workday_1.Schedule()
1652
- });
1653
- vari.setScheduleDays();
1654
- vari.schedule.showdates = true;
1655
- req.requesteddays.forEach(day => {
1656
- vari.updateWorkdayByDate;
1657
- });
1658
- }
1659
- }
1660
- }
1661
- });
1662
- return answer;
1663
- }
1664
- /**
1665
- * This function will remove a leave request from the employee's list, plus if the
1666
- * request has an approved status, it will remove any associated leaves and variations.
1667
- * @param id The string value for the identifier for the leave request.
1668
- */
1669
- deleteLeaveRequest(id) {
1670
- let req = this.requests.find(r => r.id === id);
1671
- if (req) {
1672
- if (req.status.toLowerCase() === 'approved') {
1673
- let pos = this.leaves.findIndex(l => l.requestid === id);
1674
- while (pos >= 0) {
1675
- this.leaves.splice(pos, 1);
1676
- pos = this.leaves.findIndex(l => l.requestid === id);
1677
- }
1678
- if (req.primarycode.toLowerCase() === 'mod') {
1679
- pos = this.variations.findIndex(v => (v.mod && v.startdate.getTime() === req.startdate.getTime()
1680
- && v.enddate.getTime() === req.enddate.getTime()));
1681
- if (pos >= 0) {
1682
- this.variations.splice(pos, 1);
1683
- }
1684
- }
1685
- }
1686
- let pos = this.requests.findIndex(r => r.id === id);
1687
- if (pos >= 0) {
1688
- this.requests.splice(pos, 1);
1689
- }
1690
- }
1691
- }
1692
- /***************************************************************************************
1693
- * Employee's contact information section
1694
- **************************************************************************************/
1695
- /**
1696
- * This function will either add a new contact information or update one with the
1697
- * provided type id.
1698
- * @param typeid The numeric value for the type of contact information corresponding
1699
- * to the team's contact information types.
1700
- * @param value The string value for the contact information value
1701
- * @param sortid The numeric value for the sort order for this object, gotten from the
1702
- * team's contact information types.
1703
- */
1704
- addContactInfo(typeid, value, sortid) {
1705
- let found = false;
1706
- let next = -1;
1707
- this.contactinfo.forEach((ci, c) => {
1708
- if (ci.id > next)
1709
- next = ci.id;
1710
- if (ci.typeid === typeid) {
1711
- found = true;
1712
- ci.value = value;
1713
- this.contactinfo[c] = ci;
1714
- }
1715
- });
1716
- if (!found) {
1717
- const contact = new contact_1.Contact({
1718
- id: next + 1,
1719
- typeid: typeid,
1720
- value: value,
1721
- sort: sortid
1722
- });
1723
- this.contactinfo.push(contact);
1724
- this.contactinfo.sort((a, b) => a.compareTo(b));
1725
- }
1726
- }
1727
- /**
1728
- * This function will re-sort the employee's contact information based on the team's
1729
- * contact information types' sort order.
1730
- * @param teamcontacts A map of the team's contact information types sort order.
1731
- */
1732
- resortContactInfo(teamcontacts) {
1733
- this.contactinfo.forEach((ci, c) => {
1734
- const tc = teamcontacts.get(ci.typeid);
1735
- ci.sort = (tc) ? tc : 0;
1736
- this.contactinfo[c] = ci;
1737
- });
1738
- this.contactinfo.sort((a, b) => a.compareTo(b));
1739
- }
1740
- /**
1741
- * This function will remove an employee's contact information by type id.
1742
- * @param type The numeric value for the type of contact information to remove.
1743
- */
1744
- deleteContactInfoByType(type) {
1745
- let found = -1;
1746
- this.contactinfo.forEach((ci, c) => {
1747
- if (ci.typeid === type) {
1748
- found = c;
1749
- }
1750
- });
1751
- if (found >= 0) {
1752
- this.contactinfo.splice(found, 1);
1753
- }
1754
- }
1755
- /**
1756
- * This function will remove an employee's contact information by identifier.
1757
- * @param id The numeric value for the identifier for the contact info.
1758
- */
1759
- deleteContactInfo(id) {
1760
- let found = -1;
1761
- this.contactinfo.forEach((ci, c) => {
1762
- if (ci.id === id) {
1763
- found = c;
1764
- }
1765
- });
1766
- if (found >= 0) {
1767
- this.contactinfo.splice(found, 1);
1768
- }
1769
- }
1770
- /**
1771
- * This function is used to update for add a specialty to the employee's list.
1772
- * @param specid numeric value for the specialty identifier from the team's specialty
1773
- * list.
1774
- * @param qualified boolean value to signify if the employee is qualified in it
1775
- * @param sort numeric value for the sort position, copied from the team's specialty
1776
- * list.
1777
- */
1778
- addSpecialty(specid, qualified, sort) {
1779
- let found = false;
1780
- let next = -1;
1781
- this.specialties.forEach((spc, s) => {
1782
- if (spc.id > next)
1783
- next = spc.id;
1784
- if (spc.specialtyid === specid) {
1785
- found = true;
1786
- spc.qualified = qualified;
1787
- this.specialties[s] = spc;
1788
- }
1789
- });
1790
- if (!found) {
1791
- const spc = new specialty_1.Specialty({
1792
- id: next + 1,
1793
- specialtyid: specid,
1794
- qualified: qualified,
1795
- sort: sort
1796
- });
1797
- this.specialties.push(spc);
1798
- this.specialties.sort((a, b) => a.compareTo(b));
1799
- }
1800
- }
1801
- /**
1802
- * This function will reassign the employee's specialties with the sort values for the
1803
- * team specialties, then re-sort them.
1804
- * @param teamspecs The Map of the team specialties sort number by specialty id.
1805
- */
1806
- resortSpecialties(teamspecs) {
1807
- this.specialties.forEach((spc, s) => {
1808
- const ts = teamspecs.get(spc.specialtyid);
1809
- spc.sort = (ts) ? ts : 0;
1810
- this.specialties[s] = spc;
1811
- });
1812
- this.specialties.sort((a, b) => a.compareTo(b));
1813
- }
1814
- /**
1815
- * This function will remove an employee's specialty by identifier.
1816
- * @param id The numeric value for the employee's specialty identifier.
1817
- */
1818
- deleteSpecialty(id) {
1819
- let found = -1;
1820
- this.specialties.forEach((spc, s) => {
1821
- if (spc.id === id) {
1822
- found = s;
1823
- }
1824
- });
1825
- if (found >= 0) {
1826
- this.specialties.splice(found, 1);
1827
- }
1828
- this.specialties.sort((a, b) => a.compareTo(b));
1829
- }
1830
- /**
1831
- * This function will remove an employee's specialty by specialty type
1832
- * @param type The numeric value associated with the team's specialty identifer.
1833
- */
1834
- deleteSpecialtyByType(type) {
1835
- let found = -1;
1836
- this.specialties.forEach((spc, s) => {
1837
- if (spc.specialtyid === type) {
1838
- found = s;
1839
- }
1840
- });
1841
- if (found >= 0) {
1842
- this.specialties.splice(found, 1);
1843
- }
1844
- this.specialties.sort((a, b) => a.compareTo(b));
1845
- }
1846
- /**
1847
- * This function will provide a boolean answer as to whether the employee is qualified
1848
- * in a particular specialty skill.
1849
- * @param spec The numeric value for the specialty to search for.
1850
- * @returns boolean value for the employee's qualified to this skill.
1851
- */
1852
- hasSpecialty(spec) {
1853
- let answer = false;
1854
- this.specialties.forEach(spc => {
1855
- if (spc.specialtyid === spec) {
1856
- answer = true;
1857
- }
1858
- });
1859
- return answer;
1860
- }
1861
- }
1862
- exports.Employee = Employee;