teodoro 0.0.10 → 0.1.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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/teodoro.rb +5 -11
  3. data/lib/teodoro/arquivo_de_evento.rb +22 -8
  4. data/lib/teodoro/{arquivo_de_evento_exceto_de_exclusao.rb → arquivo_de_evento_criador_de_arquivo_data.rb} +2 -8
  5. data/lib/teodoro/arquivo_de_evento_de_tabela.rb +2 -12
  6. data/lib/teodoro/arquivo_de_evento_nao_periodico.rb +9 -42
  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_de_origem.rb +1 -1
  10. data/lib/teodoro/arquivo_xml.rb +44 -73
  11. data/lib/teodoro/console.rb +2 -6
  12. data/lib/teodoro/empresa.rb +108 -14
  13. data/lib/teodoro/leiaute.rb +24 -0
  14. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1000.rb +7 -9
  15. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1005.rb +4 -4
  16. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1010.rb +3 -5
  17. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1020.rb +4 -4
  18. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1030.rb +4 -4
  19. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1040.rb +2 -4
  20. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1050.rb +4 -4
  21. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s1070.rb +2 -4
  22. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s2190.rb +2 -2
  23. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s2200.rb +138 -22
  24. data/lib/teodoro/leiaute/arquivo_s2205.rb +264 -0
  25. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s2206.rb +18 -7
  26. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s2230.rb +56 -12
  27. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s2250.rb +25 -9
  28. data/lib/teodoro/leiaute/arquivo_s2299.rb +313 -0
  29. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s2300.rb +31 -5
  30. data/lib/teodoro/{leiaute_2_4_1 → leiaute}/arquivo_s2306.rb +27 -7
  31. data/lib/teodoro/leiaute/arquivo_s2399.rb +306 -0
  32. data/lib/teodoro/leiaute/arquivo_s3000.rb +33 -0
  33. data/lib/teodoro/obj.rb +5 -0
  34. metadata +26 -21
  35. data/lib/teodoro/leiaute_2_4_1.rb +0 -22
  36. data/lib/teodoro/leiaute_2_4_1/arquivo_s2205.rb +0 -157
  37. data/lib/teodoro/leiaute_2_4_1/arquivo_s3000.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6813c49b858cd3dd4f2732bf76c0ca99c465e3ee55b713773595206b038048b4
4
- data.tar.gz: 306eb583e7c68f82cb5fbb9aa0a7983a108a82c8b37e5283c9f54d519a53ad22
3
+ metadata.gz: bbdbafcdea814fe8ee357a403df2abb2a6fa92196b7f75107e878f80492134c0
4
+ data.tar.gz: 9dd0c5a05c9b571b831a98cbc86814a172cae5fb0ae26742ea5683a7812e8a04
5
5
  SHA512:
6
- metadata.gz: cda354fd4d76b448b763ab5b447b40122c8c9e7dbbe874c81ead7e1b6cb218dfebe983f255443887ceb8901808ca213674def5e6022b25c086c3abefc54edb71
7
- data.tar.gz: aa311e5876f76f91c818f250a3f12908173ced56a8722a0db14fa85b17b2fbb4cb8abda34c302a19ea023e54d1a8cd5372ae479d23fbea7b1ab9376f8624fc81
6
+ metadata.gz: 134d47b8565a584b86a5657cb4436020a230bf0d98544093b826680c01278f18512fff744bdb6d291b045939fbd7ead5b04aad5f77e2de1a1d40723983fdee01
7
+ data.tar.gz: fff0fd3c1e7623adf26608c59bf62bc110b6546a5fc3821a410663cfe11b4f995c5e2b95572248d4b2bc8156931d35ca9b8e9b5caafe1be2d3272e444fb4bc0d
data/lib/teodoro.rb CHANGED
@@ -4,6 +4,7 @@ require 'zip'
4
4
 
5
5
  require_relative 'teodoro/console'
6
6
  require_relative 'teodoro/empresa'
7
+ require_relative 'teodoro/obj'
7
8
 
8
9
  module Teodoro
9
10
  def self.call(args)
@@ -24,15 +25,6 @@ module Teodoro
24
25
  public
25
26
 
26
27
  def call
27
- executar
28
- rescue StandardError => e
29
- Console.print e.message, *e.backtrace, color: :red
30
- exit
31
- end
32
-
33
- private
34
-
35
- def executar
36
28
  validar_argumentos
37
29
  validar_existencia_do_diretorio_de_origem
