teodoro 0.0.11 → 0.2.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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/teodoro.rb +10 -5
  3. data/lib/teodoro/arquivo_de_evento.rb +15 -15
  4. data/lib/teodoro/{arquivo_de_evento_exceto_de_exclusao.rb → arquivo_de_evento_criador_de_arquivo_data.rb} +2 -6
  5. data/lib/teodoro/arquivo_de_evento_de_tabela.rb +2 -2
  6. data/lib/teodoro/arquivo_de_evento_nao_periodico.rb +9 -33
  7. data/lib/teodoro/arquivo_de_evento_processador_de_arquivo_data.rb +30 -0
  8. data/lib/teodoro/arquivo_de_evento_retificavel.rb +23 -0
  9. data/lib/teodoro/arquivo_xml.rb +34 -22
  10. data/lib/teodoro/empresa.rb +77 -9
  11. data/lib/teodoro/leiaute.rb +24 -0
  12. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1000.rb +7 -9
  13. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1005.rb +4 -4
  14. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1010.rb +2 -4
  15. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1020.rb +4 -4
  16. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1030.rb +4 -4
  17. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1040.rb +2 -4
  18. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1050.rb +4 -4
  19. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s1070.rb +2 -4
  20. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2190.rb +2 -2
  21. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2200.rb +121 -22
  22. data/lib/teodoro/leiaute/arquivo_s2205.rb +264 -0
  23. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2206.rb +18 -7
  24. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2230.rb +56 -12
  25. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2250.rb +24 -8
  26. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2299.rb +23 -20
  27. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2300.rb +17 -9
  28. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2306.rb +27 -7
  29. data/lib/teodoro/{leiaute_2 → leiaute}/arquivo_s2399.rb +11 -8
  30. data/lib/teodoro/leiaute/arquivo_s3000.rb +33 -0
  31. metadata +25 -23
  32. data/lib/teodoro/leiaute_2.rb +0 -24
  33. data/lib/teodoro/leiaute_2/arquivo_s2205.rb +0 -157
  34. data/lib/teodoro/leiaute_2/arquivo_s3000.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c9deae607c9ff37a06e53ec8cb179d250a85ed8fda4e2480892cc4169453e43
4
- data.tar.gz: d9f73ef82b8803e52fb33b57e4b25549d84c004e2cae59c4261e6f9694f5de6c
3
+ metadata.gz: 015d00fb8014af60f05b8df90e8e920964c854a1e6dfb24261bfec4c6f51a8f5
4
+ data.tar.gz: 3c263b720d55ed5aaa24d3f6daf5540db9780743d70660611eaf543b6a1a5e06
5
5
  SHA512:
6
- metadata.gz: 11b1fac346b51fae9b6cc45f11881acb1e2c9c594afdabd6a943de5fe201f76f464c20bf084fb910e164d3886d2a22a02b1b0a34f28f43c98b0edab5f8591521
7
- data.tar.gz: 17b9915e3a32d1a8dda9de0626881eb817f8476048cbe7519ebf74fab442ff43e28887edf8c3775931d060e1857d66e97f0284c79b7b7d22b13966287177566e
6
+ metadata.gz: 6fa24cd7236ee076d2382b7cabc4ec7950f9b7442b38aa50de6853e48e8ab71100e3e09d20f36ace6f2a16918724f6597ce9287334ab8b71b907b95a54bf13bf
7
+ data.tar.gz: 5e13eacfd6948c8f620314138b7b23f73e6a7848814297d9418b89c2217e911a16e6e7ead55ec70fbb5e18fcd598eda8132460f527e4ca03bff45f99f5306730
data/lib/teodoro.rb CHANGED
@@ -27,6 +27,7 @@ module Teodoro
27
27
  def call
28
28
  validar_argumentos
29
29
  validar_existencia_do_diretorio_de_origem
30
+ validar_existencia_do_diretorio_de_destino
30
31
  validar_que_diretorio_de_origem_nao_esta_vazio
31
32
  validar_que_diretorio_de_destino_esta_vazio
32
33
 
@@ -44,7 +45,15 @@ module Teodoro
44
45
  end
45
46
 
46
47
  def origem
