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

# Accounts Mapping

export const IntegrationDesignExportsAccountsMappingDiagram = () => {
  const [isDark, setIsDark] = useState(false);
  useEffect(() => {
    const check = () => setIsDark(document.documentElement.classList.contains("dark"));
    check();
    const observer = new MutationObserver(check);
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return () => observer.disconnect();
  }, []);
  const nodeFill = isDark ? "#212222" : "#EEF4F4";
  const nodeStroke = isDark ? "#848989" : "#212222";
  const nodeTextStyle = isDark ? ",color:#EEF4F4" : ",color:#131414";
  const linkStyle = isDark ? "" : "linkStyle default stroke:#848989,stroke-width:1px;";
  const themeVariables = {
    fontSize: "12px",
    ...isDark ? {} : {
      edgeLabelBackground: "#FAFCFC"
    }
  };
  const diagram = `
%%{init: {"themeVariables": ${JSON.stringify(themeVariables)}}}%%
flowchart TD
    A[Fetch Export Item] --> B[Resolve bookkeeping method + vendor context]

    %% Journal path
    B -->|journal| C[Process each data#91;#93;.accountingEntryLines#91;#93; line]

    C --> C1[Expense #40;debit#41; account → data#91;#93;.accountingEntryLines#91;#93; .account]

    C --> C2[Counter account determined via type + subtype, mapping rules, contraAccount, and configured accounts]

    C1 --> G[Create journal entry line]
    C2 --> G

    %% Accounts Payable path
    B -->|accounts_payable| D[Resolve vendor]

    D -->|Matched| E[Use vendor-specific AP account]

    D -->|Not matched| F[Use fallback AP account #40;configuration#41;]

    E --> H[Create AP entry]
    F --> H

    %% Styling
    style A white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style B white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style C white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style C1 white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style C2 white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style D white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style E white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style F white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style G white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
    style H white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
${linkStyle}
`;
  return <Mermaid chart={diagram} />;
};

export const NoteCallout = ({title, children}) => <div className="callout-box callout-note">
    <div className="callout-row">
      <span className="callout-icon">
        <svg width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M208,104a79.86,79.86,0,0,1-30.59,62.92A24.29,24.29,0,0,0,168,186v6a8,8,0,0,1-8,8H96a8,8,0,0,1-8-8v-6a24.11,24.11,0,0,0-9.3-19A79.87,79.87,0,0,1,48,104.45C47.76,61.09,82.72,25,126.07,24A80,80,0,0,1,208,104Z" opacity="0.2" /><path d="M176,232a8,8,0,0,1-8,8H88a8,8,0,0,1,0-16h80A8,8,0,0,1,176,232Zm40-128a87.55,87.55,0,0,1-33.64,69.21A16.24,16.24,0,0,0,176,186v6a16,16,0,0,1-16,16H96a16,16,0,0,1-16-16v-6a16,16,0,0,0-6.23-12.66A87.59,87.59,0,0,1,40,104.49C39.74,56.83,78.26,17.14,125.88,16A88,88,0,0,1,216,104Zm-16,0a72,72,0,0,0-73.74-72c-39,.92-70.47,33.39-70.26,72.39a71.65,71.65,0,0,0,27.64,56.3A32,32,0,0,1,96,186v6h64v-6a32.15,32.15,0,0,1,12.47-25.35A71.65,71.65,0,0,0,200,104Zm-16.11-9.34a57.6,57.6,0,0,0-46.56-46.55,8,8,0,0,0-2.66,15.78c16.57,2.79,30.63,16.85,33.44,33.45A8,8,0,0,0,176,104a9,9,0,0,0,1.35-.11A8,8,0,0,0,183.89,94.66Z" /></svg>
      </span>
      <div>
        {title && <div className="callout-title">
            {title}
          </div>}
        <div className="callout-body">
          {children}
        </div>
      </div>
    </div>
  </div>;

export const RememberCallout = ({title, children}) => <div className="callout-box callout-remember">
    <div className="callout-row">
      <span className="callout-icon">
        <svg width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M229.66,98.34,172.39,155.8c11.46,22.93-1.72,45.86-10.11,57a8,8,0,0,1-12,.83L42.34,105.76A8,8,0,0,1,43,93.85c29.65-23.92,57.4-10,57.4-10l57.27-57.46a8,8,0,0,1,11.31,0L229.66,87A8,8,0,0,1,229.66,98.34Z" opacity="0.2" /><path d="M235.32,81.37,174.63,20.69a16,16,0,0,0-22.63,0L98.37,74.49c-10.66-3.34-35-7.37-60.4,13.14a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33c19.64-26.1,17.75-47.32,13.19-60L235.33,104A16,16,0,0,0,235.32,81.37ZM224,92.69h0l-57.27,57.46a8,8,0,0,0-1.49,9.22c9.46,18.93-1.8,38.59-9.34,48.62L48,100.08c12.08-9.74,23.64-12.31,32.48-12.31A40.13,40.13,0,0,1,96.81,91a8,8,0,0,0,9.25-1.51L163.32,32,224,92.68Z" /></svg>
      </span>
      <div>
        {title && <div className="callout-title">
            {title}
          </div>}
        <div className="callout-body">
          {children}
        </div>
      </div>
    </div>
  </div>;

Accounts Mapping determines which **General Ledger (GL) accounts** are used to record debit and credit entries for each Export Item.

All exported expenses follow **double-entry bookkeeping**, meaning every transaction must have both:

* a debit account
* a credit (counter) account

Accounts Mapping occurs **after**:

* Export Items are fetched
* [Bookkeeping method](/docs/current/integration-design/exports/integration-design-exports-bookkeeping-method-resolution) has been resolved

