scheduler-node-models 1.0.143 → 1.0.145

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scheduler-node-models",
3
- "version": "1.0.143",
3
+ "version": "1.0.145",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -354,8 +354,8 @@ class LeaveReport extends general_1.Report {
354
354
  const num = Number(empHol.tagday.substring(1));
355
355
  holidays.forEach((hol, h) => {
356
356
  if (hol.holiday && hol.holiday.id.toLowerCase() === code
357
- && hol.holiday.sort === num) {
358
- hol.periods.push(new leaves_1.LeavePeriod(empHol.code, new Date(empHol.leavedate), empHol.status, new employees_1.Leave(empHol)));
357
+ && hol.holiday.sort === num && !empHol.used) {
358
+ hol.addLeave(empHol);
359
359
  empHol.used = true;
360
360
  holidays[h] = hol;
361
361
  empHolidays[eh] = empHol;
@@ -367,9 +367,9 @@ class LeaveReport extends general_1.Report {
367
367
  empHolidays.forEach((empHol, eh) => {
368
368
  if (!empHol.used && empHol.status.toLowerCase() === 'actual') {
369
369
  holidays.forEach((hol, h) => {
370
- if (hol.holiday && hol.holiday.id.toLowerCase() === 'h'
370
+ if (!empHol.used && hol.holiday && hol.holiday.id.toLowerCase() === 'h'
371
371
  && !hol.disabled && hol.getHours() + empHol.hours <= 8.0) {
372
- hol.periods.push(new leaves_1.LeavePeriod(empHol.code, empHol.leavedate, empHol.status, new employees_1.Leave(empHol)));
372
+ hol.addLeave(empHol);
373
373
  empHol.used = true;
374
374
  holidays[h] = hol;
375
375
  empHolidays[eh] = empHol;
@@ -381,10 +381,10 @@ class LeaveReport extends general_1.Report {
381
381
  empHolidays.forEach((empHol, eh) => {
382
382
  if (!empHol.used) {
383
383
  holidays.forEach((hol, h) => {
384
- if (hol.holiday && hol.holiday.id.toLowerCase() === 'h'
384
+ if (!empHol.used && hol.holiday && hol.holiday.id.toLowerCase() === 'h'
385
385
  && hol.month.getTime() === empHol.leavedate.getTime()
386
386
  && !hol.disabled && hol.getHours() + empHol.hours <= 8.0) {
387
- hol.periods.push(new leaves_1.LeavePeriod(empHol.code, empHol.leavedate, empHol.status, new employees_1.Leave(empHol)));
387
+ hol.addLeave(empHol);
388
388
  empHol.used = true;
389
389
  holidays[h] = hol;
390
390
  empHolidays[eh] = empHol;
@@ -399,10 +399,11 @@ class LeaveReport extends general_1.Report {
399
399
  holidays.forEach((hol, h) => {
400
400
  if (!found && !hol.disabled) {
401
401
  if (hol.getHours() + empHol.hours <= 8.0) {
402
- hol.periods.push(new leaves_1.LeavePeriod(empHol.code, empHol.leavedate, empHol.status, new employees_1.Leave(empHol)));
402
+ hol.addLeave(empHol);
403
403
  holidays[h] = hol;
404
404
  found = true;
405
405
  empHol.used = true;
406
+ empHolidays[eh] = empHol;
406
407
  }
407
408
  }
408
409
  });
@@ -415,27 +416,18 @@ class LeaveReport extends general_1.Report {
415
416
  holidays.forEach((hol, h) => {
416
417
  if (!found && hol.disabled) {
417
418
  found = true;
418
- hol.periods.push(new leaves_1.LeavePeriod(empHol.code, empHol.leavedate, empHol.status, new employees_1.Leave(empHol)));
419
+ hol.addLeave(empHol);
419
420
  }
420
421
  });
421
422
  }
422
423
  });
423
424
  // next, place the non-holiday leaves into the months they are using in.
425
+ empOtherLeaves.sort((a, b) => a.compareTo(b));
424
426
  empOtherLeaves.forEach(lv => {
425
427
  months.forEach((month, m) => {
426
428
  if (month.month.getUTCFullYear() === lv.leavedate.getUTCFullYear()
427
429
  && month.month.getUTCMonth() === lv.leavedate.getUTCMonth()) {
428
- let found = false;
429
- month.periods.forEach((prd, p) => {
430
- if (!found && prd.addLeave(lv)) {
431
- found = true;
432
- month.periods[p] = prd;
433
- console.log(`${prd.start} - ${prd.end}`);
434
- }
435
- });
436
- if (!found) {
437
- month.periods.push(new leaves_1.LeavePeriod(lv.code, lv.leavedate, lv.status, new employees_1.Leave(lv)));
438
- }
430
+ month.addLeave(lv);
439
431
  months[m] = month;
440
432
  }
441
433
  });
@@ -468,8 +460,7 @@ class LeaveReport extends general_1.Report {
468
460
  if (hol.holiday.getActual(year)) {
469
461
  const formatter = new Intl.DateTimeFormat('en-US', {
470
462
  month: 'short',
471
- day: '2-digit',
472
- year: '2-digit'
463
+ day: '2-digit'
473
464
  });
474
465
  this.setCell(sheet, this.getCellID(col + 1, holRow), this.getCellID(col + 1, holRow), style, formatter.format(hol.holiday.getActual(year)));
475
466
  }
@@ -505,7 +496,7 @@ class LeaveReport extends general_1.Report {
505
496
  }
506
497
  });
507
498
  });
508
- this.setCell(sheet, this.getCellID(col + 3, holRow), this.getCellID(col + 3, holRow), {
499
+ this.setCell(sheet, this.getCellID(col + 2, holRow), this.getCellID(col + 2, holRow), {
509
500
  fill: this.fills.get('white'),
510
501
  alignment: this.alignments.get('center'),
511
502
  border: this.borders.get('blackthin')
@@ -6,10 +6,10 @@ export declare class LeavePeriod {
6
6
  end: Date;
7
7
  status: string;
8
8
  leaves: Leave[];
9
- constructor(code: string, start: Date, status: string, leave?: Leave);
9
+ constructor(leave?: Leave);
10
10
  compareTo(other?: LeavePeriod): number;
11
11
  getHours(type?: string, actual?: boolean): number;
12
- addLeave(leave: Leave): boolean;
12
+ addLeave(leave: Leave): void;
13
13
  }
14
14
  export declare class LeaveMonth {
15
15
  month: Date;
@@ -19,4 +19,5 @@ export declare class LeaveMonth {
19
19
  constructor(start: Date, disabled: boolean, holiday?: Holiday);
20
20
  compareTo(other?: LeaveMonth): number;
21
21
  getHours(type?: string, actuals?: boolean): number;
22
+ addLeave(leave: Leave): void;
22
23
  }
@@ -9,11 +9,11 @@ class LeavePeriod {
9
9
  end;
10
10
  status;
11
11
  leaves;
12
- constructor(code, start, status, leave) {
13
- this.code = code;
14
- this.start = new Date(start);
15
- this.end = new Date(start);
16
- this.status = status;
12
+ constructor(leave) {
13
+ this.code = (leave) ? leave.code : '';
14
+ this.start = (leave) ? new Date(leave.leavedate) : new Date(0);
15
+ this.end = (leave) ? new Date(leave.leavedate) : new Date(0);
16
+ this.status = (leave) ? leave.status : 'approved';
17
17
  this.leaves = [];
18
18
  if (leave) {
19
19
  this.leaves.push(new employees_1.Leave(leave));
@@ -47,33 +47,8 @@ class LeavePeriod {
47
47
  return hours;
48
48
  }
49
49
  addLeave(leave) {
50
- // the leave's hours and code must equal the previous one, unless this is the
51
- // first leave
52
- try {
53
- if (this.leaves.length === 0) {
54
- this.leaves.push(new employees_1.Leave(leave));
55
- return true;
56
- }
57
- else {
58
- let add = true;
59
- this.leaves.forEach(lv => {
60
- if (leave.hours === lv.hours
61
- && leave.code.toLowerCase() !== lv.code.toLowerCase()
62
- && leave.status.toLowerCase() !== lv.code.toLowerCase()
63
- && leave.leavedate.getUTCDate() !== (this.end.getUTCDate() + 1)) {
64
- add = false;
65
- }
66
- });
67
- if (add) {
68
- this.leaves.push(new employees_1.Leave(leave));
69
- this.end = new Date(leave.leavedate);
70
- }
71
- return add;
72
- }
73
- }
74
- catch (error) {
75
- return false;
76
- }
50
+ this.leaves.push(new employees_1.Leave(leave));
51
+ this.end = new Date(leave.leavedate);
77
52
  }
78
53
  }
79
54
  exports.LeavePeriod = LeavePeriod;
@@ -112,5 +87,20 @@ class LeaveMonth {
112
87
  });
113
88
  return hours;
114
89
  }
90
+ addLeave(leave) {
91
+ let bAdded = false;
92
+ this.periods.forEach((prd, p) => {
93
+ if (!bAdded && leave.code.toLowerCase() === prd.code.toLowerCase()
94
+ && leave.status.toLowerCase() === prd.status.toLowerCase()
95
+ && leave.leavedate.getDate() === prd.end.getDate() + 1) {
96
+ bAdded = true;
97
+ prd.addLeave(leave);
98
+ this.periods[p] = prd;
99
+ }
100
+ });
101
+ if (!bAdded) {
102
+ this.periods.push(new LeavePeriod(leave));
103
+ }
104
+ }
115
105
  }
116
106
  exports.LeaveMonth = LeaveMonth;