teodoro 0.50.0 → 0.51.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51abd5c742e7e100db3955d991f68118c97cbd5b3b140e662e54267ab880ae51
4
- data.tar.gz: 18a384c6ffdf1a4452342f2e56bf1b023336cccf429f4fe5f972913e1da09be9
3
+ metadata.gz: 4b56a0b10de8ab5ef5d882108e4a2a9242142e1ecb66c0ae73347746b8ebdd8f
4
+ data.tar.gz: 0de207a68296af5d14b7e6eb4973ee09f52b265606d61335dd1c7dae29bd4ad6
5
5
  SHA512:
6
- metadata.gz: 6a61c8d976d136490e0d02e6e3d64448df51f9d402a977515b59d8cf81bb1d339f1c4a3c642c1d6f379202c2dbf3c5809d5f4c529e6650e1665130f38b40e0fb
7
- data.tar.gz: 0cda08d5973babe35d3a30a56b22449595dd27c7843f69339f10a3cfcf323900c345ec3f9601de38e874b4034a092f6ad48c020eba85057e447004bcd7ecd125
6
+ metadata.gz: 13de1c51e869027efd596cab712fd97683bccd8c6cea8afc624e86d9c475abe52b81ef69bba4c042610047bb6098623f852a4270a33b28105408142112b84a75
7
+ data.tar.gz: 6de6a031a3d78e24a553d07e3e06664ad6ae71482aced0ed6d51a0682fa7beb58952f5b1c40f4365918f8da78aaae3c6a3d98200491d511ae9824fc50b14f53f
@@ -11,6 +11,10 @@ module Teodoro
11
11
 
12
12
  public
13
13
 
14
+ def operacao
15
+ :inclusao
16
+ end
17
+
14
18
  def nome
