teodoro 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/teodoro.rb +3 -9
- data/lib/teodoro/arquivo_de_evento.rb +15 -1
- data/lib/teodoro/arquivo_de_evento_de_tabela.rb +0 -10
- data/lib/teodoro/arquivo_de_evento_exceto_de_exclusao.rb +0 -2
- data/lib/teodoro/arquivo_de_evento_nao_periodico.rb +5 -14
- data/lib/teodoro/arquivo_de_origem.rb +1 -1
- data/lib/teodoro/arquivo_xml.rb +21 -62
- data/lib/teodoro/console.rb +2 -6
- data/lib/teodoro/empresa.rb +40 -14
- data/lib/teodoro/leiaute_2.rb +24 -0
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1000.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1005.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1010.rb +2 -2
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1020.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1030.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1040.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1050.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s1070.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2190.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2200.rb +27 -10
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2205.rb +2 -2
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2206.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2230.rb +1 -1
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2250.rb +2 -2
- data/lib/teodoro/leiaute_2/arquivo_s2299.rb +310 -0
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2300.rb +20 -2
- data/lib/teodoro/{leiaute_2_4_1 → leiaute_2}/arquivo_s2306.rb +1 -1
- data/lib/teodoro/leiaute_2/arquivo_s2399.rb +303 -0
- data/lib/teodoro/leiaute_2/arquivo_s3000.rb +41 -0
- data/lib/teodoro/obj.rb +5 -0
- metadata +23 -20
- data/lib/teodoro/leiaute_2_4_1.rb +0 -22
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c9deae607c9ff37a06e53ec8cb179d250a85ed8fda4e2480892cc4169453e43
|
4
|
+
data.tar.gz: d9f73ef82b8803e52fb33b57e4b25549d84c004e2cae59c4261e6f9694f5de6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11b1fac346b51fae9b6cc45f11881acb1e2c9c594afdabd6a943de5fe201f76f464c20bf084fb910e164d3886d2a22a02b1b0a34f28f43c98b0edab5f8591521
|
7
|
+
data.tar.gz: 17b9915e3a32d1a8dda9de0626881eb817f8476048cbe7519ebf74fab442ff43e28887edf8c3775931d060e1857d66e97f0284c79b7b7d22b13966287177566e
|
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
|
@@ -2,7 +2,17 @@ module Teodoro
|
|
2
2
|
module ArquivoDeEvento
|
3
3
|
private
|
4
4
|
|
5
|
-
|
5
|
+
def initialize(empresa:, evento:, recibo:)
|
6
|
+
@empresa = empresa
|
7
|
+
@evento = evento
|
8
|
+
@recibo = recibo
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :empresa, :evento, :recibo
|
12
|
+
|
13
|
+
def processo_de_emissao_do_evento
|
14
|
+
evento["#{noh_principal_do_evento}/ideEvento/procEmi"]
|
15
|
+
end
|
6
16
|
|
7
17
|
def criar_caminho_do_arquivo_data(nome_do_arquivo)
|
8
18
|
File.join(
|
@@ -11,6 +21,10 @@ module Teodoro
|
|
11
21
|
)
|
12
22
|
end
|
13
23
|
|
24
|
+
def destino_dos_arquivos_data
|
25
|
+
empresa.destino_dos_arquivos_data
|
26
|
+
end
|
27
|
+
|
14
28
|
def windows?
|
15
29
|
OS.windows?
|
16
30
|
end
|
@@ -2,16 +2,6 @@ module Teodoro
|
|
2
2
|
module ArquivoDeEventoDeTabela
|
3
3
|
include ArquivoDeEventoExcetoDeExclusao
|
4
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
|
14
|
-
|
15
5
|
def processar
|
16
6
|
deletar_arquivo_data_original if alteracao? || exclusao?
|
17
7
|
return if exclusao?
|
@@ -2,19 +2,6 @@ module Teodoro
|
|
2
2
|
module ArquivoDeEventoNaoPeriodico
|
3
3
|
include ArquivoDeEventoExcetoDeExclusao
|
4
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
|
17
|
-
|
18
5
|
def processar
|
19
6
|
deletar_arquivo_data_original if retificacao?
|
20
7
|
registrar_recibo
|
@@ -39,8 +26,12 @@ module Teodoro
|
|
39
26
|
de_recibo_para_nome_do_arquivo_data[numero_do_recibo_a_retificar]
|
40
27
|
end
|
41
28
|
|
29
|
+
def de_recibo_para_nome_do_arquivo_data
|
30
|
+
empresa.de_recibo_para_nome_do_arquivo_data
|
31
|
+
end
|
32
|
+
|
42
33
|
def numero_do_recibo_a_retificar
|
43
|
-
|
34
|
+
evento["#{noh_principal_do_evento}/ideEvento/nrRecibo"]
|
44
35
|
end
|
45
36
|
|
46
37
|
def registrar_recibo
|
data/lib/teodoro/arquivo_xml.rb
CHANGED
@@ -3,11 +3,11 @@ require_relative 'arquivo_de_evento_exceto_de_exclusao'
|
|
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 '
|
6
|
+
require_relative 'leiaute_2'
|
7
7
|
require_relative 'xml'
|
8
8
|
|
9
9
|
module Teodoro
|
10
|
-
class ArquivoXML
|
10
|
+
class ArquivoXML
|
11
11
|
TIPOS_DE_EVENTO_PROCESSAVEIS = %w[
|
12
12
|
S1000
|
13
13
|
S1005
|
@@ -23,23 +23,28 @@ module Teodoro
|
|
23
23
|
S2206
|
24
24
|
S2230
|
25
25
|
S2250
|
26
|
+
S2299
|
26
27
|
S2300
|
27
28
|
S2306
|
29
|
+
S2399
|
28
30
|
S3000
|
29
31
|
].freeze
|
30
32
|
|
31
33
|
private
|
32
34
|
|
33
|
-
def initialize(
|
35
|
+
def initialize(empresa:, caminho:)
|
36
|
+
@empresa = empresa
|
34
37
|
@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
38
|
end
|
38
39
|
|
39
|
-
attr_reader :
|
40
|
+
attr_reader :empresa, :caminho
|
40
41
|
|
41
42
|
public
|
42
43
|
|
44
|
+
def processavel?
|
45
|
+
TIPOS_DE_EVENTO_PROCESSAVEIS.include?(tipo_de_evento)
|
46
|
+
end
|
47
|
+
|
43
48
|
def momento_de_processamento_pelo_e_social
|
44
49
|
# otimizacao do gerenciamento de memoria
|
45
50
|
carregar_conteudo
|
@@ -54,64 +59,22 @@ module Teodoro
|
|
54
59
|
end
|
55
60
|
|
56
61
|
def processar
|
57
|
-
print "
|
58
|
-
|
59
|
-
return unless TIPOS_DE_EVENTO_PROCESSAVEIS.include?(tipo_de_evento)
|
60
|
-
|
62
|
+
Console.print "processando #{nome}.xml..."
|
61
63
|
arquivo.processar
|
62
64
|
end
|
63
65
|
|
64
66
|
private
|
65
67
|
|
68
|
+
def tipo_de_evento
|
69
|
+
@tipo_de_evento ||= nome[-6..].delete('-')
|
70
|
+
end
|
71
|
+
|
66
72
|
def carregar_conteudo
|
67
73
|
File.read(caminho)
|
68
74
|
end
|
69
75
|
|
70
76
|
def arquivo
|
71
|
-
|
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
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
def evento_de_exclusao?
|
106
|
-
tipo_de_evento == 'S3000'
|
107
|
-
end
|
108
|
-
|
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
|
-
)
|
77
|
+
classe_do_arquivo.new(empresa: empresa, evento: evento, recibo: recibo)
|
115
78
|
end
|
116
79
|
|
117
80
|
def classe_do_arquivo
|
@@ -120,10 +83,10 @@ module Teodoro
|
|
120
83
|
|
121
84
|
def modulo_do_leiaute
|
122
85
|
{
|
123
|
-
'02_04_01' =>
|
124
|
-
'02_04_02' =>
|
125
|
-
'02_05_00' =>
|
126
|
-
'
|
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
|
127
90
|
}[versao_do_leiaute_no_xml]
|
128
91
|
end
|
129
92
|
|
@@ -143,10 +106,6 @@ module Teodoro
|
|
143
106
|
@xml ||= Nokogiri::XML(carregar_conteudo)
|
144
107
|
end
|
145
108
|
|
146
|
-
def tipo_de_evento
|
147
|
-
@tipo_de_evento ||= nome[-6..].delete('-')
|
148
|
-
end
|
149
|
-
|
150
109
|
def evento
|
151
110
|
XML.new(xml_do_evento)
|
152
111
|
end
|
data/lib/teodoro/console.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
module Console
|
2
|
-
|
3
|
-
|
4
|
-
color_codes = { green: 32, red: 31 }
|
5
|
-
strings = strings.map { |string| "\e[#{color_codes[color]}m#{string}\e[0m" } if color
|
6
|
-
puts strings
|
7
|
-
end
|
2
|
+
def self.print(string = nil)
|
3
|
+
Kernel.print "\r\e[2K#{string}"
|
8
4
|
end
|
9
5
|
end
|
data/lib/teodoro/empresa.rb
CHANGED
@@ -20,6 +20,7 @@ module Teodoro
|
|
20
20
|
criar_diretorio_dos_arquivos_xml
|
21
21
|
descompactar_arquivos_de_origem
|
22
22
|
criar_diretorio_dos_arquivos_data
|
23
|
+
ordenar_arquivos_xml
|
23
24
|
processar_arquivos_xml
|
24
25
|
limpar_linha_de_feedback
|
25
26
|
end
|
@@ -27,7 +28,7 @@ module Teodoro
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def dar_feedback_para_o_usuario
|
30
|
-
|
31
|
+
puts "\e[32m#{nome_do_diretorio}\e[0m" # green
|
31
32
|
end
|
32
33
|
|
33
34
|
def nome_do_diretorio
|
@@ -63,30 +64,55 @@ module Teodoro
|
|
63
64
|
@destino_dos_arquivos_data ||= File.join(destino, 'data')
|
64
65
|
end
|
65
66
|
|
67
|
+
def ordenar_arquivos_xml
|
68
|
+
Console.print 'ordenando os arquivos XML...'
|
69
|
+
arquivos_xml.sort_by! { [_1.momento_de_processamento_pelo_e_social, _1.nome] }
|
70
|
+
end
|
71
|
+
|
66
72
|
def processar_arquivos_xml
|
67
73
|
# otimizacao do gerenciamento de memoria
|
68
74
|
arquivos_xml.shift.processar while arquivos_xml.any?
|
69
75
|
end
|
70
76
|
|
71
77
|
def arquivos_xml
|
72
|
-
@arquivos_xml ||=
|
73
|
-
|
74
|
-
|
75
|
-
ArquivoXML.new(
|
76
|
-
caminho: caminho,
|
77
|
-
destino_dos_arquivos_data: destino_dos_arquivos_data,
|
78
|
-
de_recibo_para_nome_do_arquivo_data: de_recibo_para_nome_do_arquivo_data
|
79
|
-
)
|
80
|
-
end
|
81
|
-
.sort_by { [_1.momento_de_processamento_pelo_e_social, _1.nome] }
|
78
|
+
@arquivos_xml ||= Dir[File.join(destino_dos_arquivos_xml, '*.xml')]
|
79
|
+
.map { |caminho| ArquivoXML.new(empresa: empresa, caminho: caminho) }
|
80
|
+
.select(&:processavel?)
|
82
81
|
end
|
83
82
|
|
84
|
-
def
|
85
|
-
@
|
83
|
+
def empresa
|
84
|
+
@empresa ||= Obj.new(
|
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
|
89
|
+
)
|
86
90
|
end
|
87
91
|
|
88
92
|
def limpar_linha_de_feedback
|
89
|
-
print
|
93
|
+
Console.print
|
94
|
+
end
|
95
|
+
|
96
|
+
class ContratosDeTrabalhadorSemVinculo
|
97
|
+
def <<(contrato)
|
98
|
+
contratos << contrato
|
99
|
+
end
|
100
|
+
|
101
|
+
def [](cpf_do_trabalhador:, categoria_do_trabalhador:, data:)
|
102
|
+
contratos
|
103
|
+
.select {
|
104
|
+
[_1.cpf_do_trabalhador, _1.categoria_do_trabalhador] == [cpf_do_trabalhador, categoria_do_trabalhador]
|
105
|
+
}
|
106
|
+
.sort_by(&:data_de_inicio)
|
107
|
+
.reverse
|
108
|
+
.find { _1.data_de_inicio <= data }
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def contratos
|
114
|
+
@contratos ||= []
|
115
|
+
end
|
90
116
|
end
|
91
117
|
end
|
92
118
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'leiaute_2/arquivo_s1000'
|
2
|
+
require_relative 'leiaute_2/arquivo_s1005'
|
3
|
+
require_relative 'leiaute_2/arquivo_s1010'
|
4
|
+
require_relative 'leiaute_2/arquivo_s1020'
|
5
|
+
require_relative 'leiaute_2/arquivo_s1030'
|
6
|
+
require_relative 'leiaute_2/arquivo_s1040'
|
7
|
+
require_relative 'leiaute_2/arquivo_s1050'
|
8
|
+
require_relative 'leiaute_2/arquivo_s1070'
|
9
|
+
require_relative 'leiaute_2/arquivo_s2190'
|
10
|
+
require_relative 'leiaute_2/arquivo_s2200'
|
11
|
+
require_relative 'leiaute_2/arquivo_s2205'
|
12
|
+
require_relative 'leiaute_2/arquivo_s2206'
|
13
|
+
require_relative 'leiaute_2/arquivo_s2230'
|
14
|
+
require_relative 'leiaute_2/arquivo_s2250'
|
15
|
+
require_relative 'leiaute_2/arquivo_s2299'
|
16
|
+
require_relative 'leiaute_2/arquivo_s2300'
|
17
|
+
require_relative 'leiaute_2/arquivo_s2306'
|
18
|
+
require_relative 'leiaute_2/arquivo_s2399'
|
19
|
+
require_relative 'leiaute_2/arquivo_s3000'
|
20
|
+
|
21
|
+
module Teodoro
|
22
|
+
module Leiaute_2
|
23
|
+
end
|
24
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Teodoro
|
2
|
-
module
|
2
|
+
module Leiaute_2
|
3
3
|
class ArquivoS1010
|
4
4
|
include ArquivoDeEventoDeTabela
|
5
5
|
|
@@ -18,7 +18,7 @@ module Teodoro
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def identificacao_do_arquivo_data
|
21
|
-
['RUB', "#{identificador_da_tabela_de_rubricas}
|
21
|
+
['RUB', "#{identificador_da_tabela_de_rubricas}#{codigo}"]
|
22
22
|
end
|
23
23
|
|
24
24
|
def identificador_da_tabela_de_rubricas
|