47
- @origem ||= args[0]
48
+ @origem ||= args[0].tr('\\', '/')
49
+ end
50
+
51
+ def validar_existencia_do_diretorio_de_destino
52
+ erro 'Diretório de destino não existe.' unless File.directory?(destino)
53
+ end
54
+
55
+ def destino
56
+ @destino ||= args[1].tr('\\', '/')
48
57
  end
49
58
 
50
59
  def validar_que_diretorio_de_origem_nao_esta_vazio
@@ -55,10 +64,6 @@ module Teodoro
55
64
  erro 'Diretório de destino deve estar vazio.' unless Dir.empty?(destino)
56
65
  end
57
66
 
58
- def destino
59
- @destino ||= args[1]
60
- end
61
-
62
67
  def erro(erro)
63
68
  puts erro
64
69
  exit
@@ -2,31 +2,31 @@ module Teodoro
2
2
  module ArquivoDeEvento
3
3
  private
4
4
 
5
- def initialize(empresa:, evento:, recibo:)
5
+ def initialize(empresa:, arquivo_xml:)
6
6
  @empresa = empresa
7
- @evento = evento
8
- @recibo = recibo
7
+ @arquivo_xml = arquivo_xml
9
8
  end
10
9
 
11
- attr_reader :empresa, :evento, :recibo
10
+ attr_reader :empresa, :arquivo_xml
12
11
 
13
- def processo_de_emissao_do_evento
14
- evento["#{noh_principal_do_evento}/ideEvento/procEmi"]
12
+ def versao_do_leiaute
13
+ arquivo_xml.versao_do_leiaute
15
14
  end
16
15
 
17
- def criar_caminho_do_arquivo_data(nome_do_arquivo)
18
- File.join(
19
- destino_dos_arquivos_data,
20
- "#{windows? ? nome_do_arquivo.gsub(%r{[<|>:"/\\?*]}, '_') : nome_do_arquivo}.data"
21
- )
16
+ def evento
17
+ arquivo_xml.evento
22
18
  end
23
19
 
24
- def destino_dos_arquivos_data
25
- empresa.destino_dos_arquivos_data
20
+ def recibo
21
+ arquivo_xml.recibo
26
22
  end
27
23
 
28
- def windows?
29
- OS.windows?
24
+ def versao_do_aplicativo_de_processamento_do_evento
25
+ @versao_do_aplicativo_de_processamento_do_evento ||= recibo['retornoEvento/processamento/versaoAppProcessamento']
26
+ end
27
+
28
+ def numero_do_recibo
29
+ @numero_do_recibo ||= recibo['retornoEvento/recibo/nrRecibo']
30
30
  end
31
31
  end
32
32
  end
@@ -1,6 +1,6 @@
1
1
  module Teodoro
2
- module ArquivoDeEventoExcetoDeExclusao
3
- include ArquivoDeEvento
2
+ module ArquivoDeEventoCriadorDeArquivoData
3
+ include ArquivoDeEventoProcessadorDeArquivoData
4
4
 
5
5
  private
6
6
 
@@ -14,10 +14,6 @@ module Teodoro
14
14
  (itens_do_conteudo_do_arquivo_data.map { "#{_1}=#{_2}" } + ['']).join("\n")
15
15
  end
16
16
 
17
- def versao_do_aplicativo_de_processamento_do_evento
18
- recibo['retornoEvento/processamento/versaoAppProcessamento']
19
- end
20
-
21
17
  def tipo_de_inscricao_do_empregador
22
18
  @tipo_de_inscricao_do_empregador ||= evento["#{noh_principal_do_evento}/ideEmpregador/tpInsc"]
23
19
  end
@@ -1,6 +1,6 @@
1
1
  module Teodoro
2
2
  module ArquivoDeEventoDeTabela
3
- include ArquivoDeEventoExcetoDeExclusao
3
+ include ArquivoDeEventoCriadorDeArquivoData
4
4
 
5
5
  def processar
6
6
  deletar_arquivo_data_original if alteracao? || exclusao?
@@ -37,7 +37,7 @@ module Teodoro
37
37
  end
38
38
 
39
39
  def caminho_do_arquivo_data
