> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spaceport.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Class: Invoice

[resources/invoices](../modules/resources_invoices).InvoiceClient

The InvoiceClient handles operations related to invoices, which are records of sales or usage of licensed assets.
Invoices are typically imported from external platforms (e.g., Roblox sales data) and are used as the basis
for calculating and distributing royalties to rights holders. This client can import, fetch, and even generate
mock invoice data for testing.

## Table of contents

#### Methods

* [import](#import)
* [generateMockInvoiceData](#generatemockinvoicedata)
* [generateMockCSVFile](#generatemockcsvfile)
* [getAll](#getall)

### constructor

• **new InvoiceClient**(`client`): [`InvoiceClient`](./invoice)

#### Parameters

| Name     | Type                               |
| :------- | :--------------------------------- |
| `client` | [`SpaceportSDK`](../spaceport-sdk) |

#### Returns

[`InvoiceClient`](./invoice)

## Methods

### import

▸ **import**(`params`): `Promise`\<[`ImportInvoicesResponse`](../types/import-invoices-response)>

Import invoices from a CSV file into the Directus database

This method uploads a CSV file to the backend and processes it to create
invoice records in the database. It can be used in preview mode to validate
the data before actual import.

#### Parameters

| Name     | Type                                                      | Description                                      |
| :------- | :-------------------------------------------------------- | :----------------------------------------------- |
| `params` | [`ImportInvoicesParams`](../types/import-invoices-params) | Import parameters including CSV file and options |

#### Returns

`Promise`\<[`ImportInvoicesResponse`](../types/import-invoices-response)>

Promise resolving to import results

**`Example`**

```typescript theme={null}
// Preview import without saving
const previewResult = await sdk.invoices.import({
  csvFile: csvFile,
  agreementId: 'agreement-123',
  preview: true
});

console.log(`Would import ${previewResult.invoices.length} invoices`);

// Actual import
const importResult = await sdk.invoices.import({
  csvFile: csvFile,
  agreementId: 'agreement-123',
  preview: false
});
```

### generateMockInvoiceData

▸ **generateMockInvoiceData**(`options?`): `Promise`\<[`GeneratedInvoiceCSV`](../types/generated-invoice-csv)>

Generates mock Roblox invoice data for testing purposes

This method creates realistic-looking invoice data distributed across quarters
with randomized revenue and pricing data suitable for testing royalty calculations.

#### Parameters

| Name      | Type                                                                 | Description                              |
| :-------- | :------------------------------------------------------------------- | :--------------------------------------- |
| `options` | [`GenerateInvoiceCSVOptions`](../types/generate-invoice-csv-options) | Configuration options for CSV generation |

#### Returns

`Promise`\<[`GeneratedInvoiceCSV`](../types/generated-invoice-csv)>

Promise resolving to generated CSV data and metadata

**`Example`**

```typescript theme={null}
// Generate 100 invoices across 4 quarters of 2024
const result = await sdk.invoices.generateMockInvoiceData({
  count: 100,
  startYear: 2024,
  quarters: 4,
  assetPlatformId: '123456789'
});

// Create a File object from the CSV content
const csvFile = new File([result.csvContent], 'mock-invoices.csv', {
  type: 'text/csv'
});

// Use with royalty registration
await sdk.royalties.register({
  csvFile: csvFile,
  productIds: [123, 456],
  userId: 'user-id',
  licenseeAddress: '0x...'
});
```

### generateMockCSVFile

▸ **generateMockCSVFile**(`filename?`, `options?`): `Promise`\<\{ `file`: `File` ; `metadata`: `Omit`\<[`GeneratedInvoiceCSV`](../types/generated-invoice-csv), `"csvContent"`>  }>

Generates a File object containing mock CSV data

This is a convenience method that combines generateMockInvoiceData with File creation
for direct use with file upload APIs.

#### Parameters

| Name       | Type                                                                 | Default value         | Description                              |
| :--------- | :------------------------------------------------------------------- | :-------------------- | :--------------------------------------- |
| `filename` | `string`                                                             | `'mock-invoices.csv'` | The filename for the generated file      |
| `options`  | [`GenerateInvoiceCSVOptions`](../types/generate-invoice-csv-options) | `{}`                  | Configuration options for CSV generation |

#### Returns

`Promise`\<\{ `file`: `File` ; `metadata`: `Omit`\<[`GeneratedInvoiceCSV`](../types/generated-invoice-csv), `"csvContent"`>  }>

Promise resolving to a File object and metadata

**`Example`**

```typescript theme={null}
const { file, metadata } = await sdk.invoices.generateMockCSVFile(
  'test-invoices.csv',
  { count: 50, startYear: 2024 }
);

// Use the file directly with royalty registration
await sdk.royalties.register({
  csvFile: file,
  productIds: [123],
  userId: 'user-id',
  licenseeAddress: '0x...'
});
```

### getAll

▸ **getAll**(`params?`): `Promise`\<[`Invoice`](../types/invoice)\[]>

Fetch invoices from the backend with optional filtering

This method retrieves invoice records from the database with support for
various filters including product ID, date ranges, and status.

#### Parameters

| Name     | Type                                                    | Description                             |
| :------- | :------------------------------------------------------ | :-------------------------------------- |
| `params` | [`FetchInvoicesParams`](../types/fetch-invoices-params) | Fetch parameters for filtering invoices |

#### Returns

`Promise`\<[`Invoice`](../types/invoice)\[]>

Promise resolving to array of invoices

**`Example`**

```typescript theme={null}
// Fetch invoices for specific products
const invoices = await sdk.invoices.fetch({
  product_id: [123, 456],
  status: 'published'
});

// Fetch invoices within date range
const recentInvoices = await sdk.invoices.fetch({
  date_gte: new Date('2024-01-01'),
  date_lte: new Date('2024-12-31'),
  limit: 100
});
```
