QIIUB — Tax Engine Cases

A visual walk-through of how QIIUB computes tax for every kind of sale: standard, B2B reseller, government cert, cashier override, intrinsically exempt, holiday-waived, and multi-jurisdiction. Built from the actual integration tests so every case is reproducible.

Created: 2026-05-01
Last updated: 2026-05-01
Sources: ADR-0063, ADR-0067

This document complements docs/design/tax-engine.md and docs/design/tax-holidays.md. Every case shown here is exercised by an integration test in tests/QIIUB.Tests.Integration/Features/Tax/ — when QA finds a behavior question, find the matching case below first, then point at the test.

Taxed Standard taxable line Exempt Group has no rates Waived Override or cert Mapped Profile or holiday remap
Foundation — How tax is modeled ADR-0063

1TaxRate, TaxGroup, TaxGroupRate

QIIUB models tax as individual rates (a percentage with a code) bundled into named groups via a many-to-many junction. The same physical rate can appear in any number of groups without cloning.

TaxRate

A single tax line. Code is unique per merchant. Updating Rate affects every group that references it (future sales only — historical sales are frozen via SaleTax.TaxRateValue snapshot).
CodeNameRate
ESTATALPR State IVU10.5%
MUNICIPALPR Municipal IVU1.0%
ITBISRD ITBIS Estándar18.0%
FL_STATEFL Sales Tax6.0%

TaxGroup (with junction)

A bundle of rates, ordered by TaxGroupRate.Priority. LocationProduct.TaxGroupId is authoritative — that's what the calculator reads at sale time.
Group nameRates (Priority order)
PR IVU NormalESTATAL (0), MUNICIPAL (1)
Non-Taxable— no rates —
RD ITBIS EstándarITBIS (0)
FL Sales TaxFL_STATE (0)

The "Non-Taxable" seed group

Every new merchant DB is provisioned with one seeded group: Non-Taxable (zero rates). It's universal across every jurisdiction — gift cards, Rx exemptions, certain services don't collect tax. Jurisdiction-specific groups (PR IVU Normal, FL Sales Tax) are merchant-configured.

Calculator pipeline

The calculator is a pure function. The endpoint pre-loads everything; the calculator returns the verdict per line.

INPUT (one SaleLineItem) │ ├─ IsOverride? → Waived (zero LocationProduct.TaxGroup rates) │ ├─ TaxExempt + valid cert? → Waived (cert wins over holiday) │ ├─ ApplicableHoliday? → Mapped to holiday.ToTaxGroup │ stamp Sale​LineItem.TaxHolidayId/Code │ ├─ Customer profile? → Mapped via Profile.Maps │ (specific FromTaxGroupId beats catch-all NULL) │ └─ Default → apply LocationProduct.TaxGroup as-is Classification = Taxed (or Exempt if rate-less)

The four classifications

VerdictSaleTax rowsTaxAmountDiscriminator at report time
Taxed1+> 0Standard sale
Exempt0Resolved group has no rates (Rx, gift card, services)
Waived (cashier)1+ if rated; 0 if rate-less0SaleLineItem.TaxOverrideReasonCodeId NOT NULL
Waived (cert)1+ if rated; 0 if rate-less0Sale.CustomerCertNumber NOT NULL
Mapped (holiday)1+ from ToTaxGroup, often 0 ratesper ToTaxGroupSaleLineItem.TaxHolidayId NOT NULL
Mapped (B2B profile)1+ from mapped groupper mapped ratesTaxHolidayId NULL + customer has TaxProfile
Configuration — What the merchant sets up 5 examples

2PR IVU Standard

The default jurisdiction setup for a Puerto Rico merchant. Every product's LocationProduct.TaxGroupId points at this group.

TaxGroup: "PR IVU Normal"

PriorityRate Code%Compounding
0ESTATAL10.5%No
1MUNICIPAL1.0%No

3Rx — intrinsically exempt

Pharmacy compounds and prescription drugs sell tax-free under PR law. The merchant creates a sub-typed exempt group (separate from generic Non-Taxable) so reports can distinguish "Rx exempt this month" from "gift cards exempt this month."

