# Stock transfers

[Stock transfer](https://developers.portos.sk/data-models#stocktransfer) refers to an operation that alters the quantity of products within storage. Various types of stock transfers are defined, each tailored to a specific purpose: increasing, decreasing, or fixing inaccuracies in stock quantity.

1. **Income**: This category signifies the purchase of goods from suppliers, leading to an increase in the stock quantity of the purchased items.
2. **Outcome**: Applies when goods are withdrawn from storage due to reasons such as expiration, etc.
3. **Transfer**: Relocation of goods from one stock location to another within the inventory.
4. **Sale**: Comparable to an "outcome," the system generates this transfer type automatically once a ticket is closed. Each sale stock transfer is associated with a single corresponding ticket.
5. **Invoice**: Similar to the "outcome" type, the "invoice" transfer may be used when goods are not directly sold through a cash register.
6. **Correction**: Generated automatically by system after finalizing of stock-taking process (closing the [stock taking](https://developers.portos.sk/api-reference/stock-takings)). Its role is to fix inaccuracies in stock quantities that were not matched during the stock-taking phase. May contain both positive and negative stock quantity changes.

## API methods

## Get stock transfers

<mark style="color:blue;">`GET`</mark> `http://{server-address}/stocktransfers`

Returns all stock transfers that matches query parameters. Result is of type [`QueryResult<StockTransfer>`](https://developers.portos.sk/data-models#queryresult).

#### Query Parameters

| Name                                | Type              | Description                                                                                                                      |
| ----------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| type                                | StockTransferType | Supports NData syntax.                                                                                                           |
| id                                  | string            | Supports NData syntax.                                                                                                           |
| $skip                               | int               | Pagination property. Describing number of records to skip from beginning of result collection.                                   |
| $take                               | int               | Pagination property. Maximum count of items to be returned.                                                                      |
| $sort                               | string\[]         | <p>Comma separated list of property names. Please see NData syntax.<br></p>                                                      |
| $count                              | bool              | If set to `true`, response will not contain `items` collection. Use to get resource count, not the resources themselves.         |
| specificSymbol                      | string            | Supports NData syntax.                                                                                                           |
| constantSymbol                      | string            | Supports NData syntax.                                                                                                           |
| variableSymbol                      | string            | Supports NData syntax.                                                                                                           |
| deliveryDate                        | DateTime          | Supports NData syntax.                                                                                                           |
| documentDate                        | DateTime          | Supports NData syntax.                                                                                                           |
| documentNumber                      | string            | Supports NData syntax.                                                                                                           |
| dueDate                             | DateTime          | Supports NData syntax.                                                                                                           |
| closedByUserName                    | string            | Filtering based on `closedBy.userName` property. Supports NData syntax.                                                          |
| closedAt                            | DateTime          | Supports NData syntax.                                                                                                           |
| createdByUserName                   | string            | Filtering based on `createdBy.userName` property. Supports NData syntax.                                                         |
| partnerCRN                          | string            | Filtering based on `partner.crn` property. Supports NData syntax.                                                                |
| companyCRN                          | string            | Filtering based on `company.crn` property. Supports NData syntax.                                                                |
| itemSourceOrDestinationPluCode      | int               | Filtering based on `sourcePlu.code` and `destinationPlu.code` properties in `items` collection. Supports NData syntax.           |
| currencyLabel                       | string            | Supports NData syntax.                                                                                                           |
| discountRate                        | decimal           | Supports NData syntax.                                                                                                           |
| paymentType                         | string            | Supports NData syntax.                                                                                                           |
| deliveryType                        | string            | Supports NData syntax.                                                                                                           |
| itemDestinationPluStockName         | string            | Filtering based on `destinationPlu.stockName` property in `items` collection. Supports NData syntax.                             |
| itemSourcePluCode                   | int               | Filtering based on `sourcePlu.code` property in `items` collection. Supports NData syntax.                                       |
| itemSourcePluStockName              | string            | Filtering based on `sourcePlu.stockName` property in `items` collection. Supports NData syntax.                                  |
| itemSourceOrDestinationPluStockName | string            | Filtering based on `sourcePlu.stockName` and `destinationPlu.stockName` properties in `items` collection. Supports NData syntax. |
| itemDestinationPluCode              | int               | Filtering based on `destinationPlu.code` property in `items` collection. Supports NData syntax.                                  |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Successful response" %}

```javascript
```

{% endtab %}
{% endtabs %}

## Get stock transfer

<mark style="color:blue;">`GET`</mark> `http://{server-address}/stocktransfers/{id}`

Result is of type [StockTransfer](https://developers.portos.sk/data-models#stocktransfer).

#### Path Parameters

| Name                                 | Type   | Description                |
| ------------------------------------ | ------ | -------------------------- |
| id<mark style="color:red;">\*</mark> | string | Stock transfer identifier. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Resource found." %}

```javascript
```

{% endtab %}

{% tab title="404: Not Found Resource is not found." %}

```javascript
{
    "title": "Zdroj nebol nájdený",
    "status": 404
}
```

{% endtab %}
{% endtabs %}

## Create stock transfer

<mark style="color:green;">`POST`</mark> `http://{server-address}/stocktransfers`

Creates new stock transfer. Result is of type [StockTransfer](https://developers.portos.sk/data-models#stocktransfer).

**Required rights**

Authorized user must have `StockTransferCreate` [right ](https://developers.portos.sk/user-rights)assigned. If stock transfer is marked as closed, additional `StockTransferClose` [right ](https://developers.portos.sk/user-rights)is required.

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

#### Request Body

| Name                                     | Type          | Description     |
| ---------------------------------------- | ------------- | --------------- |
| (body)<mark style="color:red;">\*</mark> | StockTransfer | Model to create |

{% tabs %}
{% tab title="201: Created Successfuly created." %}

```javascript
```

{% endtab %}
{% endtabs %}

## Create or update stock transfer

<mark style="color:orange;">`PUT`</mark> `http://{server-address}/stocktransfers/{id}`

Updates existing or creates new stock transfer. Result is of type [StockTransfer](https://developers.portos.sk/data-models#stocktransfer).

Stock transfer marked as closed cannot be updated.

**Required rights**

Authorized user must have assigned `StockTransferCreate` or `StockTransferUpdate` [right](https://developers.portos.sk/user-rights). If stock transfer is created by another user, additional `StockTransferUpdateAny` [right ](https://developers.portos.sk/user-rights)is required. If stock transfer is marked as closed, additional `StockTransferClose` [right ](https://developers.portos.sk/user-rights)is required.&#x20;

#### Path Parameters

| Name                                 | Type   | Description                |
| ------------------------------------ | ------ | -------------------------- |
| id<mark style="color:red;">\*</mark> | string | Stock transfer identifier. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

#### Request Body

| Name                                     | Type          | Description                |
| ---------------------------------------- | ------------- | -------------------------- |
| (body)<mark style="color:red;">\*</mark> | StockTransfer | Model to create or update. |

{% tabs %}
{% tab title="200: OK Successfuly created or updated." %}

```javascript
```

{% endtab %}
{% endtabs %}

## Delete stock transfer

<mark style="color:red;">`DELETE`</mark> `http://{server-address}/stocktransfers/{id}`

**Required rights**

Authorized user must have `StockTransferDelete` [right ](https://developers.portos.sk/user-rights)assigned.

#### Path Parameters

| Name                                 | Type   | Description                |
| ------------------------------------ | ------ | -------------------------- |
| id<mark style="color:red;">\*</mark> | string | Stock transfer identifier. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Successfuly deleted." %}

```javascript
```

{% endtab %}

{% tab title="404: Not Found Given resource was not found." %}

```javascript
{
    "title": "Zdroj nebol nájdený",
    "status": 404
}
```

{% endtab %}
{% endtabs %}
