Skip to content

URD: Tax & Invoice

ModuleCORE-10Versionv0.5
StatusIn-progressDate2026-06-04

Business documentation. This URD is Tax & Invoice's feature list - each feature below is one Functional Area (<AREA>). The same <AREA> keys the feature's PRDs (PRD-<AREA>-NNN) and tests (TC-<AREA>-NNN), and each feature is listed in the Delivery feature catalog. See the Feature Spine convention.

1. Purpose

Define the user-facing requirements for staying tax-compliant when selling. The module records the merchant's tax identity, applies the correct tax rules to products, and turns a completed payment into a legal Vietnamese electronic invoice that can be delivered to the buyer and submitted to the tax authority - with adjustment, cancellation, and buyer self-service claims along the way.

2. Scope

IncludedExcluded
Seller tax identity (tax code / MST, name, address)Authoritative tax-code registry (tax authority owns it)
Tax-group rule templates applied onto productsTax-rate calculation at sale time (pricing engine)
VN administrative reference data (provinces, wards, units)PDF rendering of the invoice (provider-side)
Merchant invoice profile + encrypted provider credentialsPayment capture (Payment module)
Invoice issuance lifecycle (queued → issued / failed / cancelled)Order lifecycle (Orders module)
Provider integration: VNPAY / VNIS via iiapi + T-VANMultiple providers beyond the current iiapi/T-VAN set
Tax-authority (CQT) submission and status trackingTax declaration / filing automation
Invoice adjustment, replacement, cancellationCross-merchant settlement
Invoice request + buyer self-service claim (QR)
Channel routing + profile sharing across branches
Immutable audit trail for every invoice event

3. Definitions

TermDefinition
Tax identity (MST)The seller's tax registration code, business name, and address printed as the seller on every invoice
Tax groupA reusable rule template that decides which tax applies to which products
Invoice profileA merchant's invoicing setup linking the tax identity to a provider
ProviderThe e-invoice gateway (currently VNPAY / VNIS via iiapi) that issues the legal invoice
Tax authority (CQT)Vietnam's tax authority, reached through the T-VAN network for submission and validation
IssuanceThe act of turning an order into a numbered, legal e-invoice via a provider
Buyer claimA buyer self-serving their own invoice by scanning a receipt QR before a deadline
Audit trailThe immutable record of every state change an invoice goes through

4. Conceptual Model

Conceptual only - full schema lives in the taxation and invoice developer domain models.

5. Feature Catalog

The feature list of this module. Each row is one feature (a Functional Area). Detail in §6. Mirrored in the Delivery feature catalog.

Feature IDFeaturePhaseStatusPriority
TAXTax IdentityP1BuiltHigh
GRPTax GroupsP1BuiltHigh
CFGInvoice ConfigurationP1BuiltHigh
INVInvoice LifecycleP1BuiltHigh
REQInvoice Request & Buyer ClaimP1BuiltHigh
MODIssuance ModesP1BuiltHigh
DCLTax declaration (HKD 1-3B)P2PlannedHigh
ISSInvoice issuance experienceP2PlannedHigh

Status: live from Plane where mapped, otherwise registry-declared. Vocabulary mirrors Plane (state-group / phase).

6. Features