38
30
  validar_que_diretorio_de_origem_nao_esta_vazio
@@ -41,6 +33,8 @@ module Teodoro
41
33
  processar_empresas
42
34
  end
43
35
 
36
+ private
37
+
44
38
  def validar_argumentos
45
39
  erro "#{NOME_DO_PROGRAMA} [diretório de origem] [diretório de destino]" unless args.size == 2
46
40
  end
@@ -50,7 +44,7 @@ module Teodoro
50
44
  end
51
45
 
52
46
  def origem
53
- @origem ||= args[0]
47
+ @origem ||= args[0].tr('\\', '/')
54
48
  end
55
49
 
56
50
  def validar_que_diretorio_de_origem_nao_esta_vazio
@@ -62,7 +56,7 @@ module Teodoro
62
56
  end
63
57
 
64
58
  def destino
65
- @destino ||= args[1]
59
+ @destino ||= args[1].tr('\\', '/')
66
60
  end
67
61
 
68
62
  def erro(erro)
@@ -2,17 +2,31 @@ module Teodoro
2
2
  module ArquivoDeEvento
3
3
  private
4
4
 
5
- attr_reader :evento, :destino_dos_arquivos_data
5
+ def initialize(empresa:, arquivo_xml:)
6
+ @empresa = empresa
7
+ @arquivo_xml = arquivo_xml
8
+ end
9
+
10
+ attr_reader :empresa, :arquivo_xml
11
+
12
+ def versao_do_leiaute
13
+ arquivo_xml.versao_do_leiaute
14
+ end
15
+
16
+ def evento
17
+ arquivo_xml.evento
18
+ end
19
+
20
+ def recibo
21
+ arquivo_xml.recibo
22
+ end
6
23
 
7
- def criar_caminho_do_arquivo_data(nome_do_arquivo)
8
- File.join(
9
- destino_dos_arquivos_data,
10
- "#{windows? ? nome_do_arquivo.gsub(%r{[<|>:"/\\?*]}, '_') : nome_do_arquivo}.data"
11
- )
24
+ def versao_do_aplicativo_de_processamento_do_evento
25
+ @versao_do_aplicativo_de_processamento_do_evento ||= recibo['retornoEvento/processamento/versaoAppProcessamento']
12
26
  end
13
27
 
14
- def windows?
15
- OS.windows?
28
+ def numero_do_recibo
29
+ @numero_do_recibo ||= recibo['retornoEvento/recibo/nrRecibo']
16
30
  end
17
31
  end
18
32
  end
@@ -1,11 +1,9 @@
1
1
  module Teodoro
2
- module ArquivoDeEventoExcetoDeExclusao
3
- include ArquivoDeEvento
2
+ module ArquivoDeEventoCriadorDeArquivoData
3
+ include ArquivoDeEventoProcessadorDeArquivoData
4
4
 
5
5
  private
6
6
 
7
- attr_reader :recibo
8
-
9
7
  def criar_arquivo_data
10
8
  raise caminho_do_arquivo_data if File.exist?(caminho_do_arquivo_data)
11
9
 
@@ -16,10 +14,6 @@ module Teodoro
16
14
  (itens_do_conteudo_do_arquivo_data.map { "#{_1}=#{_2}" } + ['']).join("\n")
17
15
  end
18
16
 
19
- def versao_do_aplicativo_de_processamento_do_evento
20
- recibo['retornoEvento/processamento/versaoAppProcessamento']
21
- end
22
-
23
17
  def tipo_de_inscricao_do_empregador
24
18
  @tipo_de_inscricao_do_empregador ||= evento["#{noh_principal_do_evento}/ideEmpregador/tpInsc"]
25
19
  end
@@ -1,16 +1,6 @@
1
1
  module Teodoro
2
2
  module ArquivoDeEventoDeTabela
3
- include ArquivoDeEventoExcetoDeExclusao
4
-
5
- private
6
-
7
- def initialize(evento:, recibo:, destino_dos_arquivos_data:)
8
- @evento = evento
9
- @recibo = recibo
10
- @destino_dos_arquivos_data = destino_dos_arquivos_data
11
- end
12
-
13
- public
3
+ include ArquivoDeEventoCriadorDeArquivoData
14
4
 
15
5
  def processar
16
6
  deletar_arquivo_data_original if alteracao? || exclusao?
@@ -47,7 +37,7 @@ module Teodoro
47
37
  end
48
38
 
