# Receipts

Receipt data from the wallet service. Each receipt is linked to a wallet transaction via `transaction_id`. Contains receipt identifiers, financial totals, line item entries, and price breakdowns. No filters applied — deleted and inactive receipts are included so partners can filter as needed.

**SQL:** `receipts`

## Schema

| Column Name     | Data Type     | Description                                                                                   |
|:----------------|:--------------|:----------------------------------------------------------------------------------------------|
| **Primary ID**  |               |                                                                                               |
| id              | INTEGER       | Primary key, unique identifier for each receipt                                               |
| **Other IDs**   |               |                                                                                               |
| identifier      | VARCHAR       | Unique 36-character identifier (UUID) used by the Monta API for receipt lookups and PDF URLs |
| receipt_number  | VARCHAR       | Human-readable receipt number assigned by the wallet service                                  |
| transaction_id  | INTEGER       | ID of the associated wallet transaction (NOT NULL — every receipt has one)                    |
| currency_id     | INTEGER       | ID of the currency used in the receipt                                                        |
| **Timestamps**  |               |                                                                                               |
| created_at      | TIMESTAMP_NTZ | Timestamp when the receipt was created                                                        |
| updated_at      | TIMESTAMP_NTZ | Timestamp when the receipt was last updated                                                   |
| deleted_at      | TIMESTAMP_NTZ | Timestamp when the receipt was soft deleted, null if not deleted                               |
| **Attributes**  |               |                                                                                               |
| sub_total       | NUMBER        | Subtotal amount before VAT                                                                    |
| vat             | NUMBER        | VAT amount on the receipt                                                                     |
| total           | NUMBER        | Total amount including VAT                                                                    |
| type            | VARCHAR       | Receipt type: SIMPLE or FULL                                                                  |
| version         | INTEGER       | Version number of the receipt                                                                 |
| language        | VARCHAR       | Language of the receipt                                                                       |
| entries         | VARIANT       | JSON containing receipt line item entries (title, subtitle, amount, subAmount)                 |
| price_breakdown | VARIANT       | JSON with price specifications, fees, and adjustments                                         |
| is_active       | INTEGER       | Whether the receipt is active (1) or inactive (0)                                             |

## Inclusion Criteria

Receipts are included if their `transaction_id` matches a transaction belonging to the partner's teams or operators (same wallet-ownership filtering as the `transactions` table).

No filters are applied on `deleted_at` or `is_active` — all receipts linked to the partner's transactions are included. Partners can filter these columns as needed.

## Data flow

| Upstream tables  | Downstream tables |
|:-----------------|:------------------|
| `transactions`   | ---               |

## Alignment
### Monta API
- Aligns with Monta API [get/receipts/by-charge/{chargeId}](https://developer.monta.com/api/v1/receipts/by-charge/chargeId) endpoint
- The API endpoint returns a single receipt per completed charge, fetched via the charge's transaction
- API response fields: `id`, `identifier`, `version`, `total`, `entries`, `currency`, `pdf_url`, `vat`, `created_at`
- The Monta DW table includes additional fields not in the API response: `receipt_number`, `sub_total`, `price_breakdown`, `language`, `is_active`, `deleted_at`

## Joining receipts to charges

To link a receipt to a charge session, join through the `transactions` table:

```sql
select
    r.id as receipt_id
    , r.identifier as receipt_identifier
    , r.receipt_number
    , r.total
    , t.reference_id as charge_id
from receipts r
inner join transactions t
    on r.transaction_id = t.id
where t.reference_type = 'CHARGE'
```