40
- # FIXME: Tales inicio de validade
40
+ # FIXME: Tales inicio de validade ou inicio da nova validade?
41
41
  obter_caminho_do_arquivo_data(inicio_da_validade)
42
42
  end
43
43
 
@@ -1,45 +1,21 @@
1
1
  module Teodoro
2
2
  module ArquivoDeEventoNaoPeriodico
3
- include ArquivoDeEventoExcetoDeExclusao
3
+ include ArquivoDeEventoCriadorDeArquivoData
4
+ include ArquivoDeEventoRetificavel
4
5
 
5
6
  def processar
6
- deletar_arquivo_data_original if retificacao?
7
- registrar_recibo
7
+ deletar_arquivos_data_originais if retificacao?
8
+ registrar_arquivo_data
8
9
  criar_arquivo_data
9
10
  end
10
11
 
11
12
  private
12
13
 
13
- def retificacao?
14
- evento["#{noh_principal_do_evento}/ideEvento/indRetif"] == '2'
15
- end
16
-
17
- def deletar_arquivo_data_original
18
- File.delete(caminho_do_arquivo_data_original)
19
- end
20
-
21
- def caminho_do_arquivo_data_original
22
- criar_caminho_do_arquivo_data(nome_do_arquivo_original)
23
- end
24
-
25
- def nome_do_arquivo_original
26
- de_recibo_para_nome_do_arquivo_data[numero_do_recibo_a_retificar]
27
- end
28
-
29
- def de_recibo_para_nome_do_arquivo_data
30
- empresa.de_recibo_para_nome_do_arquivo_data
31
- end
32
-
33
- def numero_do_recibo_a_retificar
34
- evento["#{noh_principal_do_evento}/ideEvento/nrRecibo"]
35
- end
36
-
37
- def registrar_recibo
38
- de_recibo_para_nome_do_arquivo_data[numero_do_recibo] = nome_do_arquivo_data
39
- end
40
-
41
- def numero_do_recibo
42
- recibo['retornoEvento/recibo/nrRecibo']
14
+ def registrar_arquivo_data
15
+ arquivos_data.registrar(
16
+ nome: nome_do_arquivo_data,
17
+ recibo: numero_do_recibo
18
+ )
43
19
  end
44
20
 
45
21
  def caminho_do_arquivo_data
@@ -0,0 +1,30 @@
1
+ module Teodoro
2
+ module ArquivoDeEventoProcessadorDeArquivoData
3
+ include ArquivoDeEvento
4
+
5
+ private
6
+
7
+ def leiaute_simplificado?
8
+ versao_do_leiaute.start_with?('_S_')
9
+ end
10
+
11
+ def processo_de_emissao_do_evento
12
+ evento["#{noh_principal_do_evento}/ideEvento/procEmi"]
13
+ end
14
+
15
+ def criar_caminho_do_arquivo_data(nome_do_arquivo)
16
+ File.join(
17
+ destino_dos_arquivos_data,
18
+ "#{windows? ? nome_do_arquivo.gsub(%r{[<|>:"/\\?*]}, '_') : nome_do_arquivo}.data"
19
+ )
20
+ end
21
+
22
+ def destino_dos_arquivos_data
23
+ empresa.destino_dos_arquivos_data
24
+ end
25
+
26
+ def windows?
27
+ OS.windows?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module Teodoro
2
+ module ArquivoDeEventoRetificavel
3
+ include ArquivoDeEvento
4
+
5
+ private
6
+
7
+ def retificacao?
8
+ @retificacao ||= evento["#{noh_principal_do_evento}/ideEvento/indRetif"] == '2'
9
+ end
10
+
11
+ def deletar_arquivos_data_originais
12
+ arquivos_data.excluir(numero_do_recibo_a_retificar)
13
+ end
14
+
15
+ def arquivos_data
16
+ empresa.arquivos_data
17
+ end
18
+
19
+ def numero_do_recibo_a_retificar
20
+ @numero_do_recibo_a_retificar ||= evento["#{noh_principal_do_evento}/ideEvento/nrRecibo"]
21
+ end
22
+ end
23
+ end
@@ -1,9 +1,11 @@
1
1
  require_relative 'arquivo_de_evento'
