# Production plan

Production planning

::: info
Каждый ответ приходит в общем конверте — `code`, `message`, `messages`, `status_code`, `time` — а полезная нагрузка лежит в `data`. Таблицы ниже описывают содержимое `data`.
:::

## POST /production-plan/create

Create a production plan for a given year and organization. This is a year-keyed upsert — if a plan already exists for the given (year, organization_id) it is updated rather than duplicated. Items carry per-product monthly targets.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/production-plan/create' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "year": 2025,
  "organization_id": "string",
  "items": [
    {
      "product_id": "string",
      "months": []
    }
  ]
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-plan/create', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "year": 2025,
    "organization_id": "string",
    "items": [
      {
        "product_id": "string",
        "months": []
      }
    ]
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "POST",
    "https://api.bito.uz/integration-api/integration/api/v2/production-plan/create",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "year": 2025,
        "organization_id": "string",
        "items": [
            {
                "product_id": "string",
                "months": [],
            },
        ],
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "year": 2025,
  "organization_id": "string",
  "items": [
    {
      "product_id": "string",
      "months": []
    }
  ]
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-plan/create');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `year` | `number` | Да | The production plan year (e.g. 2025). Together with organization_id this is the upsert key — submitting a plan for the same year + organization updates the existing plan. |
| `organization_id` | `string` | Да | Organization ObjectId this plan belongs to |
| `note` | `string` | Нет | Optional free-text note |
| `items` | `object[]` | Да | Per-product monthly production targets (at least one item required) |
| `items[].product_id` | `string` | Да | Product ObjectId |
| `items[].months` | `object[]` | Да | Monthly target entries for this product (at least one month required) |
| `items[].months[].amount` | `number` | Да | Planned production quantity for this month |
| `items[].months[].month_number` | `number` | Да | Calendar month (1 = January … 12 = December). Each month_number must be unique within an item. |

```json
{
  "year": 2025,
  "organization_id": "string",
  "note": "string",
  "items": [
    {
      "product_id": "string",
      "months": []
    }
  ]
}
```

**Ответ**

