teodoro 0.10.0 → 0.15.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/teodoro.rb +9 -2
  3. data/lib/teodoro/arquivo_data.rb +19 -22
  4. data/lib/teodoro/arquivo_data/car.rb +34 -0
  5. data/lib/teodoro/arquivo_data/tra_epg_avi.rb +55 -0
  6. data/lib/teodoro/arquivo_de_evento.rb +6 -2
  7. data/lib/teodoro/arquivo_de_evento_de_tabela.rb +52 -19
  8. data/lib/teodoro/arquivo_de_evento_nao_periodico.rb +6 -2
  9. data/lib/teodoro/arquivo_xml.rb +33 -6
  10. data/lib/teodoro/empresa.rb +17 -140
  11. data/lib/teodoro/empresa/arquivos_data.rb +31 -0
  12. data/lib/teodoro/empresa/cargos_gerados.rb +86 -0
  13. data/lib/teodoro/empresa/contratos_de_emprego.rb +59 -0
  14. data/lib/teodoro/empresa/contratos_de_trabalho_sem_vinculo.rb +59 -0
  15. data/lib/teodoro/leiaute/arquivo_s1000.rb +18 -8
  16. data/lib/teodoro/leiaute/arquivo_s1005.rb +5 -5
  17. data/lib/teodoro/leiaute/arquivo_s1010.rb +3 -3
  18. data/lib/teodoro/leiaute/arquivo_s1020.rb +3 -3
  19. data/lib/teodoro/leiaute/arquivo_s1030.rb +19 -23
  20. data/lib/teodoro/leiaute/arquivo_s1040.rb +3 -3
  21. data/lib/teodoro/leiaute/arquivo_s1050.rb +3 -3
  22. data/lib/teodoro/leiaute/arquivo_s1070.rb +4 -4
  23. data/lib/teodoro/leiaute/arquivo_s2190.rb +2 -2
  24. data/lib/teodoro/leiaute/arquivo_s2200.rb +173 -15
  25. data/lib/teodoro/leiaute/arquivo_s2205.rb +42 -42
  26. data/lib/teodoro/leiaute/arquivo_s2206.rb +177 -74
  27. data/lib/teodoro/leiaute/arquivo_s2230.rb +5 -5
  28. data/lib/teodoro/leiaute/arquivo_s2250.rb +14 -34
  29. data/lib/teodoro/leiaute/arquivo_s2299.rb +67 -3
  30. data/lib/teodoro/leiaute/arquivo_s2300.rb +141 -14
  31. data/lib/teodoro/leiaute/arquivo_s2306.rb +85 -6
  32. metadata +8 -3
  33. data/lib/teodoro/leiaute.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed476a09d21ea31620816ef10a315c152da9fe7938810d81d2a3fd29f2085e28
4
- data.tar.gz: 15caa64dd8e82804283ea2b8248888b778c07672534405cfcf2cf466b9bead9d
3
+ metadata.gz: '015674845cf1493fa899507859c34b1cd26b3627cf753059c03428d0a5db5c01'
4
+ data.tar.gz: 594294173329bb263014f8d58324af563b8bf511cb50bcd3991ae9a68be987d6
5
5
  SHA512:
6
- metadata.gz: ef9d1142cf3f02126a46d093a49010a92144d3eb373fb6692bd1b95b398c0a08ae6e2753a0ce3d5fd9d7b438642c7b4ea2e5dfbb6f0392d16602173171369e79
7
- data.tar.gz: ce85156d0fe4b50c44c24ee31e0700f0a263db2a2e1b7f0b9cdcb48c72823ad7a97bf737a6d7529d9a2ca42a7a89f07f8a5a8685ab6973763b4f43695d7d9881
6
+ metadata.gz: 6868f635b06933ce12af64d6f155ed3d86350a458c5b3d03b46130220a0a42e6f3a8a32256765d168d08ca2507aa7bac57db1271bc63db467836606d362fad0a
7
+ data.tar.gz: 3046f5c29c40b43da022af43f4557d8823086e8f5b59e602fac3706f8bc99d25fa7843243b2bf00a1a3dc196d22c68b149a6f13dabf47aebc3bc6b94ffd5e185
data/lib/teodoro.rb CHANGED
@@ -2,6 +2,7 @@ require 'forwardable'
2
2
  require 'nokogiri'
