# Phiếu nhập kho

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

## Danh sách phiếu nhập kho

`GET /shops/{SHOP_ID}/purchases`

Lấy danh sách phiếu nhập kho

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |
| `page` | query | integer |  | Số trang |
| `page_size` | query | integer |  | Kích thước trang |
| `status` | query | integer |  | Trạng thái Values: `-2` Tất cả trạng thái, `-1` Mới, `0` Đã xác nhận, `1` Đã nhập hàng, `2` Đã hủy. |
| `type` | query | string |  | Loại |
| `get_time_import` | query | boolean |  | Lấy thời gian nhập hàng |

### Phản hồi

- `200` Success (object)

```json
{
  "success": true,
  "data": [
    {
      "id": "96bbc665-3fd5-4efc-9d8a-0110ecfa1754",
      "display_id": 6392,
      "status": 0,
      "time_import": "2025-12-02T07:41:50.363889",
      "total_quantity": 1,
      "total_remain_quantity": 1,
      "total_price": 200000,
      "total_remain_price": 200000,
      "note": "nhập kho sản phẩm",
      "warehouse_id": "c52e67ad-d9d0-4276-abe4-e0c9f1f7d2da",
      "supplier_products_id": 293,
      "supplier": {
        "id": 724,
        "name": "CT TNHH Hồng Hà",
        "custom_id": "HH"
      },
      "discount": 10000,
      "transport_fee": 10000,
      "prepaid_debt": 100000,
      "auto_create_debts": true,
      "not_create_transaction": true,
      "is_lock": null,
      "created_type": "actual_purchase",
      "tags": [
        1
      ],
      "tag_info": [
        {
          "id": 1,
          "name": "Nhập hàng để bán"
        }
      ],
      "items": [
        {
          "id": "02cb1ff3-9b21-4e1c-9288-a29c16bd907d",
          "imported_price": 200000,
          "gross_price": 200000,
          "discount": 10000,
          "quantity": 1,
          "variation_id": "20e7d183-c70c-445e-8ce2-4d7e3a378e34",
          "product_name": "Áo nam",
          "note_purchase": "áo nam thời trang",
          "selling_status": "bad",
          "variation": {
            "id": "69416fa6-4c3d-451f-897d-9faa0420c060",
            "display_id": "mauma1",
            "barcode": "mauma1",
            "product_id": "f210413c-dc84-45e5-b722-9dc72ff7c9af",
            "retail_price": 10000,
            "retail_price_after_discount": 10000,
            "remain_quantity": 9,
            "weight": 0,
            "product": {
              "display_id": "Áo nam",
              "name": "Áo nam"
            },
            "variations_warehouses": []
          }
        }
      ],
      "images": [
        "https://content.pancake.vn/user-content-dev2.pancake.vn/2022/7/7/eb376f0bf90f47d25396d49e4d547700f182981b.jpg"
      ],
      "bill_images": [],
      "user_id": "cee3c05e-5f85-43c4-b27e-889b99c50097",
      "user": {
        "id": "cee3c05e-5f85-43c4-b27e-889b99c50097",
        "name": "Vũ Sơn",
        "fb_id": "377936050731194",
        "avatar_url": null
      },
      "inserted_at": "2023-09-20T02:21:51Z",
      "updated_at": "2023-09-20T02:22:05Z",
      "received_at": "2023-09-21T00:00:00Z",
      "separate_by_display_ids": null
    }
  ]
}
```

## Tạo phiếu nhập kho

`POST /shops/{SHOP_ID}/purchases`

### 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 nhập hàng cần tạo

- `purchase` (object, required): 
  - `note` (string): Ghi chú
  - `status` (integer, required): Trạng thái
  - `not_create_transaction` (boolean): Không tạo phiếu chi
  - `auto_create_debts` (boolean): Tạo công nợ theo nhà cung cấp
  - `supplier_products_id` (integer): Mã nhà cung cấp
  - `shop_id` (integer): Mã shop
  - `warehouse_id` (string, required): Mã kho
  - `change_received_at` (boolean): Đổi ngày về dự kiến
  - `received_at` (integer): Ngày về dự kiến
  - `images` (string (uri)[]): Link hình ảnh nhập hàng
  - `items` (object[], required): Danh sách sản phẩm

```json
{
  "purchase": {
    "note": "",
    "status": 1,
    "not_create_transaction": false,
    "auto_create_debts": true,
    "supplier_products_id": 169,
    "shop_id": 20,
    "warehouse_id": "c52e67ad-d9d0-4276-abe4-e0c9f1f7d2da",
    "change_received_at": true,
    "received_at": 1651683600,
    "images": [
      "https://statics.pancake.vn/user-content-dev2.pancake.vn/2021/12/27/18c4500c320cb2e993b3ff4b3be81165df64d3ba.png"
    ],
    "items": [
      {
        "imported_price": 100000,
        "gross_price": 100000,
        "discount": 10000,
        "quantity": 1,
        "variation_id": "29044dcf-2f4c-492f-a0a9-e447b20e21da",
        "index": 0
      }
    ]
  }
}
```

