odorico 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/bin/odorico +3 -0
  3. data/lib/odorico/arquivo_atestado_de_saude_ocupacional.rb +60 -0
  4. data/lib/odorico/arquivo_aviso_previo.rb +69 -0
  5. data/lib/odorico/arquivo_cargo.rb +60 -0
  6. data/lib/odorico/arquivo_comunicacao_de_acidente_de_trabalho.rb +86 -0
  7. data/lib/odorico/arquivo_condicao_ambiental_de_trabalho.rb +83 -0
  8. data/lib/odorico/arquivo_data.rb +251 -0
  9. data/lib/odorico/arquivo_empregado.rb +401 -0
  10. data/lib/odorico/arquivo_empregado_afastamento_inicio.rb +109 -0
  11. data/lib/odorico/arquivo_empregado_afastamento_termino.rb +102 -0
  12. data/lib/odorico/arquivo_empregado_desligamento.rb +237 -0
  13. data/lib/odorico/arquivo_empregado_historico_cadastral.rb +194 -0
  14. data/lib/odorico/arquivo_empregado_historico_contratual.rb +157 -0
  15. data/lib/odorico/arquivo_empresa.rb +158 -0
  16. data/lib/odorico/arquivo_estabelecimento.rb +138 -0
  17. data/lib/odorico/arquivo_horario.rb +69 -0
  18. data/lib/odorico/arquivo_lotacao.rb +60 -0
  19. data/lib/odorico/arquivo_trabalhador_sem_vinculo.rb +305 -0
  20. data/lib/odorico/arquivo_trabalhador_sem_vinculo_historico_contratual.rb +86 -0
  21. data/lib/odorico/arquivo_trabalhador_sem_vinculo_termino.rb +204 -0
  22. data/lib/odorico/console.rb +11 -0
  23. data/lib/odorico/gerador_de_arquivos.rb +126 -0
  24. data/lib/odorico/gerador_de_arquivos_csv.rb +25 -0
  25. data/lib/odorico/jornada.rb +21 -0
  26. data/lib/odorico/processamento.rb +375 -0
  27. data/lib/odorico/sistema_operacional.rb +33 -0
  28. data/lib/odorico/types.rb +203 -0
  29. data/lib/odorico/version.rb +3 -0
  30. data/lib/odorico.rb +115 -0
  31. metadata +184 -0