| Поле | Тип | Описание |
|---|---|---|
| `_id` | `string` | Production plan ObjectId |
| `number` | `string` | Auto-generated plan number |
| `year` | `number` | Plan year |
| `note` | `string` | Free-text note |
| `organization_id` | `string` | Organization ObjectId |
| `organization` | `object` |  |
| `organization._id` | `string` |  |
| `organization.name` | `string` |  |
| `created_by` | `object` |  |
| `created_by._id` | `string` |  |
| `created_by.number` | `string` |  |
| `created_by.full_name` | `string` |  |
| `updated_by` | `object` |  |
| `updated_by._id` | `string` |  |
| `updated_by.number` | `string` |  |
| `updated_by.full_name` | `string` |  |
| `created_at` | `string (date-time)` |  |
| `updated_at` | `string (date-time)` |  |
| `items` | `object[]` |  |
| `items[].product_id` | `string` | Product ObjectId |
| `items[].product` | `object` |  |
| `items[].product._id` | `string` |  |
| `items[].product.name` | `string` |  |
| `items[].product.sku` | `string` |  |
| `items[].product.barcode` | `string` |  |
| `items[].months` | `object[]` |  |
| `items[].months[].amount` | `number` | Planned quantity |
| `items[].months[].month_number` | `number` | Calendar month (1–12) |
| `items[].months[].produced` | `number` | Actual produced quantity so far |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "_id": "string",
    "number": "string",
    "year": 0,
    "note": "string",
    "organization_id": "string",
    "organization": {
      "_id": "string",
      "name": "string"
    },
    "created_by": {
      "_id": "string",
      "number": "string",
      "full_name": "string"
    },
    "updated_by": {
      "_id": "string",
      "number": "string",
      "full_name": "string"
    },
    "created_at": "2025-05-01T12:00:00Z",
    "updated_at": "2025-05-01T12:00:00Z",
    "items": [
      {
        "product_id": "string",
        "product": {
          "_id": null,
          "name": null,
          "sku": null,
          "barcode": null
        },
        "months": []
      }
    ]
  },
  "time": "2025-05-01T12:00:00Z"
}
```

## PUT /production-plan/update/{id}

Update a production plan. Internally performs the same year-keyed upsert as create — the {id} path parameter is standard-shape only; the real dedup key is body year + organization_id. Send the full plan payload including items.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X PUT 'https://api.bito.uz/integration-api/integration/api/v2/production-plan/update/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "year": 2025,
  "organization_id": "string",
  "items": [
    {
      "product_id": "string",
      "months": []
    }
  ]
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-plan/update/6712f0a9c4d1e87b3a0f9911', {
  method: 'PUT',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "year": 2025,
    "organization_id": "string",
    "items": [
      {
        "product_id": "string",
        "months": []
      }
    ]
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "PUT",
    "https://api.bito.uz/integration-api/integration/api/v2/production-plan/update/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "year": 2025,
        "organization_id": "string",
        "items": [
            {
                "product_id": "string",
                "months": [],
            },
        ],
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "year": 2025,
  "organization_id": "string",
  "items": [
    {
      "product_id": "string",
      "months": []
    }
  ]
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-plan/update/6712f0a9c4d1e87b3a0f9911');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Параметры пути**

| Параметр | Тип | Обязательно | Описание |
|---|---|---|---|
| `id` | `string` | Да | Production plan ObjectId (standard-shape; upsert key is year + organization_id in body) |

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `year` | `number` | Да | The production plan year (e.g. 2025). Together with organization_id this is the upsert key — submitting a plan for the same year + organization updates the existing plan. |
| `organization_id` | `string` | Да | Organization ObjectId this plan belongs to |
| `note` | `string` | Нет | Optional free-text note |
| `items` | `object[]` | Да | Per-product monthly production targets (at least one item required) |
| `items[].product_id` | `string` | Да | Product ObjectId |
| `items[].months` | `object[]` | Да | Monthly target entries for this product (at least one month required) |
| `items[].months[].amount` | `number` | Да | Planned production quantity for this month |
| `items[].months[].month_number` | `number` | Да | Calendar month (1 = January … 12 = December). Each month_number must be unique within an item. |

```json
{
  "year": 2025,
  "organization_id": "string",
  "note": "string",
  "items": [
    {
      "product_id": "string",
      "months": []
    }
  ]
}
```

**Ответ**

Структура ответа совпадает с [POST /production-plan/create](#post-production-plan-create).

## GET /production-plan/get-by-id/{id}

Fetch a single production plan by ObjectId, with aggregated items and per-product monthly targets.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X GET 'https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-id/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY"
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-id/6712f0a9c4d1e87b3a0f9911', {
  method: 'GET',
  headers: { 'api-key': process.env.BITO_API_KEY },
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "GET",
    "https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-id/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
)
print(res.json())
```

