CST
Código de Situação Tributária: the tax situation codes of ICMS, IPI, PIS and COFINS.
Validate
- JavaScript library
- Python library
- Go library5 cases fail
- Ruby library32 cases fail
- Rust library
- .NET library26 cases fail
- Erlang library
Checks whether a CST code is valid for a tax.
options.taxpicks the table:icms,ipi,pisorcofins(PIS and COFINS share a table). Whenoptions.taxis omitted or unknown, the function accepts a code that exists in any of the tables.- For
icmsthe code is one of the 15 Tabela B codes of 2 digits (00,02,10,15,20,30,40,41,50,51,53,60,61,70,90), bare as the NF-eCSTfield carries it next toorig, or the 3-digit form with an origin digit0-8before it.02,15,53and61are the monofasia de combustíveis codes that Ajuste SINIEF 39/23 added;12,13,52,72and74are not codes, because Ajuste SINIEF 20/24 struck them before they took effect. ipiaccepts 14 codes of 2 digits:00-05,49,50-55and99.pisandcofinsaccept 33 codes of 2 digits:01-09,49,50-56,60-67,70-75,98and99. These taxes have no 3-digit form.- Accepts a string or a safe non-negative integer. The 3-digit ICMS form accepts any run of separators (space,
.,-or/) right after the origin digit ("1--10","0 . 10"). A separator anywhere else is rejected ("0-0","00-","11-0"). Surrounding whitespace is ignored. Any other string ("abc110") is rejected, its digits are not picked out. - A single digit is padded to the 3-digit ICMS form (
0and"0"are000, also for the other taxes, so a single digit is never an IPI, PIS or COFINS code). A 2-digit value is a Tabela B code, read as written and never as origin plus a digit:isValidCst("10", { tax: "icms" })is the Tabela B code 10, and"07"is not an ICMS code. The number7is read as007, not as07. - A
nullor non-objectoptionsis read as no options, so every table is checked (until 2.4.0 it made the result false). - Until 2.4.0 a 2-digit value was never a valid ICMS code (
"10","00"withtax: "icms"were false) and only one separator was accepted after the origin digit ("1--10"was false). Both changed in 2.5.0. - Sources: the ICMS Tabela B of Convênio SINIEF s/nº 1970 as Ajuste SINIEF 39/23 gave it and Ajuste SINIEF 20/24 amended; IPI, PIS and COFINS from Instrução Normativa RFB nº 1.009/2010.
| Parameter | Type | Required |
|---|---|---|
value | string | number | yes |
options | IsValidCstOptions | no |
options.tax | "icms" | "ipi" | "pis" | "cofins" | no |
| returns | boolean |
Check if a CST (Código de Situação Tributária) code is valid for a given tax. Pass the tax through options.tax:
| Tax | Format | Accepted codes |
|---|---|---|
icms | 2 digits (Tabela B) or 3 digits (origem + CST) | the Tabela B code alone, or origem 0-8 + one of 00, 02, 10, 15, 20, 30, 40, 41, 50, 51, 53, 60, 61, 70, 90 |
ipi | 2 digits | 00, 01, 02, 03, 04, 05, 49, 50, 51, 52, 53, 54, 55, 99 |
pis | 2 digits | 01-09, 49, 50-56, 60-67, 70-75, 98, 99 |
cofins | 2 digits | same table as pis |
- Options (
IsValidCstOptions):taxpicks the table. Omitted, or outside those four values, every table is accepted; anullor non-objectoptionsis read as none. - Accepts a string with the 2 digits of a Tabela B code or the 3 digits of the ICMS form, or a number. The ICMS form may have any run of separators (space,
.,-or/) after the origin digit. - A single digit is padded to the 3-digit ICMS form; a 2-digit value is a Tabela B code and is never read as an origin plus a digit (
'10'is the Tabela B code10), while the number7is read as the ICMS code007, which is not in the table, so it isfalse.
import { isValidCst } from '@brazilian-utils/brazilian-utils';
isValidCst('000', { tax: 'icms' }); // true
isValidCst(0, { tax: 'icms' }); // true (a single digit is padded to the 3 digit form, '000')
isValidCst('0', { tax: 'icms' }); // true (padded the same way a number is)
isValidCst('110', { tax: 'icms' }); // true
isValidCst('002', { tax: 'icms' }); // true (monofasia de combustíveis)
isValidCst('60', { tax: 'icms' }); // true (a bare Tabela B code, as the NF-e CST field carries it)
isValidCst('06', { tax: 'pis' }); // true
isValidCst('99', { tax: 'ipi' }); // true
isValidCst('110'); // true (found in the icms table, tax omitted)
isValidCst('000', { tax: 'nope' }); // true (an unknown tax falls back to every table)
isValidCst('999'); // false (not in any table)
isValidCst('abc110'); // false (not a documented form)
isValidCst(-110); // false (not a non-negative safe integer)Source: ICMS Tabela B from Anexo I of Convênio SINIEF s/nº 1970 as amended by Ajuste SINIEF 20/24; IPI, PIS and COFINS from IN RFB nº 1.009/2010.
Code: brazilian-utils/javascriptTry it with JavaScript isValidCst
Shared test cases (102) and the result in each library cst.isValid
Official sources
- confaz.fazenda.gov.br/legislacao/ajustes/…/cvsn_70
- confaz.fazenda.gov.br/legislacao/ajustes/…/ajuste-sinief-39-23
- confaz.fazenda.gov.br/legislacao/ajustes/…/AJ020_24
- confaz.fazenda.gov.br/legislacao/ajustes/…/aj_003_94
- confaz.fazenda.gov.br/legislacao/ajustes/…/AJ_006_00
- confaz.fazenda.gov.br/legislacao/ajustes/…/aj_020_12
- confaz.fazenda.gov.br/legislacao/ajustes/…/aj_015_13
- normas.receita.fazenda.gov.br/sijut2consulta/link.action
See also CSOSN
Last updated on
