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

# AFAS

> Set up the connectors in AFAS to exchange data with Payt.

To establish a connection between AFAS and Payt, a number of connectors need to be set up in AFAS. This guide explains how to create connectors in AFAS, which fields can be retrieved, and how to test them.

The connectors ensure that the information from certain fields in AFAS is passed to specific fields in Payt.

```mermaid theme={null}
flowchart LR
    subgraph AFAS["AFAS"]
        A["Fieldname\nAFAS"]
    end

    subgraph GC["GetConnector"]
        direction LR
        GCA["Fieldname\nAFAS"] --> GCP["Fieldname\nPayt"]
    end

    subgraph Payt["Payt"]
        P["Fieldname\nPayt"]
    end

    AFAS --> GC --> Payt
```

## 1. Creating Connectors

This chapter covers the steps for creating the necessary connectors in AFAS.

### 1.1. Creating a user account for Payt in AFAS

Create a new user in AFAS that will be used solely for the connection with Payt. We call this the connector user.

### 1.2. Creating an AppConnector

To establish the connection between AFAS and Payt, an AppConnector for Payt must first be created in AFAS. This AppConnector serves as a container for the group of GetConnectors from Payt.

Create this AppConnector in AFAS by navigating to:\
General -> Management -> AppConnector -> New (description e.g. Payt REST API)

Select a user group with at least the following access rights (or create a new user group with these access rights):

* Access to all administrations (General -> Administration -> Filters -> All administrations)
* Access to all dossier items (CRM -> Dossier -> Filters -> CRM - Dossier items -> All dossier items)
* Access to all definition filters (General -> Management -> Definition -> Filters -> General - execute definition -> All rights)

### 1.3. Creating a user token (For use in Payt)

A user token is also required. Create this token in AFAS by navigating to:

* General -> Management -> AppConnector -> Payt REST API -> Maintenance by client -> User tokens

