# Invoice Status Management

The Status of your Invoice and Invoice Line Item records can change based on a number of factors, including, for claimed Invoices, how much has been paid via the NDIS.

At Maica, we don't think this is something that you should have to determine, calculate and manage manually......Rather, the system (insert Maica) should be able to use the record attributes, interpreting the values of certain fields to derive or set the `Status` value dynamically.  Saving you both time and uncertainty in having to figure out the most appropriate `Status` for your `Invoice` and `Invoice Line Item` records.

{% hint style="danger" %}
If you would like to introduce your own `Status` values to the `Invoice` and/or `Invoice Line Item` records, you will need to **deactivate** the Flows described below and create your own to perform the same function.

We would recommend you do this in a **Sandbox** first and perform extensive end-to-end testing to ensure that your Flow(s) support your required functionality.
{% endhint %}

## Invoice Line Item Status Management

The `Invoice Line Item` `Status` is managed by a Salesforce Flow.  A Flow is a handy, declarative (meaning codeless) tool that lets you develop automated processes for specific actions.  In this scenario, we have used a Flow to examine the `Invoice line Item` record, when it is created and updated, to review specific fields and set the `Status` value accordingly.

In the Maica package, the name of this specific Flow is `Maica - Invoice Line Item Status Management`.  You can access this Flow via Salesforce Setup, as seen below.

<figure><img src="https://558904096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKdn9R0jFmixyPeVowFpF%2Fuploads%2F7N27RT5fastDuKO1H9hM%2Fimage.png?alt=media&#x26;token=f674baba-015a-40a9-978f-3ab0d8a69534" alt=""><figcaption><p>The Maica - Invoice Line Item Status Management Flow in Salesforce Setup</p></figcaption></figure>

The Flow uses various **Roll-Up Summary** fields on the `Invoice Line Item` that summarise or consolidate data from the related `Payment Request` record(s).  These Roll-Up Summary fields are:

| Invoice Field | Logic                                                                   |
| ------------- | ----------------------------------------------------------------------- |
| `Line Total`  | **Calculated** field (Total of `GST Amount` + `Amount`)                 |
| `Claim Count` | **COUNT** of `Payment Request` records WHERE `NDIS Reference` != `null` |
| `Paid Amount` | **SUM** of `Payment Request` records WHERE `Status` = `Paid`            |

### Invoice Line Item Status Definition

The table below breaks down each `Invoice Line Item` `Status` value and how it is managed by the Flow.  Essentially, when the conditions in the `Logic` column are satisfied, the Flow will be triggered and apply the value from the `Status Value` column.

<table><thead><tr><th width="157">Status Value</th><th width="231">Description</th><th>Logic</th></tr></thead><tbody><tr><td><code>Entered</code></td><td>The <code>Invoice Line Item</code> has been entered into the system but not been submitted for claiming.</td><td><code>Line Total</code> > 0 AND<br><code>Claim Count</code> = 0 AND<br><code>Claim Balance Formula</code> = <code>Line Total</code> AND<br><code>Paid Amount</code> = 0</td></tr><tr><td><code>Claimed</code></td><td>The <code>Invoice Line Item</code> has been submitted for claiming.</td><td><code>Line Total</code> > 0 AND<br><code>Claim Count</code> > 0 AND<br><code>Claim Balance Formula</code> = <code>Line Total</code> AND<br><code>Paid Amount</code> = 0</td></tr><tr><td><code>Partially Paid</code></td><td>This means a partial amount of the <code>Invoice Line Item</code> has been approved by PRODA but not the full amount (<code>Line Total</code>).</td><td><code>Line Total</code> > 0 AND<br><code>Claim Count</code> > 0 AND<br><code>Claim Balance Formula</code> > 0 AND<br><code>Claim Balance Formula</code> &#x3C; <code>Line Total</code> AND<br><code>Paid Amount</code> &#x3C; <code>Line Total</code></td></tr><tr><td><code>Fully Paid</code></td><td>This means the full amount claimed from PRODA has been approved for payment.</td><td><code>Line Total</code> > 0 AND<br><code>Claim Count</code> > 0 AND<br><code>Claim Balance Formula</code> &#x3C;= 0 AND<br><code>Paid Amount</code> >= <code>Line Total</code></td></tr><tr><td><code>Not Paid</code></td><td>This means this <code>Invoice Line Item</code> has not been approved for payment.</td><td><code>Line Total</code> > 0 AND<br><code>Claim Count</code> > 0 AND<br><code>Claim Balance Formula</code> > 0 AND<br><code>Claim Balance Formula</code> = <code>Line Total</code> AND <br><code>Paid Amount</code> &#x3C; 0</td></tr></tbody></table>

