@seniorsistemas/hcm-clocking-event-rule-nodejs 0.35.0

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 (128) hide show
  1. package/.github/copilot-instructions.md +11 -0
  2. package/.github/workflows/release.yaml +10 -0
  3. package/.gitlab-ci.yml +68 -0
  4. package/CHANGELOG.md +274 -0
  5. package/README.doc.md +658 -0
  6. package/README.md +117 -0
  7. package/assets/favicon.ico +0 -0
  8. package/catalog-info.yaml +19 -0
  9. package/jest.config.js +17 -0
  10. package/package.json +48 -0
  11. package/prompt.md +15 -0
  12. package/run_build_win.bat +1 -0
  13. package/run_link.bat +3 -0
  14. package/run_test.bat +1 -0
  15. package/sonar-project.properties +21 -0
  16. package/src/data/changes/changes.ts +92 -0
  17. package/src/data/context/context.ts +251 -0
  18. package/src/data/context/contextReference.ts +376 -0
  19. package/src/data/contract/contract.ts +272 -0
  20. package/src/data/dataset/database.ts +130 -0
  21. package/src/data/dataset/dataset.ts +275 -0
  22. package/src/data/definition/timeEvaluationSituationDefinitionHistory.ts +1425 -0
  23. package/src/data/employee/employee.ts +434 -0
  24. package/src/data/foundation/companyBranch.ts +66 -0
  25. package/src/data/foundation/costCenter.ts +47 -0
  26. package/src/data/foundation/employer.ts +35 -0
  27. package/src/data/foundation/employmentRelationship.ts +63 -0
  28. package/src/data/foundation/holiday.ts +84 -0
  29. package/src/data/foundation/holidayGroup.ts +47 -0
  30. package/src/data/foundation/jobPosition.ts +73 -0
  31. package/src/data/foundation/person.ts +35 -0
  32. package/src/data/foundation/situation.ts +301 -0
  33. package/src/data/foundation/syndicate.ts +244 -0
  34. package/src/data/foundation/workschedule.ts +688 -0
  35. package/src/data/foundation/workshift.ts +647 -0
  36. package/src/data/foundation/workshiftBase.ts +113 -0
  37. package/src/data/histories/companyBranchHistory.ts +128 -0
  38. package/src/data/histories/costCenterHistory.ts +114 -0
  39. package/src/data/histories/employmentRelationshipHistory.ts +116 -0
  40. package/src/data/histories/histories.ts +419 -0
  41. package/src/data/histories/jobPositionHistory.ts +117 -0
  42. package/src/data/histories/leaveHistory.ts +227 -0
  43. package/src/data/histories/timeEvaluationHistory.ts +191 -0
  44. package/src/data/histories/workshiftHistory.ts +66 -0
  45. package/src/data/hourBank/hourBank.ts +43 -0
  46. package/src/data/hourBank/hourBankAccount.ts +77 -0
  47. package/src/data/log/log.ts +38 -0
  48. package/src/data/schedules/bridge.ts +84 -0
  49. package/src/data/schedules/compensation.ts +332 -0
  50. package/src/data/schedules/overtimeAuthorization.ts +174 -0
  51. package/src/data/schedules/readiness.ts +150 -0
  52. package/src/data/schedules/schedules.ts +398 -0
  53. package/src/data/schedules/workscheduleChange.ts +91 -0
  54. package/src/data/schedules/workshiftChange.ts +76 -0
  55. package/src/data/timeEvaluation/adjustmentReason.ts +46 -0
  56. package/src/data/timeEvaluation/clockingEvent.ts +198 -0
  57. package/src/data/timeEvaluation/estimatedHours.ts +245 -0
  58. package/src/data/timeEvaluation/interval.ts +568 -0
  59. package/src/data/timeEvaluation/separatedHours.ts +134 -0
  60. package/src/data/timeEvaluation/timeEvaluation.ts +1540 -0
  61. package/src/data/timeEvaluation/timeEvaluationSituation.ts +154 -0
  62. package/src/data/user/user.ts +44 -0
  63. package/src/index.ts +60 -0
  64. package/src/test/builder/bridgeBuilder.builder.ts +28 -0
  65. package/src/test/builder/clockingEvent.builder.ts +49 -0
  66. package/src/test/builder/companyBranchHistoryBuilder.ts +29 -0
  67. package/src/test/builder/compensation.builder.ts +84 -0
  68. package/src/test/builder/contextReference.builder.ts +69 -0
  69. package/src/test/builder/costCenterHistoryBuilder.ts +29 -0
  70. package/src/test/builder/database.builder.ts +21 -0
  71. package/src/test/builder/datasetBuilder.ts +111 -0
  72. package/src/test/builder/dateIntervalBuilder.ts +25 -0
  73. package/src/test/builder/employee.builder.ts +91 -0
  74. package/src/test/builder/employmentRelationshipBuilder.ts +35 -0
  75. package/src/test/builder/employmentRelationshipHistoryBuilder.ts +29 -0
  76. package/src/test/builder/historiesBuilder.ts +56 -0
  77. package/src/test/builder/holiday.builder.ts +44 -0
  78. package/src/test/builder/hourBankAccountBuilder.ts +77 -0
  79. package/src/test/builder/hourBankBuilder.ts +32 -0
  80. package/src/test/builder/interval.builder.ts +113 -0
  81. package/src/test/builder/jobPositionHistoryBuilder.ts +29 -0
  82. package/src/test/builder/overtimeAuthorization.builder.ts +42 -0
  83. package/src/test/builder/readinessBuilder.builder.ts +57 -0
  84. package/src/test/builder/schedules.builder.ts +126 -0
  85. package/src/test/builder/situation.builder.ts +59 -0
  86. package/src/test/builder/syndicate.builder.ts +96 -0
  87. package/src/test/builder/syndicateHistoryBuilder.ts +33 -0
  88. package/src/test/builder/timeEvaluation.builder.ts +138 -0
  89. package/src/test/builder/timeEvaluationHistory.builder.ts +49 -0
  90. package/src/test/builder/timeEvaluationSituation.builder.ts +34 -0
  91. package/src/test/builder/workschedule.builder.ts +96 -0
  92. package/src/test/builder/workshift.builder.ts +179 -0
  93. package/src/test/builder/workshiftBuilder.ts +55 -0
  94. package/src/test/data/clockingEvent.spec.ts +56 -0
  95. package/src/test/data/context.spec.ts +176 -0
  96. package/src/test/data/currentUser.spec.ts +11 -0
  97. package/src/test/data/dataset.spec.ts +144 -0
  98. package/src/test/data/employee/employee.spec.ts +20 -0
  99. package/src/test/data/employmentRelationship/employmentRelationship.spec.ts +48 -0
  100. package/src/test/data/estimatedHours/estimatedHours.spec.ts +96 -0
  101. package/src/test/data/histories/costCenterHistory.spec.ts +32 -0
  102. package/src/test/data/histories/histories.spec.ts +306 -0
  103. package/src/test/data/holyday.spec.ts +89 -0
  104. package/src/test/data/hourBank/hourBank.spec.ts +48 -0
  105. package/src/test/data/hourBank/hourBankAccount.spec.ts +32 -0
  106. package/src/test/data/schedules/bridge.spec.ts +13 -0
  107. package/src/test/data/schedules/compesation.spect.ts +89 -0
  108. package/src/test/data/schedules/overtimeAuthorization.spec.ts +52 -0
  109. package/src/test/data/schedules/readiness.spec.ts +64 -0
  110. package/src/test/data/schedules/schedules.spec.ts +134 -0
  111. package/src/test/data/schedules/workscheduleChange.spec.ts +21 -0
  112. package/src/test/data/syndicate/syndicate.spec.ts +51 -0
  113. package/src/test/data/timeEvaluation.spec.ts +1057 -0
  114. package/src/test/data/timeEvaluationDefinition.spec.ts +144 -0
  115. package/src/test/data/workschedule/workschedule.spec.ts +194 -0
  116. package/src/test/data/workshift/workshift.spec.ts +79 -0
  117. package/src/test/utils/date.utils.spec.ts +198 -0
  118. package/src/test/utils/dateIntervalUtils.spec.ts +210 -0
  119. package/src/test/utils/object.utils.spec.ts +83 -0
  120. package/src/utils/dateIntervalUtils.ts +284 -0
  121. package/src/utils/dateUtils.ts +456 -0
  122. package/src/utils/decompressGzipLambda.ts +15 -0
  123. package/src/utils/object.utils.ts +156 -0
  124. package/trivy/vulnerabilities_scan.json +1160 -0
  125. package/tsconfig.json +32 -0
  126. package/tsconfig.spec.json +21 -0
  127. package/tslint.json +92 -0
  128. package/typedoc.json +22 -0
