Tax Calculation Engine
The calculation engine determines all applicable taxes based on tax rules, the company profile, and the customer's tax type.
Supported Taxes
| Tax | Description | Jurisdiction |
|---|---|---|
| ISS | Service Tax | Municipal |
| PIS | Social Integration Program | Federal |
| COFINS | Contribution for Social Security Financing | Federal |
| CSLL | Social Contribution on Net Income | Federal |
| IRPJ | Corporate Income Tax | Federal |
| IRRF | Withholding Income Tax | Federal |
| CSRF | PIS + COFINS + CSLL withheld together | Federal |
| INSS | Social Security Contribution | Federal |
| CBS | Contribution on Goods and Services (2026+) | Federal |
| IBS | Tax on Goods and Services (2026+) | Federal/State |
Calculation Flow
1. Get Applicable Rules
Queries the TaxRuleService with the operation context. Rules are filtered by scope and priority.
2. Resolve Rates
- Extracts rates from applicable rules
- Falls back to the company's Tax Profile
- Applies withholding overrides from the billing account
3. Calculate Each Tax
ISS = service_value × (iss_rate / 100)
PIS = service_value × (pis_rate / 100)
COFINS = service_value × (cofins_rate / 100)
CSLL = service_value × (csll_rate / 100)
IRRF = service_value × (irrf_rate / 100) [always withheld]
CSRF = service_value × (4.65 / 100) [always withheld]
INSS = service_value × (inss_rate / 100) [always withheld]
4. Rounding
Each tax is rounded independently with Math.round(). Rounding compensation is applied to the tax with the largest contribution.
5. Result
Total taxes = sum of all taxes
Total withheld = sum of taxes with isWithheld flag
Net amount = service value - total taxes
CBS/IBS (Tax Reform 2026+)
The system already supports the new taxes from the tax reform:
| Mode | Description |
|---|---|
informative | Calculated but not included in the total (2026) |
compositive | Included in the total (2027+) |
CBS and IBS rates are configurable in the company's Tax Profile.