You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Core]: Certification with Portuguese TAX Authority (SAF-T) #407
In Portugal its required to have any invoicing system to be certified by the tax authority.
Context (Environment)
Since 2021 Its mandated to as a company make invoices this system has to be certified by AT (tax office) for this certication it has to comply with certain specifications. This request is to look if its feasable to do this for invoiceplane (see: https://community.invoiceplane.com/t/topic/10457/3)
Detailed Description
What are the requirements for certification of invoicing programs?
For an invoicing program to be certified by the Tax Authority, it must meet the following requirements:
Possibility of exporting the tax audit model file (as defined by Ordinance no. 321-A/2007, of March 26); (for example, SAF-T );
Have a system that allows the recording of records of invoices or equivalent documents and sales receipts to be identified, using an asymmetric cipher algorithm and a private key known exclusively to the program producer;
Have access control to the computer system, requiring authentication for each user;
Do not have any function that, locally or remotely, allows you to change, directly or indirectly, information of a tax nature, without generating evidence added to the original information.
Comply with the technical requirements approved by order of the director general of the Tax and Customs Authority (AT).
Public key and private key used by the program to be certified.
changed the title [-]Feature Request: Certification with Portugese TAX Authority.[/-][+][Feature Request]: Certification with Portugese TAX Authority.[/+]on Dec 17, 2023
changed the title [-][Feature Request]: Certification with Portugese TAX Authority.[/-][+][Feature Request] Certification with Portugese TAX Authority.[/+]on Dec 17, 2023
Companies will have to fulfill their VAT obligations by sending their (electronic) invoices to the VAT authorities, possibly with the help of "a certified partner". In my opinion, InvoicePlane is an application for (small) companies that creates and sends (pdf and maybe later UBL or CII) invoices to their customers and not an application that (should also) help companies comply with these (national/Portuguese) VAT obligations.
changed the title [-][Feature Request] Certification with Portugese TAX Authority.[/-][+][Core]: Certification with Portuguese TAX Authority (SAF-T)[/+]on Jun 13, 2026
Story
As a Portuguese business owner using InvoicePlane, I want to export a SAF-T (PT) XML file and have the application meet AT certification requirements so that I can legally use the software for invoicing in Portugal.
v2 Context
This is a significant compliance feature with two distinct workstreams:
SAF-T XML export — generating the AuditFile XML per Portaria 321-A/2007 (and subsequent updates). This maps directly to existing v2 models: Invoice, InvoiceItem, Client (Relation model), Payment, TaxRate, Company.
AT certification — a formal process requiring: digital signing of invoice hashes with an asymmetric key (RSA), sequential hash chaining across invoices, and submission of a public key to AT. This touches the Invoice creation flow at a deep level and must not break existing invoice generation.
Both workstreams can be built incrementally. The SAF-T export is self-contained; the hash/signing requirement changes how invoices are persisted.
Acceptance Criteria
SAF-T Export
A SaftExportService produces a valid SAF-T PT XML file for a given company and date range
The XML conforms to the official AT schema (SAFTPT1.04_01.xsd or current version)
All required sections are present: Header, MasterFiles (customers, products, tax table), SourceDocuments (invoices, payments)
Export is triggerable via an Artisan command: php artisan saft:export {company} {--year=} {--month=}
Export is triggerable via a Filament action button in the Admin panel (Company settings or Reports section)
The exported file passes AT's online validator
Invoice signing (AT certification requirement)
Each invoice record stores a hash field (SHA-256 of prior hash + date + doc no + gross total, signed with RSA-1024 private key, Base64-encoded)
Hash is computed and stored at invoice creation time via an Observer or Service method
The private key is stored outside the webroot (configurable via config/ip.php)
The public key can be exported for submission to AT
No existing invoice data can be modified without generating an audit record
Which version of the SAFT-PT XSD schema should be targeted? (1.04_01 is current as of 2023)
RSA key length: AT specifies 1024-bit for the hash control field — confirm this has not been updated to 2048-bit
The formal AT certification application must be submitted by a Portuguese legal entity. @spacecabbie has offered to handle this step — this should be tracked as a separate non-code task once the technical implementation is complete.
Added to support future implementation of this request. The issue body is unchanged.
There is no SAF-T or tax-authority-certification scaffolding in the codebase today. The closest existing feature is Peppol e-invoicing config in Modules/Invoices/Config/config.php ('peppol' => ['default_provider' => env('PEPPOL_PROVIDER', 'e_invoice_be'), ...]), which targets the Belgian e-invoice.be access point — a different standard from Portuguese SAF-T XML export and digital-signature requirements. A repo-wide search for signature/cipher logic (openssl_sign, private_key) finds nothing real (only false-positive matches on Artisan $signature command properties). This is a large compliance feature (asymmetric-key invoice signing, an audit-proof change log, and a specific XML export format) that would need its own module or a dedicated Modules/Core/Compliance area — the tests below sketch the SAF-T XML export piece only, since that's the most concretely scoped sub-requirement in the issue.
Edge cases worth covering: this needs a legal/business decision (formal certification application via a Portuguese partner, per the reporter's own note) before implementation — the tests above assume the XML/signing mechanics only; certification itself is a process, not something PHPUnit can verify. Modules\Core\Models\AuditLog already exists and could underpin the "no undetected changes" requirement.
Activity
[-]Feature Request: Certification with Portugese TAX Authority.[/-][+][Feature Request]: Certification with Portugese TAX Authority.[/+][-][Feature Request]: Certification with Portugese TAX Authority.[/-][+][Feature Request] Certification with Portugese TAX Authority.[/+]Verony-makesIT commentedon Dec 18, 2023
@nielsdrost7 & @spacecabbie,
For your information: link to the Portuguese EU e-invoicing page.
Companies will have to fulfill their VAT obligations by sending their (electronic) invoices to the VAT authorities, possibly with the help of "a certified partner".
In my opinion, InvoicePlane is an application for (small) companies that creates and sends (pdf and maybe later UBL or CII) invoices to their customers and not an application that (should also) help companies comply with these (national/Portuguese) VAT obligations.
ZanzyTHEbar commentedon Aug 27, 2025
Hey! Would love to use Invoice plane, but live in Portugal. I am developer as well - what is the status on this, and are you looking for help?
nielsdrost7 commentedon Aug 27, 2025
Hey @ZanzyTHEbar,
come find me on Discord, https://discord.gg/PPzD2hTrXt
I'll fill you in.
ZanzyTHEbar commentedon Aug 30, 2025
Done. Send me a dm.
[-][Feature Request] Certification with Portugese TAX Authority.[/-][+][Core]: Certification with Portuguese TAX Authority (SAF-T)[/+]nielsdrost7 commentedon Jun 13, 2026
Planning Note — v2 Implementation
Story
As a Portuguese business owner using InvoicePlane, I want to export a SAF-T (PT) XML file and have the application meet AT certification requirements so that I can legally use the software for invoicing in Portugal.
v2 Context
This is a significant compliance feature with two distinct workstreams:
AuditFileXML per Portaria 321-A/2007 (and subsequent updates). This maps directly to existing v2 models:Invoice,InvoiceItem,Client(Relation model),Payment,TaxRate,Company.Both workstreams can be built incrementally. The SAF-T export is self-contained; the hash/signing requirement changes how invoices are persisted.
Acceptance Criteria
SAF-T Export
SaftExportServiceproduces a valid SAF-T PT XML file for a given company and date rangeHeader,MasterFiles(customers, products, tax table),SourceDocuments(invoices, payments)php artisan saft:export {company} {--year=} {--month=}Invoice signing (AT certification requirement)
hashfield (SHA-256 of prior hash + date + doc no + gross total, signed with RSA-1024 private key, Base64-encoded)config/ip.php)Implementation
Modules/Invoices/(primary) +Modules/Core/(config, command registration)Modules/Invoices/Services/SaftExportService.php— core XML builder; injectsCompany, date range; returns XML stringModules/Invoices/Services/InvoiceHashService.php— RSA signing logic; reads private key from config pathModules/Invoices/Observers/InvoiceObserver.php— callsInvoiceHashServiceoncreatingdatabase/migrations(Invoices module) — addhash VARCHAR(172),hash_control VARCHAR(172)columns toinvoicestableModules/Invoices/Console/SaftExportCommand.php— Artisan commandModules/Invoices/Filament/Company/Resources/InvoiceResource/Pages/ExportSaft.php— Filament page or actionconfig/ip.php— addsaft.private_key_path,saft.company_at_codesettingsModules/Invoices/Enums/InvoiceType.php— ensure types map to AT document type codes (FT, FR, ND, NC)Test Scenarios (PHPUnit)
Open questions for the community
nielsdrost7 commentedon Jul 16, 2026
Test Suggestions
Added to support future implementation of this request. The issue body is unchanged.
There is no SAF-T or tax-authority-certification scaffolding in the codebase today. The closest existing feature is Peppol e-invoicing config in
Modules/Invoices/Config/config.php('peppol' => ['default_provider' => env('PEPPOL_PROVIDER', 'e_invoice_be'), ...]), which targets the Belgian e-invoice.be access point — a different standard from Portuguese SAF-T XML export and digital-signature requirements. A repo-wide search for signature/cipher logic (openssl_sign,private_key) finds nothing real (only false-positive matches on Artisan$signaturecommand properties). This is a large compliance feature (asymmetric-key invoice signing, an audit-proof change log, and a specific XML export format) that would need its own module or a dedicatedModules/Core/Compliancearea — the tests below sketch the SAF-T XML export piece only, since that's the most concretely scoped sub-requirement in the issue.it_exports_invoices_for_a_period_as_saft_compliant_xml()it_signs_each_invoice_hash_with_a_private_key_known_only_to_the_instance()it_generates_evidence_when_an_invoice_is_changed_after_signing()Edge cases worth covering: this needs a legal/business decision (formal certification application via a Portuguese partner, per the reporter's own note) before implementation — the tests above assume the XML/signing mechanics only; certification itself is a process, not something PHPUnit can verify.
Modules\Core\Models\AuditLogalready exists and could underpin the "no undetected changes" requirement.