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

# Create invoices

Zenskar helps you manage billing at scale irrespective of the complexity of the pricing structures in your contracts. To generate an invoice, you must:

## Step 1: Create a customer

[Add a customer](https://www.zenskar.com/docs/customers#%EF%B8%8F-add-a-customer).

***

## Step 2: Help Zenskar ingest usage data

> 📖 Raw metrics versus aggregates
>
> **Metrics** represent all the data that you capture to analyze trends across your business and technology domains. Raw metrics are unfiltered data. Derived metrics, on the other hand, are generated when a certain combination of selection criteria (or filters) is applied on the raw metrics.
>
> **Aggregates** are derived metrics. Average, count, distinct, maximum, minimum, and sum are some selection criteria (or filters) applied on raw metrics to derive aggregates.

<Image align="center" alt="Fig. 8: Deriving aggregates from raw metrics by applying necessary filters" border={true} caption="Fig. 1: Deriving aggregates from raw metrics by applying necessary filters" src="https://files.readme.io/968123b-metering.workflow-aggregate.SQL.svg" width="70% " />

1. **Data Sources**: [We *pull* usage data from your data infrastructure](https://www.zenskar.com/docs/data-ingestion-via-data-source-connectors). This usage data can be either *raw metrics* or *aggregates*.

| Data source                                                                               | Description                                                                                                                                                                                                   |
| :---------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [**Auth0**](https://www.zenskar.com/docs/data-source-connector-for-auth0)                 | Auth0 is a flexible, drop-in solution to add authentication and authorization services to your applications.                                                                                                  |
| [**BigQuery**](https://www.zenskar.com/docs/data-source-connector-for-bigquery)           | BigQuery is a serverless and cost-effective enterprise data warehouse that works across clouds and scales with your data.                                                                                     |
| [**CockroachDB**](https://www.zenskar.com/docs/data-source-connector-for-cockroachdb)     | A distributed SQL database designed for speed, scale, and survival.                                                                                                                                           |
| [**Google Sheets**](https://www.zenskar.com/docs/data-source-connector-for-google-sheets) | An online spreadsheet editor from Google.                                                                                                                                                                     |
| [**Looker**](https://www.zenskar.com/docs/looker)                                         | Your unified business intelligence platform. Self-service. Governed. Embedded.                                                                                                                                |
| [**Metabase**](https://www.zenskar.com/docs/data-source-connector-for-metabase)           | An open-source business intelligence platform.                                                                                                                                                                |
| [**MongoDB**](https://www.zenskar.com/docs/data-source-connector-for-mongodb)             | Cross-platform document-oriented database.                                                                                                                                                                    |
| [**MySQL**](https://www.zenskar.com/docs/data-source-connector-for-mysql)                 | An open-source relational database management system.                                                                                                                                                         |
| [**PostgreSQL**](https://www.zenskar.com/docs/data-source-connector-for-postgresql)       | PostgreSQL is a powerful, open source object-relational database system with over 35 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance. |
| [**QuickBooks**](https://www.zenskar.com/docs/data-source-connector-for-quickbooks)       | An online accounting software for small businesses.                                                                                                                                                           |
| [**Redshift**](https://www.zenskar.com/docs/data-source-connector-for-redshift)           | Amazon Redshift is a data warehouse product which forms part of the larger cloud-computing platform Amazon Web Services.                                                                                      |
| [**Snowflake**](https://www.zenskar.com/docs/data-source-connector-for-snowflake)         | Data platform as a self-managed service.                                                                                                                                                                      |

2. **Raw Metrics**: [You *push* usage data to Zenskar](https://www.zenskar.com/docs/data-ingestion-via-apis). This usage data can be either *raw metrics* or *aggregates*.

| API                                                                                                              |
| :--------------------------------------------------------------------------------------------------------------- |
| [Create raw metric](https://www.zenskar.com/docs/data-ingestion-via-apis#set-up-a-data-ingestion-api-in-zenskar) |
| [Post raw metric](https://docs.zenskar.com/update/reference/create-usage-event)                                  |

3. [Finally, derive aggregates from raw metrics](https://www.zenskar.com/docs/sql-query-templates). There are two types of queries you can write:

* **Aggregate query**: SQL query to create a intermediate aggregate table, aggregates, to hold billable aggregates for all customers in a given billing period. This query is optional if your data source contains aggregates (not raw metrics).
* **Customer-specific query**: Mandatory SQL query to fetch customer-specific billable aggregates from the aggregates table.

***

## Step 3: Create products

> 🔖 Product
>
> In Zenskar, a product is any service or product you sell to your customer as part of a contract.
>
> In a [**metered product**](https://www.zenskar.com/docs/metering), you measure customer activity or consumption of resources in a given period.
>
> In a **non-metered product**, you do not measure customer activity or consumption of resources. The number of units purchased and the charges are defined in the contract.

The legal contract you sign with your customer contains details of:

* all products
* pricing models associated with those products

Based on your legal contract, [create appropriate products in Zenskar](https://www.zenskar.com/docs/products). Common pricing models are listed below:

| Pricing model                                             |
| :-------------------------------------------------------- |
| [Flat fee](https://www.zenskar.com/docs/flat-fee-pricing) |
| [Per-unit](https://www.zenskar.com/docs/per-unit-pricing) |
| [Volume](https://www.zenskar.com/docs/volume-pricing)     |
| [Tiered](https://www.zenskar.com/docs/tiered-pricing)     |
| [Package](https://www.zenskar.com/docs/package-pricing)   |
| [Matrix](https://www.zenskar.com/docs/matrix-pricing)     |

***

## Step 4: Create contracts

### Plan

Do you want a reusable contract template that can be further customized for special cases? If yes, [create a plan](https://www.zenskar.com/docs/plans).

> 🔖 Plan
>
> A plan is a reusable contract pattern that contains product and feature definitions.
>
> A plan can be used as a guide to make tangible Zenskar contracts.\
> A contract that is based on a plan will inherit all the products and features of the plan it is based on. You can override the plan values to create customized contracts.

<Image align="center" className="border" border={true} width="75% " src="https://files.readme.io/2370c22-image.png" />

### Contract

If reusable contract templates are not needed, [you can create a contract directly using products](https://www.zenskar.com/docs/contracts). Else, you can use a contract template as base to create customized contracts.

> 🔖 Contract
>
> A contract, in general, is a formal and legally binding agreement between you and your customer. This is an all-encompassing document that defines how you and your customer will conduct business. However, in Zenskar, the concept of a contract refers only to a subset of the general contract and contains data related to usage, pricing models, and other billing determinants.

| Contract types                                                                                                          |
| :---------------------------------------------------------------------------------------------------------------------- |
| [Prepaid commitment with postpaid overages](https://www.zenskar.com/docs/prepaid-commitment-with-postpaid-overages)     |
| [Prepaid subscription with postpaid overages](https://www.zenskar.com/docs/prepaid-subscription-with-postpaid-overages) |
| Documentation for many more contract types coming soon.                                                                 |

***

## Step 5: Generate invoices

[Generate invoices](https://www.zenskar.com/docs/invoices-explainer).