15
19
  [
16
20
  'TRA',
@@ -6,8 +6,9 @@ module Teodoro
6
6
  class ArquivoData
7
7
  private
8
8
 
9
- def initialize(diretorio:, nome:, itens_do_conteudo:)
9
+ def initialize(diretorio:, nome:, itens_do_conteudo:, operacao: :inclusao)
10
10
  @diretorio = diretorio
11
+ @operacao = operacao
11
12
  @nome = nome
12
13
  @itens_do_conteudo = itens_do_conteudo
13
14
  end
@@ -16,31 +17,59 @@ module Teodoro
16
17
 
17
18
  public
18
19
 
19
- attr_reader :nome
20
+ attr_reader :operacao, :nome
20
21
 
21
- def criar
22
- raise 'evento duplicado' if File.exist?(caminho)
22
+ def salvar
23
+ if inclusao_de_arquivo?
24
+ raise 'evento duplicado' if File.exist?(caminho)
25
+ elsif atualizacao_de_arquivo?
26
+ raise 'evento não encontrado' unless File.exist?(caminho)
27
+
28
+ salvar_conteudo_do_arquivo_original
29
+ end
23
30
 
24
31
  File.open(caminho, 'w') do |file|
25
- file.puts(conteudo_do_arquivo)
32
+ file.puts(linhas_do_arquivo)
26
33
  end
27
34
  end
28
35
 
29
36
  private
30
37
 
38
+ def inclusao_de_arquivo?
39
+ operacao == :inclusao
40
+ end
41
+
42
+ def atualizacao_de_arquivo?
43
+ operacao == :atualizacao
44
+ end
45
+
46
+ def salvar_conteudo_do_arquivo_original
47
+ chaves_valores_do_arquivo_original
48
+ end
49
+
50
+ def chaves_valores_do_arquivo_original
51
+ @chaves_valores_do_arquivo_original ||=
52
+ File
53
+ .readlines(caminho)
54
+ .to_h { _1.match(/^(.+)=(.*)$/)[1..2] }
55
+ end
56
+
31
57
  def caminho
32
58
  @caminho ||= Caminho.new(diretorio: diretorio, nome_do_arquivo: nome)
33
59
  end
34
60
 
35
- def conteudo_do_arquivo
36
- itens_de_conteudo_ajustados
37
- .map { |chave, valor, formato, opcoes| [chave, Valor.new(valor, formato: formato), opcoes] }
38
- .reject { |_chave, valor, opcoes| valor.vazio? && !opcoes[:manter_se_vazio] }
39
- .map { |chave, valor| "#{chave}=#{valor}" }
61
+ def linhas_do_arquivo
62
+ chaves_valores.map { |chave, valor| "#{chave}=#{valor}" }
40
63
  end
41
64
 
42
- def itens_de_conteudo_ajustados
43
- itens_do_conteudo.map { [_1[0], _1[1], _1.size == 1 ? :vazio : _1[2], _1[3] || {}] }
65
+ def chaves_valores
66
+ ChavesValores.new(itens_do_conteudo).then do |chaves_valores|
67
+ if inclusao_de_arquivo?
68
+ chaves_valores
69
+ elsif atualizacao_de_arquivo?
70
+ chaves_valores_do_arquivo_original.merge(chaves_valores)
71
+ end
72
+ end
44
73
  end
45
74
 
46
75
  class Caminho
@@ -64,33 +93,72 @@ module Teodoro
64
93
  end
65
94
  end
66
95
 
67
- class Valor
68
- FORMATADORES = {
69
- bool: proc { _1 ? 'True' : 'False' },
70
- data: proc { "#{_1[-2..]}/#{_1[5..6]}/#{_1[0..3]}" if _1 },
71
- data_aaaammdd: proc { _1.delete('-') if _1 },
72
- decimal: proc { _1.tr('.', ',') if _1 },
73
- mes_ano: proc { "#{_1[-2..]}/#{_1[0..3]}" if _1 },
74
- vazio: proc {}
75
- }.freeze
96
+ class ChavesValores
97
+ extend Forwardable
76
98
 
77
- private
99
+ def initialize(itens)
100
+ @itens = itens
101
+ .map { Item.new(*_1) }
102
+ .select(&:selecionar?)
103
+ .map { [_1.chave, _1.valor] }
104
+ end
105
+
106
+ def_delegators :itens, :map
78
107
 
79
- def initialize(valor, formato:)
80
- @valor = valor
81
- @formato = formato
108
+ def to_hash
109
+ itens.to_h
82
110
  end
83
111
 
84
- attr_reader :valor, :formato
112
+ private
85
113
 
86
- public
114
+ attr_reader :itens
87
115
 
88
- def vazio?
89
- to_s.empty? && formato != :vazio
90
- end
116
+ class Item
117
+ def initialize(*args)
118
+ @chave = args[0]
119
+ @valor = Valor.new(args[1], formato: args.size == 1 ? :vazio : args[2])
120
+ @opcoes = args[3] || {}
121
+ end
122
+
123
+ attr_reader :chave, :valor
124
+
125
+ def selecionar?
126
+ !valor.vazio? || opcoes[:manter_se_vazio]
127
+ end
128
+
129
+ private
130
+
131
+ attr_reader :opcoes
132
+
133
+ class Valor
134
+ FORMATADORES = {
135
+ bool: proc { _1 ? 'True' : 'False' },
136
+ data: proc { "#{_1[-2..]}/#{_1[5..6]}/#{_1[0..3]}" if _1 },
137
+ data_aaaammdd: proc { _1.delete('-') if _1 },
138
+ decimal: proc { _1.tr('.', ',') if _1 },
139
+ mes_ano: proc { "#{_1[-2..]}/#{_1[0..3]}" if _1 },
140
+ vazio: proc {}
141
+ }.freeze
142
+
143
+ private
144
+
145
+ def initialize(valor, formato:)
146
+ @valor = valor
147
+ @formato = formato
148
+ end
149
+
150
+ attr_reader :valor, :formato
151
+
152
+ public
153
+
154
+ def vazio?
155
+ to_s.empty? && formato != :vazio
156
+ end
91
157
 
92
- def to_s
93
- @to_s ||= (formato ? FORMATADORES[formato].call(valor) : valor).to_s
158
+ def to_s
159
+ @to_s ||= (formato ? FORMATADORES[formato].call(valor) : valor).to_s
160
+ end
161
+ end
94
162
  end
95
163
  end
96
164
  end
@@ -6,7 +6,7 @@ module Teodoro
6
6
  deletar_arquivo_data_original if alteracao? || exclusao?
7
7
  return if exclusao?
8
8
 
9
- criar_arquivo_data
9
+ salvar_arquivo_data
10
10
  end
11
11
 
12
12
  private
@@ -46,8 +46,8 @@ module Teodoro
46
46
  evento[noh_de_informacoes_do_evento, '*', noh_de_identificacao_do_periodo, 'iniValid']
47
47
  end
48
48
 
49
- def criar_arquivo_data
50
- arquivo_data.criar
49
+ def salvar_arquivo_data
50
+ arquivo_data.salvar
51
51
  end
52
52
 
53
53
  def inicio_da_validade
@@ -3,26 +3,32 @@ module Teodoro
3
3
  include ArquivoDeEvento
4
4
 
5
5
  def processar
6
+ return if exclusao?
7
+
6
8
  if retificado?
7
9
  processar_retificacao
8
10
  else
9
11
  registrar_arquivos_data
10
- criar_arquivos_data
12
+ salvar_arquivos_data
11
13
  end
12
14
  end
13
15
 
14
16
  private
15
17
 
18
+ def exclusao?
19
+ empresa.recibos_dos_eventos_excluidos.include?(numero_do_recibo)
20
+ end
21
+
16
22
  def retificado?
17
23
  arquivo_xml_de_retificacao
18
24
  end
19
25
 
20
26
  def arquivo_xml_de_retificacao
21
- @arquivo_xml_de_retificacao ||= arquivos_xml_por_recibo_a_retificar.delete(numero_do_recibo)
27
+ @arquivo_xml_de_retificacao ||= arquivo_xml_por_recibo_de_evento_retificado.delete(numero_do_recibo)
22
28
  end
23
29
 
24
- def arquivos_xml_por_recibo_a_retificar
25
- empresa.arquivos_xml_por_recibo_a_retificar
30
+ def arquivo_xml_por_recibo_de_evento_retificado
31
+ empresa.arquivo_xml_por_recibo_de_evento_retificado
26
32
  end
27
33
 
28
34
  def processar_retificacao
@@ -38,14 +44,15 @@ module Teodoro
38
44
  end
39
45
  end
40
46
 
41
- def criar_arquivos_data
42
- arquivos_data.shift.criar while arquivos_data.any?
47
+ def salvar_arquivos_data
48
+ arquivos_data.shift.salvar while arquivos_data.any?
43
49
  end
44
50
 
45
51
  def arquivos_data
46
52
  @arquivos_data ||= dados_dos_arquivos_data.map do |dados_do_arquivo_data|
47
53
  ArquivoData.new(
48
54
  diretorio: empresa.destino_dos_arquivos_data,
55
+ operacao: dados_do_arquivo_data.operacao,
49
56
  nome: dados_do_arquivo_data.nome,
50
57
  itens_do_conteudo: dados_do_arquivo_data.itens_do_conteudo
51
58
  )
@@ -28,7 +28,6 @@ require_relative 'leiaute/arquivo_s2306'
28
28
  require_relative 'leiaute/arquivo_s2399'
29
29
  require_relative 'leiaute/arquivo_s2500'
30
30
  require_relative 'leiaute/arquivo_s2501'
31
- require_relative 'leiaute/arquivo_s3000'
32
31
  require_relative 'leiaute/arquivo_s3500'
33
32
  require_relative 'leiaute_simplificado'
34
33
  require_relative 'xml'
@@ -94,15 +93,16 @@ module Teodoro
94
93
 
95
94
  public
96
95
 
97
- attr_reader :numero_do_recibo_a_retificar, :momento_de_processamento_pelo_e_social
96
+ attr_reader :recibo_do_evento_a_excluir, :recibo_do_evento_a_retificar, :momento_de_processamento_pelo_e_social
98
97
 
99
98
  # otimizacao do gerenciamento de memoria
100
99
  def carregar
101
100
  Console.print "carregando #{nome}.xml..." do
102
101
  evento, recibo = carregar_evento_e_recibo
103
102
 
103
+ @recibo_do_evento_a_excluir = evento['infoExclusao/nrRecEvt'] if exclusao_por_recibo?
104
104
  @retificacao = evento_retificavel? && evento['ideEvento/indRetif'] == '2'
105
- @numero_do_recibo_a_retificar = evento['ideEvento/nrRecibo'] if retificacao?
105
+ @recibo_do_evento_a_retificar = evento['ideEvento/nrRecibo'] if retificacao?
106
106
  @momento_de_processamento_pelo_e_social = recibo['processamento/dhProcessamento']
107
107
 
108
108
  validar_carregamento
@@ -111,6 +111,10 @@ module Teodoro
111
111
  tratar_excecao(e)
112
112
  end
113
113
 
114
+ def exclusao_por_recibo?
115
+ tipo_de_evento == 'S3000'
116
+ end
117
+
114
118
  def retificacao?
115
119
  @retificacao
116
120
  end
@@ -8,7 +8,7 @@ module Teodoro
8
8
 
9
9
  attr_reader :empresa, :destino
10
10
 
11
- def gerar # rubocop:disable Metrics/MethodLength
11
+ def salvar # rubocop:disable Metrics/MethodLength
12
12
  ArquivoData.new(
13
13
  diretorio: destino,
14
14
  nome: 'DADOS_GERAIS',
@@ -26,7 +26,7 @@ module Teodoro
26
26
  { manter_se_vazio: true }
27
27
  ]
28
28
  ]