3
3
  require 'os'
4
4
  require 'rainbow'
5
+ require 'securerandom'
5
6
  require 'zip'
6
7
 
7
8
  require_relative 'teodoro/console'
@@ -13,6 +14,11 @@ module Teodoro
13
14
  Execution.new(args).call
14
15
  end
15
16
 
17
+ @production = true
18
+ def self.production?
19
+ @production
20
+ end
21
+
16
22
  class Execution
17
23
  NOME_DO_PROGRAMA = 'teodoro'.freeze
18
24
 
@@ -72,11 +78,12 @@ module Teodoro
72
78
  end
73
79
 
74
80
  def processar_empresas
75
- empresas.each(&:processar)
81
+ # otimizacao do gerenciamento de memoria
82
+ empresas.shift.processar while empresas.any?
76
83
  end
77
84
 
78
85
  def empresas
79
- Dir[File.join(origem, '*')].map { |caminho| Empresa.new(caminho: caminho, destino: destino) }
86
+ @empresas ||= Dir[File.join(origem, '*')].map { |caminho| Empresa.new(caminho: caminho, destino: destino) }
80
87
  end
81
88
  end
82
89
  end
@@ -1,14 +1,17 @@
1
+ require_relative 'arquivo_data/car'
2
+ require_relative 'arquivo_data/tra_epg_avi'
3
+
1
4
  module Teodoro
2
5
  class ArquivoData
3
6
  private
4
7
 
5
- def initialize(empresa:, nome:, itens_do_conteudo:)
6
- @empresa = empresa
8
+ def initialize(diretorio:, nome:, itens_do_conteudo:)
9
+ @diretorio = diretorio
7
10
  @nome = nome
8
11
  @itens_do_conteudo = itens_do_conteudo
9
12
  end
10
13
 
11
- attr_reader :empresa, :itens_do_conteudo
14
+ attr_reader :diretorio, :itens_do_conteudo
12
15
 
13
16
  public
14
17
 
@@ -17,32 +20,32 @@ module Teodoro
17
20
  def criar
18
21
  raise caminho if File.exist?(caminho)
19
22
 
20
- File.write(caminho, (itens_do_conteudo.map { "#{_1}=#{Valor.new(_2)}" } + ['']).join("\r\n"))
23
+ File.write(caminho, (itens_do_conteudo.map { "#{_1}=#{Valor.new(_2, formato: _3)}" } + ['']).join("\n"))
21
24
  end
22
25
 
23
26
  private
24
27
 
25
28
  def caminho
26
- @caminho ||= Caminho.new(empresa: empresa, nome_do_arquivo: nome)
29
+ @caminho ||= Caminho.new(diretorio: diretorio, nome_do_arquivo: nome)
27
30
  end
28
31
 
29
32
  class Caminho
30
33
  private
31
34
 
32
- def initialize(empresa:, nome_do_arquivo:)
33
- @empresa = empresa
35
+ def initialize(diretorio:, nome_do_arquivo:)
36
+ @diretorio = diretorio
34
37
  @nome_do_arquivo = nome_do_arquivo
35
38
  end
36
39
 
37
- attr_reader :empresa, :nome_do_arquivo
40
+ attr_reader :diretorio, :nome_do_arquivo
38
41
 
39
42
  public
40
43
 
41
44
  def to_str
42
45
  @to_str ||=