49
39
  def caminho_do_arquivo_data
50
- # FIXME: Tales inicio de validade
40
+ # FIXME: Tales inicio de validade ou inicio da nova validade?
51
41
  obter_caminho_do_arquivo_data(inicio_da_validade)
52
42
  end
53
43
 
@@ -1,54 +1,21 @@
1
1
  module Teodoro
2
2
  module ArquivoDeEventoNaoPeriodico
3
- include ArquivoDeEventoExcetoDeExclusao
4
-
5
- private
6
-
7
- def initialize(evento:, recibo:, destino_dos_arquivos_data:, de_recibo_para_nome_do_arquivo_data:)
8
- @evento = evento
9
- @recibo = recibo
10
- @destino_dos_arquivos_data = destino_dos_arquivos_data
11
- @de_recibo_para_nome_do_arquivo_data = de_recibo_para_nome_do_arquivo_data
12
- end
13
-
14
- attr_reader :de_recibo_para_nome_do_arquivo_data
15
-
16
- public
3
+ include ArquivoDeEventoCriadorDeArquivoData
4
+ include ArquivoDeEventoRetificavel
17
5
 
18
6
  def processar
19
- deletar_arquivo_data_original if retificacao?
20
- registrar_recibo
7
+ deletar_arquivos_data_originais if retificacao?
8
+ registrar_arquivo_data
21
9
  criar_arquivo_data
22
10
  end
23
11
 
24
12
  private
25
13
 
26
- def retificacao?
27
- evento["#{noh_principal_do_evento}/ideEvento/indRetif"] == '2'
28
- end
29
-
30
- def deletar_arquivo_data_original
31
- File.delete(caminho_do_arquivo_data_original)
32
- end
33
-
34
- def caminho_do_arquivo_data_original
35
- criar_caminho_do_arquivo_data(nome_do_arquivo_original)
36
- end
37
-
38
- def nome_do_arquivo_original
39
- de_recibo_para_nome_do_arquivo_data[numero_do_recibo_a_retificar]
40
- end
41
-
42
- def numero_do_recibo_a_retificar
43
- @numero_do_recibo_a_retificar ||= evento["#{noh_principal_do_evento}/ideEvento/nrRecibo"]
44
- end
45
-
46
- def registrar_recibo
47
- de_recibo_para_nome_do_arquivo_data[numero_do_recibo] = nome_do_arquivo_data
48
- end
49
-
50
- def numero_do_recibo
51
- 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
+ )
52
19
  end
53
20
 
54
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
@@ -14,7 +14,7 @@ module Teodoro
14
14
  public
15
15
 
16
16
  def descompactar
17
- print "\e[2Kdescompactando #{File.basename(caminho)}...\r"
17
+ Console.print "descompactando #{File.basename(caminho)}..."
18
18
 
19
19
  Zip::File.open(caminho) do |zip|
20
20
  zip
@@ -1,13 +1,15 @@
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_4_1'
8
+ require_relative 'leiaute'
7
9
  require_relative 'xml'
8
10
 
9
11
  module Teodoro
10
- class ArquivoXML # rubocop:disable Metrics/ClassLength
12
+ class ArquivoXML
11
13
  TIPOS_DE_EVENTO_PROCESSAVEIS = %w[
12
14
  S1000
13
15
  S1005
@@ -23,27 +25,31 @@ module Teodoro
23
25
  S2206
24
26
  S2230
25
27
  S2250
28
+ S2299
26
29
  S2300
27
30
  S2306
31
+ S2399
28
32
  S3000
29
33
  ].freeze
30
34
 
31
35
  private
32
36
 
33
- def initialize(caminho:, destino_dos_arquivos_data:, de_recibo_para_nome_do_arquivo_data:)
37
+ def initialize(empresa:, caminho:)
38
+ @empresa = empresa
34
39
  @caminho = caminho
35
- @destino_dos_arquivos_data = destino_dos_arquivos_data
36
- @de_recibo_para_nome_do_arquivo_data = de_recibo_para_nome_do_arquivo_data
37
40
  end
38
41
 
39
- attr_reader :caminho, :destino_dos_arquivos_data, :de_recibo_para_nome_do_arquivo_data
42
+ attr_reader :empresa, :caminho
40
43
 
41
44
  public
42
45
 
46
+ def processavel?
47
+ TIPOS_DE_EVENTO_PROCESSAVEIS.include?(tipo_de_evento)
48
+ end
49
+
43
50
  def momento_de_processamento_pelo_e_social
