scheduler-node-models 1.2.68 → 1.2.70

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.2.68",
3
+ "version": "1.2.70",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -1,7 +1,9 @@
1
+ import { Row } from "exceljs";
1
2
  import { ISite, Site } from "../sites";
2
3
  import { ITeam, Team } from "../teams";
3
4
  import { ExcelRow } from "./excelRow";
4
5
  import { LaborCode } from "../labor";
6
+ import { Employee } from "../employees";
5
7
  export declare class ExcelRowIngest {
6
8
  files: File[];
7
9
  team: Team;
@@ -19,4 +21,5 @@ export declare class ExcelRowIngest {
19
21
  * @returns A list of labor codes that can be assigned to an employee.
20
22
  */
21
23
  getForecast(date: Date): Promise<LaborCode[]>;
24
+ readExcelRow(row: Row, c: number, emp: Employee): Promise<ExcelRow[]>;
22
25
  }
@@ -34,10 +34,6 @@ class ExcelRowIngest {
34
34
  }
35
35
  async processFile(file) {
36
36
  const result = [];
37
- // create test patterns for hours, if value doesn't match the hours pattern, it will
38
- // be assumed to be a leave code
39
- const hPattern = "^[0-9]{1,2}(\.[0-9]+)?$";
40
- const hourRE = new RegExp(hPattern);
41
37
  // convert the file into a buffer to allow the exceljs library to create an excel
42
38
  // document to read through.
43
39
  const filereader = file.stream().getReader();
@@ -60,64 +56,12 @@ class ExcelRowIngest {
60
56
  console.log(name);
61
57
  if (this.site.employees) {
62
58
  let found = false;
63
- this.site.employees.forEach(emp => {
59
+ this.site.employees.forEach(async (emp) => {
64
60
  if (emp.name.getLastFirst().toLowerCase() === name.toLowerCase()) {
65
61
  found = true;
66
62
  for (let c = 3; c < 34; c++) {
67
- async () => {
68
- const colDate = new Date(this.docDate.getTime() + (24 * 3600000 * (c - 3)));
69
- console.log(colDate);
70
- // Step through the days of the month to create the excel rows to add
71
- // for this employee
72
- const sValue = row.getCell(c).toString().trim();
73
- console.log(sValue);
74
- if (sValue !== '') {
75
- if (hourRE.test(sValue)) {
76
- // test for value being an hours, if true find out which labor code
77
- // to use, then create the excel row and add to the database.
78
- let laborcode = new labor_1.LaborCode();
79
- const laborcodes = await this.getForecast(colDate);
80
- emp.assignments.forEach(asgmt => {
81
- if (asgmt.useAssignment(colDate)) {
82
- asgmt.laborcodes.forEach(alc => {
83
- laborcodes.forEach(flc => {
84
- if (flc.chargeNumber === alc.chargenumber
85
- && flc.extension === alc.extension) {
86
- laborcode.chargeNumber = flc.chargeNumber;
87
- laborcode.extension = flc.extension;
88
- }
89
- });
90
- });
91
- }
92
- });
93
- if (laborcode.chargeNumber !== '') {
94
- const eRow = new excelRow_1.ExcelRow();
95
- eRow.date = new Date(colDate);
96
- eRow.employee = emp.companyinfo.employeeid;
97
- eRow.chargeNumber = laborcode.chargeNumber;
98
- eRow.extension = laborcode.extension;
99
- eRow.premium = '1';
100
- eRow.hours = Number(sValue);
101
- result.push(eRow);
102
- }
103
- }
104
- else {
105
- // this will be a leave code, so find out which to use, then
106
- // create the excel row with the employee's standard workday.
107
- this.team.workcodes.forEach(wc => {
108
- if (wc.isLeave && wc.altcode
109
- && sValue.toLowerCase() === wc.altcode) {
110
- const eRow = new excelRow_1.ExcelRow();
111
- eRow.date = new Date(colDate);
112
- eRow.employee = emp.companyinfo.employeeid;
113
- eRow.code = wc.id;
114
- eRow.hours = emp.getStandardWorkday(colDate);
115
- result.push(eRow);
116
- }
117
- });
118
- }
119
- }
120
- };
63
+ console.log(c);
64
+ const eRow = await this.readExcelRow(row, c, emp);
121
65
  }
122
66
  }
123
67
  });
@@ -155,5 +99,65 @@ class ExcelRowIngest {
155
99
  });
156
100
  return laborcodes;
157
101
  }
102
+ async readExcelRow(row, c, emp) {
103
+ const result = [];
104
+ // create test patterns for hours, if value doesn't match the hours pattern, it will
105
+ // be assumed to be a leave code
106
+ const hPattern = "^[0-9]{1,2}(\.[0-9]+)?$";
107
+ const hourRE = new RegExp(hPattern);
108
+ const colDate = new Date(this.docDate.getTime() + (24 * 3600000 * (c - 3)));
109
+ console.log(colDate);
110
+ // Step through the days of the month to create the excel rows to add
111
+ // for this employee
112
+ const sValue = row.getCell(c).toString().trim();
113
+ console.log(sValue);
114
+ if (sValue !== '') {
115
+ if (hourRE.test(sValue)) {
116
+ // test for value being an hours, if true find out which labor code
117
+ // to use, then create the excel row and add to the database.
118
+ let laborcode = new labor_1.LaborCode();
119
+ const laborcodes = await this.getForecast(colDate);
120
+ emp.assignments.forEach(asgmt => {
121
+ if (asgmt.useAssignment(colDate)) {
122
+ asgmt.laborcodes.forEach(alc => {
123
+ laborcodes.forEach(flc => {
124
+ if (flc.chargeNumber === alc.chargenumber
125
+ && flc.extension === alc.extension) {
126
+ laborcode.chargeNumber = flc.chargeNumber;
127
+ laborcode.extension = flc.extension;
128
+ }
129
+ });
130
+ });
131
+ }
132
+ });
133
+ if (laborcode.chargeNumber !== '') {
134
+ const eRow = new excelRow_1.ExcelRow();
135
+ eRow.date = new Date(colDate);
136
+ eRow.employee = emp.companyinfo.employeeid;
137
+ eRow.chargeNumber = laborcode.chargeNumber;
138
+ eRow.extension = laborcode.extension;
139
+ eRow.premium = '1';
140
+ eRow.hours = Number(sValue);
141
+ result.push(eRow);
142
+ }
143
+ }
144
+ else {
145
+ // this will be a leave code, so find out which to use, then
146
+ // create the excel row with the employee's standard workday.
147
+ this.team.workcodes.forEach(wc => {
148
+ if (wc.isLeave && wc.altcode
149
+ && sValue.toLowerCase() === wc.altcode) {
150
+ const eRow = new excelRow_1.ExcelRow();
151
+ eRow.date = new Date(colDate);
152
+ eRow.employee = emp.companyinfo.employeeid;
153
+ eRow.code = wc.id;
154
+ eRow.hours = emp.getStandardWorkday(colDate);
155
+ result.push(eRow);
156
+ }
157
+ });
158
+ }
159
+ }
160
+ return result;
161
+ }
158
162
  }
159
163
  exports.ExcelRowIngest = ExcelRowIngest;