#### Claim Balance Formula

The Claim Balance formula logic is below:

{% code overflow="wrap" %}

```
IF(ISBLANK( maica__Paid_Amount__c ), maica__Line_Total__c, maica__Line_Total__c - maica__Paid_Amount__c)
```

{% endcode %}

## Invoice Status Management

The `Invoice` `Status` is managed exactly the same way as the `Line Item`, just a different Flow is used.  The Flow uses various **Roll-Up Summary** fields on the `Invoice` that summarise or consolidate data from the related `Invoice Line Item` record(s).  These Roll-Up Summary fields are:

| Invoice Field                | Logic                                                                      |
| ---------------------------- | -------------------------------------------------------------------------- |
| `Total Line Items`           | **COUNT** of `Invoice Line Item` records                                   |
| `Total Not Paid Items`       | **COUNT** of `Invoice Line Item` records WHERE `Status` = `Not Paid`       |
| `Total Partially Paid Items` | **COUNT** of `Invoice Line Item` records WHERE `Status` = `Partially Paid` |
| `Total Fully Paid Items`     | **COUNT** of `Invoice Line Item` records WHERE `Status` = `Fully Paid`     |

In the Maica package, the Flow is called `Maica - Invoice Status Management`.&#x20;

### Invoice Status Definition

The table below breaks down each `Invoice` `Status` value and how it is managed by the Flow.

| Status Value | Description                                                                   | Logic                                                                                                             |
| ------------ | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `Entered`    | Default value.                                                                |                                                                                                                   |
| `Cancelled`  | Means the Invoice has been manually `Cancelled`.                              | `Cancelled` = `TRUE`                                                                                              |
| `Not Paid`   | None of the associated `Invoice Line Item` records have recieved any payment. | <p><code>Total Line Items</code> > 0 AND<br><code>Total Line Items</code> = <code>Total Not Paid Items</code></p> |

Funding Structure = Agency Managed

| `Partially Paid` | The `Amount` from the associated `Invoice Line Item` record(s) has been partially claimed.  There is a `Claim Balance` remaining. | <p><code>Funding Structure</code> = <code>Agency Managed</code></p><p><code>AND</code></p><p><code>Total Line Items</code> > 0 <br>AND<br>(<br><code>Total Line Items</code> >= <code>Total Partially Paid Items</code> AND<br><code>Total Partially Paid Items</code> > 0<br>) <br>OR<br>(<br><code>Total Fully Paid Items ></code> 0 AND<br><code>Total Fully Paid Items</code> < <code>Total Line Items</code><br>)</p> |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Fully Paid`     | The `Amount` from the associated `Invoice Line Item` record(s) has been fully claimed.  There is zero `Claim Balance` remaining.  | <p><code>Funding Structure</code> = <code>Agency Managed</code></p><p>AND</p><p><code>Total Line Items</code> > 0 AND<br><code>Total Line Items</code> = <code>Total Fully Paid Items</code></p>                                                                                                                                                                                                                           |

Funding Structure <> Agency Managed

| `Partially Paid` | Payment Amount less than Total Amount.                 | <p><code>Funding Structure</code> <> <code>Agency Managed</code></p><p>AND</p><p><code>(Total Line Items</code> > 0 <br>AND<br>(<br><code>Total Line Items</code> >= <code>Total Partially Paid Items</code> AND<br><code>Total Partially Paid Items</code> > 0<br>) <br>OR<br>(<br><code>Total Fully Paid Items ></code> 0 AND<br><code>Total Fully Paid Items</code> < <code>Total Line Items</code><br>)) </p><p>OR</p><p><code>(Payment Amount</code> > 0</p><p>AND</p><p><code>Payment Amount</code> < <code>Total Amount)</code></p> |
| ---------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Fully Paid`     | Payment Amount greater than or equals to Total Amount. | <p><code>Funding Structure</code> <> <code>Agency Managed</code></p><p>AND</p><p><code>(Total Line Items</code> > 0 AND<br><code>Total Line Items</code> = <code>Total Fully Paid Items)</code></p><p>OR</p><p><code>(Payment Amount</code> > 0</p><p>AND</p><p><code>Payment Amount</code> >= <code>Total Amount)</code></p>                                                                                                                                                                                                              |
