# Kho hàng

> Base URL: `https://pos.pages.fm/api/v1`. Xác thực bằng tham số truy vấn `api_key`.

## Danh sách kho hàng

`GET /shops/{SHOP_ID}/warehouses`

Lấy danh sách kho hàng

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |

### Phản hồi

- `200` Success (object)

```json
{
  "data": [
    {
      "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
      "name": "kho test ecod",
      "address": "hâhhha",
      "full_address": "hâhhha, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
      "phone_number": "0999999999",
      "province_id": "717",
      "district_id": "71705",
      "commune_id": "7170510",
      "country_code": "84",
      "shop_id": 26290,
      "allow_create_order": true,
      "custom_id": null,
      "affiliate_shop_id": 26290,
      "affiliate_warehouse": "Kho gia dụng"
    },
    {
      "id": "644b0063-e9a8-43cd-ba08-66a8066d462e",
      "name": "kho 2",
      "address": "19/349 Minh Khai , Hai bà Trưng, Hà Nội",
      "full_address": "19/349 Minh Khai , Hai bà Trưng, Hà Nội, Phường Minh Khai, Quận Hai Bà Trưng, Hà Nội",
      "phone_number": "01655809949",
      "province_id": "101",
      "district_id": "10107",
      "commune_id": "1010735",
      "country_code": "84",
      "shop_id": 26290,
      "allow_create_order": false,
      "custom_id": null
    },
    {
      "id": "3cfcf3ab-dd77-4237-862f-356b3506fe8a",
      "name": "kho địa chỉ mới",
      "address": "34234234",
      "full_address": "34234234, Xã Cao Đức, Bắc Ninh",
      "phone_number": "0989965976",
      "province_id": "84_VN102",
      "district_id": null,
      "commune_id": "84_VN10236",
      "country_code": "84",
      "shop_id": 26290,
      "allow_create_order": true,
      "custom_id": null
    }
  ]
}
```

## Tạo kho hàng

`POST /shops/{SHOP_ID}/warehouses`

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |

### Nội dung yêu cầu

Thông tin yêu cầu chứa thông tin kho hàng cần tạo

- `name` (string, required): Tên kho hàng
- `address` (string): Địa chỉ chi tiết kho hàng(số nhà, đường, ...)
- `phone_number` (string): Số điện thoại kho hàng
- `province_id` (string): Mã tỉnh thành phố. Lấy từ API GET /geo/provinces
- `district_id` (string): Mã quận huyện. Lấy từ API GET /geo/districts
- `commune_id` (string): Mã phường xã. Lấy từ API GET /geo/communes
- `country_code` (string): Mã quốc gia
- `shelf_config` (object, required): Cấu hình kệ
  - `col` (string): Cột
- `batch_config` (object): Cấu hình lô
  - `col` (string): Column
  - `line` (string): Line
  - `row` (string): Row
- `custom_shelf_config` (object): Cấu hình kệ tùy chỉnh
  - `custom_config` (object): Custom config
- `custom_batch_config` (object): Cấu hình lô tùy chỉnh
  - `custom_config` (object): Custom config
- `hide_config_batch_shelf` (boolean): Mở cấu hình lô kệ tùy chỉnh

```json
{
  "name": "kho 2",
  "address": "19/349 Minh Khai , Hai bà Trưng, Hà Nội",
  "phone_number": "098765432",
  "province_id": "101",
  "district_id": "10107",
  "commune_id": "1010735",
  "country_code": "84",
  "shelf_config": {
    "col": "3"
  },
  "batch_config": {
    "col": "0",
    "line": "3",
    "row": "3"
  },
  "custom_batch_config": {
    "custom_config": {
      "0": "lô 1"
    }
  },
  "custom_shelf_config": {
    "custom_config": {
      "0": "1.1",
      "1": "1.2",
      "2": "1.3",
      "3": "1.4"
    }
  },
  "hide_config_batch_shelf": false
}
```

### Phản hồi

- `200` Success (Warehouse)

```json
{
  "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
  "name": "kho test ecod",
  "address": "hâhhha",
  "full_address": "hâhhha, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
  "phone_number": "0999999999",
  "province_id": "717",
  "district_id": "71705",
  "commune_id": "7170510",
  "country_code": "84",
  "shop_id": 26290,
  "allow_create_order": true,
  "custom_id": null
}
```

## Cập nhật kho hàng

`PUT /shops/{SHOP_ID}/warehouses/{WAREHOUSE_ID}`

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |
| `WAREHOUSE_ID` | path | string | yes | Mã kho hàng |

