# Invoices

Invoice data from the wallet billing service. Each invoice is a periodic billing document tied to operator billing relationships. Invoices are matched to the partner via wallet ownership — an invoice is included if either the invoiced or invoicing wallet belongs to a team or operator within the partner's scope. No filters applied on `deleted_at` — deleted invoices are included so partners can filter as needed.

**SQL:** `invoices`

## Schema

| Column Name                | Data Type     | Description                                                                           |
|:---------------------------|:--------------|:--------------------------------------------------------------------------------------|
| **Primary ID**             |               |                                                                                       |
| id                         | INTEGER       | Primary key, unique identifier for each invoice                                       |
| **Other IDs**              |               |                                                                                       |
| serial_number              | VARCHAR       | Human-readable invoice serial number assigned by the billing service                  |
| invoiced_wallet_id         | INTEGER       | ID of the wallet being invoiced (the party that owes payment)                         |
| invoicing_wallet_id        | INTEGER       | ID of the wallet issuing the invoice (the party collecting payment)                   |
| invoiced_owner_id          | INTEGER       | ID of the entity that owns the invoiced wallet (team or operator)                     |
| invoicing_owner_id         | INTEGER       | ID of the entity that owns the invoicing wallet (team or operator)                    |
| pay_identifier             | VARCHAR       | Payment identifier used for matching payments to invoices                             |
| **Timestamps**             |               |                                                                                       |
| created_at                 | TIMESTAMP_NTZ | Timestamp when the invoice was created                                                |
| deleted_at                 | TIMESTAMP_NTZ | Timestamp when the invoice was soft deleted, null if not deleted                      |
| fully_paid_at              | TIMESTAMP_NTZ | Timestamp when the invoice was fully paid                                             |
| due_at                     | TIMESTAMP_NTZ | Due date for the invoice payment                                                      |
| period_from                | TIMESTAMP_NTZ | Start of the billing period covered by this invoice                                   |
| period_to                  | TIMESTAMP_NTZ | End of the billing period covered by this invoice                                     |
| **Filters**                |               |                                                                                       |
| is_invoiced_team_match     | BOOLEAN       | True if the invoiced wallet belongs to a team within the partner's scope              |
| is_invoicing_team_match    | BOOLEAN       | True if the invoicing wallet belongs to a team within the partner's scope             |
| is_invoiced_operator_match | BOOLEAN       | True if the invoiced wallet belongs to an operator within the partner's scope         |
| is_invoicing_operator_match| BOOLEAN       | True if the invoicing wallet belongs to an operator within the partner's scope        |
| **Attributes**             |               |                                                                                       |
| invoiced_owner_type        | VARCHAR       | Type of the invoiced wallet owner: TEAM or OPERATOR                                   |
| invoicing_owner_type       | VARCHAR       | Type of the invoicing wallet owner: TEAM or OPERATOR                                  |
| currency                   | VARCHAR       | Currency code of the invoice (lowercase ISO 4217)                                     |
| statement_closing_balance  | NUMBER        | Closing balance from the invoice statement in original currency                       |
| statement_payable_amount   | NUMBER        | Payable amount from the invoice statement in original currency                        |
| statement_type             | VARCHAR       | Type of the invoice statement (e.g. COMPOSITE)                                        |
| invoice_group              | VARCHAR       | Grouping category for the invoice                                                     |

## Inclusion Criteria

Invoices are included if either the invoiced or invoicing wallet belongs to a team or operator within the partner's scope (same wallet-ownership filtering as the `transactions` table).

No filters are applied on `deleted_at` — all invoices linked to the partner's teams or operators are included. Partners can filter as needed.

## Data flow

| Upstream tables  | Downstream tables |
|:-----------------|:------------------|
| `teams`          | ---               |
| `operators`      | ---               |
| `wallets`        | ---               |