### Phản hồi

- `200` Success (object)

```json
{
  "success": true
}
```

## Chi tiết phiếu nhập kho

`GET /shops/{SHOP_ID}/purchases/{PURCHASE_ID}`

Lấy một phiếu nhập kho theo mã hoặc mã hiển thị, cùng dạng một phần tử của danh sách. Phiếu thuộc kho mà người gọi không được xem phiếu nhập trả về không tìm thấy.

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |
| `PURCHASE_ID` | path | string | yes | Mã phiếu nhập kho (UUID) hoặc mã hiển thị |

### Phản hồi

- `200` Success (object)
- `404` Phiếu nhập kho không tồn tại hoặc người gọi không được xem (ErrorResponse)

```json
{
  "success": true,
  "data": {
    "id": "96bbc665-3fd5-4efc-9d8a-0110ecfa1754",
    "display_id": 6392,
    "status": 0,
    "time_import": "2025-12-02T07:41:50.363889",
    "total_quantity": 1,
    "total_remain_quantity": 1,
    "total_price": 200000,
    "total_remain_price": 200000,
    "note": "nhập kho sản phẩm",
    "warehouse_id": "c52e67ad-d9d0-4276-abe4-e0c9f1f7d2da",
    "supplier_products_id": 293,
    "supplier": {
      "id": 724,
      "name": "CT TNHH Hồng Hà",
      "custom_id": "HH"
    },
    "discount": 10000,
    "transport_fee": 10000,
    "prepaid_debt": 100000,
    "auto_create_debts": true,
    "not_create_transaction": true,
    "is_lock": null,
    "created_type": "actual_purchase",
    "tags": [
      1
    ],
    "tag_info": [
      {
        "id": 1,
        "name": "Nhập hàng để bán"
      }
    ],
    "items": [
      {
        "id": "02cb1ff3-9b21-4e1c-9288-a29c16bd907d",
        "imported_price": 200000,
        "gross_price": 200000,
        "discount": 10000,
        "quantity": 1,
        "variation_id": "20e7d183-c70c-445e-8ce2-4d7e3a378e34",
        "product_name": "Áo nam",
        "note_purchase": "áo nam thời trang",
        "selling_status": "bad",
        "variation": {
          "id": "69416fa6-4c3d-451f-897d-9faa0420c060",
          "display_id": "mauma1",
          "barcode": "mauma1",
          "product_id": "f210413c-dc84-45e5-b722-9dc72ff7c9af",
          "retail_price": 10000,
          "retail_price_after_discount": 10000,
          "remain_quantity": 9,
          "weight": 0,
          "product": {
            "display_id": "Áo nam",
            "name": "Áo nam"
          },
          "variations_warehouses": []
        }
      }
    ],
    "images": [
      "https://content.pancake.vn/user-content-dev2.pancake.vn/2022/7/7/eb376f0bf90f47d25396d49e4d547700f182981b.jpg"
    ],
    "bill_images": [],
    "user_id": "cee3c05e-5f85-43c4-b27e-889b99c50097",
    "user": {
      "id": "cee3c05e-5f85-43c4-b27e-889b99c50097",
      "name": "Vũ Sơn",
      "fb_id": "377936050731194",
      "avatar_url": null
    },
    "inserted_at": "2023-09-20T02:21:51Z",
    "updated_at": "2023-09-20T02:22:05Z",
    "received_at": "2023-09-21T00:00:00Z",
    "separate_by_display_ids": null
  }
}
```

## Cập nhật phiếu nhập kho

`PUT /shops/{SHOP_ID}/purchases/{PURCHASE_ID}`

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |
| `PURCHASE_ID` | path | string | yes | Mã phiếu nhập kho |

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

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

- `purchase` (object, required): 
  - `note` (string): Ghi chú
  - `status` (integer): Trạng thái Values: `-1` Mới, `0` Đã xác nhận, `1` Đã nhập hàng, `2` Đã hủy.
  - `not_create_transaction` (boolean): Không tạo phiếu chi
  - `auto_create_debts` (boolean): Tạo công nợ theo nhà cung cấp
  - `supplier_products_id` (integer): Mã nhà cung cấp
  - `warehouse_id` (string, required): Mã kho
  - `change_received_at` (boolean): Đổi ngày về dự kiến
  - `received_at` (integer): Ngày về dự kiến
  - `images` (string (uri)[]): Link hình ảnh nhập hàng
  - `items` (object[]): Danh sách sản phẩm