Then follow the instructions on this page:\
[Manually add user token to your own app connector](https://help.afas.nl/help/NL/SE/App_Apps_Custom_Tokens_Manual.htm)

Be sure to keep the copied token on hand to enter in the onboarding wizard in Payt. If you're unsure where to insert the token in Payt, please contact your Payt implementation specialist.

### 1.4. Creating GetConnectors

The GetConnectors needed for the integration can be imported. These GetConnectors will be provided by Payt during implementation. If you use different fields, you can create your own connectors or modify the fields in the imported connector.

Import the following required GetConnectors:

* `Payt_administrations`
* `Payt_payment_conditions`
* `Payt_sales_entries_v12`
* `Payt_distribution_methods - Extended v2.0 - Tab Digital`
* `Payt_sales_invoices_for_cp_ordermanagement_v11`
* `Payt_subject_attachments`
* `Payt_Verkoopfactuurregels`

Import them as follows:

* Click General -> Output -> Management -> GetConnector
* Right-click in the GetConnectors window
* Click Actions -> Import
* Select all of the GetConnectors that are mentioned above.

For attachments, use the GetConnector `Payt_subject_attachments`.\
Additionally, there's an optional GetConnector `Payt_verstrekking` to retrieve information from the digital tab. See section 4.1.

#### Creating your own connector in AFAS

If you want to create new connectors, you can do so in AFAS via:\
General -> Output -> Management -> GetConnector -> New

### 1.5. Adding GetConnectors to the AppConnector for use

To be able to use the GetConnectors, they must be added to the AppConnector for Payt.

Do this in AFAS by going to the AppConnector you added in 1.2 and follow the same steps as in 1.4.\
General -> Management -> AppConnector -> Payt REST API -> GetConnectors -> New

### 1.6. Adding AppConnectorSubject for dossier items

To get the PDF files of the invoices into Payt, the standard AFAS connector `AppConnectorSubject` must be added to the AppConnector for Payt.

Do this in AFAS via:\
General -> Management -> AppConnector -> Payt REST API -> Connectors -> New -> AppConnectorSubject

## 2. All required AFAS fields

The Payt GetConnectors are prefilled with the most commonly used fields in AFAS to populate fields in Payt. If you want to use different AFAS fields to populate Payt and thus configure your own connectors, you can use the fields in this chapter.

### 2.1. GetConnector: `Payt_administrations`

The `Payt_administrations` connector should pass the basic data of the administration. These are the following field names:

| Field name in Payt                           | Explanation                 | Type |
| -------------------------------------------- | --------------------------- | ---- |
| **administration\_name** *(mandatory)*       | Administration name         | Text |
| **administration\_code** *(mandatory)*       | Administration code in AFAS | Text |
| **administration\_origin\_id** *(mandatory)* | Administration ID in AFAS   | Text |

### 2.2. GetConnector: `Payt_payment_conditions`

The `Payt_payment_conditions` connector can transmit the payment terms used in AFAS. On the Payt side this determines which steps are applicable to an invoice.

The field names for this connector are:

| Field name in Payt                                | Explanation                   | Type |
| ------------------------------------------------- | ----------------------------- | ---- |
| **payment\_condition\_code** *(mandatory)*        | Payment condition             | Text |
| **payment\_condition\_description** *(mandatory)* | Payment condition description | Text |

See section 4.2 for more info on payment conditions.

### 2.3. GetConnector: Payt\_subject\_attachments

For invoice attachments, use the `Payt_subject_attachments` connector. This is a linking table to match the actual attachment to an invoice via `invoice_dossier_item_extra` from the `Payt_sales_invoices` GetConnector.

These are AFAS field names:

* `attachment_id`
* `subject_id`
* `file_id`
* `file_name`

### 2.4. GetConnector: `Payt_sales_entries_v12`

The `Payt_sales_invoices` GetConnector retrieves sales entries from AFAS.

It’s possible other entries need to be retrieved as well, such as journal entries. In that case, use the `Payt_sales_entries` GetConnector. It's important to ensure only entries needed in Payt are passed through this connector. You can apply filters in the GetConnector.

All available headers can be found here (always up to date):\
/imports/csv

### 2.5. Note on debtor name/address fields

At least one of the following fields must be filled:

* `debtor_company_name`
* `debtor_firstname`
* `debtor_lastname`

Sometimes, it’s not possible to distinguish between `debtor_company_name` and `debtor_lastname` because the source system only has one name field. In that case, use `debtor_name`, optionally combined with `debtor_is_company` (value 1 or 0).

**NOTE:** If no email address is provided, but the other 4 fields are valid and filled in, no emails will be sent: only letters.

## 3. Check data for accuracy

After creating the connectors, you can check the data for accuracy.

<Steps>
  <Step title="Open the REST services URL">
    Navigate to your AFAS REST services endpoint. Replace `CLIENT_UID` with your 5-digit UID (usually present in all usernames):

    ```
    https://CLIENT_UID.AFASonlineconnector.nl/profitrestservices/
    ```

    or

    ```
    https://CLIENT_UID.rest.afas.online/profitrestservices/
    ```
  </Step>

  <Step title="Authenticate with your token">
    Click **Token Authentication** and enter the token in the following format:

    ```xml theme={null}
    <token><version>1</version><data>LONG_TOKEN_FROM_AFAS</data></token>
    ```
  </Step>
</Steps>

## 4. Additional Information

### 4.1. Digital tab

If you're using the `digital` tab in AFAS, you can use the optional connector Payt\_verstrekking to retrieve the right information. It first selects based on the sales relationship. Then, if available, the `Work email address` from Projects is used. If unavailable Subscriptions is used as a fallback, with Sales Invoices as a final fallback option.

The regular email address is used as `debtor_invoice_email`, and the reminder email as `debtor_reminder_email`.

### 4.2. Payment Conditions

If you don't want to use your default payment conditions, for example to separate direct debit invoices, you can use the field `invoice_payment_condition` with the value true/false (check this in the GetConnectors `Payt_sales_entries` and `Payt_sales_invoices`).

Payt will then match these payment conditions for you via the implementation specialist or support desk.

## 5. Questions

You may still have questions after reading this document.

Do you have questions about the expected content in the column "Fieldname Payt"? Then Payt is the right place to ask. The implementation specialist can assist you.

Do you have questions about how to set up an AppConnector or GetConnector in AFAS? Please contact your AFAS consultant.
