# Công nợ khách hàng

* /api/accounting/debts: Tính năng này dùng để lấy danh sách công nợ khách hàng ở trên Nhanh.vn. Dữ liệu sẽ được phân trang, mỗi trang tối đa không quá 50.

## Request

* Xem các [common request params](/v2/readme.md#request-params)
* Các key của mảng **data array** dùng để tạo **data** json string:

| Key            | Type                          | Description                                                                                     |
| -------------- | ----------------------------- | ----------------------------------------------------------------------------------------------- |
| page           | int                           | Phân trang, giá trị mặc định sẽ là 1.                                                           |
| icpp           | int                           | Số lượng sản phẩm trên 1 trang. Tối đa không quá 50. Mặc định nếu không set giá trị gì sẽ là 50 |
| contactType    | string $$^{{\color{red}\*}}$$ | Công nợ theo khách hàng, giá trị mặc định: customer                                             |
| id             | int                           | Tìm theo ID đối tượng khách hàng                                                                |
| fromDate       | date                          | Tìm kiếm thời gian bắt đầu từ ngày định dạng (yyyy-mm-dd). VD: 2022-09-25                       |
| toDate         | date                          | Tìm kiếm thời gian đến ngày (yyyy-mm-dd). VD: 2022-09-25                                        |
| code           | string                        | Tìm kiếm theo mã khách hàng                                                                     |
| name           | string                        | Tìm kiếm theo tên khách hàng/ ID khách hàng                                                     |
| address        | string                        | Tìm kiếm theo địa chỉ khách hàng                                                                |
| mobile         | string                        | Tìm kiếm theo số điện thoại khách hàng                                                          |
| itemSubType    | int                           | Tìm kiếm theo loại khách hàng.Giá trị 1: Khách lẻ,2: Khách sỉ,3: Đại lý                         |
| debtType       | int                           | Tìm kiếm theo loại công nợ.Giá trị 1: Phải thu,2: Phải trả,3: Phải thu/Phải trả                 |
| fromLastRemain | float(optional)               | Từ giá trị                                                                                      |
| toLastRemain   | float(optional)               | Đến giá trị                                                                                     |

## Response

* JSON decode the response to get the structure:

| Key      | Type  | Description                               |
| -------- | ----- | ----------------------------------------- |
| code     | int   | 1 = success or 0 = failed                 |
| messages | array | is an array of error messages if code = 0 |
| data     | array | is an array of transaction list           |

```javascript
[
    "totalPages": 30, // int
    "debts": [
        id => [
            ...
        ], // each debts item, all properties are listed in the table below
        ...
    ]
]
```

| Key               | Type   | Description                                  |
| ----------------- | ------ | -------------------------------------------- |
| customerCode      | string | Mã khách hàng                                |
| customerName      | string | Tên khách hàng                               |
| customerMobile    | string | Số điện thoại khách hàng                     |
| firstRemainDebit  | float  | Số dư đầu kì nợ(phải thu) (nếu lọc fromDate) |
| firstRemainCredit | float  | Số dư đầu kì có(phải trả) (nếu lọc fromDate) |
| debit             | float  | Phát sinh trong kì nợ                        |
| credit            | float  | Phát sinh trong kì có                        |
| receive           | float  | Số dư cuối kì nợ (phải thu)                  |
| pay               | float  | Số dư cuối kì có (phải trả)                  |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.nhanh.vn/v2/accounting/debts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