```json
{
  "purchase": {
    "note": "",
    "status": 1,
    "not_create_transaction": false,
    "auto_create_debts": true,
    "supplier_products_id": 169,
    "warehouse_id": "c52e67ad-d9d0-4276-abe4-e0c9f1f7d2da",
    "change_received_at": true,
    "received_at": 1651683600,
    "images": [
      "https://statics.pancake.vn/user-content-dev2.pancake.vn/2021/12/27/18c4500c320cb2e993b3ff4b3be81165df64d3ba.png"
    ],
    "items": [
      {
        "imported_price": 100000,
        "quantity": 1,
        "variation_id": "29044dcf-2f4c-492f-a0a9-e447b20e21da"
      }
    ]
  }
}
```

### Phản hồi

- `200` Success (object)

```json
{
  "success": true
}
```

## Tách phiếu nhập kho

`POST /shops/{SHOP_ID}/purchases/separate`

Tách một phiếu nhập kho thành nhiều phiếu nhập kho

### 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 tách nhập hàng

- `newPurchase` (object, required): Thông tin phiếu nhập kho mới
  - `auto_create_debts` (boolean): Tạo công nợ theo nhà cung cấp
  - `discount` (integer): Giảm giá
  - `images` (string (uri)[]): Link hình ảnh nhập hàng
  - `items` (object[]): Danh sách sản phẩm
  - `not_create_transaction` (boolean): Không tạo phiếu chi
  - `note` (string): Ghi chú
  - `prepaid_debt` (integer): Trả trước NCC
  - `received_at` (integer): Ngày về dự kiến
  - `status` (integer): Trạng thái
  - `supplier_products_id` (integer): Mã nhà cung cấp
  - `tags` (integer[]): Danh sách mã thẻ
  - `transport_fee` (integer): Phí vận chuyển
  - `warehouse_id` (string): Mã kho
- `oldPurchase` (object, required): Thông tin phiếu nhập kho cũ
  - `id` (string, required): Mã phiếu nhập kho
  - `auto_create_debts` (boolean): Tạo công nợ theo nhà cung cấp
  - `discount` (integer): Giảm giá
  - `images` (string (uri)[]): Link hình ảnh nhập hàng
  - `items` (object[]): Danh sách sản phẩm
  - `not_create_transaction` (boolean): Không tạo phiếu chi
  - `note` (string): Ghi chú
  - `prepaid_debt` (integer): Trả trước NCC
  - `received_at` (integer): Ngày về dự kiến
  - `status` (integer): Trạng thái
  - `supplier_products_id` (integer): Mã nhà cung cấp
  - `tags` (integer[]): Danh sách mã thẻ
  - `transport_fee` (integer): Phí vận chuyển
  - `warehouse_id` (string): Mã kho

```json
{
  "newPurchase": {
    "auto_create_debts": true,
    "discount": 500,
    "images": [
      "https://statics.pancake.vn/user-content-dev2.pancake.vn/2021/12/27/18c4500c320cb2e993b3ff4b3be81165df64d3ba.png"
    ],
    "items": [
      {
        "imported_price": 100000,
        "quantity": 1,
        "variation_id": "ddefd476-bc91-4151-8cd2-2cf5ad227f09",
        "index": 0
      }
    ],
    "not_create_transaction": false,
    "note": "Tách phiếu nhập",
    "prepaid_debt": 20000,
    "received_at": 1683997200,
    "status": 0,
    "supplier_products_id": 293,
    "tags": [
      1
    ],
    "transport_fee": 0,
    "warehouse_id": "c52e67ad-d9d0-4276-abe4-e0c9f1f7d2da"
  },
  "oldPurchase": {
    "auto_create_debts": true,
    "discount": 500,
    "id": "0ecbdb3b-a376-4a3d-9b8a-174ae15ae886",
    "images": [
      "https://statics.pancake.vn/user-content-dev2.pancake.vn/2021/12/27/18c4500c320cb2e993b3ff4b3be81165df64d3ba.png"
    ],
    "items": [
      {
        "imported_price": 100000,
        "quantity": 23,
        "variation_id": "ddefd476-bc91-4151-8cd2-2cf5ad227f09",
        "index": 0
      }
    ],
    "not_create_transaction": false,
    "note": "Nhập hàng để bán",
    "prepaid_debt": 20000,
    "received_at": 1683997200,
    "status": 0,
    "supplier_products_id": 293,
    "tags": [
      1
    ],
    "transport_fee": 0,
    "warehouse_id": "c52e67ad-d9d0-4276-abe4-e0c9f1f7d2da"
  }
}
```

### Phản hồi

- `200` Success (object)

```json
{
  "success": true
}
```