@@ -0,0 +1,203 @@
1
+ require 'dry-struct'
2
+
3
+ module Types # rubocop:disable Metrics/ModuleLength
4
+ include Dry.Types
5
+
6
+ def self.Values(*values) # rubocop:disable Naming/MethodName
7
+ Types::Any.constrained(included_in: values)
8
+ end
9
+
10
+ # True = Bool.constrained(eql: true)
11
+ # False = Bool.constrained(eql: "False")
12
+
13
+ TrueFalseBool =
14
+ Types::Strict::Bool.enum(
15
+ true => 'True',
16
+ false => 'False'
17
+ )
18
+ True = TrueFalseBool.constrained(eql: 'True')
19
+ False = TrueFalseBool.constrained(eql: 'False')
20
+
21
+ ZeroUmBool =
22
+ Types::Strict::Bool.enum(
23
+ true => '1',
24
+ false => '0'
25
+ )
26
+ ZeroBool = ZeroUmBool.constrained(eql: '0')
27
+
28
+ SNBool =
29
+ Types::Strict::Bool.enum(
30
+ true => 'S',
31
+ false => 'N'
32
+ )
33
+ NBool = SNBool.constrained(eql: 'N')
34
+
35
+ Date =
36
+ Types::Strict::Date.constructor do |value|
37
+ next nil if value.nil?
38
+
39
+ case value
40
+ when /\d{8}/
41
+ ::Date.new(value[0..3].to_i, value[4..5].to_i, value[6..7].to_i)
42
+ when /^\d{4}-\d{2}-\d{2}$/
43
+ ::Date.parse(value)
44
+ else
45
+ # "1991-08-31".to_date
46
+ ::Date.new(value[6..9].to_i, value[3..4].to_i, value[0..1].to_i)
47
+ end
48
+ end
49
+
50
+ AnoMesDia =
51
+ Types::Strict::String.constructor do |data_nao_formatada|
52
+ "#{data_nao_formatada[0..3]}-#{data_nao_formatada[4..5]}-#{data_nao_formatada[6..7]}"
53
+ end
54
+
55
+ AnoMes =
56
+ Types::Strict::String.constructor do |data_nao_formatada|
57
+ "#{data_nao_formatada[3..6]}-#{data_nao_formatada[0..1]}"
58
+ end
59
+
60
+ Integer = Types::Coercible::Integer
61
+ Decimal =
62
+ Types::Strict::String.constructor do |value|
63
+ next nil if value.nil?
64
+
65
+ valor = Types::Coercible::Decimal[value.sub('.', '').sub(',', '.')]
66
+
67
+ format('%#.2f', valor)
68
+ end
69
+
70
+ # TIPO_INSCRICAO_EMPREGADOR = %w[1].freeze
71
+ # TipoInscricaoEmpregador = Types.Values(*TIPO_INSCRICAO_EMPREGADOR)
72
+ TipoInscricaoEmpregador = Types::Strict::Integer.enum(
73
+ 1 => '1'
74
+ )
75
+ # INDICATIVO_SITUACAO_PJ = %w[0].freeze
76
+ # IndicativoSituacaoPJ = Types.Values(*INDICATIVO_SITUACAO_PJ)
77
+
78
+ IndicativoCooperativa = Types::Strict::Integer.enum(
79
+ 0 => '0'
80
+ )
81
+
82
+ CLASSIFICACAO_TRIBUTARIA = %w[01 02 03 04 99].freeze
83
+ ClassificacaoTributaria = Types.Values(*CLASSIFICACAO_TRIBUTARIA)
84
+
85
+ # Validações do Estabelecimento
86
+ TipoInscricaoEstabelecimento = Types::Strict::Integer.enum(
87
+ 1 => '1'
88
+ )
89
+
90
+ ContratacaoPessoaComDeficiencia = Types::Strict::Integer.enum(
91
+ 0 => '0',
92
+ 2 => '2',
93
+ 9 => '9'
94
+ )
95
+
96
+ # Validações Empregado
97
+ TIPO_LOGRADOURO = %w[V].freeze
98
+ TipoLogradouro = Types.Values(*TIPO_LOGRADOURO)
99
+
100
+ TipoAdmissao = Types::Strict::Integer.enum(
101
+ 1 => '1',
102
+ 2 => '2'
103
+ )
104
+
105
+ IndicativoAdmissao = Types::Strict::Integer.enum(
106
+ 1 => '1'
107
+ )
108
+
109
+ TipoRegimeJornada = Types::Strict::Integer.enum(
110
+ 1 => '1',
111
+ 2 => '2',
112
+ 3 => '3',
113
+ 4 => '4'
114
+ )
115
+
116
+ NaturezaAtividade = Types::Strict::Integer.enum(
117
+ 1 => '1',
118
+ 2 => '2'
119
+ )
120
+
121
+ OpcaoFgts = Types::Strict::Integer.enum(
122
+ 1 => '1'
123
+ )
124
+
125
+ UnidadeSalarial = Types::Strict::Integer.enum(
126
+ 5 => '5'
127
+ )
128
+
129
+ TipoContrato = Types::Strict::Integer.enum(
130
+ 1 => '1',
131
+ 2 => '2'
132
+ )
133
+
134
+ TipoInscricaoLocalTrabalho = Types::Strict::Integer.enum(
135
+ 1 => '1'
136
+ )
137
+
138
+ TIPOS_DE_JORNADA = {
139
+ 1 => '1',
140
+ 2 => '2',
141
+ 3 => '3',
142
+ 9 => '9'
143
+ }.freeze
144
+
145
+ TIPOS_DE_JORNADA_LEIAUTE_SIMPLIFICADO = {
146
+ 2 => '2',
147
+ 3 => '3',
148
+ 4 => '4',
149
+ 5 => '5',
150
+ 6 => '6',
151
+ 7 => '7',
152
+ 9 => '9'
153
+ }.freeze
154
+
155
+ TipoJornada = Types::Strict::Integer.enum(
156
+ TIPOS_DE_JORNADA.merge(TIPOS_DE_JORNADA_LEIAUTE_SIMPLIFICADO)
157
+ )
158
+
159
+ JornadaTempoParcial = Types::Strict::Integer.enum(
160
+ 0 => '0',
161
+ 1 => '1',
162
+ 2 => '2',
163
+ 3 => '3'
164
+ )
165
+
166
+ CATEGORIA_TRABALHADOR = %w[101 103 105 111].freeze
167
+ CategoriaTrabalhador = Types.Values(*CATEGORIA_TRABALHADOR)
168
+
169
+ CATEGORIA_TRABALHADOR_TSV = %w[701 723 901].freeze
170
+ CategoriaTrabalhadorTsv = Types.Values(*CATEGORIA_TRABALHADOR_TSV)
171
+
172
+ CATEGORIA_TRABALHADOR_TSV_CONTRATUAL = %w[723].freeze
173
+ CategoriaTrabalhadorTsvContratual = Types.Values(*CATEGORIA_TRABALHADOR_TSV_CONTRATUAL)
174
+
175
+ CAUSAS_DESLIGAMENTO = %w[01 02 03 04 05 06 07 09 10 14 17 27 33].freeze
176
+ CausasDesligamento = Types.Values(*CAUSAS_DESLIGAMENTO)
177
+
178
+ # Lotações Tributárias
179
+ TIPO_LOTACAO = %w[01].freeze
180
+ TipoLotacao = Types.Values(*TIPO_LOTACAO)
181
+
182
+ TipoInscricaoLotacao = Types::Strict::Integer.enum(
183
+ 1 => '1'
184
+ )
185
+
186
+ TipoRegimeTrabalhista = Types::Strict::Integer.enum(
187
+ 1 => '1'
188
+ )
189
+
190
+ TipoRegimePrevidenciario = Types::Strict::Integer.enum(
191
+ 1 => '1'
192
+ )
193
+
194
+ # Horários
195
+ TipoIntervalo = Types::Strict::Integer.enum(
196
+ 1 => '1',
197
+ 2 => '2'
198
+ )
199
+
200
+ # Afastamentos
201
+ MOTIVOS_AFASTAMENTO_TRABALHADOR = %w[01 03 06 15 17 19 20 21 29 33 35 37].freeze
202
+ MotivosAfastamento = Types.Values(*MOTIVOS_AFASTAMENTO_TRABALHADOR)
203
+ end
@@ -0,0 +1,3 @@
1
+ module Odorico
2
+ VERSION = '1.0.0'.freeze
3
+ end
data/lib/odorico.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'net/http'
2
+
3
+ require_relative 'odorico/version'
4
+ require_relative 'odorico/console'
5
+
6
+ module Odorico
7
+ def self.[](args)
8
+ Execucao.new(args)[]
9
+ end
10
+
11
+ class Execucao
12
+ NOME_DO_PROGRAMA = 'odorico'.freeze
13
+
14
+ private
15
+
16
+ def initialize(args)
17
+ @args = args
18
+ end
19
+
20
+ attr_reader :args, :grupo_da_empresa_no_e_social_informado
21
+
22
+ public
23
+
24
+ def []
25
+ validar_argumentos
26
+ solicitar_grupo_de_empresa_no_e_social
27
+ validar_grupo_da_empresa_no_e_social
28
+ validar_que_nao_ha_nova_versao_disponivel
29
+ processar
30
+ end
31
+
32
+ private
33
+
34
+ def validar_argumentos
35
+ return if args.size == 1
36
+
37
+ puts "#{NOME_DO_PROGRAMA} [diretório dos arquivos .data]"
38
+ puts "Saiba mais em sites.google.com/fortestecnologia.com.br/#{NOME_DO_PROGRAMA}."
39
+ exit
40
+ end
41
+
42
+ def solicitar_grupo_de_empresa_no_e_social
43
+ puts 'ATENÇÃO! Antes de prosseguir, execute os seguintes passos:'
44
+ puts '1. Entre no portal do eSocial desta empresa;'
45
+ puts '2. Acesse a tela que exibe o grupo ao qual a empresa pertence (Empregador/Contribuinte > Consulta obrigatoriedade);' # rubocop:disable Layout/LineLength
46
+ puts '3. Salve o print dessa tela na pasta que possui os dados de importação dessa empresa;'
47
+ puts '4. Informe aqui o grupo da empresa:'
48
+ @grupo_da_empresa_no_e_social_informado = $stdin.gets.chomp
49
+ end
50
+
51
+ def validar_grupo_da_empresa_no_e_social
52
+ return if grupo_valido?
53
+
54
+ puts "\e[1m[ERRO] Grupo inválido: \"#{grupo_da_empresa_no_e_social_informado}\".\e[22m\n\n"
55
+ exit
56
+ end
57
+
58
+ def grupo_valido?
59
+ %w[2 3].include?(grupo_da_empresa_no_e_social_informado)
60
+ end
61
+
62
+ def validar_que_nao_ha_nova_versao_disponivel
63
+ return unless nova_versao_disponivel?
64
+
65
+ puts 'Há uma nova versão disponível. Execute o seguinte comando para atualizar:',
66
+ "gem update #{NOME_DO_PROGRAMA}"
67
+ exit
68
+ end
69
+
70
+ def nova_versao_disponivel?
71
+ carregar_versao_disponivel != versao_corrente
72
+ end
73
+
74
+ def carregar_versao_disponivel
75
+ Console.print 'Verificando se há nova versão disponível...' do
76
+ carregar_dados_da_gem
77
+ .then { JSON.parse(_1) }
78
+ .then { _1['version'] }
79
+ end
80
+ rescue StandardError
81
+ puts 'Erro! Não foi possível carregar a versão disponível. Verifique seu acesso à internet.'
82
+ exit
83
+ end
84
+
85
+ def carregar_dados_da_gem
86
+ Net::HTTP.get(uri_da_gem)
87
+ end
88
+
89
+ def uri_da_gem
90
+ URI("https://rubygems.org/api/v1/gems/#{NOME_DO_PROGRAMA}.json")
91
+ end
92
+
93
+ def versao_corrente
94
+ Odorico::VERSION
95
+ end
96
+
97
+ def processar
98
+ puts "\n[INFO] Buscando arquivos do diretório '#{diretorio_data}'"
99
+ pp Processamento.new(diretorio_data, grupo_da_empresa_no_e_social_informado.to_i).executar
100
+ puts "[INFO] Validação finalizada.\n\n"
101
+ rescue ArquivoEmpresa::GrupoDaEmpresaNaoDefinido,
102
+ ArquivoEmpresa::GrupoDetectadoDiferenteDoGrupoInformado => e
103
+ imprimir_erro(e.message)
104
+ end
105
+
106
+ def diretorio_data
107
+ @diretorio_data ||= args[0]
108
+ end
109
+
110
+ def imprimir_erro(mensagem)
111
+ puts "\e[1m[ERRO] #{mensagem}.\e[22m\n\n"
112
+ mensagem
113
+ end
114
+ end
115
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: odorico
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fortes Tecnologia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-struct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ executables:
128
+ - odorico
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - bin/odorico
133
+ - lib/odorico.rb
134
+ - lib/odorico/arquivo_atestado_de_saude_ocupacional.rb
135
+ - lib/odorico/arquivo_aviso_previo.rb
136
+ - lib/odorico/arquivo_cargo.rb
137
+ - lib/odorico/arquivo_comunicacao_de_acidente_de_trabalho.rb
138
+ - lib/odorico/arquivo_condicao_ambiental_de_trabalho.rb
139
+ - lib/odorico/arquivo_data.rb
140
+ - lib/odorico/arquivo_empregado.rb
141
+ - lib/odorico/arquivo_empregado_afastamento_inicio.rb
142
+ - lib/odorico/arquivo_empregado_afastamento_termino.rb
143
+ - lib/odorico/arquivo_empregado_desligamento.rb
144
+ - lib/odorico/arquivo_empregado_historico_cadastral.rb
145
+ - lib/odorico/arquivo_empregado_historico_contratual.rb
146
+ - lib/odorico/arquivo_empresa.rb
147
+ - lib/odorico/arquivo_estabelecimento.rb
148
+ - lib/odorico/arquivo_horario.rb
149
+ - lib/odorico/arquivo_lotacao.rb
150
+ - lib/odorico/arquivo_trabalhador_sem_vinculo.rb
151
+ - lib/odorico/arquivo_trabalhador_sem_vinculo_historico_contratual.rb
152
+ - lib/odorico/arquivo_trabalhador_sem_vinculo_termino.rb
153
+ - lib/odorico/console.rb
154
+ - lib/odorico/gerador_de_arquivos.rb
155
+ - lib/odorico/gerador_de_arquivos_csv.rb
156
+ - lib/odorico/jornada.rb
157
+ - lib/odorico/processamento.rb
158
+ - lib/odorico/sistema_operacional.rb
159
+ - lib/odorico/types.rb
160
+ - lib/odorico/version.rb
161
+ homepage:
162
+ licenses: []
163
+ metadata:
164
+ rubygems_mfa_required: 'true'
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '2.7'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubygems_version: 3.2.15
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: ''
184
+ test_files: []