TaxGroup: "Exempt — Rx"

No rates assigned. The calculator classifies any line in this group as Exempt.

4B2B reseller profile (SC 2916)

A Hacienda Form SC 2916 reseller default-exempts only the 1% municipal IVU. The merchant models this as a CustomerTaxProfile that remaps lines whose default group is "PR IVU Normal" to a "Resale-State-Only" group containing only the 10.5% state rate.

CustomerTaxProfile: "Reseller PR SC 2916"

RequiresCert = true · IsActive = true
Map: FromMap: To
PR IVU Normal (full 11.5%)Resale-State-Only (10.5% state)
Catch-all (NULL)Not used — non-resale items keep their group

5Tax holiday — Carta Circular 25-10 (hurricane prep)

An admin pre-configures the holiday once. The calculator picks it up automatically during the window. No master-data mutation.

TaxHoliday: "HUR-PREP-2026"

CodeHUR-PREP-2026
Window (local AST)2026-05-22 00:00 → 2026-05-26 00:00
Window (UTC stored)[2026-05-22 04:00, 2026-05-26 04:00) — half-open
TimeZoneAmerica/Puerto_Rico
Remap target→ Non-Taxable (zero rates)
IsActiveActive

Scope

TypeTargetMaxUnitPrice
CategoryGenerators (portátiles)$3,000
CategoryBatteries (AA, AAA, C, D, 6V, 9V)— no cap —
CategoryLED Flashlights, Lanterns, Candles— no cap —
CategoryFirst Aid Kits, Fire Extinguishers— no cap —

Locations

Empty — applies to ALL stores (single-jurisdiction merchant).

Sale flow — Cases the calculator handles 7 cases

6Walk-in customer — Taxed

The reference case. No customer, no holiday, no override — pipeline falls through to the default branch.

$100 t-shirt sold at PR location, no customer

Inputs

LocationProduct.TaxGroupPR IVU Normal
Customernull
UnitPrice × Qty$100 × 1
IsOverridefalse
ApplicableHolidaynull

Pipeline

override skip cert skip holiday skip profile skip default → PR IVU Normal applied as-is
QIIUB Demo Store
San Juan, PR

1× T-Shirt$100.00

Subtotal$100.00
IVU Estatal 10.5%$10.50
IVU Municipal 1.0%$1.00
TOTAL$111.50

Classification: Taxed

7Back-to-school holiday — Mapped to Non-Taxable

Carta Circular 24-12. Holiday is active; product matches a scoped category. The calculator remaps to the holiday's destination group (Non-Taxable, zero rates) and stamps the snapshot.

$50 school uniform sold July 18 (mid-window), no customer

Inputs

LocationProduct.TaxGroupPR IVU Normal
Product.Categories[School Uniforms]
UnitPrice × Qty$50 × 1
ApplicableHolidayBACK-TO-SCHOOL-2026-JUL
└─ ToTaxGroupNon-Taxable (0 rates)

Pipeline

override skip cert skip holiday → remap to Non-Taxable stamp TaxHolidayId/Code
QIIUB Demo Store
San Juan, PR

1× School Uniform$50.00

Subtotal$50.00
IVU$0.00
TOTAL$50.00

Classification: Mapped

8Hurricane prep — generator at $3,000 cap (boundary)

Carta Circular 25-10 caps generators at $3,000 per unit. The cap is inclusive (≤). Per-unit, not per-line — a $1,500 generator × 2 still qualifies.

