AP voucher validation rules
Updated: 2026-11-04
Code:
validateRecord in PCE_LIB_AP_Validate.js Applies to: transaction sublist save, PCE AP invoice save, AP CSV import, and AP Write. UI, CSV, and API share this rule set.
HTML: HTML
A failure blocks the save or write. A tax difference inside the tolerance is a warning only; the save still succeeds. On the API, warnings come back in warnings.
Formats 21 and 25 must first resolve to one format master row via invCatCode or docFormatName. A miss is a lookup error, not one of the field rules below.
These fields are not in this validation: total, file business tax, already filed, source transaction, clientRef.
Traditional Chinese: 進項憑證檢核規則.
1. Document formats
| Code | Name |
|---|---|
| 21 | Triplicate GUI (invCatCode 01) / computer GUI (05) |
| 22 | Duplicate cash-register GUI, and other vouchers that show tax |
| 23 | Purchase return or allowance for triplicate / computer / triplicate cash-register GUI (line by line) |
| 24 | Purchase return or allowance for duplicate cash-register GUI and other tax-bearing vouchers (line by line) |
| 25 | Input triplicate cash-register GUI (06) / general-tax e-invoice (07) |
| 26 | Summary of input triplicate and computer GUI with tax of 500 or less per document |
| 27 | Summary of input duplicate cash-register GUI and other tax-bearing vouchers with tax of 500 or less per document |
| 28 | Customs-collected business tax payment certificate |
| 29 | Customs refund of overpaid business tax |
Document format is required. If it is missing, nothing else is checked. Code DocTypeRequired.
2. Fields checked on every row
| Field | Rule | Code |
|---|---|---|
| Document date | Required | DocDateRequired |
| Document period | Required. If blank, the document date is converted. ROC 5-digit YYYMM (3-digit year + 2-digit month 01–12, e.g. 11508) | DocPeriodRequired, DocPeriodFormat |
| Filing period | Required. It is not filled in automatically. Same YYYMM format | FilingPeriodRequired, FilingPeriodFormat |
| Buyer tax ID | Required, 8 digits, checksum must pass | BuyerTaxIdRequired, BuyerTaxIdLengthNotValid, BuyerTaxIdNotValid |
| Tax type | Required. Only 1 taxable, 2 zero-rated, 3 exempt | TaxTypeRequired, TaxTypeInvalid |
| Deduction code | Required. Taxable may be 1–4. Zero-rated or exempt may only be 3 or 4 | DeductionCodeRequired, DeductionCodeInvalid |
Deduction codes: 1 deductible purchases and expenses, 2 deductible fixed assets, 3 non-deductible purchases and expenses, 4 non-deductible fixed assets.
The tax-type list may also contain F (void) and D (blank / unused). This validation still accepts only 1, 2, and 3.
3. Number fields: required, one-of, or forbidden
A row follows one number path. Filling both, or filling neither when one is required, is rejected.
| Format | Invoice no. | Other doc no. | Utility carrier serial | Customs certificate |
|---|---|---|---|---|
| 21 | Required | Forbidden | Forbidden | Forbidden |
| 22, not summarized | One of invoice no. or other doc no. | One of the two | Forbidden | Forbidden |
| 22, summary (A) | Forbidden | Required | Forbidden | Forbidden |
| 23 | Required | Forbidden | Forbidden | Forbidden |
| 24 | One of invoice no. or other doc no. | One of the two | Forbidden | Forbidden |
| 25 | One of invoice no. or carrier serial | Forbidden | One of the two | Forbidden |
| 26 | Required | Forbidden | Forbidden | Forbidden |
| 27 | One of invoice no. or other doc no. | One of the two | Forbidden | Forbidden |
| 28, 29 | Forbidden | Forbidden | Forbidden | Required |
One-of failures: invoice vs other doc is GuiNumberCommonNumberConflict; format 25 invoice vs carrier is GuiNumberUtilityConflict. Forbidden-field codes: GuiNumberMustNotHave, CommonNumberMustNotHave, UtilityCarrierMustNotHave, CustomsAuthCodeMustNotHave. Format 22 summary with an invoice number: GuiNumberMustNotHaveOnSummary. Format 22 summary without an other-doc number: SummaryMarkRequiresOtherDoc.
3.1 Invoice number format, track, and duplicates
When an invoice number is present:
- It must be 1–2 uppercase letters plus 8 digits. Zero letters, or lowercase, is rejected. Codes
GuiFormatError,GuiTrackRequired. - The track must be on the MOF track table. The period prefers the bi-monthly period of the document date (an odd month rolls forward; 11507 and 11508 are both period 11508). If there is no date, the document period is used. Format 23 is checked against tracks for 21 and 25. Format 24 is checked against tracks for 22. Other formats use their own code. Codes
GuiTrackPeriodRequired,GuiTrackDocTypeRequired,GuiTrackNotAllowed. - The number must be unique on the same format master row (the lookup row selected). Format 21 triplicate and format 21 computer GUI are two master rows and do not collide with each other. The search covers active PCE AP invoices (the current record is excluded on edit). If the account has API intake rows, pending and failed rows are included; rejected and posted rows are not. In one API call or one CSV file, a later row also treats a number that already passed validation as a duplicate. Formats 23 and 24 skip the duplicate check. Code
GuiNumberDuplicated.
3.2 Other document number
On formats 22, 24, and 27, an other-doc number may not look like an invoice track (leading letters plus 8 digits). Code CommonNumberSimilarToGuiNumber.
3.3 Utility carrier serial
Format 25 only, and only on the carrier path:
- Length 10. Code
UtilityCarrierLength. - Must start with
BB(the value is uppercased before the check). CodeUtilityCarrierPrefix. - Must not duplicate an existing AP invoice (the current record is excluded on edit). Code
UtilityCarrierDuplicated.
3.4 Customs certificate
Formats 28 and 29 only:
- Required, length 14. Codes
CustomsAuthCodeRequired,CustomsAuthCodeLength. - Character 1 may not be blank. Code
CustomsAuthCodePos1. - Character 3 may not be
1. CodeCustomsAuthCodePos3.
4. Seller tax ID
| Case | Rule |
|---|---|
| Formats 28, 29 | Forbidden. Code SellerTaxIdMustNotHave |
| Summary mark A (including formats 26 and 27, which must be A) | Forbidden. Code SellerTaxIdMustNotHave |
| Formats 21, 23, 25, and not summary A | Required |
| Formats 22, 24, with an invoice number | Required |
Missing when required: SellerTaxIdRequired. A value must be 8 digits with a valid checksum: SellerTaxIdLengthError, SellerTaxIdValueError.
Format 22 on the other-doc path, without summary A, may leave the seller tax ID blank.
5. Sales amount
After removing decimal points, more than 12 characters is rejected (the minus sign counts). Code SalesAmtLengthError.
| Case | Rule | Code |
|---|---|---|
| Formats 28, 29 | Required. This field is the business-tax base | TaxBaseRequired |
| Format 29 | Must be about tax ÷ 5% (rounded). The difference may not exceed 1 | TaxBaseNotMatchTaxAmt |
| Tax type 1, and not 28 or 29 | Must be greater than 0 | SalesAmtShouldBeGreaterThanZero |
Formats 28 and 29 do not use the “taxable amount must be greater than 0” rule. Zero-rated and exempt rows have no “greater than 0” rule.
6. Tax amount
Tax type 2 or 3: tax must be 0. Code TaxAmtShouldBeZero.
If the tax type is not 1, 2, or 3, the tax formula is skipped (the tax type itself is rejected first).
If format 22, 24, 27, or 25 has not chosen exactly one number path, tax is not checked yet, so the one-of error is not repeated.
When the path is chosen and the tax type is taxable:
| Case | Rule |
|---|---|
| 22 or 27, with an invoice number | Tax must be 0 (sales amount is tax-inclusive). Code TaxAmtShouldBeZero |
| 21, 23, 24, 25 | Tax must equal sales × 5% (rounded). Format 24 has no “tax 0 means tax-inclusive” path |
| 26, 28, 29 | The × 5% check is not applied |
× 5% difference: 0 passes; 1–5 is a warning and the save still succeeds; more than 5 is rejected. Default path code TaxAmtNotEqual (warning TaxAmtToleranceWarning). The 22/27 other-doc path uses TaxAmtOtherDocInvalid (warning TaxAmtOtherDocToleranceWarning).
6.1 Average tax per summarized document
Formats 26 and 27, when taxable and the summary quantity is greater than 0: average tax per document may not exceed 500. Code SummaryTaxPerDocExceed.
- Format 26: entered tax ÷ summary quantity.
- Format 27 with tax 0 (tax-inclusive): implied tax is sales × 5% ÷ 1.05, rounded, then divided by the quantity.
- Format 27 with non-zero tax: entered tax ÷ quantity.
7. Tax type by format
| Format | Allowed tax types | Code |
|---|---|---|
| 28 | Taxable (1) or exempt (3) only. Zero-rated is not allowed | TaxTypeNotAllowed |
| 29 | Taxable (1) only | TaxTypeNotAllowed |
| Others | 1, 2, 3 | TaxTypeInvalid |
8. Summary mark and quantity
Summary mark: A summary, B allocation.
| Rule | Code |
|---|---|
| Formats 26 and 27 must be summary (A) | SummaryMarkMustBeA |
| Format 22 may not be allocation (B) | SummaryMarkShareNotAllowed |
| Allocation (B) may not have a summary quantity (including format 25) | ShareMarkNoSummaryQty |
| Formats 26 and 27, or formats 22/25 with summary (A): quantity must be a number greater than 1 | SummaryQtyInvalid |
9. Document period and filing period
After both values are valid YYYMM:
| Format | Rule | Code |
|---|---|---|
| 23, 24, 29 | Document period and filing period must fall in the same bi-monthly period. An odd month rolls forward; 11507 and 11508 are both period 11508 | DocPeriodMustEqualFiling |
| 21, 22, 25, 26, 27, 28 | Document period may not be later than the filing period | DocPeriodAfterFiling |
| 21, 22, 25, 26, 27, 28 | Document period may not be more than 120 months (10 years) before the filing period. Exactly 120 months is allowed | DeductionPeriodExceed10Years |
Formats 23, 24, and 29 do not also run the 10-year check. They are already limited to the same bi-monthly period.
10. Error codes
| Code | Meaning |
|---|---|
DocTypeRequired | Document format is required |
DocDateRequired | Document date is required |
DocPeriodRequired | Document period is required |
DocPeriodFormat | Document period is not ROC YYYMM |
FilingPeriodRequired | Filing period is required |
FilingPeriodFormat | Filing period is not ROC YYYMM |
DocPeriodMustEqualFiling | 23/24/29 are not in the same bi-monthly period |
DocPeriodAfterFiling | Document period is after the filing period |
DeductionPeriodExceed10Years | Deduction window exceeds 10 years |
BuyerTaxIdRequired | Buyer tax ID is required |
BuyerTaxIdLengthNotValid | Buyer tax ID is not 8 digits |
BuyerTaxIdNotValid | Buyer tax ID checksum failed |
SellerTaxIdRequired | Seller tax ID is required |
SellerTaxIdLengthError | Seller tax ID is not 8 digits |
SellerTaxIdValueError | Seller tax ID checksum failed |
SellerTaxIdMustNotHave | Seller tax ID is not allowed in this case |
GuiNumberRequired | Invoice number is required |
GuiFormatError | Invoice number format is invalid |
GuiTrackRequired | Invoice number has no track |
GuiTrackPeriodRequired | Track period cannot be determined |
GuiTrackDocTypeRequired | Document format cannot be determined |
GuiTrackNotAllowed | Track is not on the MOF table |
GuiNumberDuplicated | Duplicate invoice number |
GuiNumberMustNotHave | Invoice number is not allowed for this format |
GuiNumberMustNotHaveOnSummary | Format 22 summary may not have an invoice number |
GuiNumberCommonNumberConflict | Invoice number and other doc no. must be one of the two |
GuiNumberUtilityConflict | Format 25 invoice number and carrier serial must be one of the two |
CommonNumberMustNotHave | Other doc no. is not allowed for this format |
CommonNumberSimilarToGuiNumber | Other doc no. looks like an invoice track |
SummaryMarkRequiresOtherDoc | Format 22 summary requires an other doc no. |
UtilityCarrierMustNotHave | Carrier serial is not allowed for this format |
UtilityCarrierLength | Carrier serial is not 10 characters |
UtilityCarrierPrefix | Carrier serial does not start with BB |
UtilityCarrierDuplicated | Duplicate carrier serial |
CustomsAuthCodeMustNotHave | Customs certificate is not allowed for this format |
CustomsAuthCodeRequired | Customs certificate is required |
CustomsAuthCodeLength | Customs certificate is not 14 characters |
CustomsAuthCodePos1 | Customs certificate character 1 is blank |
CustomsAuthCodePos3 | Customs certificate character 3 is 1 |
SalesAmtLengthError | Sales amount is too long |
SalesAmtShouldBeGreaterThanZero | Taxable sales amount must be greater than 0 |
TaxBaseRequired | Formats 28/29 require a tax base |
TaxBaseNotMatchTaxAmt | Format 29 tax base does not match the tax |
TaxAmtShouldBeZero | Tax must be 0 |
TaxAmtNotEqual | Tax differs from sales × 5% by more than 5 |
TaxAmtToleranceWarning | Tax differs by 1–5 (warning) |
TaxAmtOtherDocInvalid | Other-doc tax is not valid |
TaxAmtOtherDocToleranceWarning | Other-doc tax differs by 1–5 (warning) |
SummaryTaxPerDocExceed | Average tax per document is over 500 |
TaxTypeRequired | Tax type is required |
TaxTypeInvalid | Tax type is not 1, 2, or 3 |
TaxTypeNotAllowed | Tax type is not allowed for format 28/29 |
DeductionCodeRequired | Deduction code is required |
DeductionCodeInvalid | Deduction code does not match the tax type |
SummaryMarkMustBeA | Formats 26/27 must be summary |
SummaryMarkShareNotAllowed | Format 22 may not be allocation |
ShareMarkNoSummaryQty | Allocation may not have a summary quantity |
SummaryQtyInvalid | Summary quantity must be greater than 1 |