# Set the invoice number expression

## Overview

[Video: Set the invoice number expression](https://www.youtube.com/watch?v=A7Jha_qfa5U)

This flow describes how to set the invoice number expression of a facility. Care uses the expression to give each new [invoice](https://docs.ohc.network/concepts/billing/invoice.md) of the facility its number. The expression is part of the [billing settings](https://docs.ohc.network/concepts/billing/billing-settings.md) of the facility.

## Pre-requisites

* You are a member of the facility in any role, or of its geographic organization or an organization above it.
* You have the permissions listed below.

## Permissions

| Permission | Access |
| - | - |
| Can Update on Facility | Lets you save the billing settings of the facility. It counts when you hold it through a role in the facility's root organization, which Care names Administration. A role in the facility's geographic organization, or in an organization above it, also counts. A role that you hold only in a department or team of the facility does not count. By default, the Facility Admin, Administrator and Staff roles hold it. Every member of the facility can open the page and use its buttons. Without this permission, Care refuses the save with a message that contains "You do not have permission to create Facilities". |

## Steps

### 1. Open the invoice number expression

In the facility sidebar, under **Administration**, select **Settings**.

Care shows the settings sidebar of the facility.

In the **Billing** group, select **Billing**.

Under **Configuration**, select **Settings**.

The **Invoice Number Expression** page opens. It shows the saved expression, or "-" if the facility has none.

Under **Supported variables:**, the page lists three variables. It also shows an example expression.

![The facility sidebar, with Settings outlined under Administration](/assets/images/set-invoice-number-expression-1-9fd35be0b8e26d50957e3b617117a6fc.webp)

### 2. Start editing

Select **Edit**.

![The Invoice Number Expression page, with the supported variables, the current expression and the Edit button outlined](/assets/images/set-invoice-number-expression-2-31b770c6d8f01d426eee46351a8d192b.webp)

### 3. Type the expression

Type the expression in the box.

Start the expression with the letter f.

After the f, write the text of the invoice number in quotes.

Put each variable in braces inside the quotes.

| Variable | What Care puts in its place |
| - | - |
| `{invoice_count}` | The number of invoices that the facility already has, of every status, including refund invoices. It is 0 for the first invoice. |
| `{current_year_yy}` | The year in which Care creates the invoice, in 2 digits. |
| `{current_year_yyyy}` | The year in which Care creates the invoice, in 4 digits. |

If the facility already has invoices, `{invoice_count}` counts them too. The next number continues from that count.

To start the numbers at 1, write `{invoice_count + 1}`.

To start at a different number, add that number, as in `{invoice_count + 100}`.

When you save, Care tests the expression with sample values: 1234 invoices and the year 2025. Some examples below show the number that these sample values give.

| Expression | Result |
| - | - |
| `f'#INV-{invoice_count + 100}-{current_year_yy}'` | The example on the page. For a facility with no invoices, the numbers start at 100. Each number ends with the year in 2 digits. With the sample values, #INV-1334-25. |
| `f'INV-{invoice_count + 1}'` | INV-1 for the first invoice of the facility, then INV-2. With the sample values, INV-1235. |
| `f'CGH-{current_year_yy}-{invoice_count + 1:05d}'` | CGH-25-01235 with the sample values. The `:05d` part adds zeros in front of the number until it has 5 digits. |

Note: Do not leave out the f at the start. Without it, Care saves the expression but does not fill in the variables. Every invoice then gets the same text, such as `INV-{invoice_count}`.

Note: Use no names other than the three variables on the page. Care refuses an expression that uses another name, such as `f'INV-{invoice_number}'`.

Note: Do not call a function. Care refuses an expression such as `'INV-' + str(invoice_count + 1)`. Care also refuses text with braces that is not in quotes, such as `INV-{invoice_count}`.

![The expression box, with an expression that starts with f and pads the invoice count to five digits](/assets/images/set-invoice-number-expression-3-b9cb445389b5ec7c5e225599e5729f91.webp)

### 4. Save the expression

Select **Save**.

Note: **Save** stays disabled while the box is empty.

To stop without a change, select **Cancel**. Care keeps the saved expression.

If Care accepts the expression, the page shows **Saved successfully**.

If Care refuses the save, the page shows **Error**, and Care shows a message. Use this table to find what to do.

| If the message contains | What to do |
| - | - |
| Invalid Expression | Check that the text is in quotes. Check that each name in braces is one of the three variables. Check that the expression calls no function. Compare it with the example on the page. |
| You do not have permission to create Facilities | You do not hold the permission listed above in the right organization. Ask for a role that has it in the facility's root organization, Administration. |

![The Invoice Number Expression page after saving, with the new expression and the Saved successfully message](/assets/images/set-invoice-number-expression-4-45108cad49ca76754cb8dbc950be5705.webp)

## Expected Outcome

* The page shows **Saved successfully**.
* From then on, Care numbers each new invoice of the facility from the expression when it creates the invoice.
* Refund invoices for returned items get their numbers from the same expression.
* The expression applies only to this facility. Other facilities keep their own numbering.

## Related

Concepts:

* [Billing settings](https://docs.ohc.network/concepts/billing/billing-settings.md)
* [Invoice](https://docs.ohc.network/concepts/billing/invoice.md)

Flows:

* [Create an invoice](https://docs.ohc.network/flows/billing/invoice/create-invoice.md)
* [Set the discount configuration](https://docs.ohc.network/flows/billing/billing-settings/set-discount-configuration.md)
* [Create a discount code](https://docs.ohc.network/flows/billing/billing-settings/create-discount-code.md)
* [Edit or delete a discount code](https://docs.ohc.network/flows/billing/billing-settings/edit-or-delete-discount-code.md)
* [Create a discount component](https://docs.ohc.network/flows/billing/billing-settings/create-discount-component.md)
* [Edit or delete a discount component](https://docs.ohc.network/flows/billing/billing-settings/edit-or-delete-discount-component.md)