One sub-section per feature, in catalog order. Each feature keeps its description, requirements, and acceptance together. Priority = MoSCoW (Must / Should / Could / Won't).

TAX - Tax Identity Built

Feature ID: tax/TAX · Phase: P1 · PRDs: - · Dev: @nx/taxation

What it does for users: owners register the merchant's tax code (MST), business name, and address that print as the seller on every issued invoice, with VN province/ward lookups when entering addresses.

Requirements

IDPRequirement
URD-TAX-001MRegister the seller tax identity (MST, business name, address) used on issued invoices
URD-TAX-002MLook up Vietnamese provinces, wards, and administrative units when entering addresses
URD-TAX-003STax code is validated for correct Vietnamese format before it is accepted

Acceptance

AC-TAX-01: Register seller tax identity
GivenWhenThen
A merchant entering tax detailsThe seller tax identity (MST, name, address) is savedIt is used as the seller on issued invoices

GRP - Tax Groups Built

Feature ID: tax/GRP · Phase: P1 · PRDs: - · Dev: @nx/taxation

What it does for users: owners define reusable tax-group templates that automatically apply the correct tax onto matching products, and reconcile that tax whenever a product changes.

Requirements

IDPRequirement
URD-GRP-001MDefine a tax-group rule template that classifies which tax applies to which products
URD-GRP-002MApplying a tax group provisions the correct tax onto its matching products
URD-GRP-003MChanging or removing a product reconciles its applied tax automatically
URD-GRP-004SA tax group is only usable when compatible with the merchant's tax method

Acceptance

AC-GRP-01: Tax-group provisioning
GivenWhenThen
A tax group matching a productThe product is created or updatedThe correct tax is applied onto that product
A product is removedThe change is processedIts applied tax is reconciled / removed

CFG - Invoice Configuration Built

Feature ID: tax/CFG · Phase: P1 · PRDs: - · Dev: @nx/invoice

What it does for users: owners set up the merchant's invoicing - connect a provider with encrypted credentials, configure serial/category/policy per invoice type, route each sale channel to a config, and share profiles across branches.

Requirements

IDPRequirement
URD-CFG-001MCreate a merchant invoice profile linked to the seller tax identity
URD-CFG-002MConnect a provider (VNPAY / VNIS via iiapi) with credentials stored encrypted
URD-CFG-003MConfigure per invoice type the serial, category, tax method, and issuance policy
URD-CFG-004MRoute each sale channel to the provider config that should issue its invoices
URD-CFG-005MConfigure a retry policy (max retries + delay schedule) for failed issuance
URD-CFG-006SShare an invoice profile across branches (private / all-branches / whitelist)
URD-CFG-007SGuided onboarding wizard for step-by-step provider setup

Acceptance

AC-CFG-01: Connect a provider
GivenWhenThen
An invoice profile linked to the seller tax identityA provider is connected with credentialsCredentials are stored encrypted and the profile can issue invoices
A sale channelIt is routed to a provider configThat config issues the channel's invoices

INV - Invoice Lifecycle Built

Feature ID: tax/INV · Phase: P1 · PRDs: PRD-INV-001 · PRD-INV-003 · Dev: @nx/invoice

What it does for users: a completed payment queues and issues a legal e-invoice via the provider, captures its number and tax-authority code, retries failures, submits to the tax authority, and records every event in an immutable audit trail - with adjustment, replacement, and cancellation.

Requirements

IDPRequirement
URD-INV-001MQueue an invoice for issuance automatically on a successful payment
URD-INV-002MIssue the invoice via the provider and capture its number + tax-authority code
URD-INV-003MTrack invoice status (pending → processing → success / failed / cancelled)
URD-INV-004MRetry a failed issuance per the configured policy
URD-INV-005MSubmit the issued invoice to the tax authority (CQT via T-VAN) when enabled, and track its status
URD-INV-006MRecord an immutable audit trail entry for every invoice event
URD-INV-007MAdjust an issued invoice (correction linked to the original)
URD-INV-008MReplace or cancel an issued invoice with a reason
URD-INV-009SProcess inbound provider webhooks with signature validation to update status
URD-INV-010MOnly an issued (SUCCESS) invoice can be adjusted or cancelled; the correction always links back to the original (PRD-INV-003)
URD-INV-011MAn adjustment creates a new correction invoice (adjustment origin) linked to the original and is processed asynchronously via the issuance queue, claimed under an optimistic lock so a retried job issues it at most once
URD-INV-012MThe correction carries its own line items, description, and totals, and is issued through the provider referencing the original issuance
URD-INV-013MAdjustment is supported for VAT, POS-VAT, and ticket-VAT invoice types; an unsupported type is refused
URD-INV-014MCancellation marks the invoice cancelled with a required reason; for an issued invoice it also calls the provider cancellation
URD-INV-015MCancellation is idempotent (re-cancelling is a no-op) and is blocked while the invoice is being processed
URD-INV-016SEvery adjustment and cancellation writes an immutable audit entry and notifies connected clients in real time

Acceptance

AC-INV-01: Issue on payment
GivenWhenThen
A successful payment for an orderThe payment-success event is receivedAn invoice is queued for issuance
The provider acceptsIssuance completesInvoice number + tax-authority code are recorded; status is success
The provider rejectsIssuance failsA retry is scheduled per policy
Max retries exceededLast retry failsStatus is failed; the failure is recorded in the audit trail
AC-INV-03: Tax-authority submission
GivenWhenThen
Tax-authority submission is enabledAn invoice is issuedThe invoice is submitted to CQT via T-VAN
CQT acceptsThe response returnsThe invoice status is updated to accepted
CQT rejectsThe response returnsThe status records the rejection reason
AC-INV-04: Adjust an issued invoice
GivenWhenThen
An issued (SUCCESS) invoiceAn adjustment is requested with a description and adjustment itemsA linked correction invoice is created (PENDING) and queued
The queued adjustment is processedThe worker issues it via the provider referencing the originalIts status becomes SUCCESS, an audit entry is recorded, and clients update live
The original is not in SUCCESS stateAn adjustment is requestedIt is refused - only issued invoices can be adjusted
AC-INV-05: Cancel an invoice
GivenWhenThen
An issued (SUCCESS) invoiceCancellation is requested with a reasonThe provider cancellation is called, the invoice is marked cancelled, and the reason + an audit entry are recorded
An invoice currently processingCancellation is requestedIt is refused until processing completes
An already-cancelled invoiceCancellation is requested againThe request is a no-op (idempotent)

REQ - Invoice Request & Buyer Claim Built

Feature ID: tax/REQ · Phase: P1 · PRDs: - · Dev: @nx/invoice

What it does for users: a cashier collects buyer info and issues the invoice directly, or the buyer self-serves via a receipt QR with a claim token and deadline; invoices and claim links are delivered by QR, email, or SMS.

Requirements

IDPRequirement
URD-REQ-001MCapture buyer info (name, tax code, address, email) for an invoice
URD-REQ-002MDirect flow: cashier collects buyer info and issues the invoice
URD-REQ-003SBuyer self-service: receipt QR with a claim token and deadline
URD-REQ-004SClaim lifecycle: pending → claimed / expired
URD-REQ-005SDeliver the invoice / claim link by receipt QR, email, or SMS

Acceptance

AC-REQ-01: Buyer self-service claim
GivenWhenThen
A receipt with a valid claim QRBuyer opens the link before the deadlineBuyer can submit their info
Buyer submits infoSubmission succeedsThe invoice is issued with the buyer details
The deadline has passedBuyer opens the linkThe claim is expired and no invoice is issued

MOD - Issuance Modes Built

Feature ID: tax/MOD · Phase: P1 · PRDs: - · Dev: @nx/invoice

What it does for users: invoices can be issued in real time on payment, manually by a cashier at the counter, in scheduled batches, or by the buyer self-claiming via QR.

Requirements

IDPRequirement
URD-MOD-001MReal-time: issue immediately on payment
URD-MOD-002SManual: cashier-initiated issuance at the counter
URD-MOD-003SScheduled: batch issuance by a scheduled job
URD-MOD-004SBuyer self-service: buyer claims and issues via QR

Acceptance

AC-MOD-01: Real-time issuance
GivenWhenThen
Real-time mode is configuredA payment succeedsThe invoice is issued immediately

DCL - Tax Declaration (HKD 1-3B) Planned

Feature ID: tax/DCL · Phase: P2 (Jul-Aug) · PRDs: PRD-DCL-001 · Dev: @nx/ledger · @nx/taxation

What it does for users: a household business in the 1-3B band keeps its tax book and files its tax from inside KICKO - book S2a from real sales, PIT by its industry's rates, the official 01/CNKD form, submitted via T-VAN - no accountant needed.

Requirements

IDPRequirement
URD-DCL-001MBook S2a reflects the merchant's real sales per tax group
URD-DCL-002MTax rates are determined by the merchant's industry (configurable mapping)
URD-DCL-003MPIT is computed from revenue per the merchant's applicable rates
URD-DCL-004MDeclaration form 01/CNKD is generated (PDF/XML) for a period
URD-DCL-005MThe declaration is submitted via T-VAN and its status tracked to authority acknowledgement
URD-DCL-006MClient screens: review the book → preview 01/CNKD → submit
URD-DCL-007SSubmission history per period is kept

Acceptance

AC-DCL-01: One full tax period
GivenWhenThen
A 1-3B merchant with a month of salesThey review S2a, preview and submit 01/CNKDT-VAN accepts; status reaches "acknowledged"; the filing is archived per period

ISS - Invoice Issuance Experience Planned

Feature ID: tax/ISS · Phase: P2 (Jul) · PRDs: PRD-ISS-001 · Dev: @nx/invoice

What it does for users: a merchant actually issues e-invoices in daily operation - one action at the POS at payment, a place to see and manage every invoice, fixes via adjustment/replacement, and company VAT invoices carrying the buyer's MST. (The backend lifecycle and provider integration are built - this increment puts them in users' hands.)

