Skip to content

Commit 794cdce

Browse files
Adicionado valor total no final da planilha
1 parent 37d0064 commit 794cdce

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ PDF2PlanilhaVet/
6666
|----------------------------------|------------|----------|
6767
| Fosfatase Alcalina - Meg | 06/04/2024 | R$ 20,00 |
6868
| A.L.T. (TGP) - Meg | 06/04/2024 | R$ 20,00 |
69-
| Pesquisa de hemoparasitas - Meg | 26/04/2025 | R$ 30,00 |
69+
| Pesquisa de hemoparasitas - Meg | 26/04/2025 | R$ 30,00 |
7070

7171
---
7272

gerar_planilha.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
print(f"Erro ao extrair dados de {arquivo}: {e}")
5151
continue
5252

53-
data_frame_da_planilha = pd.DataFrame(dados_da_planilha)
53+
dados_da_planilha_com_total = calcula_total(dados_da_planilha)
54+
55+
data_frame_da_planilha = pd.DataFrame(dados_da_planilha_com_total)
5456
os.makedirs(pasta_saida, exist_ok=True)
5557

5658
data_hoje = datetime.now().strftime("%Y-%m-%d")

utils/functions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,26 @@ def verifica_se_tem_tabela(caminho_pdf):
118118
return True
119119
return False
120120

121+
122+
def calcula_total(dados_da_planilha):
123+
total = 0
124+
125+
for item in dados_da_planilha:
126+
valor_str = item['Valor'].replace('R$', '').replace(',', '.').strip()
127+
if valor_str:
128+
try:
129+
total += float(valor_str)
130+
except ValueError:
131+
pass # ignora se não for número válido
132+
133+
total_formatado = f'R$ {total:.2f}'.replace('.', ',')
134+
135+
dados_da_planilha.append({
136+
'Exames': 'TOTAL',
137+
'Data': '',
138+
'Valor': total_formatado
139+
})
140+
141+
print("Total: ", total_formatado)
142+
143+
return dados_da_planilha

0 commit comments

Comments
 (0)