43
46
  File.join(
44
- empresa.destino_dos_arquivos_data,
45
- "#{windows? ? nome_do_arquivo.gsub(%r{[<|>:"/\\?*]}, '_') : nome_do_arquivo}.data"
47
+ diretorio,
48
+ "#{windows? ? nome_do_arquivo.to_s.gsub(%r{[<|>:"/\\?*]}, '_') : nome_do_arquivo}.data"
46
49
  )
47
50
  end
48
51
 
@@ -58,29 +61,23 @@ module Teodoro
58
61
  bool: proc { _1 ? 'True' : 'False' },
59
62
  data: proc { "#{_1[-2..]}/#{_1[5..6]}/#{_1[0..3]}" if _1 },
60
63
  data_aaaammdd: proc { _1.delete('-') if _1 },
64
+ decimal: proc { _1.tr('.', ',') if _1 },
61
65
  mes_ano: proc { "#{_1[-2..]}/#{_1[0..3]}" if _1 }
62
66
  }.freeze
63
67
 
64
68
  private
65
69
 
66
- def initialize(arg)
67
- @arg = arg
70
+ def initialize(valor, formato:)
71
+ @valor = valor
72
+ @formato = formato
68
73
  end
69
74
 
70
- attr_reader :arg
75
+ attr_reader :valor, :formato
71
76
 
72
77
  public
73
78
 
74
79
  def to_s
75
- @to_s ||= (tipo ? FORMATADORES[tipo].call(valor) : valor).to_s
76
- end
77
-
78
- def tipo
79
- @tipo ||= arg[1] if arg.is_a?(Array)
80
- end
81
-
82
- def valor
83
- @valor ||= arg.is_a?(Array) ? arg[0] : arg
80
+ @to_s ||= (formato ? FORMATADORES[formato].call(valor) : valor).to_s
84
81
  end
85
82
  end
86
83
  end