Requirements

IDPRequirement
URD-ISS-001MCashier issues the e-invoice right at the POS at payment (MTT) - one action
URD-ISS-002MInvoice screens: list + detail with provider status and tax-authority code
URD-ISS-003MAdjustment and replacement invoices can be issued for an issued invoice
URD-ISS-004MA company VAT invoice carries the buyer's MST + company name
URD-ISS-005MFailed issuance is visible and retryable
URD-ISS-006SThe issued invoice can be printed/shared with the customer (link/PDF)
URD-ISS-007SProvider connection (VNPAY) is verifiable end-to-end from the config screens

Acceptance

AC-ISS-01: Issue in the real flow
GivenWhenThen
A paid sale at the POSCashier issues the invoiceInvoice issued with provider number + authority code, visible in the list
The buyer is a business customer with MSTThe invoice is issuedIt carries the buyer's MST and company name
The provider failsIssuance runsThe failure is visible and can be retried without re-creating the sale

7. Constraints & Non-Goals

Constraints

IDConstraint
C-01One active invoice profile per merchant
C-02One active config mapping per sale channel
C-03Provider credentials are stored encrypted
C-04The invoice audit trail is immutable
C-05A claim token is unique and bound to a single invoice request
C-06All records use soft-delete; nothing is physically removed

Non-Goals

  • Multiple invoice providers beyond the current iiapi / T-VAN set
  • PDF rendering of the invoice (produced provider-side)
  • Tax-rate calculation at sale time (owned by the pricing engine)
  • Tax declaration / filing automation

8. Version History

DateAuthorDescriptionVer
2026-02-26P. Do - Product OwnerInitial user storiesv0.1
2026-02-27QECode-level assessment, requirement adjustmentsv0.2
2026-04-16P. Do - Product OwnerVNPAY IIAPI + T-VAN + buyer-claim modelv0.3
2026-05-30MigrationRestructured to module-docs convention; AREA codes realigned to taxation + invoice buildv0.4
2026-06-04Claude (AI pair)Reorganize by feature (Feature Spine)v0.5

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.