@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,376 @@
1
+ import { DateUtils } from "src/utils/dateUtils";
2
+ import { TimeEvaluationSituationDefinitionHistory } from "../definition/timeEvaluationSituationDefinitionHistory";
3
+ import { Holiday } from "./../foundation/holiday";
4
+ import { Situation } from "./../foundation/situation";
5
+ import { JobPosition } from "../foundation/jobPosition";
6
+ import { CompanyBranch } from "../foundation/companyBranch";
7
+ import { Workshift, WorkshiftGroup, WorkshiftDetail } from "../foundation/workshift";
8
+ import { Workschedule } from "../foundation/workschedule";
9
+ import { Syndicate } from "../foundation/syndicate";
10
+ import { EmploymentRelationship } from "../foundation/employmentRelationship";
11
+ import { CostCenter } from "../foundation/costCenter";
12
+
13
+ /**
14
+ * @hidden
15
+ * Parâmetros para criar um ContextReference.
16
+ */
17
+ export interface ContextReferenceParams {
18
+ situations: Situation[];
19
+ holidays: Holiday[];
20
+ timeEvaluationSituationDefinitions: TimeEvaluationSituationDefinitionHistory[];
21
+ jobPositions: JobPosition[];
22
+ companyBranches: CompanyBranch[];
23
+ workshifts: Workshift[];
24
+ workshiftGroups: WorkshiftGroup[];
25
+ workshiftDetails: WorkshiftDetail[];
26
+ workschedules: Workschedule[];
27
+ syndicates: Syndicate[];
28
+ employmentRelationships: EmploymentRelationship[];
29
+ costCenters: CostCenter[];
30
+ }
31
+
32
+ /**
33
+ * @hidden
34
+ * Parâmetros para criar uma referência de contexto.
35
+ */
36
+ export class ContextReference {
37
+ private readonly _situations: Map<string, Situation>;
38
+ private readonly _situationsByCode: Map<number, Situation>;
39
+ private readonly _jobPositions: Map<string, JobPosition>;
40
+ private readonly _workshifts: Map<string, Workshift>;
41
+ private readonly _workshiftGroups: Map<string, WorkshiftGroup>;
42
+ private readonly _workshiftDetails: Map<string, WorkshiftDetail>;
43
+ private readonly _workschedules: Map<string, Workschedule>;
44
+ private readonly _companyBranches: Map<string, CompanyBranch>;
45
+ private readonly _holidays: Map<string, Holiday>;
46
+ private readonly _timeEvaluationSituationDefinitions: Map<string, TimeEvaluationSituationDefinitionHistory>;
47
+ private readonly _syndicates: Map<string, Syndicate>;
48
+ private readonly _employmentRelationships: Map<string, EmploymentRelationship>;
49
+ private readonly _costCenters: Map<string, CostCenter>;
50
+
51
+ // Instância global da ContextReference
52
+ private static _globalInstance: ContextReference | null = null;
53
+
54
+ constructor(params: ContextReferenceParams) {
55
+ this._holidays = new Map<string, Holiday>();
56
+ this._situations = new Map<string, Situation>();
57
+ this._situationsByCode = new Map<number, Situation>();
58
+ this._jobPositions = new Map<string, JobPosition>();
59
+ this._timeEvaluationSituationDefinitions = new Map<string, TimeEvaluationSituationDefinitionHistory>();
60
+ this._companyBranches = new Map<string, CompanyBranch>();
61
+ this._workshifts = new Map<string, Workshift>();
62
+ this._workshiftGroups = new Map<string, WorkshiftGroup>();
63
+ this._workshiftDetails = new Map<string, WorkshiftDetail>();
64
+ this._workschedules = new Map<string, Workschedule>();
65
+ this._syndicates = new Map<string, Syndicate>();
66
+ this._employmentRelationships = new Map<string, EmploymentRelationship>();
67
+ this._costCenters = new Map<string, CostCenter>();
68
+
69
+ this.mapSituation(params);
70
+ this.mapHoliday(params);
71
+ this.mapTimeEvaluationDefinition(params);
72
+ this.jobPosition(params);
73
+ this.companyBranch(params);
74
+ this.mapWorkshift(params);
75
+ this.mapWorkshiftGroups(params);
76
+ this.mapWorkshiftDetails(params);
77
+ this.mapWorkschedule(params);
78
+ this.mapSyndicate(params);
79
+ this.mapEmploymentRelationship(params);
80
+ this.mapCostCenter(params);
81
+
82
+ }
83
+
84
+
85
+ private mapTimeEvaluationDefinition(params: ContextReferenceParams) {
86
+ if (Array.isArray(params.timeEvaluationSituationDefinitions)) {
87
+ for (const timeEvaluationSituationDefinitionHistory of params.timeEvaluationSituationDefinitions) {
88
+
89
+ const newTimeEvaluationSituationDefinitionHistory = TimeEvaluationSituationDefinitionHistory.clone(timeEvaluationSituationDefinitionHistory);
90
+
91
+ const key = this.generateKeySituationDefinition(
92
+ newTimeEvaluationSituationDefinitionHistory.code,
93
+ newTimeEvaluationSituationDefinitionHistory.startDate,
94
+ newTimeEvaluationSituationDefinitionHistory.endDate
95
+ );
96
+
97
+ this._timeEvaluationSituationDefinitions.set(key, newTimeEvaluationSituationDefinitionHistory);
98
+ }
99
+ }
100
+ }
101
+
102
+ private mapHoliday(params: ContextReferenceParams) {
103
+ if (Array.isArray(params.holidays)) {
104
+ for (const holiday of params.holidays) {
105
+ this._holidays.set(holiday.key, Holiday.clone(holiday));
106
+ }
107
+ }
108
+ }
109
+
110
+ private mapSituation(params: ContextReferenceParams) {
111
+ if (Array.isArray(params.situations)) {
112
+ for (const situation of params.situations) {
113
+ const newSituation = Situation.clone(situation);
114
+ this._situationsByCode.set(situation.code, newSituation);
115
+ this._situations.set(newSituation.id, newSituation);
116
+ }
117
+ }
118
+ }
119
+
120
+ private jobPosition(params: ContextReferenceParams) {
121
+ if (Array.isArray(params.jobPositions)) {
122
+ for (const jobPosition of params.jobPositions) {
123
+ const newJobPosition = new JobPosition({
124
+ structureCode: jobPosition.structureCode,
125
+ code: jobPosition.code
126
+ });
127
+
128
+ const key = this.generateKeyJobPosition(jobPosition.structureCode, jobPosition.code);
129
+ this._jobPositions.set(key, newJobPosition);
130
+ }
131
+ }
132
+ }
133
+
134
+
135
+ private mapWorkshift(params: ContextReferenceParams) {
136
+ if (Array.isArray(params.workshifts)) {
137
+ for (const workshift of params.workshifts) {
138
+ const newWorkshift = Workshift.clone(workshift);
139
+ this._workshifts.set(Workshift.getKey(newWorkshift), newWorkshift);
140
+ }
141
+ }
142
+ }
143
+
144
+ private mapWorkshiftGroups(params: ContextReferenceParams) {
145
+ if (Array.isArray(params.workshiftGroups)) {
146
+ for (const workshiftGroup of params.workshiftGroups) {
147
+ const newWorkshiftGroup = WorkshiftGroup.clone(workshiftGroup);
148
+ this._workshiftGroups.set(WorkshiftGroup.getKey(newWorkshiftGroup), newWorkshiftGroup);
149
+ }
150
+ }
151
+ }
152
+
153
+ private mapWorkshiftDetails(params: ContextReferenceParams) {
154
+ if (Array.isArray(params.workshiftDetails)) {
155
+ for (const workshiftDetail of params.workshiftDetails) {
156
+ const newWorkshiftDetail = WorkshiftDetail.clone(workshiftDetail);
157
+ this._workshiftDetails.set(WorkshiftDetail.getKey(newWorkshiftDetail), newWorkshiftDetail);
158
+ }
159
+ }
160
+ }
161
+
162
+ private mapWorkschedule(params: ContextReferenceParams) {
163
+ if (Array.isArray(params.workschedules)) {
164
+ for (const workschedule of params.workschedules) {
165
+ const newWorkschedule = new Workschedule({
166
+ id: workschedule.id,
167
+ code: workschedule.code,
168
+ workload: workschedule.workload,
169
+ type: workschedule.type,
170
+ definitionType: workschedule.definitionType,
171
+ clockingRegisters: workschedule.clockingRegisters,
172
+ clockingEvent: workschedule.clockingEvent
173
+ });
174
+
175
+ this._workschedules.set(workschedule.id, newWorkschedule);
176
+ }
177
+ }
178
+ }
179
+
180
+
181
+ private companyBranch(params: ContextReferenceParams) {
182
+ if (Array.isArray(params.companyBranches)) {
183
+ for (const companyBrach of params.companyBranches) {
184
+ const newCompanyBranch = CompanyBranch.clone(companyBrach);
185
+ this._companyBranches.set(CompanyBranch.getKey(newCompanyBranch), newCompanyBranch);
186
+ }
187
+ }
188
+ }
189
+
190
+ private mapSyndicate(params: ContextReferenceParams) {
191
+ if (Array.isArray(params.syndicates)) {
192
+ for (const syndicate of params.syndicates) {
193
+ const newSyndicate = Syndicate.clone(syndicate);
194
+ this._syndicates.set(Syndicate.getKey(syndicate), newSyndicate);
195
+ }
196
+ }
197
+ }
198
+
199
+ private mapEmploymentRelationship(params: ContextReferenceParams) {
200
+ if (Array.isArray(params.employmentRelationships)) {
201
+ for (const employmentRelationship of params.employmentRelationships) {
202
+ const newEmploymentRelationship = new EmploymentRelationship({
203
+ id: employmentRelationship.id,
204
+ code: employmentRelationship.code,
205
+ contractType: employmentRelationship.contractType
206
+ });
207
+
208
+ this._employmentRelationships.set(employmentRelationship.id, newEmploymentRelationship);
209
+ }
210
+ }
211
+ }
212
+
213
+ private mapCostCenter(params: ContextReferenceParams) {
214
+ if (Array.isArray(params.costCenters)) {
215
+ for (const costCenter of params.costCenters) {
216
+ const newCostCenter = new CostCenter({
217
+ code: costCenter.code
218
+ });
219
+
220
+ this._costCenters.set(costCenter.code, newCostCenter);
221
+ }
222
+ }
223
+ }
224
+
225
+ private generateKeyJobPosition(structureCode: number, code: number): string {
226
+ return `${structureCode}_${code}`;
227
+ }
228
+
229
+ private generateKeySituationDefinition(code: number, startDate: Date, endDate: Date | null): string {
230
+ const endDateStr = endDate ? DateUtils.dateToIsoDateStr(endDate) : "null";
231
+ return `${code}_${DateUtils.dateToIsoDateStr(startDate)}_${endDateStr}`;
232
+ }
233
+
234
+ getSituationById(id: string): Situation | undefined {
235
+ return this._situations.get(id);
236
+ }
237
+
238
+ getSituationByCode(code: number): Situation | undefined {
239
+ return this._situationsByCode.get(code);
240
+ }
241
+
242
+ getHolidayByKey(key: string): Holiday {
243
+ const holiday = this._holidays.get(key);
244
+ if (!holiday) {
245
+ throw new Error(`Holiday with key ${key} not found`);
246
+ }
247
+ return holiday;
248
+ }
249
+
250
+ /**
251
+ * Buscar uma definição de situação
252
+ * @param code codigo da situação
253
+ * @param startDate data inicial
254
+ * @param endDate data final
255
+ * @returns Definição de situação
256
+ */
257
+ getTimeEvaluationSituationDefinitionHistory(key: string): TimeEvaluationSituationDefinitionHistory {
258
+ const timeEvaluationSituationDefinitionHistory = this._timeEvaluationSituationDefinitions.get(key);
259
+ if (!timeEvaluationSituationDefinitionHistory) {
260
+ throw new Error(`Time evaluation situation definition history with ${key} not found`);
261
+ }
262
+ return timeEvaluationSituationDefinitionHistory;
263
+ }
264
+
265
+ /**
266
+ * Busca o cargo de um colaborador com base no código do cargo e na estrutura do cargo.
267
+ * @param code código do cargo
268
+ * @param structureCode estrutura do cargo
269
+ * @returns cargo
270
+ */
271
+ getJobPosition(key: string): JobPosition | undefined {
272
+ return this._jobPositions.get(key);
273
+ }
274
+
275
+ /**
276
+ * Busca o centro de custo com base no código do centro de custo.
277
+ * @param code código do centro de custo
278
+ * @returns centro de custo
279
+ */
280
+ getCostCenter(code: string): CostCenter {
281
+ const costCenter = this._costCenters.get(code);
282
+ if (!costCenter) {
283
+ throw new Error(`Cost center with code ${code} not found`);
284
+ }
285
+ return costCenter;
286
+ }
287
+
288
+ /**
289
+ * Busca a filial de uma empresa com base na chave da filial.
290
+ * @param key chave da filial
291
+ * @returns filial da empresa
292
+ */
293
+ getCompanyBranch(key: string): CompanyBranch | undefined {
294
+ return this._companyBranches.get(key);
295
+ }
296
+
297
+ /**
298
+ * Busca a escala de trabalho com base no id da escala.
299
+ * @param id id da escala
300
+ * @returns escala de trabalho
301
+ */
302
+ getWorkshift(id: string): Workshift | undefined {
303
+ return this._workshifts.get(id);
304
+ }
305
+
306
+ /**
307
+ * Busca turma de uma escala com base no id da turma.
308
+ *
309
+ * @param id id da turma da escala.
310
+ * @returns workshiftGroup ou undefined se não encontrado
311
+ */
312
+ getWorkshiftGroup(id: string): WorkshiftGroup | undefined {
313
+ return this._workshiftGroups.get(id);
314
+ }
315
+
316
+ /**
317
+ * Busca as configurações de feriado de uma escala com base na chave do detalhe.
318
+ *
319
+ * @param key chave de identificação das configurações da escala.
320
+ * @returns workshiftDetail ou undefined se não encontrado
321
+ */
322
+ getWorkshiftDetail(key: string): WorkshiftDetail | undefined {
323
+ return this._workshiftDetails.get(key);
324
+ }
325
+
326
+ /**
327
+ * Busca o horário de trabalho com base no id da escala.
328
+ * @param id id da escala
329
+ * @returns escala de trabalho
330
+ */
331
+ getWorkschedule(id: string): Workschedule | undefined {
332
+ return this._workschedules.get(id);
333
+ }
334
+
335
+ /**
336
+ * Busca o sindicato do histórico vigente na data de apuração com base no código.
337
+ * @param code código do sindicato
338
+ * @returns Objeto Syndicate
339
+ */
340
+ getSyndicate(code: string): Syndicate | undefined {
341
+ return this._syndicates.get(code);
342
+ }
343
+
344
+ /**
345
+ * Busca o vínculo do histórico vigente na data de apuração com base no ID do vínculo.
346
+ * @param id ID do vínculo
347
+ * @returns Objeto EmploymentRelationship
348
+ */
349
+ getEmploymentRelationship(id: string): EmploymentRelationship {
350
+ const employmentRelationship = this._employmentRelationships.get(id);
351
+ if (!employmentRelationship) {
352
+ throw new Error(`Employment relationship with id ${id} not found`);
353
+ }
354
+ return employmentRelationship;
355
+ }
356
+
357
+ /**
358
+ * Define a instância global de ContextReference
359
+ * @param instance Instância a ser definida globalmente
360
+ */
361
+ public static setGlobalInstance(instance: ContextReference | null) {
362
+ ContextReference._globalInstance = instance;
363
+ }
364
+
365
+ /**
366
+ * Obtém a instância global de ContextReference
367
+ * @returns Instância global
368
+ * @throws Se a instância global não foi definida
369
+ */
370
+ public static getGlobalInstance(): ContextReference {
371
+ if (!ContextReference._globalInstance) {
372
+ throw new Error("ContextReference global instance not set. Use setGlobalInstance().");
373
+ }
374
+ return ContextReference._globalInstance;
375
+ }
376
+ }
@@ -0,0 +1,272 @@
1
+ import { ContextReference } from "../context/contextReference";
2
+ import { Employee } from "../employee/employee";
3
+ import { Histories } from "../histories/histories";
4
+ import { Holiday } from "../foundation/holiday";
5
+ import { HourBankAccount } from "../hourBank/hourBankAccount";
6
+ import { Schedules } from "../schedules/schedules";
7
+ import { TimeEvaluation } from "../timeEvaluation/timeEvaluation";
8
+
9
+ /**
10
+ * Interface para os parâmetros do construtor de Contract.
11
+ * @hidden
12
+ */
13
+ export interface ContractParams {
14
+ id: string;
15
+ holidaysKeys: string[];
16
+ timeEvaluation: TimeEvaluation[];
17
+ employee: Employee;
18
+ histories: Histories;
19
+ schedules: Schedules;
20
+ hourBankAccounts: HourBankAccount[];
21
+ }
22
+
23
+ /**
24
+ * O contrato é a unidade de trabalho do colaborador, onde são armazenadas as informações de apuração, colaborador, históricos, programações, banco de horas e feriados.
25
+ *
26
+ * O contrato é composto por:
27
+ * - Apurações de cada dia, deve ser feito uma iteração para cada dia do contrato, onde são apuradas as situações do colaborador.
28
+ * - Colaborador, informações do colaborador.
29
+ * - Contas nos bancos de horas: código do banco de horas, data de criação e, se existir, data de extinção.
30
+ * - Históricos: históricos do colaborador, como sindicato, afastamento, escala, etc.
31
+ * - Programações: programações do colaborador, como escala, horário de trabalho, etc.
32
+ * - Feriados: feriados dos dias apurados.
33
+ *
34
+ * @example
35
+ * ```javascript
36
+ * context.contracts.forEach(contract => {
37
+ * context.logInfo(`Colaborador: ${contract.employee.person.name}`);
38
+ * });
39
+ * ```
40
+ */
41
+
42
+ export class Contract {
43
+ private readonly _id: string;
44
+ private readonly _holidaysKeys: string[];
45
+ private readonly _timeEvaluation: TimeEvaluation[];
46
+ private readonly _employee: Employee;
47
+ private readonly _histories: Histories;
48
+ private readonly _schedules: Schedules;
49
+ private readonly _hourBankAccounts: HourBankAccount[];
50
+
51
+ /**
52
+ * @hidden
53
+ */
54
+ constructor(params: ContractParams) {
55
+
56
+ this._id = params.id;
57
+
58
+ if (params.employee) {
59
+ this._employee = Employee.clone(params.employee);
60
+ }
61
+
62
+ this._histories = new Histories({
63
+ jobPositionHistories: params.histories.jobPositionHistories,
64
+ companyBranchHistories: params.histories.companyBranchHistories,
65
+ employmentRelationshipHistories: params.histories.employmentRelationshipHistories,
66
+ timeEvaluationHistories: params.histories.timeEvaluationHistories,
67
+ workshiftHistories: params.histories.workshiftHistories,
68
+ costCenterHistories: params.histories.costCenterHistories,
69
+ leaveHistories: params.histories.leaveHistories,
70
+ });
71
+
72
+
73
+ if (params.schedules) {
74
+ this._schedules = Schedules.clone(params.schedules);
75
+
76
+ } else {
77
+ this._schedules = Schedules.default();
78
+ }
79
+
80
+ this._hourBankAccounts = [];
81
+ if (params.hourBankAccounts && Array.isArray(params.hourBankAccounts)) {
82
+ for (const account of params.hourBankAccounts) {
83
+ const newAccount = new HourBankAccount({
84
+ hourBank: account.hourBank,
85
+ creationDate: account.creationDate,
86
+ extinctionDate: account.extinctionDate,
87
+ });
88
+ this._hourBankAccounts.push(newAccount);
89
+ }
90
+ }
91
+
92
+ if (params.holidaysKeys && Array.isArray(params.holidaysKeys)) {
93
+ this._holidaysKeys = params.holidaysKeys;
94
+ } else {
95
+ this._holidaysKeys = [];
96
+ }
97
+
98
+
99
+
100
+ this._timeEvaluation = [];
101
+ for (const timeEvaluationItem of params.timeEvaluation) {
102
+ const timeEvaluation = TimeEvaluation.clone(timeEvaluationItem, this);
103
+ this._timeEvaluation.push(timeEvaluation);
104
+ }
105
+
106
+
107
+ }
108
+
109
+ /**
110
+ * @hidden
111
+ * Id do contrato.
112
+ * @return Id do contrato.
113
+ */
114
+ get id(): string {
115
+ return this._id;
116
+ }
117
+
118
+ /**
119
+ * Colaborador do contrato de apuração, dentro do colaborador pode ser encontrado:
120
+ * - Informações pessoais do colaborador, como nome.
121
+ * - Informação da empresa do colaborador.
122
+ * - Informações sobre históricos atuais como: centro de custo, filial, cargo, vínculo empregatício, etc.
123
+ *
124
+ * @example
125
+ * ```javascript
126
+ * let contract = context.contracts[0];
127
+ * console.log(`Colaborador: ${contract.employee.person.name}`);
128
+ * ```
129
+ *
130
+ * @return Colaborador do contrato.
131
+ * @see {@link Employee}
132
+ */
133
+ get employee(): Employee {
134
+ return this._employee;
135
+ }
136
+
137
+ /**
138
+ * Lista das apurações do contrato do colaborador, somente os dias apurados serão listados.
139
+ * Cada apuração representa um dia de trabalho do colaborador, onde são apuradas as situações do colaborador, como faltas, atrasos, horas extras, etc.
140
+ *
141
+ * @example
142
+ * ```javascript
143
+ * let contract = context.contracts[0];
144
+ * for (const timeEvaluation of contract.timeEvaluation) {
145
+ * console.log(`Data: ${timeEvaluation.date}`);
146
+ * }
147
+ * ```
148
+ * @return Lista de apurações do contrato do colaborador.
149
+ * @see {@link TimeEvaluation}
150
+ */
151
+ get timeEvaluation(): TimeEvaluation[] {
152
+ return this._timeEvaluation;
153
+ }
154
+
155
+ /**
156
+ * @hidden
157
+ * Chaves dos feriados do contrato.
158
+ */
159
+ get holidaysKeys(): string[] {
160
+ return this._holidaysKeys;
161
+ }
162
+
163
+ /**
164
+ * Busca os feriados do contrato do colaborador no período apurado.
165
+ * Caso não encontre feriados, retorna undefined.
166
+ * Atenção: o sistema carrega os feriados do contrato do colaborador no período apurado mais 3 dias antes e 3 dias depois.
167
+ *
168
+ * @example
169
+ * ```javascript
170
+ * let contract = context.contracts[0];
171
+ * // Parâmetro date deve ser uma data no período de apuração do contrato.
172
+ * let holiday = contract.getHolidayByDate(new Date("2023-01-01"));
173
+ * if (holiday) {
174
+ * console.log(`Feriado encontrado na data: ${DateUtils.format(holiday.date)}`);
175
+ * } else {
176
+ * console.log("Feriado não encontrado nesta data.");
177
+ * }
178
+ * ```
179
+ *
180
+ * @param date Data do feriado.
181
+ * @return Feriado ou undefined.
182
+ * @see {@link Holiday}
183
+ */
184
+ public getHolidayByDate(date: Date): Holiday | undefined {
185
+
186
+ for (const key of this._holidaysKeys) {
187
+ const holiday = ContextReference.getGlobalInstance().getHolidayByKey(key);
188
+ if (holiday && holiday.date.getTime() === date.getTime()) {
189
+ return holiday;
190
+ }
191
+ }
192
+
193
+ return undefined;
194
+ }
195
+
196
+
197
+ /**
198
+ * Retorna informações sobre os históricos do colaborador no período da apuração.
199
+ * Os históricos podem incluir informações como: centro de custo, filial, cargo, vínculo empregatício, etc.
200
+ *
201
+ * @example
202
+ * ```javascript
203
+ * let contract = context.contracts[0];
204
+ * context.logInfo(`Existem ${contract.histories.jobPositionHistories.length} históricos de cargo no período.`);}`);
205
+ * ```
206
+ */
207
+ get histories(): Histories {
208
+ return this._histories;
209
+ }
210
+
211
+ /**
212
+ * Programações do colaborador no período da apuração.
213
+ * As programações podem incluir informações como: pontes, troca de escala, troca de horário, etc.
214
+ *
215
+ * @example
216
+ * ```javascript
217
+ * let contract = context.contracts[0];
218
+ * context.logInfo(`Existem ${contract.schedules.bridges.length} pontes no período.`);}`);
219
+ * ```
220
+ * @return Programações do colaborador no período da apuração.
221
+ * @see {@link Schedules}
222
+ */
223
+ get schedules(): Schedules {
224
+ return this._schedules;
225
+ }
226
+
227
+ /**
228
+ * Conta de banco de horas do colaborador no período da apuração.
229
+ *
230
+ * @example
231
+ * ```javascript
232
+ * let contract = context.contracts[0];
233
+ * for (const account of contract.hourBankAccounts) {
234
+ * context.logInfo(`Conta de banco de horas criada na data ${DateUtils.format(account.creationDate)}`);
235
+ * context.logInfo(`Banco de horas: ${account.hourBank.code}`);
236
+ * }
237
+ * ```
238
+ * @return Contas dos bancos de horas do colaborador no período da apuração.
239
+ * @see {@link HourBankAccount}
240
+ */
241
+ get hourBankAccounts(): HourBankAccount[] {
242
+ return this._hourBankAccounts;
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Enumeração para os tipos de contrato de trabalho.
248
+ * @enum
249
+ */
250
+ export enum ContractType {
251
+ /**
252
+ * Contrato de trabalho de um empregado.
253
+ */
254
+ EMPLOYEE = "EMPLOYEE",
255
+ /**
256
+ * Contrato de trabalho de um diretor.
257
+ */
258
+ DIRECTOR = "DIRECTOR",
259
+ /**
260
+ * Contrato de trabalho de um estagiário.
261
+ */
262
+ TRAINEE = "TRAINEE",
263
+ /**
264
+ * Contrato de trabalho de um aprendiz.
265
+ */
266
+ APRENTICE = "APPRENTICE",
267
+ /**
268
+ * Contrato de trabalho de um terceiro.
269
+ */
270
+ THIRD_PARTY = "THIRD_PARTY",
271
+ }
272
+