scheduler-node-models 1.0.143 → 1.0.144

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.144",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -355,7 +355,7 @@ class LeaveReport extends general_1.Report {
355
355
  holidays.forEach((hol, h) => {
356
356
  if (hol.holiday && hol.holiday.id.toLowerCase() === code
357
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)));
358
+ hol.periods.push(new leaves_1.LeavePeriod(new employees_1.Leave(empHol)));
359
359
  empHol.used = true;
360
360
  holidays[h] = hol;
361
361
  empHolidays[eh] = empHol;
@@ -369,7 +369,7 @@ class LeaveReport extends general_1.Report {
369
369
  holidays.forEach((hol, h) => {
370
370
  if (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.periods.push(new leaves_1.LeavePeriod(new employees_1.Leave(empHol)));
373
373
  empHol.used = true;
374
374
  holidays[h] = hol;
375
375
  empHolidays[eh] = empHol;
@@ -384,7 +384,7 @@ class LeaveReport extends general_1.Report {
384
384
  if (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.periods.push(new leaves_1.LeavePeriod(new employees_1.Leave(empHol)));
388
388
  empHol.used = true;
389
389
  holidays[h] = hol;
390
390
  empHolidays[eh] = empHol;
@@ -399,7 +399,7 @@ 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.periods.push(new leaves_1.LeavePeriod(new employees_1.Leave(empHol)));
403
403
  holidays[h] = hol;
404
404
  found = true;
405
405
  empHol.used = true;
@@ -415,27 +415,19 @@ class LeaveReport extends general_1.Report {
415
415
  holidays.forEach((hol, h) => {
416
416
  if (!found && hol.disabled) {
417
417
  found = true;
418
- hol.periods.push(new leaves_1.LeavePeriod(empHol.code, empHol.leavedate, empHol.status, new employees_1.Leave(empHol)));
418
+ hol.periods.push(new leaves_1.LeavePeriod(new employees_1.Leave(empHol)));
419
419
  }
420
420
  });
421
421
  }
422
422
  });
423
423
  // next, place the non-holiday leaves into the months they are using in.
424
+ empOtherLeaves.sort((a, b) => a.compareTo(b));
424
425
  empOtherLeaves.forEach(lv => {
426
+ let lvFound = false;
425
427
  months.forEach((month, m) => {
426
- if (month.month.getUTCFullYear() === lv.leavedate.getUTCFullYear()
428
+ if (!lvFound && 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
  });
@@ -505,7 +497,7 @@ class LeaveReport extends general_1.Report {
505
497
  }
506
498
  });
507
499
  });
508
- this.setCell(sheet, this.getCellID(col + 3, holRow), this.getCellID(col + 3, holRow), {
500
+ this.setCell(sheet, this.getCellID(col + 2, holRow), this.getCellID(col + 2, holRow), {
509
501
  fill: this.fills.get('white'),
510
502
  alignment: this.alignments.get('center'),
511
503
  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,21 @@ 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.leaves.push(new employees_1.Leave(leave));
98
+ prd.end = new Date(leave.leavedate);
99
+ this.periods[p] = prd;
100
+ }
101
+ });
102
+ if (!bAdded) {
103
+ this.periods.push(new LeavePeriod(leave));
104
+ }
105
+ }
115
106
  }
116
107
  exports.LeaveMonth = LeaveMonth;