@@ -0,0 +1,130 @@
1
+ import { TimeEvaluationSituationDefinitionHistory } from "../definition/timeEvaluationSituationDefinitionHistory";
2
+ import { CompanyBranch } from "../foundation/companyBranch";
3
+ import { JobPosition } from "../foundation/jobPosition";
4
+ import { Holiday } from "./../foundation/holiday";
5
+ import { Situation } from "./../foundation/situation";
6
+ import { Workschedule } from "../foundation/workschedule";
7
+ import { Workshift, WorkshiftDetail, WorkshiftGroup } from "../foundation/workshift";
8
+ import { Syndicate } from "../foundation/syndicate";
9
+ import { EmploymentRelationship } from "../foundation/employmentRelationship";
10
+ import { CostCenter } from "../foundation/costCenter";
11
+
12
+ /**
13
+ * @hidden
14
+ */
15
+ export interface DatabaseParams {
16
+ situations: Situation[];
17
+ holidays: Holiday[];
18
+ jobPositions: JobPosition[];
19
+ workshifts: Workshift[];
20
+ workshiftGroups: WorkshiftGroup[];
21
+ workshiftDetails: WorkshiftDetail[];
22
+ workschedules: Workschedule[];
23
+ companyBranches: CompanyBranch[];
24
+ timeEvaluationSituationDefinitions: TimeEvaluationSituationDefinitionHistory[];
25
+ syndicates: Syndicate[];
26
+ employmentRelationships: EmploymentRelationship[];
27
+ costCenters: CostCenter[];
28
+ }
29
+
30
+ /**
31
+ * @hidden
32
+ * Representa o banco de dados do sistema, contendo informações sobre situações, feriados, cargos, filiais, definições de situações de avaliação de tempo, escalas de trabalho, turnos, sindicatos e relacionamentos empregatícios.
33
+ * Fornece métodos para acessar essas informações de forma organizada.
34
+ */
35
+ export class Database {
36
+ private readonly _situations: Situation[];
37
+ private readonly _holidays: Holiday[];
38
+ private readonly _jobPosition: JobPosition[];
39
+ private readonly _companyBranches: CompanyBranch[];
40
+ private readonly _timeEvaluationSituationDefinitions: TimeEvaluationSituationDefinitionHistory[];
41
+ private readonly _workschedules: Workschedule[];
42
+ private readonly _workshifts: Workshift[];
43
+ private readonly _workshiftGroups: WorkshiftGroup[];
44
+ private readonly _workshiftDetails: WorkshiftDetail[];
45
+ private readonly _syndicates: Syndicate[];
46
+ private readonly _employmentRelationships: EmploymentRelationship[];
47
+ private readonly _costCenters: CostCenter[];
48
+
49
+ constructor(params: DatabaseParams) {
50
+ this._situations = params.situations;
51
+ this._holidays = params.holidays;
52
+ this._jobPosition = params.jobPositions;
53
+ this._companyBranches = params.companyBranches;
54
+ this._timeEvaluationSituationDefinitions = params.timeEvaluationSituationDefinitions;
55
+ this._workschedules = params.workschedules;
56
+ this._workshifts = params.workshifts;
57
+ this._workshiftGroups = params.workshiftGroups;
58
+ this._workshiftDetails = params.workshiftDetails;
59
+ this._syndicates = params.syndicates;
60
+ this._employmentRelationships = params.employmentRelationships;
61
+ this._costCenters = params.costCenters;
62
+ }
63
+
64
+
65
+ get situations(): Situation[] {
66
+ return this._situations;
67
+ }
68
+
69
+ get workschedules(): Workschedule[] {
70
+ return this._workschedules;
71
+ }
72
+
73
+ get workshifts(): Workshift[] {
74
+ return this._workshifts;
75
+ }
76
+
77
+ get workshiftGroups(): WorkshiftGroup[] {
78
+ return this._workshiftGroups;
79
+ }
80
+
81
+ get workshiftDetails(): WorkshiftDetail[] {
82
+ return this._workshiftDetails;
83
+ }
84
+
85
+ get holidays(): Holiday[] {
86
+ return this._holidays;
87
+ }
88
+
89
+
90
+ get timeEvaluationSituationDefinitions(): TimeEvaluationSituationDefinitionHistory[] {
91
+ return this._timeEvaluationSituationDefinitions;
92
+ }
93
+
94
+ get jobPositions(): JobPosition[] {
95
+ return this._jobPosition;
96
+ }
97
+
98
+ get companyBranches(): CompanyBranch[] {
99
+ return this._companyBranches;
100
+ }
101
+
102
+ get syndicates(): Syndicate[] {
103
+ return this._syndicates;
104
+ }
105
+
106
+ get employmentRelationships(): EmploymentRelationship[] {
107
+ return this._employmentRelationships;
108
+ }
109
+
110
+ get costCenters(): CostCenter[] {
111
+ return this._costCenters;
112
+ }
113
+
114
+ static empty(): Database {
115
+ return new Database({
116
+ situations: [],
117
+ holidays: [],
118
+ jobPositions: [],
119
+ workshifts: [],
120
+ workshiftGroups: [],
121
+ workshiftDetails: [],
122
+ workschedules: [],
123
+ companyBranches: [],
124
+ timeEvaluationSituationDefinitions: [],
125
+ syndicates: [],
126
+ employmentRelationships: [],
127
+ costCenters: []
128
+ });
129
+ }
130
+ }
@@ -0,0 +1,275 @@
1
+ import { ObjectUtils } from "../../utils/object.utils";
2
+ import { DateUtils } from "../../utils/dateUtils";
3
+ import { Changes, ChangesItems, ChangesType } from "../changes/changes";
4
+ import { ContextReference } from "../context/contextReference";
5
+ import { Contract, ContractParams } from "../contract/contract";
6
+ import { Log, LogType } from "../log/log";
7
+ import { TimeEvaluation } from "./../timeEvaluation/timeEvaluation";
8
+ import { TimeEvaluationSituation } from "../timeEvaluation/timeEvaluationSituation";
9
+ import { Database } from "./database";
10
+ import { User } from "../user/user";
11
+ import fs from 'fs';
12
+ import findUp from 'find-up';
13
+ /**
14
+ * Representa o parâmetros recebidos pela regra de apuração.
15
+ * Nas informações estão diponíveis: data inicial e final da apuração, data da apuração, contratos e logs.
16
+ *
17
+ * O Consultor deve iterar sobre os contratos e apurar as situações de cada contrato.
18
+ * @hidden
19
+ */
20
+ export interface DatasetParams {
21
+ batchId: string;
22
+ startDate: Date;
23
+ endDate: Date;
24
+ contracts: Contract[];
25
+ database: Database;
26
+ currentUser: User;
27
+ }
28
+
29
+
30
+ /**
31
+ * @hidden
32
+ */
33
+ export class Dataset {
34
+
35
+ private readonly _batchId: string;
36
+ /**
37
+ * Data inicial da apuração.
38
+ */
39
+ private readonly _startDate: Date;
40
+ /**
41
+ * Data final da apuração.
42
+ */
43
+ private readonly _endDate: Date;
44
+ /**
45
+ * Contratos.
46
+ */
47
+ private readonly _contracts: Contract[];
48
+ private readonly _logs: Log[];
49
+ private readonly _database: Database;
50
+ /**
51
+ * Usuário corrente.
52
+ */
53
+ private readonly _currentUser: User;
54
+
55
+ /** @hidden */
56
+ constructor(params: DatasetParams) {
57
+ this._batchId = params.batchId;
58
+ this._startDate = ObjectUtils.toDateOrThrow(params.startDate, "Dataset.startDate");
59
+ this._endDate = ObjectUtils.toDateOrThrow(params.endDate, "Dataset.endDate");
60
+ this._contracts = [];
61
+ this._logs = [];
62
+ this._database = params.database;
63
+ this._currentUser = new User({ userName: params.currentUser.userName });
64
+
65
+ const contextRef = new ContextReference({
66
+ situations: params.database.situations,
67
+ holidays: params.database.holidays,
68
+ timeEvaluationSituationDefinitions: params.database.timeEvaluationSituationDefinitions,
69
+ jobPositions: params.database.jobPositions,
70
+ companyBranches: params.database.companyBranches,
71
+ workschedules: params.database.workschedules,
72
+ workshifts: params.database.workshifts,
73
+ workshiftGroups: params.database.workshiftGroups,
74
+ workshiftDetails: params.database.workshiftDetails,
75
+ syndicates: params.database.syndicates,
76
+ employmentRelationships: params.database.employmentRelationships,
77
+ costCenters: params.database.costCenters,
78
+ });
79
+
80
+ ContextReference.setGlobalInstance(contextRef);
81
+
82
+ if (Array.isArray(params.contracts)) {
83
+ for (const contract of params.contracts) {
84
+ const contractParams: ContractParams = {
85
+ id: contract.id,
86
+ holidaysKeys: contract.holidaysKeys,
87
+ timeEvaluation: contract.timeEvaluation,
88
+ employee: contract.employee,
89
+ histories: contract.histories,
90
+ schedules: contract.schedules,
91
+ hourBankAccounts: contract.hourBankAccounts
92
+ };
93
+
94
+ const newContract = new Contract(contractParams);
95
+ this._contracts.push(newContract);
96
+ }
97
+ }
98
+ }
99
+
100
+ static empty(): Dataset {
101
+ return new Dataset({
102
+ batchId: "",
103
+ startDate: new Date(),
104
+ endDate: new Date(),
105
+ contracts: [],
106
+ database: new Database({
107
+ situations: [],
108
+ holidays: [],
109
+ timeEvaluationSituationDefinitions: [],
110
+ jobPositions: [],
111
+ companyBranches: [],
112
+ workschedules: [],
113
+ workshifts: [],
114
+ workshiftGroups: [],
115
+ workshiftDetails: [],
116
+ syndicates: [],
117
+ employmentRelationships: [],
118
+ costCenters: []
119
+ }),
120
+ currentUser: new User({ userName: "" })
121
+ });
122
+ }
123
+
124
+
125
+ get batchId(): string {
126
+ return this._batchId;
127
+ }
128
+
129
+ /**
130
+ * Data inicial da apuração.
131
+ */
132
+ get startDate(): Date {
133
+ return this._startDate;
134
+ }
135
+
136
+ /**
137
+ * Data final da apuração.
138
+ */
139
+ get endDate(): Date {
140
+ return this._endDate;
141
+ }
142
+
143
+ /**
144
+ * Contratos apurados.
145
+ */
146
+ get contracts(): Contract[] {
147
+ return this._contracts;
148
+ }
149
+
150
+ get database(): Database {
151
+ return this._database;
152
+ }
153
+
154
+ /**
155
+ * Usuário corrente.
156
+ */
157
+ get currentUser(): User {
158
+ return this._currentUser;
159
+ }
160
+
161
+ /**
162
+ * Extrai as alterações feitas na regra para serem enviadas ao cálculo de apuração.
163
+ * @returns Json com as alteraçõe da regra.
164
+ */
165
+ processChanges(): Changes {
166
+
167
+ const changes = new Changes();
168
+ let sequence = 0;
169
+
170
+ this.contracts.forEach((contract: Contract) => {
171
+ contract.timeEvaluation.forEach((timeEvaluation: TimeEvaluation) => {
172
+ if (timeEvaluation.errorMessage) {
173
+ changes.changesItems.push(
174
+ new ChangesItems({
175
+ contractId: contract.id || null,
176
+ type: ChangesType.ERROR,
177
+ timeEvaluationDate: DateUtils.dateToIsoDateStr(timeEvaluation.date),
178
+ key: "",
179
+ value: timeEvaluation.errorMessage || "",
180
+ sequence,
181
+ })
182
+ );
183
+ sequence++;
184
+ } else {
185
+ timeEvaluation.timeEvaluationSituations.forEach((timeEvaluationSituation: TimeEvaluationSituation) => {
186
+ if (timeEvaluationSituation.changed) {
187
+ changes.changesItems.push(
188
+ new ChangesItems({
189
+ contractId: contract.id || null,
190
+ type: ChangesType.SITUATION,
191
+ timeEvaluationDate: DateUtils.dateToIsoDateStr(timeEvaluation.date),
192
+ key: String(timeEvaluationSituation.situation.code),
193
+ value: String(timeEvaluationSituation.numberOfHours),
194
+ sequence,
195
+ })
196
+ );
197
+
198
+ sequence++
199
+ }
200
+ });
201
+ if (timeEvaluation.generatePendingAdjustment !== undefined) {
202
+ changes.changesItems.push(
203
+ new ChangesItems({
204
+ contractId: contract.id || null,
205
+ type: ChangesType.PENDENCY,
206
+ timeEvaluationDate: DateUtils.dateToIsoDateStr(timeEvaluation.date),
207
+ key: "",
208
+ value: timeEvaluation.generatePendingAdjustment ? "true" : "false",
209
+ sequence,
210
+ })
211
+ );
212
+ sequence++;
213
+ }
214
+
215
+ }
216
+ });
217
+ });
218
+
219
+ this._logs.forEach((log: Log) => {
220
+ changes.changesItems.push(
221
+ new ChangesItems({
222
+ contractId: null,
223
+ type: ChangesType.LOG,
224
+ timeEvaluationDate: null,
225
+ key: log.type,
226
+ value: log.message,
227
+ sequence,
228
+ })
229
+ );
230
+ sequence++;
231
+ });
232
+
233
+ sequence++;
234
+ return changes;
235
+ }
236
+
237
+ /**
238
+ * @hidden
239
+ */
240
+ public getProjectVersionSync(): string | undefined {
241
+ const packageJsonPath = findUp.sync('package.json');
242
+ if (!packageJsonPath) {
243
+ return undefined;
244
+ }
245
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
246
+
247
+ return packageJson.dependencies?.['hcm-clocking-event-rule-nodejs'];
248
+
249
+ }
250
+
251
+
252
+ /**
253
+ * Logar de informações no log de processo.
254
+ * @param message Mensagem de informação.
255
+ */
256
+ public logInfo(message: string) {
257
+ this._logs.push(new Log({ type: LogType.INFO, message }));
258
+ }
259
+
260
+ /**
261
+ * Logar de aviso no log de processo.
262
+ * @param message Mensagem de aviso.
263
+ */
264
+ public logWarning(message: string) {
265
+ this._logs.push(new Log({ type: LogType.WARNING, message }));
266
+ }
267
+
268
+ /**
269
+ * Logar de erro no log de processo.
270
+ * @param message Mensagem de erro.
271
+ */
272
+ public logError(message: string) {
273
+ this._logs.push(new Log({ type: LogType.ERROR, message }));
274
+ }
275
+ }