teodoro 0.3.1 → 0.7.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.
- checksums.yaml +4 -4
- data/lib/teodoro.rb +1 -0
- data/lib/teodoro/arquivo_de_evento.rb +0 -4
- data/lib/teodoro/arquivo_de_evento_criador_de_arquivo_data.rb +32 -1
- data/lib/teodoro/arquivo_de_evento_nao_periodico.rb +10 -3
- data/lib/teodoro/arquivo_de_evento_processador_de_arquivo_data.rb +2 -2
- data/lib/teodoro/arquivo_de_evento_retificavel.rb +8 -8
- data/lib/teodoro/arquivo_xml.rb +39 -17
- data/lib/teodoro/empresa.rb +193 -153
- data/lib/teodoro/leiaute/arquivo_s1000.rb +20 -40
- data/lib/teodoro/leiaute/arquivo_s1005.rb +6 -20
- data/lib/teodoro/leiaute/arquivo_s1010.rb +2 -2
- data/lib/teodoro/leiaute/arquivo_s1020.rb +7 -22
- data/lib/teodoro/leiaute/arquivo_s1030.rb +7 -16
- data/lib/teodoro/leiaute/arquivo_s1040.rb +2 -2
- data/lib/teodoro/leiaute/arquivo_s1050.rb +5 -8
- data/lib/teodoro/leiaute/arquivo_s1070.rb +3 -3
- data/lib/teodoro/leiaute/arquivo_s2190.rb +3 -5
- data/lib/teodoro/leiaute/arquivo_s2200.rb +58 -261
- data/lib/teodoro/leiaute/arquivo_s2205.rb +21 -48
- data/lib/teodoro/leiaute/arquivo_s2206.rb +20 -108
- data/lib/teodoro/leiaute/arquivo_s2230.rb +96 -90
- data/lib/teodoro/leiaute/arquivo_s2250.rb +8 -17
- data/lib/teodoro/leiaute/arquivo_s2299.rb +3 -112
- data/lib/teodoro/leiaute/arquivo_s2300.rb +46 -175
- data/lib/teodoro/leiaute/arquivo_s2306.rb +8 -12
- data/lib/teodoro/leiaute/arquivo_s2399.rb +1 -147
- data/lib/teodoro/leiaute/arquivo_s3000.rb +28 -4
- data/lib/teodoro/xml.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 948116a90b820e721da13b71f2abee576b7154819653eecf1ef63452b9375c9b
|
4
|
+
data.tar.gz: c23144f5cae471db91509309da02f1b611218082ba3af45bfc31b7d6b2ae74d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf4ed05a27bc7ecde19dbd6a98115d464d736d3a2da197a37240e42946bd3df40ed4e55d0a96cdbde81321558f3659656aeea1b99114ef66daf360abd0430460
|
7
|
+
data.tar.gz: f6a047db79b4da62c8b6783765e4e398fe15ae07ed99dfd55a9eefcd48b0f783bdd782d333af98fc94f1784448f2fa0f3c13fb4955f95ef8fbe3ba409cbbeb85
|
data/lib/teodoro.rb
CHANGED
@@ -11,11 +11,42 @@ module Teodoro
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def conteudo_do_arquivo_data
|
14
|
-
(itens_do_conteudo_do_arquivo_data.map { "#{_1}=#{_2}" } + ['']).join("\n")
|
14
|
+
(itens_do_conteudo_do_arquivo_data.map { "#{_1}=#{Valor.new(_2)}" } + ['']).join("\r\n")
|
15
15
|
end
|
16
16
|
|
17
17
|
def tipo_de_inscricao_do_empregador
|
18
18
|
@tipo_de_inscricao_do_empregador ||= evento["#{noh_principal_do_evento}/ideEmpregador/tpInsc"]
|
19
19
|
end
|
20
|
+
|
21
|
+
class Valor
|
22
|
+
FORMATADORES = {
|
23
|
+
bool: proc { _1 ? 'True' : 'False' },
|
24
|
+
data: proc { "#{_1[-2..]}/#{_1[5..6]}/#{_1[0..3]}" if _1 },
|
25
|
+
data_aaaammdd: proc { _1.delete('-') if _1 },
|
26
|
+
mes_ano: proc { "#{_1[-2..]}/#{_1[0..3]}" if _1 }
|
27
|
+
}.freeze
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def initialize(arg)
|
32
|
+
@arg = arg
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :arg
|
36
|
+
|
37
|
+
public
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
@to_s ||= (tipo ? FORMATADORES[tipo].call(valor) : valor).to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def tipo
|
44
|
+
@tipo ||= arg[1] if arg.is_a?(Array)
|
45
|
+
end
|
46
|
+
|
47
|
+
def valor
|
48
|
+
@valor ||= arg.is_a?(Array) ? arg[0] : arg
|
49
|
+
end
|
50
|
+
end
|
20
51
|
end
|
21
52
|
end
|
@@ -4,9 +4,12 @@ module Teodoro
|
|
4
4
|
include ArquivoDeEventoRetificavel
|
5
5
|
|
6
6
|
def processar
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
if retificado?
|
8
|
+
processar_retificacao
|
9
|
+
else
|
10
|
+
registrar_arquivo_data
|
11
|
+
criar_arquivo_data
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
private
|
@@ -18,6 +21,10 @@ module Teodoro
|
|
18
21
|
)
|
19
22
|
end
|
20
23
|
|
24
|
+
def arquivos_data
|
25
|
+
empresa.arquivos_data
|
26
|
+
end
|
27
|
+
|
21
28
|
def caminho_do_arquivo_data
|
22
29
|
criar_caminho_do_arquivo_data(nome_do_arquivo_data)
|
23
30
|
end
|
@@ -4,20 +4,20 @@ module Teodoro
|
|
4
4
|
|
5
5
|
private
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def retificado?
|
8
|
+
arquivo_xml_de_retificacao
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def arquivo_xml_de_retificacao
|
12
|
+
@arquivo_xml_de_retificacao ||= arquivos_xml_por_recibo_a_retificar[numero_do_recibo]
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
empresa.
|
15
|
+
def arquivos_xml_por_recibo_a_retificar
|
16
|
+
empresa.arquivos_xml_por_recibo_a_retificar
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def processar_retificacao
|
20
|
+
arquivo_xml_de_retificacao.processar
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/teodoro/arquivo_xml.rb
CHANGED
@@ -9,7 +9,7 @@ require_relative 'leiaute'
|
|
9
9
|
require_relative 'xml'
|
10
10
|
|
11
11
|
module Teodoro
|
12
|
-
class ArquivoXML
|
12
|
+
class ArquivoXML # rubocop:disable Metrics/ClassLength
|
13
13
|
TIPOS_DE_EVENTO_PROCESSAVEIS = %w[
|
14
14
|
S1000
|
15
15
|
S1005
|
@@ -32,6 +32,18 @@ module Teodoro
|
|
32
32
|
S3000
|
33
33
|
].freeze
|
34
34
|
|
35
|
+
TIPOS_DE_EVENTO_RETIFICAVEIS = %w[
|
36
|
+
S2200
|
37
|
+
S2205
|
38
|
+
S2206
|
39
|
+
S2230
|
40
|
+
S2250
|
41
|
+
S2299
|
42
|
+
S2300
|
43
|
+
S2306
|
44
|
+
S2399
|
45
|
+
].freeze
|
46
|
+
|
35
47
|
private
|
36
48
|
|
37
49
|
def initialize(empresa:, caminho:)
|
@@ -43,16 +55,29 @@ module Teodoro
|
|
43
55
|
|
44
56
|
public
|
45
57
|
|
46
|
-
|
47
|
-
|
58
|
+
attr_reader :numero_do_recibo_a_retificar, :momento_de_processamento_pelo_e_social
|
59
|
+
|
60
|
+
# otimizacao do gerenciamento de memoria
|
61
|
+
def carregar
|
62
|
+
Console.print "carregando #{nome}.xml..."
|
63
|
+
|
64
|
+
evento, recibo =
|
65
|
+
carregar_xml
|
66
|
+
.then do |xml|
|
67
|
+
%w[evento recibo].map { XML.new(Nokogiri::XML(xml.css("eSocial/retornoProcessamentoDownload/#{_1}/*").to_s)) }
|
68
|
+
end
|
69
|
+
|
70
|
+
@retificacao = TIPOS_DE_EVENTO_RETIFICAVEIS.include?(tipo_de_evento) && evento['*/ideEvento/indRetif'] == '2'
|
71
|
+
@numero_do_recibo_a_retificar = evento['*/ideEvento/nrRecibo'] if retificacao?
|
72
|
+
@momento_de_processamento_pelo_e_social = recibo['retornoEvento/processamento/dhProcessamento']
|
48
73
|
end
|
49
74
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
75
|
+
def retificacao?
|
76
|
+
@retificacao
|
77
|
+
end
|
78
|
+
|
79
|
+
def processavel?
|
80
|
+
TIPOS_DE_EVENTO_PROCESSAVEIS.include?(tipo_de_evento)
|
56
81
|
end
|
57
82
|
|
58
83
|
def nome
|
@@ -60,17 +85,14 @@ module Teodoro
|
|
60
85
|
end
|
61
86
|
|
62
87
|
def processar
|
63
|
-
|
88
|
+
Console.print "processando #{nome}.xml..."
|
89
|
+
|
64
90
|
validar_versao_do_leiaute
|
65
91
|
processar_arquivo
|
66
92
|
end
|
67
93
|
|
68
94
|
private
|
69
95
|
|
70
|
-
def tipo_de_evento
|
71
|
-
@tipo_de_evento ||= nome[-6..].delete('-')
|
72
|
-
end
|
73
|
-
|
74
96
|
def carregar_xml
|
75
97
|
Nokogiri::XML(carregar_conteudo)
|
76
98
|
end
|
@@ -79,8 +101,8 @@ module Teodoro
|
|
79
101
|
File.read(caminho)
|
80
102
|
end
|
81
103
|
|
82
|
-
def
|
83
|
-
|
104
|
+
def tipo_de_evento
|
105
|
+
@tipo_de_evento ||= nome[-6..].delete('-')
|
84
106
|
end
|
85
107
|
|
86
108
|
def validar_versao_do_leiaute
|
@@ -110,7 +132,7 @@ module Teodoro
|
|
110
132
|
def arquivo
|
111
133
|
classe_do_arquivo.new(
|
112
134
|
empresa: empresa,
|
113
|
-
arquivo_xml: Obj.new(
|
135
|
+
arquivo_xml: Obj.new(evento: evento, recibo: recibo)
|
114
136
|
)
|
115
137
|
end
|
116
138
|
|
data/lib/teodoro/empresa.rb
CHANGED
@@ -5,229 +5,269 @@ module Teodoro
|
|
5
5
|
class Empresa
|
6
6
|
private
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
10
|
-
@destino = File.join(destino, nome_do_diretorio)
|
8
|
+
def initialize(args)
|
9
|
+
@impl = Impl.new(**args)
|
11
10
|
end
|
12
11
|
|
13
|
-
attr_reader :
|
12
|
+
attr_reader :impl
|
14
13
|
|
15
14
|
public
|
16
15
|
|
17
16
|
def processar
|
18
|
-
|
19
|
-
criar_diretorio_destino
|
20
|
-
criar_diretorio_dos_arquivos_xml
|
21
|
-
descompactar_arquivos_de_origem
|
22
|
-
criar_diretorio_dos_arquivos_data
|
23
|
-
ordenar_arquivos_xml
|
24
|
-
processar_arquivos_xml
|
25
|
-
limpar_linha_de_feedback
|
17
|
+
impl.processar
|
26
18
|
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
def dar_feedback_para_o_usuario
|
31
|
-
puts Rainbow(nome_do_diretorio).green
|
32
|
-
end
|
33
|
-
|
34
|
-
def nome_do_diretorio
|
35
|
-
@nome_do_diretorio ||= File.basename(caminho)
|
36
|
-
end
|
37
|
-
|
38
|
-
def criar_diretorio_destino
|
39
|
-
Dir.mkdir(destino)
|
40
|
-
end
|
41
|
-
|
42
|
-
def criar_diretorio_dos_arquivos_xml
|
43
|
-
Dir.mkdir(destino_dos_arquivos_xml)
|
44
|
-
end
|
45
|
-
|
46
|
-
def destino_dos_arquivos_xml
|
47
|
-
@destino_dos_arquivos_xml ||= File.join(destino, 'xmls')
|
48
|
-
end
|
49
|
-
|
50
|
-
def descompactar_arquivos_de_origem
|
51
|
-
arquivos_de_origem.each(&:descompactar)
|
52
|
-
end
|
20
|
+
class Impl
|
21
|
+
private
|
53
22
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
23
|
+
def initialize(caminho:, destino:)
|
24
|
+
@caminho = caminho
|
25
|
+
@destino = File.join(destino, nome_do_diretorio)
|
26
|
+
end
|
58
27
|
|
59
|
-
|
60
|
-
Dir.mkdir(destino_dos_arquivos_data)
|
61
|
-
end
|
28
|
+
attr_reader :caminho, :destino
|
62
29
|
|
63
|
-
|
64
|
-
@destino_dos_arquivos_data ||= File.join(destino, 'data')
|
65
|
-
end
|
30
|
+
public
|
66
31
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
32
|
+
attr_reader :arquivos_xml_por_recibo_a_retificar
|
33
|
+
|
34
|
+
def processar
|
35
|
+
dar_feedback_para_o_usuario
|
36
|
+
criar_diretorio_destino
|
37
|
+
criar_diretorio_dos_arquivos_xml
|
38
|
+
descompactar_arquivos_de_origem
|
39
|
+
criar_diretorio_dos_arquivos_data
|
40
|
+
carregar_arquivos_xml
|
41
|
+
classificar_arquivos_xml
|
42
|
+
ordenar_arquivos_xml
|
43
|
+
processar_arquivos_xml
|
44
|
+
limpar_linha_de_feedback
|
45
|
+
end
|
71
46
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
47
|
+
def destino_dos_arquivos_data
|
48
|
+
@destino_dos_arquivos_data ||= File.join(destino, 'data')
|
49
|
+
end
|
76
50
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
.select(&:processavel?)
|
81
|
-
end
|
51
|
+
def arquivos_data
|
52
|
+
@arquivos_data ||= ArquivosData.new(destino_dos_arquivos_data)
|
53
|
+
end
|
82
54
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
arquivos_data: ArquivosData.new(destino_dos_arquivos_data),
|
87
|
-
contratos_de_emprego: ContratosDeEmprego.new,
|
88
|
-
contratos_de_trabalho_sem_vinculo: ContratosDeTrabalhoSemVinculo.new
|
89
|
-
)
|
90
|
-
end
|
55
|
+
def contratos_de_emprego
|
56
|
+
@contratos_de_emprego ||= ContratosDeEmprego.new
|
57
|
+
end
|
91
58
|
|
92
|
-
|
93
|
-
|
94
|
-
|
59
|
+
def contratos_de_trabalho_sem_vinculo
|
60
|
+
@contratos_de_trabalho_sem_vinculo ||= ContratosDeTrabalhoSemVinculo.new
|
61
|
+
end
|
95
62
|
|
96
|
-
class ArquivosData
|
97
63
|
private
|
98
64
|
|
99
|
-
def
|
100
|
-
|
65
|
+
def dar_feedback_para_o_usuario
|
66
|
+
puts Rainbow(nome_do_diretorio).green
|
101
67
|
end
|
102
68
|
|
103
|
-
|
69
|
+
def nome_do_diretorio
|
70
|
+
@nome_do_diretorio ||= File.basename(caminho)
|
71
|
+
end
|
104
72
|
|
105
|
-
|
73
|
+
def criar_diretorio_destino
|
74
|
+
Dir.mkdir(destino)
|
75
|
+
end
|
106
76
|
|
107
|
-
def
|
108
|
-
(
|
77
|
+
def criar_diretorio_dos_arquivos_xml
|
78
|
+
Dir.mkdir(destino_dos_arquivos_xml)
|
109
79
|
end
|
110
80
|
|
111
|
-
def
|
112
|
-
|
113
|
-
.map { |nome| File.join(destino_dos_arquivos_data, "#{nome}.data") }
|
114
|
-
.each { File.delete(_1) }
|
81
|
+
def destino_dos_arquivos_xml
|
82
|
+
@destino_dos_arquivos_xml ||= File.join(destino, 'xmls')
|
115
83
|
end
|
116
84
|
|
117
|
-
|
85
|
+
def descompactar_arquivos_de_origem
|
86
|
+
arquivos_de_origem.each(&:descompactar)
|
87
|
+
end
|
118
88
|
|
119
|
-
def
|
120
|
-
|
89
|
+
def arquivos_de_origem
|
90
|
+
Dir[File.join(caminho, '*.zip')]
|
91
|
+
.map { |caminho| ArquivoDeOrigem.new(caminho: caminho, destino_dos_arquivos_xml: destino_dos_arquivos_xml) }
|
121
92
|
end
|
122
|
-
end
|
123
93
|
|
124
|
-
|
125
|
-
|
126
|
-
Contrato.new(**admissao).then do
|
127
|
-
contratos_por_matricula[_1.matricula] = _1
|
128
|
-
end
|
94
|
+
def criar_diretorio_dos_arquivos_data
|
95
|
+
Dir.mkdir(destino_dos_arquivos_data)
|
129
96
|
end
|
130
97
|
|
131
|
-
def
|
132
|
-
|
98
|
+
def carregar_arquivos_xml
|
99
|
+
arquivos_xml.each(&:carregar)
|
133
100
|
end
|
134
101
|
|
135
|
-
def
|
136
|
-
|
137
|
-
.
|
138
|
-
.
|
102
|
+
def arquivos_xml
|
103
|
+
@arquivos_xml ||=
|
104
|
+
Dir[File.join(destino_dos_arquivos_xml, '*.xml')]
|
105
|
+
.map { |caminho| ArquivoXML.new(empresa: self, caminho: caminho) }
|
139
106
|
end
|
140
107
|
|
141
|
-
def
|
142
|
-
|
108
|
+
def classificar_arquivos_xml
|
109
|
+
Console.print 'classificando os arquivos XML...'
|
110
|
+
|
111
|
+
arquivos_xml
|
112
|
+
.select(&:processavel?)
|
113
|
+
.partition(&:retificacao?)
|
114
|
+
.then do |de_retificacao, exceto_de_retificacao|
|
115
|
+
@arquivos_xml_por_recibo_a_retificar = de_retificacao.map { [_1.numero_do_recibo_a_retificar, _1] }.to_h
|
116
|
+
@arquivos_xml = exceto_de_retificacao
|
117
|
+
end
|
143
118
|
end
|
144
119
|
|
145
|
-
|
120
|
+
def ordenar_arquivos_xml
|
121
|
+
Console.print 'ordenando os arquivos XML...'
|
122
|
+
arquivos_xml.sort_by! { [_1.momento_de_processamento_pelo_e_social, _1.nome] }
|
123
|
+
end
|
146
124
|
|
147
|
-
def
|
148
|
-
|
125
|
+
def processar_arquivos_xml
|
126
|
+
# otimizacao do gerenciamento de memoria
|
127
|
+
arquivos_xml.shift.processar while arquivos_xml.any?
|
149
128
|
end
|
150
129
|
|
151
|
-
def
|
152
|
-
|
130
|
+
def limpar_linha_de_feedback
|
131
|
+
Console.print
|
153
132
|
end
|
154
133
|
|
155
|
-
class
|
134
|
+
class ArquivosData
|
156
135
|
private
|
157
136
|
|
158
|
-
def initialize(
|
159
|
-
@
|
160
|
-
@data_de_admissao = data_de_admissao
|
161
|
-
@categoria_do_trabalhador = categoria_do_trabalhador
|
162
|
-
@cpf_do_trabalhador = cpf_do_trabalhador
|
163
|
-
@recibo = recibo
|
137
|
+
def initialize(destino_dos_arquivos_data)
|
138
|
+
@destino_dos_arquivos_data = destino_dos_arquivos_data
|
164
139
|
end
|
165
140
|
|
166
|
-
attr_reader :
|
141
|
+
attr_reader :destino_dos_arquivos_data
|
167
142
|
|
168
143
|
public
|
169
144
|
|
170
|
-
|
145
|
+
def registrar(recibo:, nome:)
|
146
|
+
(nomes_por_recibo[recibo] ||= []) << nome
|
147
|
+
end
|
171
148
|
|
172
|
-
|
149
|
+
def excluir(recibo)
|
150
|
+
(nomes_por_recibo.delete(recibo) || [])
|
151
|
+
.map { |nome| File.join(destino_dos_arquivos_data, "#{nome}.data") }
|
152
|
+
.each { File.delete(_1) }
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
173
156
|
|
174
|
-
def
|
175
|
-
|
157
|
+
def nomes_por_recibo
|
158
|
+
@nomes_por_recibo ||= {}
|
176
159
|
end
|
177
160
|
end
|
178
|
-
end
|
179
161
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
162
|
+
class ContratosDeEmprego
|
163
|
+
def registrar_admissao(admissao:, afastamento:)
|
164
|
+
contratos_por_matricula[admissao.matricula] = Contrato.new(admissao: admissao, afastamento: afastamento)
|
165
|
+
end
|
184
166
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
_1.cpf_do_trabalhador == cpf_do_trabalhador &&
|
189
|
-
_1.categoria_do_trabalhador == categoria_do_trabalhador &&
|
190
|
-
_1.ativo?(data)
|
191
|
-
}
|
192
|
-
.max_by(&:data_de_inicio)
|
193
|
-
end
|
167
|
+
def [](matricula)
|
168
|
+
contratos_por_matricula[matricula]
|
169
|
+
end
|
194
170
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
171
|
+
def *(cpf_do_trabalhador:, data:)
|
172
|
+
contratos
|
173
|
+
.select { _1.cpf_do_trabalhador == cpf_do_trabalhador && _1.ativo?(data) }
|
174
|
+
.sort_by(&:data_de_admissao)
|
175
|
+
end
|
200
176
|
|
201
|
-
|
202
|
-
|
203
|
-
|
177
|
+
def remover(recibo)
|
178
|
+
contratos_por_matricula.delete_if { _2.recibo == recibo }
|
179
|
+
end
|
204
180
|
|
205
|
-
|
181
|
+
private
|
182
|
+
|
183
|
+
def contratos_por_matricula
|
184
|
+
@contratos_por_matricula ||= {}
|
185
|
+
end
|
186
|
+
|
187
|
+
def contratos
|
188
|
+
contratos_por_matricula.values
|
189
|
+
end
|
190
|
+
|
191
|
+
class Contrato
|
192
|
+
private
|
193
|
+
|
194
|
+
def initialize(admissao:, afastamento:)
|
195
|
+
@admissao = admissao
|
196
|
+
@afastamento = afastamento
|
197
|
+
end
|
206
198
|
|
207
|
-
|
208
|
-
|
199
|
+
attr_reader :admissao, :data_de_desligamento
|
200
|
+
|
201
|
+
public
|
202
|
+
|
203
|
+
extend Forwardable
|
204
|
+
|
205
|
+
def_delegators :admissao, :matricula, :data_de_admissao, :categoria_do_trabalhador, :cpf_do_trabalhador,
|
206
|
+
:recibo
|
207
|
+
|
208
|
+
attr_accessor :afastamento
|
209
|
+
|
210
|
+
attr_writer :data_de_desligamento
|
211
|
+
|
212
|
+
def ativo?(data)
|
213
|
+
data_de_admissao <= data && (!data_de_desligamento || data_de_desligamento >= data)
|
214
|
+
end
|
215
|
+
end
|
209
216
|
end
|
210
217
|
|
211
|
-
class
|
218
|
+
class ContratosDeTrabalhoSemVinculo
|
219
|
+
def registrar_inicio_de_contrato(inicio_de_contrato:, afastamento:)
|
220
|
+
contratos << Contrato.new(inicio_de_contrato: inicio_de_contrato, afastamento: afastamento)
|
221
|
+
end
|
222
|
+
|
223
|
+
def [](cpf_do_trabalhador:, categoria_do_trabalhador:, data:)
|
224
|
+
contratos
|
225
|
+
.select {
|
226
|
+
_1.cpf_do_trabalhador == cpf_do_trabalhador && _1.categoria_do_trabalhador == categoria_do_trabalhador &&
|
227
|
+
_1.ativo?(data)
|
228
|
+
}
|
229
|
+
.max_by(&:data_de_inicio)
|
230
|
+
end
|
231
|
+
|
232
|
+
def *(cpf_do_trabalhador:, data:)
|
233
|
+
contratos
|
234
|
+
.select { _1.cpf_do_trabalhador == cpf_do_trabalhador && _1.ativo?(data) }
|
235
|
+
.sort_by(&:data_de_inicio)
|
236
|
+
end
|
237
|
+
|
238
|
+
def remover(recibo)
|
239
|
+
contratos.delete_if { _1.recibo == recibo }
|
240
|
+
end
|
241
|
+
|
212
242
|
private
|
213
243
|
|
214
|
-
def
|
215
|
-
@
|
216
|
-
@categoria_do_trabalhador = categoria_do_trabalhador
|
217
|
-
@data_de_inicio = data_de_inicio
|
218
|
-
@recibo = recibo
|
244
|
+
def contratos
|
245
|
+
@contratos ||= []
|
219
246
|
end
|
220
247
|
|
221
|
-
|
248
|
+
class Contrato
|
249
|
+
private
|
222
250
|
|
223
|
-
|
251
|
+
def initialize(inicio_de_contrato:, afastamento:)
|
252
|
+
@inicio_de_contrato = inicio_de_contrato
|
253
|
+
@afastamento = afastamento
|
254
|
+
end
|
255
|
+
|
256
|
+
attr_reader :inicio_de_contrato, :data_do_termino
|
257
|
+
|
258
|
+
public
|
259
|
+
|
260
|
+
extend Forwardable
|
261
|
+
|
262
|
+
def_delegators :inicio_de_contrato, :cpf_do_trabalhador, :categoria_do_trabalhador, :data_de_inicio, :recibo
|
224
263
|
|
225
|
-
|
264
|
+
attr_accessor :afastamento
|
226
265
|
|
227
|
-
|
266
|
+
attr_writer :data_do_termino
|
228
267
|
|
229
|
-
|
230
|
-
|
268
|
+
def ativo?(data)
|
269
|
+
data_de_inicio <= data && (!data_do_termino || data_do_termino >= data)
|
270
|
+
end
|
231
271
|
end
|
232
272
|
end
|
233
273
|
end
|