29
- ).criar
29
+ ).salvar
30
30
  end
31
31
 
32
32
  private
@@ -48,13 +48,13 @@ module Teodoro
48
48
  end
49
49
 
50
50
  def processar
51
- criar_arquivo_data
51
+ salvar_arquivo_data
52
52
  end
53
53
 
54
54
  private
55
55
 
56
- def criar_arquivo_data
57
- arquivo_data.criar
56
+ def salvar_arquivo_data
57
+ arquivo_data.salvar
58
58
  end
59
59
 
60
60
  def arquivo_data # rubocop:disable Metrics/MethodLength
@@ -11,10 +11,6 @@ module Teodoro
11
11
 
12
12
  public
13
13
 
14
- def to_a
15
- contratos
16
- end
17
-
18
14
  def registrar_admissao(admissao:, inicio_de_afastamento:)
19
15
  contratos_por_matricula[admissao.matricula_do_trabalhador] =
20
16
  Contrato.new(admissao: admissao, inicio_de_afastamento: inicio_de_afastamento)
@@ -36,10 +32,6 @@ module Teodoro
36
32
  .sort_by(&:data_de_admissao)
37
33
  end
38
34
 
39
- def remover(recibo)
40
- contratos_por_matricula.delete_if { |_matricula, contratos| contratos.recibo == recibo }
41
- end
42
-
43
35
  private