44
51
  # otimizacao do gerenciamento de memoria
45
- carregar_conteudo
46
- .then { |conteudo| Nokogiri::XML(conteudo) }
52
+ carregar_xml
47
53
  .then { |xml| Nokogiri::XML(xml.css('eSocial/retornoProcessamentoDownload/recibo/*').to_s) }
48
54
  .then { |xml_do_recibo| XML.new(xml_do_recibo) }
49
55
  .then { |recibo| recibo['retornoEvento/processamento/dhProcessamento'] }
@@ -54,81 +60,35 @@ module Teodoro
54
60
  end
55
61
 
56
62
  def processar
57
- print "\e[2Kprocessando #{nome}.xml...\r"
58
-
59
- return unless TIPOS_DE_EVENTO_PROCESSAVEIS.include?(tipo_de_evento)
60
-
61
- arquivo.processar
63
+ dar_feedback_para_o_usuario
64
+ validar_versao_do_leiaute
65
+ processar_arquivo
62
66
  end
63
67
 
64
68
  private
65
69
 
66
- def carregar_conteudo
67
- File.read(caminho)
68
- end
69
-
70
- def arquivo
71
- if evento_de_tabela?
72
- evento_de_tabela
73
- elsif evento_nao_periodico?
74
- evento_nao_periodico
75
- elsif evento_de_exclusao?
76
- evento_de_exclusao
77
- end
78
- end
79
-
80
- def evento_de_tabela?
81
- tipo_de_evento.start_with?('S10')
82
- end
83
-
84
- def evento_de_tabela
85
- classe_do_arquivo.new(
86
- evento: evento,
87
- recibo: recibo,
88
- destino_dos_arquivos_data: destino_dos_arquivos_data
89
- )
90
- end
91
-
92
- def evento_nao_periodico?
93
- tipo_de_evento.start_with?('S2')
94
- end
95
-
96
- def evento_nao_periodico
97
- classe_do_arquivo.new(
98
- evento: evento,
99
- recibo: recibo,
100
- destino_dos_arquivos_data: destino_dos_arquivos_data,
101
- de_recibo_para_nome_do_arquivo_data: de_recibo_para_nome_do_arquivo_data
102
- )
70
+ def tipo_de_evento
71
+ @tipo_de_evento ||= nome[-6..].delete('-')
103
72
  end
104
73
 
105
- def evento_de_exclusao?
106
- tipo_de_evento == 'S3000'
74
+ def carregar_xml
75
+ Nokogiri::XML(carregar_conteudo)
107
76
  end
108
77
 
109
- def evento_de_exclusao
110
- classe_do_arquivo.new(
111
- evento: evento,
112
- de_recibo_para_nome_do_arquivo_data: de_recibo_para_nome_do_arquivo_data,
113
- destino_dos_arquivos_data: destino_dos_arquivos_data
114
- )
78
+ def carregar_conteudo
79
+ File.read(caminho)
115
80
  end
116
81
 
117
- def classe_do_arquivo
118
- modulo_do_leiaute.const_get("Arquivo#{tipo_de_evento}")
82
+ def dar_feedback_para_o_usuario
83
+ Console.print "processando #{nome}.xml..."
119
84
  end
120
85
 
121
- def modulo_do_leiaute
122
- {
123
- '02_04_01' => Leiaute_2_4_1,
124
- '02_04_02' => Leiaute_2_4_1, # FIXME: Tales
125
- '02_05_00' => Leiaute_2_4_1, # FIXME: Tales
126
- '01_00_00' => Leiaute_2_4_1 # FIXME: Tales
127
- }[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)
128
88
  end
129
89
 
130
- def versao_do_leiaute_no_xml
131
- namespace_do_evento.match(%r{.+/v(.+)$})[1]
90
+ def versao_do_leiaute
91
+ @versao_do_leiaute ||= namespace_do_evento.match(%r{.+/v(.+)$})[1]
132
92
  end
133
93
 
134
94
  def namespace_do_evento
@@ -140,11 +100,22 @@ module Teodoro
140
100
  end
141
101
 
142
102
  def xml
143
- @xml ||= Nokogiri::XML(carregar_conteudo)
103
+ @xml ||= carregar_xml
144
104
  end
145
105
 
146
- def tipo_de_evento
147
- @tipo_de_evento ||= nome[-6..].delete('-')
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}")
148
119
  end
149
120
 
150
121
  def evento