# 報價單

## quote_convert

把報價單轉成訂單，報價單變成 CONVERTED；issue_bill（預設 true）同時開一張全額的請款單。要帶 quote_get 拿到的 version。

給 Agent 的原文：

> Turn a quote into an order; the quote becomes CONVERTED. issue_bill (default true) also issues a bill for the full amount.
> Send the version from quote_get.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `quote` | string | 必填 | Quote number (QT-000001) or id |
| `version` | integer | 必填 |  |
| `due_date` | date（可以是 null） |  | Empty uses the default payment term; not allowed with issue_bill: false |
| `issue_bill` | boolean |  | Also issue a bill for the full amount (needs bills:create) default: true |
| `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. |

授權項目：`quotes:convert`；issue_bill 是 true（沒帶也是）時，另外要 bills:create。

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

## quote_create

建立報價單（DRAFT），不會成立訂單或開請款單。可以先試算看金額。

給 Agent 的原文：

> Create a quote (status DRAFT). It does not create an order or a bill. Use dry_run to see the amounts first.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `items` | Item[] | 必填 |  |
| `items[].name` | string | 必填 |  |
| `items[].unit_price` | string | 必填 | Amount as a string, e.g. "12000" or "12.50" |
| `items[].quantity` | integer |  | default: 1 |
| `items[].discount` | Discount（可以是 null） |  |  |
| `items[].description` | string |  |  |
| `items[].ref` | string |  | Item code in an external system |
| `currency` | string（可以是 null） |  | Empty uses the default currency of the workspace |
| `locale` | string（可以是 null） |  |  |
| `tax_included` | boolean |  | default: true |
| `tax_type` | TAXABLE \| ZERO_RATED \| EXEMPT |  | default: "TAXABLE" |
| `buyer` | Buyer（可以是 null） |  |  |
| `buyer.legal_name` | string |  | Empty uses the customer name |
| `buyer.tax_id` | string |  |  |
| `buyer.address` | string |  |  |
| `buyer.primary_email` | string |  |  |
| `buyer.cc_emails` | string[] |  | default: [] |
| `notes` | string（可以是 null） |  | Empty uses the default notes of the locale |
| `customer` | Customer（可以是 null） |  | Required unless customer_id is given |
| `customer.name` | string | 必填 |  |
| `customer.ref` | string |  | Customer code in an external system; only stored and used for filtering |
| `customer_id` | string（可以是 null） |  | Customer number or id (needs customers:read): customer and buyer fields you leave out are filled from the customer |
| `valid_until` | date（可以是 null） |  | Omitted uses the default validity; null means none |
| `agent_note` | string |  |  |
| `metadata` | MetadataEntry[]（可以是 null） |  |  |
| `metadata[].key` | string | 必填 |  |
| `metadata[].value` | string | 必填 |  |
| `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. |

授權項目：`quotes:write`；帶 customer_id 從客戶帶入資料時，另外要 customers:read。

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

## quote_get

用編號（QT-000001）或 id 查一張報價單，附 version、分享連結（要 pii:read）和 allowed_actions。

給 Agent 的原文：

> Get one quote by number (QT-000001) or id, with its version, share_url (needs pii:read) and allowed_actions.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `quote` | string | 必填 | Quote number (QT-000001) or id |

授權項目：`quotes:read`

核可：不用

## quote_search

查報價單，新的在前；回摘要，要一張的完整內容用 quote_get。

給 Agent 的原文：

> Search quotes, newest first. Returns summaries; use quote_get for one quote.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `limit` | integer |  | 1 to 100 default: 20 |
| `cursor` | string（可以是 null） |  | next_cursor from the previous page |
| `keyword` | string |  | Part of the quote number or customer name; an email or phone needs pii:read |
| `item_name` | string |  |  |
| `customer_ref` | string（可以是 null） |  |  |
| `statuses` | DRAFT \| SENT \| ACCEPTED \| REJECTED \| EXPIRED \| CONVERTED[]（可以是 null） |  |  |
| `created_from` | date（可以是 null） |  |  |
| `created_to` | date（可以是 null） |  |  |

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

