# 請款單

## bill_cancel

取消一張 UNPAID 的請款單（沒有付款、沒有有效的發票）；訂單留著，這筆金額可以再請款。

給 Agent 的原文：

> Cancel one UNPAID bill (no payments, no valid e-invoice); the order stays and the amount can be billed again.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `bill` | string | 必填 | Bill number (BL-000001) or id |
| `reason` | string | 必填 |  |
| `idempotency_key` | string | 必填 | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`bills:cancel`

寫入、核可：看情況（這張請款單（或訂單的任一張請款單）寄出過要人核可。）

## bill_create

從訂單開一張請款單：金額（或訂單總額的百分比；都不帶就是還沒請款的金額）、到期日、標題。同一張訂單的請款單加起來不能超過總額。可以先試算看稅額和還沒請款的金額。

給 Agent 的原文：

> Issue a bill from an order: amount (or percent of the order total; neither = the unbilled amount), due_date and title.
> The bills of an order cannot add up to more than its total. Use dry_run to see the tax and the unbilled amount first.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `order` | string | 必填 | Order number (OD-000001) or id |
| `amount` | string（可以是 null） |  | Amount of this bill; empty uses the unbilled amount of the order; not with percent |
| `percent` | integer（可以是 null） |  | 1 to 100: this percent of the order total (rounded); not with amount |
| `due_date` | date（可以是 null） |  | Empty uses the default payment term |
| `title` | string |  | e.g. Deposit, Final payment; up to 100 characters |
| `dry_run` | boolean |  | default: false |
| `idempotency_key` | string |  | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`bills:create`

寫入、可試算、核可：不用

## bill_get

用編號（BL-000001）或 id 查一張請款單：金額、訂單、version、分享連結（要 pii:read）、allowed_actions，以及這把權杖讀得到的付款、退款、統一發票和寄信紀錄。

給 Agent 的原文：

> Get one bill by number (BL-000001) or id: amounts, order, version, share_url (needs pii:read), allowed_actions, and the
> payments, refunds, e-invoices and emails this token may read.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `bill` | string | 必填 | Bill number (BL-000001) or id |

授權項目：`bills:read`

核可：不用

## bill_regenerate_share_link

重新產生請款單的分享連結，舊的馬上失效。

給 Agent 的原文：

> Make a new share link for a bill; the old one stops working at once.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `bill` | string | 必填 | Bill number (BL-000001) or id |
| `idempotency_key` | string | 必填 | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`bills:update`、`pii:read`

寫入、核可：不用

## bill_search

查請款單（新的在前，或照到期日）；回摘要，要一張的完整內容用 bill_get。

給 Agent 的原文：

> Search bills (newest first, or by due date). Returns summaries; use bill_get for one bill.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `limit` | integer |  | 1 to 100 default: 20 |
| `cursor` | string（可以是 null） |  | next_cursor from the previous page |
| `keyword` | string |  | Part of the bill/order number or customer name; an email or phone needs pii:read |
| `item_name` | string |  |  |
| `customer_ref` | string（可以是 null） |  |  |
| `status` | UNPAID \| PAID \| CANCELLED（可以是 null） |  |  |
| `overdue` | boolean |  | default: false |
| `created_from` | date（可以是 null） |  |  |
| `created_to` | date（可以是 null） |  |  |
| `due_date_from` | date（可以是 null） |  |  |
| `due_date_to` | date（可以是 null） |  |  |
| `order_by` | CREATED_DESC \| DUE_DATE_ASC |  | default: "CREATED_DESC" |
| `has_refunds` | boolean |  | default: false |
| `has_einvoice` | boolean（可以是 null） |  |  |
| `emailed` | boolean（可以是 null） |  |  |
| `currency` | string（可以是 null） |  |  |
| `overdue_days_min` | integer（可以是 null） |  |  |
| `overdue_days_max` | integer（可以是 null） |  |  |

授權項目：`bills:read`；keyword 像 Email 或電話時，另外要 pii:read。

核可：不用

## bill_send

把請款單寄給客戶（主要 Email 和副本）。一張時跟網站一樣，不能寄就失敗；好幾張時每張各自檢查，回排進佇列的和略過的。可以先試算看會寄給誰。寄出前要先試算，把結果給使用者看、問過使用者，再帶試算給的確認碼寄。

給 Agent 的原文：

> Email bills to their customers (primary email and cc). With one bill it fails like the website does; with several, each
> bill is checked on its own and the result lists the queued and the skipped ones. Use dry_run to see who would get them.
> Before sending, call with dry_run: true, show the user the bills, amounts and recipients, and ask whether to send;
> then call again with the confirmation_code from the dry run.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `bills` | string[] | 必填 | 1 to 100 bill numbers (BL-000001) or ids |
| `message` | string |  | A note added to the email |
| `dry_run` | boolean |  | default: false |
| `confirmation_code` | string（可以是 null） |  | Required unless dry_run is true: the confirmation_code returned by a dry run with the same parameters. |
| `idempotency_key` | string |  | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`bills:send`

寫入、可試算、核可：不用、寄出前要先試算帶確認碼

## bill_update_due_date

改 UNPAID 請款單的到期日，要帶 bill_get 拿到的 version。

給 Agent 的原文：

> Change the due date of an UNPAID bill. Send the version from bill_get.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `bill` | string | 必填 | Bill number (BL-000001) or id |
| `version` | integer | 必填 |  |
| `due_date` | date | 必填 |  |
| `idempotency_key` | string | 必填 | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`bills:update`

寫入、核可：不用