2
- require_relative 'arquivo_de_evento_exceto_de_exclusao'
2
+ require_relative 'arquivo_de_evento_processador_de_arquivo_data'
3
+ require_relative 'arquivo_de_evento_criador_de_arquivo_data'
4
+ require_relative 'arquivo_de_evento_retificavel'
3
5
  require_relative 'arquivo_de_evento_de_tabela'
4
6
  require_relative 'arquivo_de_evento_nao_periodico'
5
7
  require_relative 'cnpj'
6
- require_relative 'leiaute_2'
8
+ require_relative 'leiaute'
7
9
  require_relative 'xml'
8
10
 
9
11
  module Teodoro
@@ -47,8 +49,7 @@ module Teodoro
47
49
 
48
50
  def momento_de_processamento_pelo_e_social
49
51
  # otimizacao do gerenciamento de memoria
50
- carregar_conteudo
51
- .then { |conteudo| Nokogiri::XML(conteudo) }
52
+ carregar_xml
52
53
  .then { |xml| Nokogiri::XML(xml.css('eSocial/retornoProcessamentoDownload/recibo/*').to_s) }
53
54
  .then { |xml_do_recibo| XML.new(xml_do_recibo) }
54
55
  .then { |recibo| recibo['retornoEvento/processamento/dhProcessamento'] }
@@ -59,8 +60,9 @@ module Teodoro
59
60
  end
60
61
 
61
62
  def processar
62
- Console.print "processando #{nome}.xml..."
63
- arquivo.processar
63
+ dar_feedback_para_o_usuario
64
+ validar_versao_do_leiaute
65
+ processar_arquivo
64
66
  end
65
67
 
66
68
  private
@@ -69,29 +71,24 @@ module Teodoro
69
71
  @tipo_de_evento ||= nome[-6..].delete('-')
70
72
  end
71
73
 
72
- def carregar_conteudo
73
- File.read(caminho)
74
+ def carregar_xml
75
+ Nokogiri::XML(carregar_conteudo)
74
76
  end
75
77
 
76
- def arquivo
77
- classe_do_arquivo.new(empresa: empresa, evento: evento, recibo: recibo)
78
+ def carregar_conteudo
79
+ File.read(caminho)
78
80
  end
79
81
 
80
- def classe_do_arquivo
81
- modulo_do_leiaute.const_get("Arquivo#{tipo_de_evento}")
82
+ def dar_feedback_para_o_usuario
83
+ Console.print "processando #{nome}.xml..."
82
84
  end
83
85
 
84
- def modulo_do_leiaute
85
- {
86
- '02_04_01' => Leiaute_2,
87
- '02_04_02' => Leiaute_2,
88
- '02_05_00' => Leiaute_2,
89
- '_S_01_00_00' => Leiaute_2 # FIXME: Tales
90
- }[versao_do_leiaute_no_xml]
86
+ def validar_versao_do_leiaute
87
+ raise unless %w[02_04_01 02_04_02 02_05_00 _S_01_00_00].include?(versao_do_leiaute)
91
88
  end
92
89
 
93
- def versao_do_leiaute_no_xml
94
- namespace_do_evento.match(%r{.+/v(.+)$})[1]
90
+ def versao_do_leiaute
91
+ @versao_do_leiaute ||= namespace_do_evento.match(%r{.+/v(.+)$})[1]
95
92
  end
96
93
 
97
94
  def namespace_do_evento
@@ -103,7 +100,22 @@ module Teodoro
103
100
  end
104
101
 
105
102
  def xml
106
- @xml ||= Nokogiri::XML(carregar_conteudo)
103
+ @xml ||= carregar_xml
104
+ end
105
+
106
+ def processar_arquivo
107
+ arquivo.processar
108
+ end
109
+
110
+ def arquivo
111
+ classe_do_arquivo.new(
112
+ empresa: empresa,
113
+ arquivo_xml: Obj.new(versao_do_leiaute: versao_do_leiaute, evento: evento, recibo: recibo)
114
+ )
115
+ end
116
+
117
+ def classe_do_arquivo
118
+ Leiaute.const_get("Arquivo#{tipo_de_evento}")
107
119
  end
