> ## Documentation Index
> Fetch the complete documentation index at: https://foliant-help.iforiti.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 範本中的單據編號

> 使用 {{ document_number }} 列印發票、折讓單和報價單的編號，使用 {{ document_date }} 列印發票日期，並列印作廢註記。

開啟單據編號後，Foliant 會為發票、折讓單和報價單分別產生連續編號，例如 `INV-0042`。範本可使用 `{{ document_number }}` 列印編號，在視覺化編輯器中則使用 **單據編號** 區塊。

## 開始之前

* 請在 **設定 › 文件與列印 › 單據編號** 中開啟編號功能。請參閱[設定單據編號](https://foliant-help.iforiti.com/zh-Hant/invoices-and-numbering/document-numbering.md)。
* 在範本的設定頁面，將範本的 **單據類型** 設為 **發票**、**折讓單** 或 **報價單**。類型為 **其他（不編號）** 的範本不會取得編號。

## 在視覺化編輯器中

新增 **單據編號** 區塊（位於 **法規遵循**）。此區塊會以單據的語言列印編號和單據日期，並附上標籤，例如「發票編號」和「發票日期」（折讓單為「折讓單日期」，報價單為「報價單日期」）。此區塊只會出現在有編號的單據上。

您也可以將 **單據編號** 和 **單據日期** 加入 **頁首** 區塊的 **標題下方的詳細資料**，或將 **單據編號** 設為 **條碼 / QR** 區塊要編碼的內容。

## 在程式碼中

| 變數 | 說明 |
| - | - |
| `{{ document_number }}` | 單據的編號。單據沒有編號時為空白。 |
| `{{ document_issued_at }}` | 編號的核發時間。單據沒有編號時為空白。請使用 `date` 設定格式。 |
| `{{ document_date }}` | 單據的日期，一定有值：若已核發編號，則為核發時間，否則為訂單日期（折讓單則為退款日期）。請將它當作發票日期使用。請使用 `date` 設定格式。 |
| `{{ document_voided }}` | 單據已取消時為 true。其編號仍視為已使用，且不會再次核發。 |
| `{{ document_kind }}` | `invoice`、`credit_note` 或 `quote`；範本未編號時為空白。 |

僅在有編號時才列印編號：

```liquid theme={null}
{% if document_number %}
  <p>{{ 'document_number.invoice' | t }}: {{ document_number }}</p>
  <p>{{ 'document_date.invoice' | t }}: {{ document_date | date: '%d %B %Y' }}</p>
  {% if document_voided %}<p>{{ 'document_number.void' | t }}</p>{% endif %}
{% endif %}
```

`'document_date.invoice' | t` 會以單據的語言列印「發票日期」；其他類型請使用 `document_date.credit_note` 或 `document_date.quote`。

## 發票日期

發票的日期是核發日期，也就是取得編號的那一天。它不是訂單日期，也不是今天的日期（今天的日期會在您每次重新列印時改變）。`{{ document_date }}` 提供的就是這個日期：

* 在有編號的單據上，它是核發編號的日期，以您商店的時區為準。下個月再次列印單據也不會改變。
* 在沒有編號的單據上，它是訂單日期。若是從其他地方匯入的訂單，則為訂單的處理日期。折讓單使用退款日期。

因此，不論是否開啟編號，同一個範本都能使用。內建的發票、折讓單和報價單範本已會列印此日期，標籤為「發票日期」、「折讓單日期」或「報價單日期」。如果您自己的範本以 `'now' | date` 列印日期，請改為 `{{ document_date | date: '%d %B %Y' }}`。

## 如果您的範本沒有列印編號

若有編號單據的範本完全沒有使用 `document_number`，Foliant 會在結尾加上一行小字，顯示編號和核發日期，例如「發票編號：INV-0042 · 2026 年 10 月 4 日」，確保編號不會遺漏。在您想要的位置加入 `{{ document_number }}`，這行額外的文字就會消失。如果您的範本已列印 `document_date` 或 `document_issued_at`，這行只會顯示編號。

## 注意事項

* 單據會在第一次下載、列印或匯出時取得編號，之後不會改變。
* 編輯器的預覽會顯示您下一張單據將取得的編號，但不會實際用掉該編號。
* 編號的條碼：`{{ document_number | barcode }}`。請參閱[條碼和 QR 碼](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-barcodes-and-qr-codes.md)。
* 適用於所有已選取訂單的範本一律不會編號。

## 相關文章

* [設定單據編號](https://foliant-help.iforiti.com/zh-Hant/invoices-and-numbering/document-numbering.md)
* [區塊參考](https://foliant-help.iforiti.com/zh-Hant/template-editor/block-catalogue.md)
* [條碼和 QR 碼](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-barcodes-and-qr-codes.md)
* [日期、語言和翻譯](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-dates-and-languages.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.