Three side-by-side generator scenarios during HUR-PREP-2026
Generator UnitPriceQtyCap checkVerdictTax
$2001200 ≤ 3000 ✓Mapped$0.00
$3,00013000 ≤ 3000 ✓ (inclusive)Mapped$0.00
$3,00113001 ≤ 3000 ✗Taxed$345.12 (11.5%)
$1,50021500 ≤ 3000 ✓ (UnitPrice, not LineExtended)Mapped$0.00
$5,00015000 ≤ 3000 ✗Taxed$575.00
All-or-nothing, NOT "tax only the excess." A $3,001 generator pays the full 11.5% IVU on the entire $3,001 ($345.12), not 11.5% on just the $1 over the cap. Hacienda CC RI 25-10 explicitly: "there is no partial exemption for amounts exceeding this threshold." The hard cliff at $3,000.01 is intentional — it disincentivizes pricing tricks like listing a generator at "$2,999.99" to skirt the cap. Same convention as Texas / Florida back-to-school holidays.
Why per-unit: a generator is a unit, not divisible. Splitting one $5,000 generator into two $2,500 line items doesn't make sense — the customer takes home one physical generator. Hacienda's cap is per-article and the test cases prove the boundary at $3,000 inclusive.

9B2B reseller buying in-scope item during a holiday

Holiday wins over the customer's profile. The reseller would normally pay 10.5% (state portion only, per their SC 2916 cert mapping). During an active back-to-school holiday on an in-scope item, the holiday's 0% applies because it's statutory and more favorable.

$50 school uniform — same item, two scenarios for the same B2B customer
DateItemPipeline pathResult
Jul 18 (in window) School uniform (in scope) holiday → Non-Taxable, snapshot stamped Mapped — $0.00
Jul 18 (in window) Cleaning supplies (out of scope) profile → Resale-State-Only (10.5%) Mapped — $5.25 (10.5%)
Jul 25 (post-window) School uniform profile → Resale-State-Only (10.5%) Mapped — $5.25 (10.5%)
Audit trail discriminator: the holiday-path line has SaleLineItem.TaxHolidayId NOT NULL; the profile-path line has it NULL but the customer has TaxProfileId. Same merchant, same customer, same product — the snapshot tells the report which path fired.

10Government cert customer — Waived

A government agency with a full-exemption cert. The cert wins over a holiday because it's a customer-level statutory mechanism. Snapshot lands on Sale.CustomerCertNumber, NOT on the line's TaxHolidayId.

$100 office supplies, government cert valid through 2027-12-31

Inputs

Customer.TaxExempttrue
CertNumberGOV-PR-9988
CertExpiryDate2027-12-31
LocationProduct.TaxGroupPR IVU Normal

Pipeline

override skip cert → Waived (zero rates of original group) snapshot Sale.CustomerCertNumber holiday not reached
QIIUB Demo Store
San Juan, PR

Office supplies (mixed)$100.00

Subtotal$100.00
IVU Estatal 10.5%$0.00
IVU Municipal 1.0%$0.00
TOTAL$100.00

Classification: Waived (cert)

11Cashier override — Waived (god-mode)

Override is the highest-priority branch. It always wins, regardless of cert, holiday, or profile. Snapshot lives on SaleLineItem.TaxOverrideReasonCodeId + TaxOverrideNotes — a clear "explicit human intent" audit signal.

$100 line, cashier applies "Manager Override" reason code

Inputs

LocationProduct.TaxGroupPR IVU Normal
IsOverridetrue
TaxOverrideReasonCodeId42
TaxOverrideNotes"Damaged box discount"

Pipeline

override → Waived emit PR IVU Normal rates with TaxAmount=0 cert not reached holiday not reached
QIIUB Demo Store
San Juan, PR

1× Misc item$100.00

Subtotal$100.00
IVU Estatal 10.5%$0.00 *
IVU Municipal 1.0%$0.00 *
TOTAL$100.00

* Tax overridden by cashier
Reason: MGR-OVERRIDE — Damaged box discount

12Pharmacy Rx — Exempt (intrinsically)

The default branch with a rate-less group. The calculator emits zero SaleTax rows and classifies as Exempt. Different from Waived — the line is exempt by its TaxGroup, not by a customer-level mechanism.

$35 prescription fill, no customer needed

Inputs

LocationProduct.TaxGroupExempt — Rx (no rates)
UnitPrice × Qty$35 × 1

Pipeline

override skip cert skip holiday skip profile skip default → Exempt — Rx group has no rates classification = Exempt, zero SaleTax rows
Qiiub Rx Pharmacy
San Juan, PR

