# Invoicing

## Invoicing

### **Prerequisites**

Certain integrations need to be in place before the set-up and testing of an invoice integration:

* Transfer of voyage related data to the accounting system.
* Synchronization of business partners between Dataloy VMS and the accounting system.
* Exchange rate transfer to Dataloy VMS.
* Map accounts between Dataloy VMS and the accounting system.

### **Integration Set-Up**

When invoices are posted in Dataloy VMS, the document status is automatically set to Ready-for-Posting. Set up a scheduled task and use the request under Data Transaction to extract invoices and credit notes that are ready for posting. When an invoice is transferred to accounting, update the status to Posted.

### **Reverse Invoice**

To reverse a posted invoice you need the document key and POST as in the example below

```
POST /Document/{document key}/reverse
```

### **Dissolve Invoice**

To dissolve an assembled invoice you need the document key and POST as in the example below

```
POST /Document/{document key}/dissolve
```

### **Data Transaction**

To get invoices that are ready for posting in [Webhooks](https://api.dataloy.com/api-release-8.18/dataloy-rest-api/webhooks) the following subscription can be created:

```
{
    "eventType":"U",
    "user": the user code to be used in the subscription,
    "objectType":"Document",
    "expression": "dlpObject.getInvoicingStatus() != null && dlpObject.getInvoicingStatus().getStatusTypeCode().equals(\"RFP\") && (dlpObject.getDocumentType().getDocumentType().equals(\"INO\") || dlpObject.getDocumentType().getDocumentType().equals(\"INI\") || dlpObject.getDocumentType().getDocumentType().equals(\"CRI\") || dlpObject.getDocumentType().getDocumentType().equals(\"CRO\"))",
    "url": "your webhook url"
}
```

Alternatively, a scheduled job can be set-up to use the following request:

### **Get invoices that are ready for posting to accounting**

| `GET /Document?filter=invoicingStatus.statusTypeCode(EQ)RFP&filter=documentType.documentType(IN)(INI,INO,CRI,CRO)` |
| ------------------------------------------------------------------------------------------------------------------ |

### **Payment Terms**

There will be only one Document object in the API despite two payment terms for an invoice (for example 95/5 percent). However, the Document will have two documentPaymentTerms objects in the Document.documentPaymentTerms list.

To create two documents when integrating:

1. Loop on paymentTerms and create one document for each payment term.
2. Calculate the following values:
   * *dueDate*: document.documentPaymentTerms.dueDate<br>
   * *documentAmount*: document.documentAmount \* document.documentPaymentTerms.percentage / 100<br>
   * *companyCurrencyAmount*: document.companyCurrencyAmount \* document.documentPaymentTerms.percentage / 100<br>
   * *sourceCurrencyAmount*: document.sourceCurrencyAmount \* document.documentPaymentTerms.percentage / 100

### **Test Data**

Test data for invoicing integration can be generated in the Dataloy VMS finance module (Accounts Receivable, Accounts Payable and Hire Payable).

### **Post Transaction**&#x20;

When an invoice is successfully transferred to an accounting system, the document status must be updated to *Posted* in Dataloy VMS. This is done in a PUT request:

### **Update status to posted for a specific invoice**

```
PUT request on /Document/{key}
  
{
    "invoicingStatus": "POS"
}
```