@@ -0,0 +1,34 @@
1
+ module Teodoro
2
+ class ArquivoData
3
+ module CAR
4
+ module Identificacao
5
+ def self.new(codigo_do_cargo)
6
+ ['CAR', codigo_do_cargo]
7
+ end
8
+ end
9
+
10
+ module ItensDeConteudo
11
+ def self.new(dados) # rubocop:disable Metrics/MethodLength
12
+ [
13
+ ['RequestVerificationToken'],
14
+ ['SomenteVisualizacao'],
15
+ ['BloquearCodigo'],
16
+ ['BloquearAntigoPeriodoValidade'],
17
+ ['CodigoCargo', dados.codigo_do_cargo],
18
+ ['InicioValidade', dados.inicio_da_validade, :mes_ano],
19
+ ['FimValidade', dados.fim_da_validade, :mes_ano],
20
+ ['DadosCargo_DescricaoCargo', dados.nome_do_cargo],
21
+ ['DadosCargo_CodigoCBO', dados.cbo],
22
+ ['DadosCargo_CodigoCBO_TEXT'],
23
+ ['autocomplete_DadosCargo_CodigoCBO'],
24
+ ['PreencherCargoPublico', dados.orgao_publico?, :bool],
25
+ ['IdEventoXml', dados.id_do_evento],
26
+ ['NrReciboEventoOriginal', dados.numero_do_recibo],
27
+ ['DescricaoProcEmi', dados.processo_de_emissao_do_evento],
28
+ ['VerProc', dados.versao_do_aplicativo_de_processamento_do_evento]
29
+ ]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,55 @@
1
+ module Teodoro
2
+ class ArquivoData
3
+ class TRA_EPG_AVI # rubocop:disable Naming/ClassAndModuleCamelCase
4
+ private
5
+
6
+ def initialize(dados)
7
+ @dados = dados
8
+ end
9
+
10
+ attr_reader :dados
11
+
12
+ public
13
+
14
+ def nome
15
+ [
16
+ 'TRA',
17
+ "[#{dados.cpf_do_trabalhador}]",
18
+ "[EPG_#{dados.matricula_do_trabalhador}_#{dados.data_de_admissao.delete('-')}]",
19
+ '-AVI'
20
+ ].join
21
+ end
22
+
23
+ def itens_do_conteudo # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
24
+ [
25
+ # rubocop:disable Layout/LineLength
26
+ ['ESX_CPF', dados.cpf_do_trabalhador],
27
+ ['ESX_MATRICULA', dados.matricula_do_trabalhador],
28
+ %w[ESX_SEMVINCULO 0],
29
+ ['ESX_DATAADMISSAO', dados.data_de_admissao, :data],
30
+ ['OperacaoAvisoPrevio'],
31
+ ['MostrarCancelamento'],
32
+ ['MostrarAvisoPrevio'],
33
+ ['IdContrato'],
34
+ ['IdCancelamentoAvisoPrevio'],
35
+ ['BloquearCodigo'],
36
+ ['BloquearAntigoPeriodoValidade'],
37
+ ['IdeVinculo_Cpf'],
38
+ ['NomeTrabalhador'],
39
+ ['IdeVinculo_Matricula', dados.matricula_do_trabalhador],
40
+ ['InfoAvisoPrevio_DetalhamentoAvisoPrevio_TipoAvisoPrevio', dados.tipo_do_aviso_previo],
41
+ ['InfoAvisoPrevio_DetalhamentoAvisoPrevio_TipoAvisoPrevio_TEXT'],
42
+ ['InfoAvisoPrevio_DetalhamentoAvisoPrevio_DataAvisoPrevio', dados.data_do_aviso_previo, :data],
43
+ ['InfoAvisoPrevio_DetalhamentoAvisoPrevio_DataPrevistaDesligamento', dados.data_de_previsao_do_desligamento, :data],
44
+ ['InfoAvisoPrevio_DetalhamentoAvisoPrevio_Observacao', dados.observacao],
45
+ ['IdEventoXml', dados.id_do_evento],
46
+ ['NrReciboEventoOriginal', dados.numero_do_recibo],
47
+ ['RequestVerificationToken'],
48
+ ['DescricaoProcEmi', dados.processo_de_emissao_do_evento],
49
+ ['VerProc', dados.versao_do_aplicativo_de_processamento_do_evento]
50
+ # rubocop:enable Layout/LineLength
51
+ ]
52
+ end
53
+ end
54
+ end
55
+ end
@@ -9,6 +9,10 @@ module Teodoro
9
9
 
10
10
  attr_reader :empresa, :arquivo_xml
11
11
 
12
+ def leiaute_simplificado?
13
+ arquivo_xml.leiaute_simplificado?
14
+ end
15
+
12
16
  def evento
13
17
  arquivo_xml.evento
14
18
  end
@@ -18,11 +22,11 @@ module Teodoro
18
22
  end
19
23
 
20
24
  def id_do_evento
21
- evento.css('/*').first.attributes['Id'].value
25
+ @id_do_evento ||= evento.css('/*').first.attributes['Id'].value
22
26
  end
23
27
 
24
28
  def processo_de_emissao_do_evento
25
- evento['ideEvento/procEmi']
29
+ @processo_de_emissao_do_evento ||= evento['ideEvento/procEmi']
26
30
  end
27
31
 
28
32
  def tipo_de_inscricao_do_empregador
@@ -24,16 +24,17 @@ module Teodoro
24
24
  end
25
25
 
26
26
  def caminho_do_arquivo_data_original
27
- ArquivoData::Caminho.new(empresa: empresa, nome_do_arquivo: nome_do_arquivo_data_original)
27
+ ArquivoData::Caminho.new(
28
+ diretorio: empresa.destino_dos_arquivos_data,
29
+ nome_do_arquivo: nome_do_arquivo_data_original
30
+ )
28
31
  end
29
32
 
30
33
  def nome_do_arquivo_data_original
