feat: e-invoice services, SDI channels, inbox, polling and conservation (#74 #75 #76 #77 #79)

Adds the company tables of the electronic invoice and the services that drive them:
the builder turns an issued document into the FatturaPA model, the service generates,
checks and sends the file through the channel chosen by the routing rules (with a
fallback) and applies the SDI notifications to the e-invoice and its document. The
channel settings keep their secrets protected and out of the audit trail; a job reads
the PEC mailbox and the intermediaries every 15 minutes, storing supplier invoices in
the inbox and acknowledging a message only once all its files are kept. The inbox
registers received invoices through the purchase import, and the conservation export
packs a period with a SHA-256 index. A rejected invoice can now be corrected and
generated again; the courtesy PDF embeds the XML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-13 12:20:59 +01:00
1 parent 709bb13532
commit fb12411404
24 files changed
+4016 -10

No files matched your search

+175
View File
@@ -733,6 +733,7 @@ Migrazioni applicate in ordine:
- `core` 20261113001 `create_inventory` (M20261113_001_CreateInventory)
- `core` 20261113002 `create_ledger` (M20261113_002_CreateLedger)
- `core` 20261113003 `create_treasury` (M20261113_003_CreateTreasury)
- `core` 20261113004 `create_einvoicing` (M20261113_004_CreateEInvoicing)
#### `attachments`
@@ -1241,6 +1242,180 @@ Migrazioni applicate in ordine:
- indice unico `ux_dunning_levels_level` su `level`
#### `e_invoice_channels`
| Colonna | Tipo | Null | Default | Note |
|---|---|---|---|---|
| `id` | Int64 | no | | chiave primaria, identity |
| `code` | String(20) | no | | |
| `enabled` | Bool | no | `false` | |
| `paused` | Bool | no | `false` | |
| `mailbox` | String(254) | sì | | |
| `smtp_host` | String(200) | sì | | |
| `smtp_port` | Int32 | no | `465` | |
| `imap_host` | String(200) | sì | | |
| `imap_port` | Int32 | no | `993` | |
| `tls` | Bool | no | `true` | |
| `user_name` | String(254) | sì | | |
| `protected_password` | Text | sì | | |
| `exchange_address` | String(254) | sì | | |
| `archive_folder` | String(100) | sì | | |
| `endpoint` | String(300) | sì | | |
| `protected_certificate` | Text | sì | | |
| `protected_certificate_password` | Text | sì | | |
| `protected_api_key` | Text | sì | | |
| `test_environment` | Bool | no | `false` | |
| `last_check_at` | DateTimeUtc | sì | | |
| `last_check_ok` | Bool | sì | | |
| `last_check_message` | String(1000) | sì | | |
| `last_poll_at` | DateTimeUtc | sì | | |
| `last_poll_message` | String(1000) | sì | | |
| `last_poll_failed` | Bool | no | `false` | |
| `is_demo` | Bool | no | `false` | |
| `created_at` | DateTimeUtc | no | | |
| `created_by` | String(100) | sì | | |
| `updated_at` | DateTimeUtc | sì | | |
| `updated_by` | String(100) | sì | | |
| `row_version` | Int64 | no | `1` | |
- indice unico `ux_e_invoice_channels_code` su `code`
#### `e_invoice_conservation`
| Colonna | Tipo | Null | Default | Note |
|---|---|---|---|---|
| `id` | Int64 | no | | chiave primaria, identity |
| `from_date` | Date | no | | |
| `to_date` | Date | no | | |
| `file_count` | Int32 | no | `0` | |
| `file_name` | String(100) | no | | |
| `hash` | String(64) | no | | |
| `size` | Int64 | no | `0` | |
| `created_at` | DateTimeUtc | no | | |
| `created_by` | String(100) | sì | | |
| `updated_at` | DateTimeUtc | sì | | |
| `updated_by` | String(100) | sì | | |
| `row_version` | Int64 | no | `1` | |
#### `e_invoice_inbox`
| Colonna | Tipo | Null | Default | Note |
|---|---|---|---|---|
| `id` | Int64 | no | | chiave primaria, identity |
| `file_name` | String(100) | no | | |
| `hash` | String(64) | no | | |
| `content` | Bytes | no | | |
| `metadata_file_name` | String(100) | sì | | |
| `metadata` | Bytes | sì | | |
| `exchange_id` | String(40) | sì | | |
| `received_at` | DateTimeUtc | no | | |
| `channel_code` | String(20) | sì | | |
| `supplier_vat` | String(30) | sì | | |
| `supplier_name` | String(200) | sì | | |
| `document_type` | String(10) | sì | | |
| `number` | String(40) | sì | | |
| `document_date` | Date | sì | | |
| `total_amount` | Decimal(19,6) | sì | | |
| `party_id` | Int64 | sì | | |
| `status` | String(40) | no | | |
| `purchase_document_id` | Int64 | sì | | |
| `error` | String(500) | sì | | |
| `is_demo` | Bool | no | `false` | |
| `created_at` | DateTimeUtc | no | | |
| `created_by` | String(100) | sì | | |
| `updated_at` | DateTimeUtc | sì | | |
| `updated_by` | String(100) | sì | | |
| `row_version` | Int64 | no | `1` | |
- indice `ix_e_invoice_inbox_file` su `file_name`
- indice `ix_e_invoice_inbox_status` su `status`, `received_at`
- indice unico `ux_e_invoice_inbox_hash` su `hash`
#### `e_invoice_notifications`
| Colonna | Tipo | Null | Default | Note |
|---|---|---|---|---|
| `id` | Int64 | no | | chiave primaria, identity |
| `e_invoice_id` | Int64 | sì | | -> `e_invoices` (Cascade) |
| `code` | String(4) | no | | |
| `file_name` | String(100) | no | | |
| `invoice_file_name` | String(100) | sì | | |
| `exchange_id` | String(40) | sì | | |
| `received_at` | DateTimeUtc | no | | |
| `outcome` | String(10) | sì | | |
| `description` | String(1000) | sì | | |
| `errors` | Text | sì | | |
| `channel_code` | String(20) | sì | | |
| `content` | Bytes | no | | |
| `is_demo` | Bool | no | `false` | |
| `created_at` | DateTimeUtc | no | | |
| `created_by` | String(100) | sì | | |
| `updated_at` | DateTimeUtc | sì | | |
| `updated_by` | String(100) | sì | | |
| `row_version` | Int64 | no | `1` | |
- indice `ix_e_invoice_notifications_invoice` su `e_invoice_id`
- indice unico `ux_e_invoice_notifications_file` su `file_name`
#### `e_invoice_routing`
| Colonna | Tipo | Null | Default | Note |
|---|---|---|---|---|
| `id` | Int64 | no | | chiave primaria, identity |
| `position` | Int32 | no | `0` | |
| `condition` | String(40) | no | | |
| `value` | String(40) | sì | | |
| `channel_code` | String(20) | no | | |
| `fallback_channel_code` | String(20) | sì | | |
| `disabled` | Bool | no | `false` | |
| `is_demo` | Bool | no | `false` | |
| `created_at` | DateTimeUtc | no | | |
| `created_by` | String(100) | sì | | |
| `updated_at` | DateTimeUtc | sì | | |
| `updated_by` | String(100) | sì | | |
| `row_version` | Int64 | no | `1` | |
#### `e_invoices`
| Colonna | Tipo | Null | Default | Note |
|---|---|---|---|---|
| `id` | Int64 | no | | chiave primaria, identity |
| `family` | String(40) | no | | |
| `document_id` | Int64 | no | | |
| `kind` | String(40) | no | | |
| `document_number` | String(40) | sì | | |
| `document_date` | Date | no | | |
| `party_id` | Int64 | sì | | |
| `document_type` | String(10) | no | | |
| `file_name` | String(60) | no | | |
| `progressive` | Int64 | no | | |
| `format` | String(10) | no | | |
| `recipient_code` | String(7) | sì | | |
| `recipient_pec` | String(254) | sì | | |
| `total_amount` | Decimal(19,6) | no | `0` | |
| `status` | String(40) | no | | |
| `channel_code` | String(20) | sì | | |
| `exchange_id` | String(40) | sì | | |
| `message_id` | String(200) | sì | | |
| `generated_at` | DateTimeUtc | no | | |
| `sent_at` | DateTimeUtc | sì | | |
| `last_notification_at` | DateTimeUtc | sì | | |
| `last_message` | String(1000) | sì | | |
| `send_attempts` | Int32 | no | `0` | |
| `content` | Bytes | no | | |
| `superseded` | Bool | no | `false` | |
| `is_demo` | Bool | no | `false` | |
| `created_at` | DateTimeUtc | no | | |
| `created_by` | String(100) | sì | | |
| `updated_at` | DateTimeUtc | sì | | |
| `updated_by` | String(100) | sì | | |
| `row_version` | Int64 | no | `1` | |
- indice `ix_e_invoices_document` su `family`, `document_id`
- indice `ix_e_invoices_exchange` su `exchange_id`
- indice `ix_e_invoices_status` su `superseded`, `status`
- indice unico `ux_e_invoices_file` su `file_name`
#### `exchange_rates`
| Colonna | Tipo | Null | Default | Note |