TF Fiscal

Tax Calculation

POST/api/tax/purchase

Purchase credit × cost

For each purchase item, returns how much of each tax is recoverable (credit) and how much goes into cost, plus the taxes the buyer itself owes on entry (DIFAL, FCP and partial advance payment). This is the data used to split inventory/cost and recoverable tax when posting the invoice.

The call only calculates: nothing is stored and the tax authority is not queried. The buyer is the token company. Two modes: previsao (purchase order, before the invoice: the engine calculates what the supplier should itemize) and nota (invoice already synchronized by /api/invoice/received/sync: uses the amounts itemized in the stored XML). When data is missing or a rule is ambiguous, the item returns a pending item and no rate is assumed.

Required headers

tokenstringstringCompany token; CNPJ, state and tax regime are read from the company's registration
signstringstringMD5 signature: md5(token + "/api/tax/purchase" + body without line breaks + timestamp)
timestampstringstringUnix timestamp in seconds, 5-minute tolerance

Body

modo*stringstringprevisao or nota
chavestringstringnota mode: 44-digit key of an invoice received by the token CNPJ
data_operacaostringstringprevisao mode: YYYY-MM-DD; defines the rules and rates in force.
data_entradastringstringnota mode, optional: entry date; defaults to the issue date
regime_federalstringstringreal or presumido (CRT 3).
fornecedorobjectobjectprevisao mode: cnpj, uf, crt (1 to 4) and industrial (manufacturer: calculates the IPI it would itemize)
finalidadestringstringDefault purpose of the items
itens[]arrayarray
detalhadobooleanbooleanIncludes the legal basis of each tax and the table versions

 * Required field.

Company registration: regime_federal and contribuinte_ipi (true/false) in /api/company/edit. Without contribuinte_ipi, an item with itemized IPI returns the pending item contribuinte_ipi_ausente.

Rules by tax

TaxTreatment
ICMSResale and manufacturing: credit (LC 87/1996, art. 20). Use and consumption: cost. Fixed assets: credit through CIAP in 48 instalments (the taxed-output factor is applied by the ERP). Simples Nacional supplier: only the informed credit (vCredICMSSN / pCredSN). Buyer under the Simples Nacional or MEI: no credit, ICMS goes to cost (LC 123/2006, art. 23)
ICMS-STCost. Invoice with ST for manufacturing: pending item st_industrializacao
DIFAL / FCPInterstate purchase for use and consumption or fixed assets: base × (internal − interstate), single or double base according to the buyer state rule (uf_regra_compra table); without a rule, pending item difal_base_sem_regra. IPI is part of the base. Use and consumption: cost; fixed assets: CIAP. When the invoice has ICMS-ST withheld, DIFAL is not added (warning difal_coberto_pela_st)
Partial advance paymentInterstate purchase for resale, according to the buyer state rule; without a rule nothing is calculated and the warning antecipacao_parcial_sem_regra is returned
IPIBuyer that is an IPI taxpayer, for resale or manufacturing: credit. Other cases: cost. Buyer under the Simples (CRT 1, 2 and 4): cost
PIS / COFINSLucro real: 1.65% and 7.6% on the value without IPI and without the itemized ICMS, for resale and manufacturing (use and consumption only with insumo = true). Fixed assets: base only, for the credit on depreciation. Single-phase product for resale, lucro presumido and Simples: no credit
IBS / CBS2026: informational only, no effect on cost

Own ICMS is already inside the price and only enters through the credit side. Each item satisfies custo_aquisicao + total_recuperavel = desembolso; the engine checks it and, if it does not match, the item is parcial with the warning fechamento_divergente.

Response fields

statusstringstringdeterminado, parcial or pendente (the worst among the items)
comprador/fornecedor/emitente/notaobjectobjectData used in the calculation; emitente and nota in nota mode
itens[]arrayarray
itens[].pendencias/avisosarrayarrayStable codigo and mensagem
totaisobjectobjectSums of the calculated items

Common errors

MessageCause
Empresa não cadastrada para este token / 该token未关联公司The token is not linked to a registered company
Corpo da requisição inválido: envie um objeto JSON / 请求体无效,请传入 JSON 对象The body is not a valid JSON object
Falha no cálculo da compra. Tente novamente mais tarde. / 采购税额计算失败,请稍后重试Internal calculation failure; the request can be retried later

Examples

# sign = md5(token + path + body + timestamp)
# Template generated from the endpoint path; replace the placeholders
curl -X POST "https://api.tffiscal.com/api/tax/purchase" \
  -H "Content-Type: application/json" \
  -H "token: $TOKEN" \
  -H "timestamp: $TIMESTAMP" \
  -H "sign: $SIGN" \
  -d @body.json