inss_calculator 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +57 -0
- data/lib/inss_calculator/discount_previdence_calculator.rb +4 -0
- data/lib/inss_calculator/first_discount_calculator.rb +20 -5
- data/lib/inss_calculator/fourth_discount_calculator.rb +21 -6
- data/lib/inss_calculator/second_discount_calculator.rb +21 -6
- data/lib/inss_calculator/third_discount_calculator.rb +21 -6
- data/lib/inss_calculator/version.rb +1 -1
- data/lib/inss_calculator.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e12311e6e06783b04c8602f840b94674b7fbb935a20c86c302de4c3801d899fd
|
4
|
+
data.tar.gz: 8798314565756151e4821114d5c27dde36c33285eb453cb59a6e84c6ecc66530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48c832e1fb4bc2543b72bb9f78f87fbb98eb6a0dc129b9c927422da978bfff8f688f9f45587630887a5be9fded9a8c2ee5267eee929d28e0309b1d0e0be8dad8
|
7
|
+
data.tar.gz: 695c126b9665d5efb414f9c7b8e1339394e6798b2ecb40cb5b20b6120e447129217ceca69bc5e5b16a42bf9faf47fa193c1b2bdb92c6ca12548353a3ff94cbe9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1 +1,58 @@
|
|
1
1
|
# InssCalculator
|
2
|
+
|
3
|
+
Calculadora do desconto do INSS sobre o salário bruto 2024
|
4
|
+
|
5
|
+
## Instalation
|
6
|
+
|
7
|
+
```
|
8
|
+
bundle add inss_calculator
|
9
|
+
```
|
10
|
+
|
11
|
+
Não conhecia [esse comando?](https://bundler.io/v2.5/man/bundle-add.1.html) Ele adiciona ao seu Gemfile a gem e ainda a instala.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```
|
16
|
+
gross_salary = 3000
|
17
|
+
calculator = InssCalculator::DiscountPrevidenceCalculator.new(gross_salary)
|
18
|
+
calculator.contribution => 258.81
|
19
|
+
calculator.salary => 3000.0
|
20
|
+
calculator.net_salary => 2741.19
|
21
|
+
```
|
22
|
+
### Precisas realizar uma query ao Banco de Dados por grupo de faixa salarial?
|
23
|
+
|
24
|
+
InssCalculator providencia as seguintes constantes:
|
25
|
+
|
26
|
+
```
|
27
|
+
InssCalculator::FIRST_SALARY_BASE = 0.0
|
28
|
+
InssCalculator::FIRST_SALARY_LIMIT = 1412.0
|
29
|
+
|
30
|
+
InssCalculator::SECOND_SALARY_BASE = 1412.01
|
31
|
+
InssCalculator::SECOND_SALARY_LIMIT = 2666.68
|
32
|
+
|
33
|
+
InssCalculator::THIRD_SALARY_BASE = 2666.69
|
34
|
+
InssCalculator::THIRD_SALARY_LIMIT = 4000.03
|
35
|
+
|
36
|
+
InssCalculator::FOURTH_SALARY_BASE = 4000.04
|
37
|
+
InssCalculator::FOURTH_SALARY_LIMIT = 7786.02
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
Desta forma, uma requisição que busca somente a primeira faixa salarial seria:
|
42
|
+
|
43
|
+
```
|
44
|
+
YourModel.where("salary <= ?", InssCalculator::FIRST_SALARY_LIMIT)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Nota sobre trabalhar com números decimais em Ruby
|
48
|
+
|
49
|
+
Após investigar os resultados dos exemplos contábeis, concluiu-se que os números são truncados.
|
50
|
+
|
51
|
+
Cada faixa salarial trunca seu resultado final após aplicar a sua alíquota correspondente.
|
52
|
+
|
53
|
+
Por isso o uso do método `.truncate` ao invés de um arredondamento ao final de cada cálculo parcial.
|
54
|
+
|
55
|
+
Para mais detalhes, veja a regra e o exemplo [deste site](https://www.contabilizei.com.br/contabilidade-online/desconto-inss/)
|
56
|
+
|
57
|
+
|
58
|
+
### Feito com amor, feito com Ruby S2
|
@@ -5,14 +5,29 @@ module InssCalculator
|
|
5
5
|
# In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
|
6
6
|
class FirstDiscountCalculator < DiscountCalculatorBase
|
7
7
|
QUOTATION = 0.075
|
8
|
-
SALARY_BASE = 0.00
|
9
|
-
SALARY_LIMIT = 1412.0
|
10
|
-
FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
|
11
8
|
|
12
9
|
def contribution
|
13
|
-
return
|
10
|
+
return full_contribution if salary > salary_limit
|
14
11
|
|
15
|
-
|
12
|
+
calculate_contribution
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def calculate_contribution
|
18
|
+
((salary - salary_base) * QUOTATION).truncate(2)
|
19
|
+
end
|
20
|
+
|
21
|
+
def full_contribution
|
22
|
+
((salary_limit - salary_base) * QUOTATION).truncate(2)
|
23
|
+
end
|
24
|
+
|
25
|
+
def salary_limit
|
26
|
+
InssCalculator::FIRST_SALARY_LIMIT
|
27
|
+
end
|
28
|
+
|
29
|
+
def salary_base
|
30
|
+
InssCalculator::FIRST_SALARY_BASE
|
16
31
|
end
|
17
32
|
end
|
18
33
|
end
|
@@ -5,16 +5,31 @@ module InssCalculator
|
|
5
5
|
# In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
|
6
6
|
class FourthDiscountCalculator < DiscountCalculatorBase
|
7
7
|
QUOTATION = 0.14
|
8
|
-
SALARY_BASE = 4000.04
|
9
|
-
SALARY_LIMIT = 7786.02
|
10
|
-
FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
|
11
8
|
|
12
9
|
def contribution
|
13
|
-
return NO_CONTRIBUTION if salary
|
10
|
+
return NO_CONTRIBUTION if salary < salary_base
|
14
11
|
|
15
|
-
return
|
12
|
+
return full_contribution if salary > salary_limit
|
16
13
|
|
17
|
-
|
14
|
+
calculate_contribution
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def calculate_contribution
|
20
|
+
((salary - salary_base) * QUOTATION).truncate(2)
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_contribution
|
24
|
+
((salary_limit - salary_base) * QUOTATION).truncate(2)
|
25
|
+
end
|
26
|
+
|
27
|
+
def salary_limit
|
28
|
+
InssCalculator::FOURTH_SALARY_LIMIT
|
29
|
+
end
|
30
|
+
|
31
|
+
def salary_base
|
32
|
+
InssCalculator::FOURTH_SALARY_BASE
|
18
33
|
end
|
19
34
|
end
|
20
35
|
end
|
@@ -5,16 +5,31 @@ module InssCalculator
|
|
5
5
|
# In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
|
6
6
|
class SecondDiscountCalculator < DiscountCalculatorBase
|
7
7
|
QUOTATION = 0.09
|
8
|
-
SALARY_BASE = 1412.0
|
9
|
-
SALARY_LIMIT = 2666.68
|
10
|
-
FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
|
11
8
|
|
12
9
|
def contribution
|
13
|
-
return NO_CONTRIBUTION if salary
|
10
|
+
return NO_CONTRIBUTION if salary < salary_base
|
14
11
|
|
15
|
-
return
|
12
|
+
return full_contribution if salary > salary_limit
|
16
13
|
|
17
|
-
|
14
|
+
calculate_contribution
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def calculate_contribution
|
20
|
+
((salary - salary_base) * QUOTATION).truncate(2)
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_contribution
|
24
|
+
((salary_limit - salary_base) * QUOTATION).truncate(2)
|
25
|
+
end
|
26
|
+
|
27
|
+
def salary_limit
|
28
|
+
InssCalculator::SECOND_SALARY_LIMIT
|
29
|
+
end
|
30
|
+
|
31
|
+
def salary_base
|
32
|
+
InssCalculator::SECOND_SALARY_BASE
|
18
33
|
end
|
19
34
|
end
|
20
35
|
end
|
@@ -5,16 +5,31 @@ module InssCalculator
|
|
5
5
|
# In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
|
6
6
|
class ThirdDiscountCalculator < DiscountCalculatorBase
|
7
7
|
QUOTATION = 0.12
|
8
|
-
SALARY_BASE = 2666.68
|
9
|
-
SALARY_LIMIT = 4000.03
|
10
|
-
FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
|
11
8
|
|
12
9
|
def contribution
|
13
|
-
return NO_CONTRIBUTION if salary
|
10
|
+
return NO_CONTRIBUTION if salary < salary_base
|
14
11
|
|
15
|
-
return
|
12
|
+
return full_contribution if salary > salary_limit
|
16
13
|
|
17
|
-
|
14
|
+
calculate_contribution
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def calculate_contribution
|
20
|
+
((salary - salary_base) * QUOTATION).truncate(2)
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_contribution
|
24
|
+
((salary_limit - salary_base) * QUOTATION).truncate(2)
|
25
|
+
end
|
26
|
+
|
27
|
+
def salary_limit
|
28
|
+
InssCalculator::THIRD_SALARY_LIMIT
|
29
|
+
end
|
30
|
+
|
31
|
+
def salary_base
|
32
|
+
InssCalculator::THIRD_SALARY_BASE
|
18
33
|
end
|
19
34
|
end
|
20
35
|
end
|
data/lib/inss_calculator.rb
CHANGED
@@ -11,4 +11,15 @@ require_relative 'inss_calculator/fourth_discount_calculator'
|
|
11
11
|
module InssCalculator
|
12
12
|
class Error < StandardError; end
|
13
13
|
# Your code goes here...
|
14
|
+
FIRST_SALARY_BASE = 0.0
|
15
|
+
FIRST_SALARY_LIMIT = 1412.0
|
16
|
+
|
17
|
+
SECOND_SALARY_BASE = 1412.01
|
18
|
+
SECOND_SALARY_LIMIT = 2666.68
|
19
|
+
|
20
|
+
THIRD_SALARY_BASE = 2666.69
|
21
|
+
THIRD_SALARY_LIMIT = 4000.03
|
22
|
+
|
23
|
+
FOURTH_SALARY_BASE = 4000.04
|
24
|
+
FOURTH_SALARY_LIMIT = 7786.02
|
14
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inss_calculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Felipe Souza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Calcula o valor a descontar de acordo com a faixa salarial. Os novos
|
14
14
|
valores corrente em 2024.
|