## Implementation

See the corresponding how-to article for API usage and step-by-step instructions:

* [How to Apply Accounts Mapping for Export Items](/docs/current/how-tos/accounting-integrations/how-to-determine-accounts-mapping-for-as-erp-processing)

## Mapping Inputs

Accounts Mapping depends on:

* `data[].type` and `data[].subType` (e.g., `card_purchase`, `invoice`, `wallet_topup`)
* Expense category (Expense GL Account)
* Bookkeeping method:
  * `journal`
  * `accounts_payable`

## Required Account Configuration

The integration must obtain the following GL accounts from user configuration in the Accounting System:

* Pleo Wallet Account
* Pleo Out-of-Pocket Account
* Pleo Contra Account
* Accounts Payable Account (fallback)

These accounts define the base posting structure used across all Export Items.

## Vendor-Specific Accounts Payable

### When Accounts Payable Applies

If:

```json theme={null}
data[].bookkeeping.method = accounts_payable
```

the counter account is determined using vendor resolution logic.

### Vendor Resolution Logic

1. If `data[].vendor` exists:

* Match vendor in the Accounting System using:
  * `vendor.code` (preferred)
  * or `supplier.code` (legacy support)

2. If a match is found:

* Use vendor-specific Accounts Payable account

3. If no match or vendor is missing:

* Use fallback Accounts Payable account from configuration

#### Example

* Vendor = `ACME Ltd` → matched → `2901-AP-ACME`
* Vendor not found → `2000-AP-Default`

<NoteCallout title="Legacy Support">
  Some older integrations may still provide `supplier.code` for vendor matching. Use only when [applicable](/docs/current/integration-design/exports/integration-design-exports-bookkeeping-method-accounts-payable#legacy-support).
</NoteCallout>

## Expense Booking Logic

### Scope

This section defines how debit and credit accounts are assigned once:

* bookkeeping method is resolved
* (for Accounts Payable) vendor resolution is completed

### Line-Level Expense Account

Each Export Item line provides the expense (debit) account:

```json theme={null}
data[].accountingEntryLines[].account
```

### Fields

* **id** – internal Pleo account ID
* **name** – category name
* **code** – ERP-facing GL account code
* **identifier** – ERP-facing identifier

### Counter Account Sources

The counter account is determined as follows:

#### Journal Entries

If:

```pseudo theme={null}
data[].bookkeeping.method = journal
```

Counter account is determined using:

* `data[].type` + `data[].subType`
* Expense Type Mapping rules
* `data[].contraAccount` (when provided)
* configured accounts:
  * Wallet account
  * Out-of-pocket account
  * Contra account

#### Accounts Payable Entries

If:

```pseudo theme={null}
data[].bookkeeping.method = accounts_payable
```

Counter account is:

* vendor-specific AP account (if resolved)
* otherwise fallback AP account

## Mapping Rule Summary

1. Identify bookkeeping method

2. Set expense (debit) account from:
   * `data[].accountingEntryLines[].account`

3. Determine counter account:
   * journal
     * Based on Expense Type Mapping rules
     * `data[].type` + `data[].subType`
     * `data[].contraAccount` (if applicable)
     * configured wallet / out-of-pocket / contra accounts
   * Accounts Payable
     * Vendor-specific Accounts Payable account if matched
     * Otherwise fallback Accounts Payable account

### Example Mapping Table

| Export Item Type | Bookkeeping Method | Debit Account (Expense)                 | Credit Account (Counter)                   |
| ---------------- | ------------------ | --------------------------------------- | ------------------------------------------ |
| `card_purchase`  | `journal`          | `data[].accountingEntryLines[].account` | `data[].contraAccount` (wallet/bank)       |
| `invoice`        | `accounts_payable` | `data[].accountingEntryLines[].account` | Vendor AP account or fallback              |
| `wallet_topup`   | `journal`          | Wallet account                          | Contra account (direction depends on flow) |

<RememberCallout title="Counter Account Rule">
  * Each transaction always has one expense (debit) account and one counter (credit) account
  * Direction may invert for refunds or reversals as defined by mapping rules
</RememberCallout>

### Expense Type Mapping Dependency

Accounts Mapping relies on Expense Type Mapping, which defines:

* how `type` and `subType` determine accounting treatment
* how counter accounts are selected for journal entries

<IntegrationDesignExportsAccountsMappingDiagram />

## Upstream Dependencies

* Export Job has been started (status = in\_progress)
* Fetch Export Item Data (data layer)
* Bookkeeping method resolved

## Downstream Dependencies

* **Data Mapping** – ensures amounts, dates, dimensions, identifiers, and VAT/tax information are recorded correctly
* **Attachment Handling** – links receipts and supporting documentation
* **Accounting Periods** – assigns entries to the correct accounting period
* **Posting Behaviour** – determines whether entries are created as drafts or finalised
* **Export Item status update** – updates outcome of Export Item (`successful` or `failed`)
* **Export Job status update** – updates outcome of Export Job (`completed`, `completed_with_errors` or `failed`)

***

## What Comes Next?

* [Data Mapping](/docs/current/integration-design/exports/integration-design-exports-data-mapping)

***

## Related Reading

* [How to Apply Accounts Mapping for Export Items](/docs/current/how-tos/accounting-integrations/how-to-determine-accounts-mapping-for-as-erp-processing)
* [Export Integration Workflow Guide](/docs/current/guides/export-integration-workflow-guide)
* [AS/ERP Processing Workflow Guide](/docs/current/guides/accounting-system-processing-workflow-guide)

***
