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

# Flex

# Access & Budget

To grant access & budget to an employee, you can do so via the [Set Access Endpoint](/api-reference/endpoints/put-apiv2employees-flexaccess).

You can control if a module is available to the employee via the `allowedModules` field.

To further restrict access to a module, we allow to override the `Default Tax Rules` by adding a `Template` to the `FlexEmployeeAccessDetails`.

## Tax Rules

### Basics

Tax rules determine the budget available to the employee for each submodule, as well as some additional settings for the `Meals` and `Mobility` module.

<Accordion title="Model">
  ```typescript theme={null}
  class FlexBaseTaxRule {
      module: FlexModuleType // Meals, Health ... ;
      budgets?: Array<FlexTaxRuleBudget> | null;
  }

  class FlexTaxRuleBudget {
      interval!: FlexBudgetInterval // Day, Month, Year;
      budget!: MonetaryAmountInput;
  }
  ```
</Accordion>

When granting access to flex, the tax rules applied for all available benefits are determined by the system via the TaxAffiliation of the company associated with the Employee.
These tax rules are maintained by become1 and kept up to date.

## Orverride default tax rules (Templates)

If you want to override the default tax rules, `Templates` come into play.

You can create a `Template` with the [Create Flex Template Endpoint](/api-reference/endpoints/post-apiv2flextax-rule-templates)

<Info>Templates are Immutable and can not be updated.</Info>

This template can then be appended to the [Set Access Endpoint](/api-reference/endpoints/put-apiv2employees-flexaccess).

<Note>The custom and default rules get merged. <br /> <br />If you define a custom tax rule for the internet module, but allow internet and meals, the custom rule for meals will apply, as well as the default rule for meals.</Note>

### All modules

As mentioned above, all modules allow the generic restriction of budgets for the `Day`, `Month` and `Year` Intervals.

<Accordion title="Model">
  ```typescript theme={null}
  class FlexBaseTaxRule {
      module: FlexModuleType // Meals, Health ... ;
      budgets?: Array<FlexTaxRuleBudget> | null;
  }

  class FlexTaxRuleBudget {
      interval!: FlexBudgetInterval // Day, Month, Year;
      budget!: MonetaryAmountInput;
  }
  ```
</Accordion>

### Meals

Since the tax regulations for meals require to limit the days per month, the `maxDaysPerMonth` field is an addition to the `MealsTaxRule`.

```typescript theme={null}
class MealsTaxRule {
    module: "MEALS"
    budgets: Array<FlexTaxRuleBudget>;
    maxDaysPerMonth: number | null
}
```

### Mobility

For mobility, it is possible to additionally specify `isOnlyPublicTransportAllowed`

```typescript theme={null}
class MealsTaxRule {
    module: "MOBILITY"
    budgets: Array<FlexTaxRuleBudget>;
    isOnlyPublicTransportAllowed: boolean | null
}
```

### Example

<AccordionGroup>
  <Accordion title="Create Template">
    `POST /api/v2/flex-tax-rule-templates`

    ```json Body theme={null}
    {
        "companyIds": ["4ac30a1c-edc8-48ad-9a4a-45ead3fec134"],
        "name" : "API_TEMPLATE_123",
        "rules" : [
            {
                "module" : "MOBILITY",
                "budgets" : [
                    {
                        "interval" : "MONTH",
                        "budget" : {
                            "value" : 10000,
                            "currency" : "EUR_CENT"
                        }

                    }
                ],
                "isOnlyPublicTransportAllowed" : true
            },
            {
                "module" : "MEALS",
                "budgets" : [
                    {
                        "interval" : "MONTH",
                        "budget" : {
                            "value" : 10000,
                            "currency" : "EUR_CENT"
                        }

                    },
                    {
                        "interval" : "DAY",
                        "budget" : {
                            "value" : 2000,
                            "currency" : "EUR_CENT"
                        }

                    }
                ],
                "maxDaysPerMonth" : 10
            },
            {
                "module" : "HOLIDAY",
                "budgets" : [
                    {
                        "interval" : "YEAR",
                        "budget" : {
                            "value" : 25000,
                            "currency" : "EUR_CENT"
                        }

                    }
                ]
            }
        ]
    }

    ```

    Resulting Template ID : "2ac30a1c-edc8-48ad-9a4a-45ead3fec132"
  </Accordion>

  <Accordion title="Set Flex Access">
    `POST /api/v2/employees/{employeeId}/flex`

    ```json Body theme={null}
    {
      "budget": {
        "value": 10000,
        "currency": "EUR_CENT"
      },
      "allowedModules": [
        "MEALS",
        "INTERNET",
        "MOBILITY",
        "HOLIDAY"
      ],
      "accumulateBudget": true,
      "flexTaxRuleTemplateId": "2ac30a1c-edc8-48ad-9a4a-45ead3fec132",
      "startDate": "2023-11-07T05:31:56Z",
      "endDate": "2023-11-07T05:31:56Z"
    }

    ```
  </Accordion>
</AccordionGroup>

## Completely overwrite flex access

By default, calling the [Set Flex Access Endpoint](/api-reference/endpoints/put-apiv2employees-flexaccess) will only overwrite the existing flex access
for the period of the input.

**Example**

| Flex Access               | stardDate & endDate |
| ------------------------- | ------------------- |
| Existing Flex Acccess (E) | Jan 2024 - Dec 2026 |
| Input (I)                 | Feb 2024 - Dec 2025 |

The resulting flex access settings would be:

| Flex Access               | stardDate & endDate |
| ------------------------- | ------------------- |
| Existing Flex Acccess (E) | Jan 2024 - Feb 2024 |
| Input (I)                 | Feb 2024 - Dec 2025 |
| Existing Flex Acccess (E) | Jan 2026 - Dec 2026 |

To prevent this, you can either send a request to the [Revoke Flex Access Endpoint](/api-reference/endpoints/delete-apiv2employees-flexaccess) before or after the updating request
to terminate all settings after the end date of the updated settings.

Setting the validUntil to null in the updating request will also overwrite all future settings.

**Example**

| Flex Access               | stardDate & endDate |
| ------------------------- | ------------------- |
| Existing Flex Acccess (E) | Jan 2024 - Dec 2026 |
| Input (I)                 | Feb 2024 - null     |

The resulting flex access settings would be:

| Flex Access               | stardDate & endDate |
| ------------------------- | ------------------- |
| Existing Flex Acccess (E) | Jan 2024 - Feb 2024 |
| Input (I)                 | Feb 2024 - null     |

## Payroll Transactions

PayrollTransactions represent allocation of receipts to a specific month in the payroll.
They can be retrieved via the [Get Payroll Transactions Endpoint](/api-reference/endpoints/get-apiv2flexpayroll-transactions)

All payroll transactions are set to the first day of the month they occur in the payroll.<br />
Meals and moblity - self proof documents are the exception.<br />
Those have the `payrollReferenceDate` set to the respective day of occurence.