44
36
 
45
37
  def contratos
@@ -11,10 +11,6 @@ module Teodoro
11
11
 
12
12
  public
13
13
 
14
- def to_a
15
- contratos
16
- end
17
-
18
14
  def registrar_inicio_de_contrato(inicio_de_contrato:, inicio_de_afastamento:)
19
15
  contratos << Contrato.new(inicio_de_contrato: inicio_de_contrato, inicio_de_afastamento: inicio_de_afastamento)
20
16
  trabalhadores << inicio_de_contrato.trabalhador
@@ -38,10 +34,6 @@ module Teodoro
38
34
  .sort_by(&:data_de_inicio)
39
35
  end
40
36
 
41
- def remover(recibo)
42
- contratos.delete_if { _1.recibo == recibo }
43
- end
44
-
45
37
  private
46
38
 
47
39
  def contratos
@@ -48,13 +48,13 @@ module Teodoro
48
48
  end
49
49
 
50
50
  def processar
51
- criar_arquivo_data
51
+ salvar_arquivo_data
52
52
  end
53
53
 
54
54
  private
55
55
 
56
- def criar_arquivo_data
57
- arquivo_data.criar
56
+ def salvar_arquivo_data
57
+ arquivo_data.salvar
58
58
  end
59
59
 
60
60
  def arquivo_data # rubocop:disable Metrics/MethodLength
@@ -41,8 +41,6 @@ module Teodoro
41
41
 
42
42
  attr_accessor :inicio_da_validade
43
43
 
44
- attr_reader :arquivos_xml_por_recibo_a_retificar
45
-
46
44
  def processar # rubocop:disable Metrics/MethodLength