1× Prescription fill$35.00

Subtotal$35.00
TOTAL$35.00

Classification: Exempt
Edge cases — Reality bites 3 cases

13Multi-jurisdiction — same merchant, PR + FL stores

A merchant chain has stores in San Juan and Miami. Each PR holiday must NOT fire on Florida sales, and vice versa. The TaxHolidayLocation junction makes this explicit.

"PR Back-to-School 2026" with Locations = [SanJuanLocationId]
Sale atHoliday's Locations checkVerdictTax
San Juan, PRcontains SanJuanLocationId ✓Mapped$0.00 (PR holiday applied)
Miami, FLdoes NOT contain MiamiLocationId ✗TaxedFL sales tax applied as normal
Empty Locations = applies to all stores. Single-jurisdiction merchants don't touch this — zero configuration. Multi-jurisdiction merchants opt in by adding location rows. UI offers two selection modes (individual stores + by LocationGroup) that produce the same per-LocationId storage.

14Return after the window — snapshot mirrors original

Customer returns a school uniform on Jul 25 — the back-to-school window ended Jul 19. The original sale was Mapped (0% tax via holiday). The refund must mirror.

Original Jul 18 sale + Return Jul 25
StepWhat the engine readsOutcome
Original Jul 18 saleSaleTax: 0 rows · TaxHolidayCode = "BACK-TO-SCHOOL-2026-JUL"$0 tax collected
Return Jul 25Original.SaleTax (frozen): 0 rows
Original.TaxClassification = Mapped
Original.TaxHolidayId NOT NULL
$0 tax refunded — mirrors original
No date arithmetic needed. The return engine doesn't ask "is the holiday still active today?" — it reads the snapshot from the original sale and refunds exactly what was paid. The snapshot architecture is what makes returns trustworthy across event boundaries.

15Catalog churn — product added mid-window

Holiday active, scope = category "School Supplies". Merchant adds a new product P to the category at 14:00. Sale of P at 14:00:01.

Why the new product auto-qualifies — no holiday edit needed
TimeSystem stateResult
Jul 18 13:59Product P does not exist
Jul 18 14:00:00Admin assigns P to "School Supplies"ProductCategory row created
Jul 18 14:00:01Sale of P · resolver joins ProductCategory liveMapped — 0% applied
The resolver joins ProductCategory at sale time — it doesn't snapshot scope at holiday creation. Frozen snapshots would force the merchant to re-edit the holiday every time a SKU changes category, which is operationally hostile in a fast-moving catalog. The live join is one extra category lookup per line — negligible.
Reporting — Filtering by what actually happened Filter buckets

16How the snapshot fields support filterable reports

The combination of SaleLineItem.TaxClassification + the snapshot fields means every line falls into a filterable bucket. No need to reconstruct rules from the master records, even when those master records change later.

FilterBucket meaningUse case
TaxClassification = Mapped
AND TaxHolidayId IS NOT NULL
Holiday-waived sales — group by TaxHolidayCode for per-event totals Hacienda planilla supporting evidence; merchant ROI on the back-to-school promotion
TaxClassification = Waived
AND TaxOverrideReasonCodeId IS NOT NULL
Cashier-override-waived sales Audit cashier-discretion overrides; flag stores with anomalous override frequency
TaxClassification = Waived
AND CustomerCertNumber IS NOT NULL
Government / charity cert sales — group by cert Annual sales-by-cert report for cert customers' own filings
TaxClassification = Mapped
AND TaxHolidayId IS NULL
B2B-profile-mapped sales — group by customer's profile Reseller-by-reseller breakdown for SC 2916 audit
TaxClassification = Exempt Intrinsically-exempt items — group by resolved TaxGroupId (Rx vs gift card vs services) Rx sales reporting; subtype-by-subtype exemption breakdown
TaxClassification = Taxed Standard taxable sales The default report; no special filter needed
The snapshot survives master-record changes. A holiday can be soft-deleted; a cert can be revoked; a profile can be renamed. Historical reports stay correct because every signal lives on the immutable line.