31
- "#{nome_base_do_arquivo_data}[#{inicio_da_validade_original.delete('-')}]"
32
- end
33
-
34
- def nome_base_do_arquivo_data
35
- @nome_base_do_arquivo_data ||=
36
- identificacao_do_arquivo_data[0] + identificacao_do_arquivo_data[1..].map { "[#{_1}]" }.join
34
+ NomeDoArquivoData.new(
35
+ identificacao: identificacao_do_arquivo_data,
36
+ inicio_da_validade: inicio_da_validade_original
37
+ )
37
38
  end
38
39
 
39
40
  def inicio_da_validade_original
@@ -44,18 +45,6 @@ module Teodoro
44
45
  arquivo_data.criar
45
46
  end
46
47
 
47
- def arquivo_data
48
- ArquivoData.new(
49
- empresa: empresa,
50
- nome: nome_do_arquivo_data,
51
- itens_do_conteudo: itens_do_conteudo_do_arquivo_data
52
- )
53
- end
54
-
55
- def nome_do_arquivo_data
56
- "#{nome_base_do_arquivo_data}[#{inicio_da_validade.delete('-')}]"
57
- end
58
-
59
48
  def inicio_da_validade
60
49
  @inicio_da_validade ||= validade['iniValid']
61
50
  end
@@ -84,5 +73,49 @@ module Teodoro
84
73
  def fim_da_validade
85
74
  validade['fimValid']
86
75
  end
76
+
77
+ module DescritorDeArquivoData
78
+ include ArquivoDeEventoDeTabela
79
+
80
+ private
81
+
82
+ def arquivo_data
83
+ ArquivoData.new(
84
+ diretorio: empresa.destino_dos_arquivos_data,
85
+ nome: nome_do_arquivo_data,
86
+ itens_do_conteudo: itens_do_conteudo_do_arquivo_data
87
+ )
88
+ end
89
+
90
+ def nome_do_arquivo_data
91
+ NomeDoArquivoData.new(
92
+ identificacao: identificacao_do_arquivo_data,
93
+ inicio_da_validade: inicio_da_validade
94
+ )
95
+ end
96
+ end
97
+
98
+ class NomeDoArquivoData
99
+ private
100
+
101
+ def initialize(identificacao:, inicio_da_validade:)
102
+ @identificacao = identificacao
103
+ @inicio_da_validade = inicio_da_validade
104
+ end
105
+
106
+ attr_reader :identificacao, :inicio_da_validade
107
+
108
+ public
109
+
110
+ def to_s
111
+ @to_s ||= "#{nome_base_do_arquivo_data}[#{inicio_da_validade.delete('-')}]"
112
+ end
113
+
114
+ private
115
+
116
+ def nome_base_do_arquivo_data
117
+ identificacao[0] + identificacao[1..].map { "[#{_1}]" }.join
118
+ end
119
+ end
87
120
  end
88
121
  end
@@ -39,12 +39,16 @@ module Teodoro
39
39
  end
40
40
 
41
41
  def criar_arquivos_data
42
- arquivos_data.each(&:criar)
42
+ arquivos_data.shift.criar while arquivos_data.any?
43
43
  end
44
44
 
45
45
  def arquivos_data
46
46
  @arquivos_data ||= dados_dos_arquivos_data.map {
47
- ArquivoData.new(empresa: empresa, nome: _1.nome, itens_do_conteudo: _1.itens_do_conteudo)
47
+ ArquivoData.new(
48
+ diretorio: empresa.destino_dos_arquivos_data,
49
+ nome: _1.nome,
50
+ itens_do_conteudo: _1.itens_do_conteudo
51
+ )
48
52
  }
49
53
  end
50
54
  end
@@ -3,7 +3,25 @@ require_relative 'arquivo_de_evento'
3
3
  require_relative 'arquivo_de_evento_de_tabela'
