npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

icms-teste

v2.0.2

Published

ICMS Library

Downloads

8

Readme

Cargon ICMS Library

  • Website: https://cargon.com.br/
  • ICMS Library with two main functionalities:
    • findTaxBracket( ): Find up-to-date ICMS tax brackets data, including exempt states.
    • calculateIcms( ): ICMS calculator

Usage

npm install icms-teste

Then require or import the functions before start using it

import { findTaxBracket, calculateIcms } from 'icms';

//OR

const icms = require('icms');

findTaxBracket( )

This function queries our up-to-date database and returns the tax bracket data for in-state or interstate transactions, even when they are exempt from taxes.

  • Inputs:

    first parameter = origin state. ("PR", "SP", "MG", ...)

    second parameter = optional destination state. ("SP", "RJ", ...)

  • Outputs:

    bracket = tax bracket percentage in an integer number. (12 = 12%, 7 = 7%).

    legal_text = legal text regarding an specific state policy, if there is one.

import { findTaxBracket } from 'icms-teste'

const result = findTaxBracket("PR", "PR");
/*
 result = {
    bracket: 0,
    legal_text: 'ICMS Isento conforme Convênios ICMS 4/2004, 111/2012, 60/2014, 29/2015 e 65/2015; Convênios ICMS 107/2015 e 133/2019'
 }
*/

In-state transaction

  • Transaction where the origin state is the same as the destination state.
  • The second parameter is optional, if you dont include it, we will consider the destination state the same as the origin state, meaning an in-state transaction.
const result = findTaxBracket("PR", "PR");

// OR

const result = findTaxBracket("PR");
/*
   result = {
    bracket: 0,
    legal_text: 'ICMS Isento conforme Convênios ICMS 4/2004, 111/2012, 60/2014, 29/2015 e 65/2015; Convênios ICMS 107/2015 e 133/2019'
   }
*/

Interstate transaction

  • Transaction where the destination state is different from the origin state.
  • In this case, you are required to instance the second parameter of the function.
const result = findTaxBracket("ES", "SP");

/*
   result = {
      bracket: 12,
      legal_text: null
   }
*/

Observation & other cases:

  1. No data found: if no data about the states inputted in the functon was found, we will throw an error.

  2. State is exempt from taxes: if the state has an exempt policy and does not have tax brackets, we will return 0 as the bracket:

{
   bracket: 0, //Tax bracket = 0%, meaning it is exempt from taxes
   legal_text: 'ICMS Isento conforme Convênios ICMS 4/2004, 111/2012, 60/2014, 29/2015 e 65/2015; Convênios ICMS 107/2015 e 133/2019'
}
  1. Lega text: if there is an legal text, we will return it; otherwise, we will return null
{
   bracket: 12,
   legal_text: null //No legal text
}

calculateIcms( )

Function that calculate ICMS tax bracket with an "inside" operation.

  • Required input Object:

    ammount = initial ammount to be used in the calculation base.

    bracket = percentage of bracket tax being applied to the calculation base. (20 = 20%, 3 = 3%)

    reducedBasePercentage = the optional percentage that will reduce the calculation base ammount. (13 = 13%, 8 = 8%)

  • Optional input object:

    decimals = the level of precision in regards to the decimal values being returned.

  • Outputs:

    initialAmmount = initial ammount inputted by the user.

    icmsPercentage = tax percentage inputted by the user.

    baseReductionPercentage = base reduction percentage inputted by the user (if there's one).

    icmsAmmount = ammount of ICMS tax bracket. The result of applying the ICMS percentage into the calculation base.

    calculationBase = calculation base used to calculate the Tax Bracket. Can be inferred as the sum of the initial ammount and the icms ammount.

    insidePercent = percentage of the ammount inputted by the user compared with the total ammount (initial ammount + tax bracket)

import { calculateIcms } from 'icms-teste'

const result = calculateIs(
   {
      ammount: 1000,
      bracket: 18,
      reducedBasePercentage: 20, //OPTIONAL
   },
   {
      decimals: 2, //OPTIONAL
   }
);

/*
 result = {
  initialAmmount: 1000,
  icmsPercentage: 0.18,
  baseReductionPercentage: 0.2,
  calculationBase: 975.61,
  icmsAmmount: 175.61,
  insidePercent: 0.82
}
*/

Base reduction

  • The percentage of base calculation reduction is applied directly into the calculation base, reducing its ammount.
  • If you don't want to apply it, you simply put "0" in the field, or don't even include it in the parameters
const result = calculateIcms(
   {
      ammount: 1000,
      bracket: 18,
      reducedBasePercentage: 0,
   },
   {
      decimals: 2,
   }
);

//OR

const result = calculateIcms(
   {
      ammount: 1000,
      bracket: 18,
   },
   {
      decimals: 2,
   }
);

/*
 result = {
  initialAmmount: 1000,
  icmsPercentage: 0.18,
  baseReductionPercentage: 0,
  calculationBase: 1219.51,
  icmsAmmount: 219.51,
  insidePercent: 0.82
}
*/

Exempt from taxes

  • The percentage of ICMS Tax Bracket being applied into the calculation base.
  • If the calculation is for an exempt state, simply put 0 into the "bracket" field.
const result = calculateIcms(
   {
      ammount: 1000,
      bracket: 0,
      reducedBasePercentage: 10,
   },
   {
      decimals: 0,
   }
);

/*
 result = {
  initialAmmount: 1000,
  icmsPercentage: 0,
  baseReductionPercentage: 0.1,
  calculationBase: 900,
  icmsAmmount: 0,
  insidePercent: 1
}
*/

Observations

  1. Percentage is returned in decimals: All the percentage values used in the calculation are returned in decimals. If you want to convert them to integer, multiply it by 100.

  2. Percentages are applied in the calculation base: Both the icms percentage and the base reduction percentage are applied in the new base of calculation, not necessarily in the ammount inputted by the user. That's how the calculation works.