### Nội dung yêu cầu

Thông tin yêu cầu chứa thông tin kho hàng cần cập nhật

- `name` (string, required): Tên kho hàng
- `address` (string): Địa chỉ chi tiết kho hàng(số nhà, đường, ...)
- `phone_number` (string): Số điện thoại kho hàng
- `province_id` (string): Mã tỉnh thành phố. Lấy từ API GET /geo/provinces
- `district_id` (string): Mã quận huyện. Lấy từ API GET /geo/districts
- `commune_id` (string): Mã phường xã. Lấy từ API GET /geo/communes
- `country_code` (string): Mã quốc gia
- `shelf_config` (object, required): Cấu hình kệ
  - `col` (string): Cột
- `batch_config` (object): Cấu hình lô
  - `col` (string): Column
  - `line` (string): Line
  - `row` (string): Row
- `custom_shelf_config` (object): Cấu hình kệ tùy chỉnh
  - `custom_config` (object): Custom config
- `custom_batch_config` (object): Cấu hình lô tùy chỉnh
  - `custom_config` (object): Custom config
- `hide_config_batch_shelf` (boolean): Mở cấu hình lô kệ tùy chỉnh

```json
{
  "name": "Kho mặc định",
  "address": "190 La Thành",
  "phone_number": "0366452565",
  "province_id": "101",
  "district_id": "10113",
  "commune_id": "1011309",
  "country_code": "84",
  "shelf_config": {
    "col": "3"
  },
  "batch_config": {
    "col": "0",
    "line": "3",
    "row": "3"
  },
  "custom_batch_config": {
    "custom_config": {
      "0": "lô 1"
    }
  },
  "custom_shelf_config": {
    "custom_config": {
      "0": "1.1",
      "1": "1.2",
      "2": "1.3",
      "3": "1.4"
    }
  },
  "hide_config_batch_shelf": false
}
```

### Phản hồi

- `200` Success (Warehouse)

```json
{
  "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
  "name": "kho test ecod",
  "address": "SCB",
  "full_address": "SCB, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
  "phone_number": "0999999999",
  "province_id": "717",
  "district_id": "71705",
  "commune_id": "7170510",
  "country_code": "84",
  "shop_id": 26290,
  "allow_create_order": true,
  "custom_id": null
}
```

## Lịch sử xuất nhập kho

`GET /shops/{SHOP_ID}/inventory_histories`

Lấy lịch sử xuất nhập kho

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |
| `page` | query | integer | yes | Số trang |
| `page_size` | query | integer | yes | Kích thước trang |
| `warehouse_id` | query | string |  | Mã kho |
| `variation_ids[]` | query | string[] |  | Danh sách mã mẫu mã |
| `startDate` | query | integer |  | Ngày bắt đầu |
| `endDate` | query | integer |  | Ngày kết thúc |

### Phản hồi

- `200` Success (object)

```json
{
  "success": true,
  "data": [
    {
      "avg_price": 1,
      "current_inventory": [
        {
          "actual_remain_quantity": 1,
          "avg_price": 1,
          "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
          "name": "kho test ecod",
          "remain_quantity": 1,
          "total_quantity": 1
        }
      ],
      "editor_id": "cee3c05e-5f85-43c4-b27e-889b99c50097",
      "id": 1,
      "inserted_at": "2024-01-01T00:00:00Z",
      "quantity": 1,
      "ref_display_id": "12345",
      "remain_quantity": 1,
      "table_name": "Purchase",
      "type": "import",
      "variation_now": {
        "barcode": "BARCODE123",
        "display_id": "13109",
        "fields": [
          {
            "id": "field-id-1",
            "keyValue": "Màu",
            "name": "Màu",
            "value": "Trắng"
          }
        ],
        "id": "415040f4-ab63-465e-8699-e9ebfff4c6c7",
        "images": [
          "https://statics.pancake.vn/user-content.pancake.vn/2021/8/5/fccd6.jpg"
        ],
        "is_hidden": true,
        "is_locked": true,
        "is_sell_negative_variation": true,
        "last_imported_price": 1,
        "product_id": "3487e126-b0d9-4dae-89a9-ee60bef2f4e9",
        "retail_price": 1,
        "weight": 1
      },
      "warehouse": {
        "custom_id": null,
        "ffm_id": null,
        "full_address": "hâhhha, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
        "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
        "name": "kho test ecod",
        "phone_number": "0999999999"
      }
    }
  ]
}
```
