# dalbaengenharia/lan-amento-notas-medi-o architecture

> Architecture diagram of the GitHub repository dalbaengenharia/lan-amento-notas-medi-o, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dalbaengenharia/lan-amento-notas-medi-o
- Repository: https://github.com/dalbaengenharia/lan-amento-notas-medi-o

## Overview

This repository automates accounts-payable invoice processing in Protheus: it selects branches and pending invoices, checks each document against its server-hosted PDF, then enters invoice, tax, and related details and reports outcomes. The main control path is visible in the sampled entry point and loop; the invoice routines and CTE handling are only partially sampled, so their internal steps are not expanded. The graph also includes the documented database lookup and AI-assisted tax/document checks as distinct capabilities.

Main entry points: [`Lancamentos/lancamentoBase.py`](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancamentoBase.py) (Base invoice posting), [`LOOP.py`](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/LOOP.py) (Branch processing), [`Lancamentos/lancar_imposto.py`](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancar_imposto.py) (Tax entry), [`main.py`](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/main.py) (Application entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Automation runtime"]
  node_main["Application entry<br/>[main.py]"]
  node_protheus_lib["Protheus browser tools"]
  node_branch_loop["Branch processing<br/>[LOOP.py]"]
  node_cleanup["Invoice cleanup<br/>[limpeza.py]"]
end

subgraph group_validation["Document validation"]
  node_document_check["Document verification<br/>[texto_notas.py]"]
  node_pdf_fetch["PDF retrieval"]
  node_llm_client["LLM requests<br/>[consulta_llm.py]"]
end

subgraph group_posting["Invoice posting"]
  node_invoice_entry["Invoice workflow<br/>[LancarNotas.py]"]
  node_invoice_base["Base invoice posting<br/>[lancamentoBase.py]"]
  node_cte_entry["CTE handling<br/>[lancamento_cte.py]"]
  node_tax_entry["Tax entry<br/>[lancar_imposto.py]"]
  node_tax_mapping["Tax mapping"]
  node_protheus_tables["ERP table helpers"]
  node_posting_report["Posting reports<br/>[relatorio.py]"]
  node_cent_adjust["Cent adjustment<br/>[ajuste_centavo.py]"]
end

subgraph group_lookups["Data lookups"]
  node_branch_list["Branch and tax lists<br/>[lista.py]"]
  node_invoice_query["Pending invoice query<br/>[consultaGeral.py]"]
  node_municipality_query["Municipality lookup"]
end

node_operator(("Operator"))
node_protheus["Protheus ERP"]
node_smb["Document file share"]
node_gemini["Gemini API"]
node_postgres[("Protheus database")]

node_operator -->|"starts"| node_main
node_main -->|"uses browser tools"| node_protheus_lib
node_main -->|"opens and logs in"| node_protheus
node_main -->|"starts processing"| node_branch_loop
node_branch_loop -->|"reads branches"| node_branch_list
node_branch_loop -->|"requests pending invoices"| node_invoice_query
node_invoice_query -->|"queries"| node_postgres
node_branch_loop -->|"selects and reviews invoices"| node_protheus
node_branch_loop -->|"dispatches invoice"| node_invoice_entry
node_branch_loop -->|"runs cleanup"| node_cleanup
node_cleanup -->|"cleans invoice state"| node_protheus
node_invoice_entry -->|"runs posting"| node_invoice_base
node_invoice_base -->|"validates document"| node_document_check
node_document_check -->|"requests PDF text"| node_pdf_fetch
node_pdf_fetch -->|"lists and downloads PDFs"| node_smb
node_document_check -->|"sends document text"| node_llm_client
node_llm_client -->|"requests analysis"| node_gemini
node_invoice_base -->|"handles CTE"| node_cte_entry
node_invoice_base -->|"enters taxes"| node_tax_entry
node_invoice_base -->|"adjusts cents"| node_cent_adjust
node_invoice_base -->|"records outcomes"| node_posting_report
node_tax_entry -->|"requests tax extraction"| node_document_check
node_tax_entry -->|"uses tax codes"| node_branch_list
node_tax_entry -->|"maps tax fields"| node_tax_mapping
node_tax_entry -->|"reads and edits grids"| node_protheus_tables
node_invoice_base -->|"enters invoice details"| node_protheus
node_municipality_query -->|"queries municipality"| node_postgres

click node_main "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/main.py"
click node_protheus_lib "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Protheus_Biblioteca.py"
click node_branch_loop "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/LOOP.py"
click node_cleanup "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/limpeza.py"
click node_invoice_entry "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/LancarNotas.py"
click node_invoice_base "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancamentoBase.py"
click node_cte_entry "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancamento_cte.py"
click node_tax_entry "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancar_imposto.py"
click node_tax_mapping "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/mapeamento_impostos.py"
click node_protheus_tables "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/tabelas/tabelas_protheus.py"
click node_posting_report "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/relatorio.py"
click node_cent_adjust "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/ajuste_centavo.py"
click node_document_check "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/verificar_notas/texto_notas.py"
click node_pdf_fetch "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/verificar_notas/consultar_notas/consultar_notas_pdf.py"
click node_llm_client "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/verificar_notas/consulta_llm/consulta_llm.py"
click node_branch_list "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Listas/lista.py"
click node_invoice_query "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/ConsultaBanco/consultaGeral.py"
click node_municipality_query "https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/ConsultaBanco/consulta_municipios.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_protheus_lib,node_branch_loop,node_cleanup toneBlue
class node_document_check,node_pdf_fetch,node_llm_client,node_postgres toneAmber
class node_invoice_entry,node_invoice_base,node_cte_entry,node_tax_entry,node_tax_mapping,node_protheus_tables,node_posting_report,node_cent_adjust,node_gemini toneMint
class node_branch_list,node_invoice_query,node_municipality_query toneRose
class node_operator,node_protheus,node_smb toneIndigo
```

## Components

### Automation runtime

- [Application entry](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/main.py): `main.py`
- [Protheus browser tools](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Protheus_Biblioteca.py): `Protheus_Biblioteca.py`
- [Branch processing](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/LOOP.py): `LOOP.py`
- [Invoice cleanup](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/limpeza.py): `limpeza.py`

### Document validation

- [Document verification](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/verificar_notas/texto_notas.py): `verificar_notas/texto_notas.py`
- [PDF retrieval](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/verificar_notas/consultar_notas/consultar_notas_pdf.py): `verificar_notas/consultar_notas/consultar_notas_pdf.py`
- [LLM requests](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/verificar_notas/consulta_llm/consulta_llm.py): `verificar_notas/consulta_llm/consulta_llm.py`

### Invoice posting

- [Invoice workflow](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/LancarNotas.py): `LancarNotas.py`
- [Base invoice posting](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancamentoBase.py): `Lancamentos/lancamentoBase.py`
- [CTE handling](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancamento_cte.py): `Lancamentos/lancamento_cte.py`
- [Tax entry](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/lancar_imposto.py): `Lancamentos/lancar_imposto.py`
- [Tax mapping](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/mapeamento_impostos.py): `Lancamentos/mapeamento_impostos.py`
- [ERP table helpers](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/tabelas/tabelas_protheus.py): `tabelas/tabelas_protheus.py`
- [Posting reports](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/relatorio.py): `Lancamentos/relatorio.py`
- [Cent adjustment](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Lancamentos/ajuste_centavo.py): `Lancamentos/ajuste_centavo.py`

### Data lookups

- [Branch and tax lists](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/Listas/lista.py): `Listas/lista.py`
- [Pending invoice query](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/ConsultaBanco/consultaGeral.py): `ConsultaBanco/consultaGeral.py`
- [Municipality lookup](https://github.com/dalbaengenharia/lan-amento-notas-medi-o/blob/main/ConsultaBanco/consulta_municipios.py): `ConsultaBanco/consulta_municipios.py`

### Other components

- **Operator**
- **Protheus ERP**
- **Document file share**
- **Gemini API**
- **Protheus database**

## Connections

- Operator → Application entry: starts
- Application entry → Protheus browser tools: uses browser tools
- Application entry → Protheus ERP: opens and logs in
- Application entry → Branch processing: starts processing
- Branch processing → Branch and tax lists: reads branches
- Branch processing → Pending invoice query: requests pending invoices
- Pending invoice query → Protheus database: queries
- Branch processing → Protheus ERP: selects and reviews invoices
- Branch processing → Invoice workflow: dispatches invoice
- Branch processing → Invoice cleanup: runs cleanup
- Invoice cleanup → Protheus ERP: cleans invoice state
- Invoice workflow → Base invoice posting: runs posting
- Base invoice posting → Document verification: validates document
- Document verification → PDF retrieval: requests PDF text
- PDF retrieval → Document file share: lists and downloads PDFs
- Document verification → LLM requests: sends document text
- LLM requests → Gemini API: requests analysis
- Base invoice posting → CTE handling: handles CTE
- Base invoice posting → Tax entry: enters taxes
- Base invoice posting → Cent adjustment: adjusts cents
- Base invoice posting → Posting reports: records outcomes
- Tax entry → Document verification: requests tax extraction
- Tax entry → Branch and tax lists: uses tax codes
- Tax entry → Tax mapping: maps tax fields
- Tax entry → ERP table helpers: reads and edits grids
- Base invoice posting → Protheus ERP: enters invoice details
- Municipality lookup → Protheus database: queries municipality