108
120
 
109
121
  def evento
@@ -83,9 +83,9 @@ module Teodoro
83
83
  def empresa
84
84
  @empresa ||= Obj.new(
85
85
  destino_dos_arquivos_data: destino_dos_arquivos_data,
86
- de_recibo_para_nome_do_arquivo_data: {},
87
- admissoes_por_matricula: {},
88
- contratos_de_trabalhador_sem_vinculo: ContratosDeTrabalhadorSemVinculo.new
86
+ arquivos_data: ArquivosData.new(destino_dos_arquivos_data),
87
+ contratos_de_emprego: ContratosDeEmprego.new,
88
+ contratos_de_trabalho_sem_vinculo: ContratosDeTrabalhoSemVinculo.new
89
89
  )
90
90
  end
91
91
 
@@ -93,19 +93,87 @@ module Teodoro
93
93
  Console.print
94
94
  end
95
95
 
96
- class ContratosDeTrabalhadorSemVinculo
96
+ class ArquivosData
97
+ private
98
+
99
+ def initialize(destino_dos_arquivos_data)
100
+ @destino_dos_arquivos_data = destino_dos_arquivos_data
101
+ end
102
+
103
+ attr_reader :destino_dos_arquivos_data
104
+
105
+ public
106
+
107
+ def registrar(recibo:, nome:)
108
+ (nomes_por_recibo[recibo] ||= []) << nome
109
+ end
110
+
111
+ def excluir(recibo)
112
+ (nomes_por_recibo.delete(recibo) || [])
113
+ .map { |nome| File.join(destino_dos_arquivos_data, "#{nome}.data") }
114
+ .each { File.delete(_1) }
115
+ end
116
+
117
+ private
118
+
119
+ def nomes_por_recibo
120
+ @nomes_por_recibo ||= {}
121
+ end
122
+ end
123
+
124
+ class ContratosDeEmprego
125
+ def <<(contrato)
126
+ contratos_por_matricula[contrato.matricula] = contrato
127
+ end
128
+
129
+ def [](matricula)
130
+ contratos_por_matricula[matricula]
131
+ end
132
+
133
+ def *(cpf_do_trabalhador:, data:)
134
+ contratos
135
+ .select { _1.cpf_do_trabalhador == cpf_do_trabalhador }
136
+ .select { _1.data_de_admissao <= data } # data de rescisao
137
+ .sort_by(&:data_de_admissao)
138
+ end
139
+
140
+ def remover(recibo)
141
+ contratos_por_matricula.delete_if { _2.recibo == recibo }
142
+ end
143
+
144
+ private
145
+
146
+ def contratos_por_matricula
147
+ @contratos_por_matricula ||= {}
148
+ end
149
+
150
+ def contratos
151
+ contratos_por_matricula.values
152
+ end
153
+ end
154
+
155
+ class ContratosDeTrabalhoSemVinculo
97
156
  def <<(contrato)
98
157
  contratos << contrato
99
158
  end
100
159
 
101
160
  def [](cpf_do_trabalhador:, categoria_do_trabalhador:, data:)
102
161
  contratos
103
- .select {
104
- [_1.cpf_do_trabalhador, _1.categoria_do_trabalhador] == [cpf_do_trabalhador, categoria_do_trabalhador]
105
- }
162
+ .select { _1.cpf_do_trabalhador == cpf_do_trabalhador }
163
+ .select { _1.categoria_do_trabalhador == categoria_do_trabalhador}
164
+ .select { _1.data_de_inicio <= data }
165
+ .max_by(&:data_de_inicio)
166
+ end
167
+
168
+ def *(cpf_do_trabalhador:, data:)
169
+ contratos
170
+ .select { _1.cpf_do_trabalhador == cpf_do_trabalhador }
171
+ .select { _1.data_de_inicio <= data } # FIXME: Tales data de termino
106
172
  .sort_by(&:data_de_inicio)
107
- .reverse
108
- .find { _1.data_de_inicio <= data }
173
+ end
174
+
175
+ def remover(recibo)
176
+ contratos.delete_if { _1.recibo == recibo }
109
177
  end
110
178
 
111
179
  private