4
4
  require_relative 'arquivo_de_evento_nao_periodico'
5
5
  require_relative 'cnpj'
6
- require_relative 'leiaute'
6
+ require_relative 'leiaute/arquivo_s1000'
7
+ require_relative 'leiaute/arquivo_s1005'
8
+ require_relative 'leiaute/arquivo_s1010'
9
+ require_relative 'leiaute/arquivo_s1020'
10
+ require_relative 'leiaute/arquivo_s1030'
11
+ require_relative 'leiaute/arquivo_s1040'
12
+ require_relative 'leiaute/arquivo_s1050'
13
+ require_relative 'leiaute/arquivo_s1070'
14
+ require_relative 'leiaute/arquivo_s2190'
15
+ require_relative 'leiaute/arquivo_s2200'
16
+ require_relative 'leiaute/arquivo_s2205'
17
+ require_relative 'leiaute/arquivo_s2206'
18
+ require_relative 'leiaute/arquivo_s2230'
19
+ require_relative 'leiaute/arquivo_s2250'
20
+ require_relative 'leiaute/arquivo_s2299'
21
+ require_relative 'leiaute/arquivo_s2300'
22
+ require_relative 'leiaute/arquivo_s2306'
23
+ require_relative 'leiaute/arquivo_s2399'
24
+ require_relative 'leiaute/arquivo_s3000'
7
25
  require_relative 'xml'
8
26
 
9
27
  module Teodoro
@@ -108,7 +126,12 @@ module Teodoro
108
126
  end
109
127
 
110
128
  def validar_versao_do_leiaute
111
- raise unless %w[02_04_01 02_04_02 02_05_00 _S_01_00_00].include?(versao_do_leiaute)
129
+ raise unless [
130
+ '02_04_01',
131
+ '02_04_02',
132
+ '02_05_00',
133
+ *('_S_01_00_00' unless Teodoro.production?)
134
+ ].include?(versao_do_leiaute)
112
135
  end
113
136
 
114
137
  def versao_do_leiaute
@@ -120,7 +143,7 @@ module Teodoro
120
143
  end
121
144
 
122
145
  def xml_do_evento
123
- @xml_do_evento ||= Nokogiri::XML(xml.css('eSocial/retornoProcessamentoDownload/evento/*').to_s)
146
+ @xml_do_evento ||= Nokogiri::XML(xml.css('/eSocial/retornoProcessamentoDownload/evento/*').to_s)
124
147
  end
125
148
 
126
149
  def xml
@@ -134,16 +157,20 @@ module Teodoro
134
157
  def arquivo
135
158
  classe_do_arquivo.new(
136
159
  empresa: empresa,
137
- arquivo_xml: Obj.new(evento: evento, recibo: recibo)
160
+ arquivo_xml: Obj.new(leiaute_simplificado?: leiaute_simplificado?, evento: evento, recibo: recibo)
138
161
  )
139
162
  end
140
163
 
164
+ def leiaute_simplificado?
165
+ versao_do_leiaute == '_S_01_00_00'
166
+ end
167
+
141
168
  def classe_do_arquivo
142
169
  Leiaute.const_get("Arquivo#{tipo_de_evento}")
143
170
  end
144
171
 
145
172
  def evento
146
- XML.new(Nokogiri::XML(xml_do_evento.css('*/*').to_s))
173
+ XML.new(Nokogiri::XML(xml_do_evento.css('/*/*').to_s))
147
174
  end
148
175
 
149
176
  def recibo
@@ -151,7 +178,7 @@ module Teodoro
151
178
  end
152
179
 
153
180
  def xml_do_recibo
154
- Nokogiri::XML(xml.css('eSocial/retornoProcessamentoDownload/recibo/*/*').to_s)
181
+ Nokogiri::XML(xml.css('/eSocial/retornoProcessamentoDownload/recibo/*/*').to_s)
155
182
  end
156
183
  end
157
184
  end