47
45
  dar_feedback_para_o_usuario
48
46
  criar_diretorios_destino
@@ -51,7 +49,7 @@ module Teodoro
51
49
  classificar_arquivos_xml
52
50
  ordenar_arquivos_xml
53
51
  processar_arquivos_xml
54
- gerar_arquivo_de_dados_gerais
52
+ salvar_arquivo_de_dados_gerais
55
53
  processar_cargos_gerados
56
54
  processar_funcoes_geradas
57
55
  remover_matricula_do_nome_dos_arquivos_data_de_admissao_de_trabalhador_sem_vinculo
@@ -92,14 +90,15 @@ module Teodoro
92
90
  end
93
91
 
94
92
  def inicios_de_afastamento_por_numero_do_recibo
95
- contratos_de_trabalho
96
- .sum([], &:inicios_de_afastamento)
97
- .group_by(&:numero_do_recibo)
98
- .transform_values { _1.size == 1 ? _1.first : raise }
93
+ @inicios_de_afastamento_por_numero_do_recibo ||= {}
94
+ end
95
+
96
+ def recibos_dos_eventos_excluidos
97
+ @recibos_dos_eventos_excluidos ||= Set.new
99
98
  end
100
99
 
101
- def contratos_de_trabalho
102
- [*contratos_de_emprego, *contratos_de_trabalho_sem_vinculo]
100
+ def arquivo_xml_por_recibo_de_evento_retificado
101
+ @arquivo_xml_por_recibo_de_evento_retificado ||= {}
103
102
  end
104
103
 
105
104
  private
@@ -155,15 +154,20 @@ module Teodoro
155
154
  .map { |caminho| ArquivoXML.new(empresa: self, caminho: caminho) }
156
155
  end
157
156
 
158
- def classificar_arquivos_xml
157
+ def classificar_arquivos_xml # rubocop:disable Metrics/MethodLength
159
158
  Console.print 'classificando os arquivos XML...' do
160
159
  arquivos_xml
160
+ .tap { @arquivos_xml = [] }
161
161
  .select(&:processavel?)
162
- .partition(&:retificacao?)
163
- .then do |de_retificacao, exceto_de_retificacao|
164
- @arquivos_xml_por_recibo_a_retificar = de_retificacao.map { [_1.numero_do_recibo_a_retificar, _1] }.to_h
165
- @arquivos_xml = exceto_de_retificacao
166
- end
162
+ .each do |arquivo_xml|
163
+ if arquivo_xml.exclusao_por_recibo?
164
+ recibos_dos_eventos_excluidos << arquivo_xml.recibo_do_evento_a_excluir
165
+ elsif arquivo_xml.retificacao?
166
+ arquivo_xml_por_recibo_de_evento_retificado[arquivo_xml.recibo_do_evento_a_retificar] = arquivo_xml
167
+ else
168
+ arquivos_xml << arquivo_xml
169
+ end
170
+ end
167
171
  end
168
172
  end
169
173
 
@@ -178,8 +182,8 @@ module Teodoro
178
182
  arquivos_xml.shift.processar while arquivos_xml.any?
179
183
  end
180
184
 
181
- def gerar_arquivo_de_dados_gerais
182
- arquivo_de_dados_gerais.gerar
185
+ def salvar_arquivo_de_dados_gerais
186
+ arquivo_de_dados_gerais.salvar
183
187
  end
184
188
 
185
189
  def arquivo_de_dados_gerais
@@ -5,7 +5,7 @@ module Teodoro
5
5
 
6
6
  private
7
7
 
8
- def criar_arquivo_data
8
+ def salvar_arquivo_data
9
9
  super
10
10
 
11
11
  registrar_inicio_da_validade
@@ -8,6 +8,7 @@ module Teodoro
8
8
  def dados_dos_arquivos_data # rubocop:disable Metrics/MethodLength
9
9
  [
10
10
  Obj.new(
11
+ operacao: :inclusao,
11
12
  nome: "PRE[#{cpf_do_trabalhador}]",
12
13
  itens_do_conteudo: [
13
14
  ['NrRecibo', recibo['recibo/nrRecibo']],