Skip to content

Commit

Permalink
Merge pull request #2 from dadosjusbr/corrige-rb-para-ro
Browse files Browse the repository at this point in the history
modificando rubricas R/B para R/O
  • Loading branch information
joellensilva authored Dec 14, 2024
2 parents e527b4f + 48f4315 commit 5ac53c1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ statusDadosjusbr>=0.1
protoDadosjusbr>=0.7
openpyxl==3.0.9
requests==2.25.1
pandas==1.2.3
pandas>=1.2.3
python-dotenv==0.20.0
protobuf==3.18.0
53 changes: 39 additions & 14 deletions src/parser.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
"""
Script responsável por iterar sobre os membros da folha,
listando cada rubrica do contracheque e das indenizações e seus respectivos valores recebidos por cada membro.
"""

import re
import number
from status import status
from coleta import coleta_pb2 as Coleta

from headers_keys import (HEADERS, INDENIZATORIAS, OBRIGATORIOS,
REMTEMP, REMUNERACAOBASICA, EVENTUALTEMP, OBRIGATORIOS)
from headers_keys import (
HEADERS,
INDENIZATORIAS,
OBRIGATORIOS,
REMTEMP,
REMUNERACAOBASICA,
EVENTUALTEMP,
OBRIGATORIOS,
)


# Listando os membros da folha de contracheque
def parse_employees(file, colect_key, month, year):
employees = {}
counter = 1
for row in file:
if "1 Remuneração" in str(row[0]):
break
if not number.is_nan(row[0]) and str(row[0]) != "Matrícula" and "MEMBROS ATIVOS" not in str(row[0]):
if (
not number.is_nan(row[0])
and str(row[0]) != "Matrícula"
and "MEMBROS ATIVOS" not in str(row[0])
):
member = Coleta.ContraCheque()
member.id_contra_cheque = colect_key + "/" + str(counter)
member.chave_coleta = colect_key
Expand All @@ -23,16 +40,16 @@ def parse_employees(file, colect_key, month, year):
member.local_trabalho = row[3]
member.tipo = Coleta.ContraCheque.Tipo.Value("MEMBRO")
member.ativo = True
member.remuneracoes.CopyFrom(
create_remuneration(row, month, year)
)
member.remuneracoes.CopyFrom(create_remuneration(row, month, year))

employees[str(row[0])] = member
counter += 1

return employees


# Listando cada rubrica da folha de indenizações e seus valores
# R = Receita; O = Outras
def remunerations(row):
remuneration_array = Coleta.Remuneracoes()
# VERBAS INDENIZATÓRIAS
Expand All @@ -56,6 +73,9 @@ def remunerations(row):
return remuneration_array


# Listando cada rubrica do contracheque e seus valores
# Apenas a Remuneração do Cargo Efetivo é do tipo B = Base
# Os demais são O, outras remunerações, ou D, descontos
def create_remuneration(row, month, year):
remuneration_array = Coleta.Remuneracoes()
# REMUNERAÇÃO BÁSICA
Expand All @@ -65,7 +85,10 @@ def create_remuneration(row, month, year):
remuneration.categoria = REMUNERACAOBASICA
remuneration.item = key
remuneration.valor = float(number.format_value(row[value]))
remuneration.tipo_receita = Coleta.Remuneracao.TipoReceita.Value("B")
if value == 4:
remuneration.tipo_receita = Coleta.Remuneracao.TipoReceita.Value("B")
else:
remuneration.tipo_receita = Coleta.Remuneracao.TipoReceita.Value("O")
remuneration_array.remuneracao.append(remuneration)
# REMUNERAÇÃO EVENTUAL OU TEMPORÁRIA
for key, value in HEADERS[EVENTUALTEMP].items():
Expand All @@ -74,21 +97,21 @@ def create_remuneration(row, month, year):
remuneration.categoria = EVENTUALTEMP
remuneration.item = key
remuneration.valor = float(number.format_value(row[value]))
remuneration.tipo_receita = Coleta.Remuneracao.TipoReceita.Value("B")
remuneration.tipo_receita = Coleta.Remuneracao.TipoReceita.Value("O")
remuneration_array.remuneracao.append(remuneration)
# OBRIGATÓRIOS/LEGAIS
for key, value in HEADERS[OBRIGATORIOS].items():
remuneration = Coleta.Remuneracao()
remuneration.natureza = Coleta.Remuneracao.Natureza.Value("D")
remuneration.categoria = OBRIGATORIOS
remuneration.item = key
remuneration.valor = abs(
float(number.format_value(row[value]))) * (-1)
remuneration.valor = abs(float(number.format_value(row[value]))) * (-1)
remuneration_array.remuneracao.append(remuneration)

return remuneration_array


# Mapeando as indenizações para cada membro da folha de contracheque
def update_employees(file_indenizacoes, employees):
for row in file_indenizacoes:
registration = str(row[0])
Expand All @@ -100,15 +123,17 @@ def update_employees(file_indenizacoes, employees):
return employees


# Executando todas as funções,
# iterando os contracheques e indenizações e retornando a folha completa
def parse(data, colect_key):
employees = {}
payroll = Coleta.FolhaDePagamento()
employees.update(parse_employees(
data.contracheques, colect_key, data.month, data.year))
employees.update(
parse_employees(data.contracheques, colect_key, data.month, data.year)
)

if len(employees) == 0:
status.exit_from_error(status.Error(
status.DataUnavailable, "Sem dados"))
status.exit_from_error(status.Error(status.DataUnavailable, "Sem dados"))

update_employees(data.indenizacoes, employees)

Expand Down

0 comments on commit 5ac53c1

Please sign in to comment.