scheduler-node-models 1.2.67 → 1.2.69
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,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,11 @@ 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
|
-
|
|
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
|
+
const eRow = await this.readExcelRow(row, c, emp);
|
|
121
64
|
}
|
|
122
65
|
}
|
|
123
66
|
});
|
|
@@ -155,5 +98,65 @@ class ExcelRowIngest {
|
|
|
155
98
|
});
|
|
156
99
|
return laborcodes;
|
|
157
100
|
}
|
|
101
|
+
async readExcelRow(row, c, emp) {
|
|
102
|
+
const result = [];
|
|
103
|
+
// create test patterns for hours, if value doesn't match the hours pattern, it will
|
|
104
|
+
// be assumed to be a leave code
|
|
105
|
+
const hPattern = "^[0-9]{1,2}(\.[0-9]+)?$";
|
|
106
|
+
const hourRE = new RegExp(hPattern);
|
|
107
|
+
const colDate = new Date(this.docDate.getTime() + (24 * 3600000 * (c - 3)));
|
|
108
|
+
console.log(colDate);
|
|
109
|
+
// Step through the days of the month to create the excel rows to add
|
|
110
|
+
// for this employee
|
|
111
|
+
const sValue = row.getCell(c).toString().trim();
|
|
112
|
+
console.log(sValue);
|
|
113
|
+
if (sValue !== '') {
|
|
114
|
+
if (hourRE.test(sValue)) {
|
|
115
|
+
// test for value being an hours, if true find out which labor code
|
|
116
|
+
// to use, then create the excel row and add to the database.
|
|
117
|
+
let laborcode = new labor_1.LaborCode();
|
|
118
|
+
const laborcodes = await this.getForecast(colDate);
|
|
119
|
+
emp.assignments.forEach(asgmt => {
|
|
120
|
+
if (asgmt.useAssignment(colDate)) {
|
|
121
|
+
asgmt.laborcodes.forEach(alc => {
|
|
122
|
+
laborcodes.forEach(flc => {
|
|
123
|
+
if (flc.chargeNumber === alc.chargenumber
|
|
124
|
+
&& flc.extension === alc.extension) {
|
|
125
|
+
laborcode.chargeNumber = flc.chargeNumber;
|
|
126
|
+
laborcode.extension = flc.extension;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (laborcode.chargeNumber !== '') {
|
|
133
|
+
const eRow = new excelRow_1.ExcelRow();
|
|
134
|
+
eRow.date = new Date(colDate);
|
|
135
|
+
eRow.employee = emp.companyinfo.employeeid;
|
|
136
|
+
eRow.chargeNumber = laborcode.chargeNumber;
|
|
137
|
+
eRow.extension = laborcode.extension;
|
|
138
|
+
eRow.premium = '1';
|
|
139
|
+
eRow.hours = Number(sValue);
|
|
140
|
+
result.push(eRow);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// this will be a leave code, so find out which to use, then
|
|
145
|
+
// create the excel row with the employee's standard workday.
|
|
146
|
+
this.team.workcodes.forEach(wc => {
|
|
147
|
+
if (wc.isLeave && wc.altcode
|
|
148
|
+
&& sValue.toLowerCase() === wc.altcode) {
|
|
149
|
+
const eRow = new excelRow_1.ExcelRow();
|
|
150
|
+
eRow.date = new Date(colDate);
|
|
151
|
+
eRow.employee = emp.companyinfo.employeeid;
|
|
152
|
+
eRow.code = wc.id;
|
|
153
|
+
eRow.hours = emp.getStandardWorkday(colDate);
|
|
154
|
+
result.push(eRow);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
158
161
|
}
|
|
159
162
|
exports.ExcelRowIngest = ExcelRowIngest;
|