```php [PHP]
<?php
$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-id/6712f0a9c4d1e87b3a0f9911');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY')],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Параметры пути**

| Параметр | Тип | Обязательно | Описание |
|---|---|---|---|
| `id` | `string` | Да | Production plan ObjectId |

**Тело запроса**

Тело запроса не требуется.

**Ответ**

Структура ответа совпадает с [POST /production-plan/create](#post-production-plan-create).

## POST /production-plan/get-paging

Paginated list of production plans. The search field matches against the plan number.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-paging' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "page": 1,
  "limit": 20
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-paging', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "page": 1,
    "limit": 20
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "POST",
    "https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-paging",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "page": 1,
        "limit": 20,
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "page": 1,
  "limit": 20
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-paging');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `page` | `number` | Да | По умолчанию: `1` |
| `limit` | `number` | Да | По умолчанию: `20` |
| `search` | `string` | Нет | Search string matched against plan number |
| `updated_at` | `string (date-time)` | Нет | Only records updated at or after this time. |
| `organization_id` | `string` | Нет | Organization ObjectId. |
| `sort_by` | `string` | Нет | Field name to sort by. |
| `asc` | `integer` | Нет | Sort direction: `1` ascending, `-1` descending.. Допустимые значения: `-1`, `1` |

```json
{
  "page": 1,
  "limit": 20,
  "search": "string",
  "updated_at": "2025-05-01T12:00:00Z",
  "organization_id": "64b7f4d9e2b3b6a0b7c5d7ff",
  "sort_by": "string",
  "asc": -1
}
```

**Ответ**

| Поле | Тип | Описание |
|---|---|---|
| `total` | `number` |  |
| `list` | `object[]` |  |
| `list[]._id` | `string` |  |
| `list[].number` | `string` |  |
| `list[].year` | `number` |  |
| `list[].note` | `string` |  |
| `list[].organization_id` | `string` |  |
| `list[].organization` | `object` |  |
| `list[].organization._id` | `string` |  |
| `list[].organization.name` | `string` |  |
| `list[].created_by` | `object` |  |
| `list[].created_by._id` | `string` |  |
| `list[].created_by.number` | `string` |  |
| `list[].created_by.full_name` | `string` |  |
| `list[].updated_by` | `object` |  |
| `list[].updated_by._id` | `string` |  |
| `list[].updated_by.number` | `string` |  |
| `list[].updated_by.full_name` | `string` |  |
| `list[].created_at` | `string (date-time)` |  |
| `list[].updated_at` | `string (date-time)` |  |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "total": 0,
    "list": [
      {
        "_id": "string",
        "number": "string",
        "year": 0,
        "note": "string",
        "organization_id": "string",
        "organization": {
          "_id": null,
          "name": null
        },
        "created_by": {
          "_id": null,
          "number": null,
          "full_name": null
        },
        "updated_by": {
          "_id": null,
          "number": null,
          "full_name": null
        },
        "created_at": "2025-05-01T12:00:00Z",
        "updated_at": "2025-05-01T12:00:00Z"
      }
    ]
  },
  "time": "2025-05-01T12:00:00Z"
}
```

## POST /production-plan/delete-many

Soft-delete one or more production plans by their ObjectIds. Sets is_deleted=true; no physical deletion.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/production-plan/delete-many' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "ids": [
    "string"
  ]
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-plan/delete-many', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "ids": [
      "string"
    ]
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "POST",
    "https://api.bito.uz/integration-api/integration/api/v2/production-plan/delete-many",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "ids": [
            "string",
        ],
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "ids": [
    "string"
  ]
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-plan/delete-many');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `ids` | `string[]` | Да | Production plan ObjectIds to soft-delete (at least one required) |

```json
{
  "ids": [
    "string"
  ]
}
```

**Ответ**

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": "ok",
  "time": "2025-05-01T12:00:00Z"
}
```

## POST /production-plan/get-by-year

Fetch the production plan for a year + organization. Together these are the plan's natural key — the same pair create/update upsert on — so this is the lookup to use when you hold the business key rather than the ObjectId. Returns an empty object when no plan exists for that pair.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-year' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "year": 2026,
  "organization_id": "string"
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-year', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "year": 2026,
    "organization_id": "string"
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "POST",
    "https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-year",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "year": 2026,
        "organization_id": "string",
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "year": 2026,
  "organization_id": "string"
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-plan/get-by-year');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `year` | `number` | Да | Calendar year of the plan, e.g. 2026 |
| `organization_id` | `string` | Да | Organization ObjectId the plan belongs to |

```json
{
  "year": 2026,
  "organization_id": "string"
}
```

**Ответ**

Структура ответа совпадает с [POST /production-plan/create](#post-production-plan-create).

---

*Эта страница сгенерирована из спецификации OpenAPI.*