核可：不用

## quote_send

把報價單寄給報價單上的買方（附 PDF 和分享連結），草稿寄出之後變成已送出。寄出前要先試算，把結果給使用者看、問過使用者，再帶試算給的確認碼寄。

給 Agent 的原文：

> Email a quotation to the buyer on the quote (primary email and CC), with the PDF attached and a link to the quote's share
> page. A DRAFT quote becomes SENT once the email is sent. Only DRAFT, SENT and ACCEPTED quotes can be sent. Before sending,
> call with dry_run: true, show the user the quote, amount and recipients, and ask whether to send;
> then call again with the confirmation_code from the dry run.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `quote` | string | 必填 | Quote number (QT-000001) or id |
| `message` | string |  | A note added to the email, up to 1,000 characters |
| `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. |

授權項目：`quotes:send`

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

## quote_set_status

把報價單的狀態改成 DRAFT、SENT、ACCEPTED、REJECTED 或 EXPIRED（CONVERTED 只能經 quote_convert）。

給 Agent 的原文：

> Change the status of a quote among DRAFT, SENT, ACCEPTED, REJECTED and EXPIRED (CONVERTED only comes from quote_convert).

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `quote` | string | 必填 | Quote number (QT-000001) or id |
| `status` | DRAFT \| SENT \| ACCEPTED \| REJECTED \| EXPIRED | 必填 |  |
| `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. |

授權項目：`quotes:write`

寫入、核可：不用

## quote_update

整份換掉報價單的內容（CONVERTED 的不行），要帶 quote_get 拿到的 version。

給 Agent 的原文：

> Replace the whole content of a quote (not CONVERTED). Send the version from quote_get.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `items` | Item[] | 必填 |  |
| `items[].name` | string | 必填 |  |
| `items[].unit_price` | string | 必填 | Amount as a string, e.g. "12000" or "12.50" |
| `items[].quantity` | integer |  | default: 1 |
| `items[].discount` | Discount（可以是 null） |  |  |
| `items[].description` | string |  |  |
| `items[].ref` | string |  | Item code in an external system |
| `currency` | string（可以是 null） |  | Empty uses the default currency of the workspace |
| `locale` | string（可以是 null） |  |  |
| `tax_included` | boolean |  | default: true |
| `tax_type` | TAXABLE \| ZERO_RATED \| EXEMPT |  | default: "TAXABLE" |
| `buyer` | Buyer（可以是 null） |  |  |
| `buyer.legal_name` | string |  | Empty uses the customer name |
| `buyer.tax_id` | string |  |  |
| `buyer.address` | string |  |  |
| `buyer.primary_email` | string |  |  |
| `buyer.cc_emails` | string[] |  | default: [] |
| `notes` | string（可以是 null） |  | Empty uses the default notes of the locale |
| `quote` | string | 必填 | Quote number (QT-000001) or id |
| `version` | integer | 必填 |  |
| `customer` | Customer | 必填 |  |
| `customer.name` | string | 必填 |  |
| `customer.ref` | string |  | Customer code in an external system; only stored and used for filtering |
| `valid_until` | date（可以是 null） |  |  |
| `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. |

授權項目：`quotes:write`、`pii:read`

寫入、核可：不用

## quote_update_agent_data

換掉報價單上給 agent 用的備註和 metadata；網站、PDF、分享頁都不顯示，不用帶 version。

給 Agent 的原文：

> Replace the agent note and metadata of a quote. Not shown on the website, PDF or share page; no version needed.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `agent_note` | string | 必填 |  |
| `metadata` | MetadataEntry[] | 必填 |  |
| `metadata[].key` | string | 必填 |  |
| `metadata[].value` | string | 必填 |  |
| `quote` | string | 必填 | Quote number (QT-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. |

授權項目：`quotes:write`

寫入、核可：不用
