-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: getContraCheque07_5PorCentoINSS
- Loading branch information
1 parent
9206c29
commit 8661d16
Showing
18 changed files
with
540 additions
and
41 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
src/main/java/com/stone/apicontracheques/domain/CalculadoraContracheque.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.stone.apicontracheques.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
|
||
import com.stone.apicontracheques.domain.enums.TipoLancamento; | ||
import com.stone.apicontracheques.domain.lancamentos.FGTS; | ||
import com.stone.apicontracheques.domain.lancamentos.INSS; | ||
import com.stone.apicontracheques.domain.lancamentos.ImpostoDeRenda; | ||
import com.stone.apicontracheques.domain.lancamentos.Lancamento; | ||
import com.stone.apicontracheques.domain.lancamentos.PlanoDeSaude; | ||
import com.stone.apicontracheques.domain.lancamentos.PlanoDental; | ||
import com.stone.apicontracheques.domain.lancamentos.Salario; | ||
import com.stone.apicontracheques.domain.lancamentos.ValeTransporte; | ||
|
||
public class CalculadoraContracheque{ | ||
|
||
private List<Lancamento> lancamentos = new ArrayList<>(); | ||
private Funcionario funcionario; | ||
private double totalDescontos = 0; | ||
|
||
public CalculadoraContracheque() { | ||
} | ||
|
||
public CalculadoraContracheque(Funcionario funcionario) { | ||
this.funcionario = funcionario; | ||
} | ||
public List<Lancamento> getLancamentos() { | ||
if(lancamentos.isEmpty()){ | ||
adicionaLancamentoSeAplicavel(new Salario(funcionario)); | ||
adicionaLancamentoSeAplicavel(new INSS(funcionario)); | ||
adicionaLancamentoSeAplicavel(new ImpostoDeRenda(funcionario)); | ||
adicionaLancamentoSeAplicavel(new PlanoDeSaude(funcionario)); | ||
adicionaLancamentoSeAplicavel(new PlanoDental(funcionario)); | ||
adicionaLancamentoSeAplicavel(new ValeTransporte(funcionario)); | ||
adicionaLancamentoSeAplicavel(new FGTS(funcionario)); | ||
} | ||
return lancamentos; | ||
} | ||
|
||
public void adicionaLancamentoSeAplicavel(Lancamento lancamento) { | ||
if(lancamento.aplicavel()){ | ||
this.lancamentos.add(lancamento); | ||
} | ||
} | ||
|
||
public void setLancamentos(List<Lancamento> lancamentos) { | ||
this.lancamentos = lancamentos; | ||
} | ||
|
||
public Funcionario getFuncionario() { | ||
return funcionario; | ||
} | ||
|
||
public void setFuncionario(Funcionario funcionario) { | ||
this.funcionario = funcionario; | ||
} | ||
|
||
public Contracheque getContraCheque(){ | ||
Contracheque contracheque = new Contracheque(); | ||
contracheque.setMesReferencia(Calendar.getInstance().get(Calendar.MONTH+1) ); | ||
contracheque.setSalarioBruto(funcionario.getSalarioBruto()); | ||
contracheque.setSalarioLiquido(getSalarioLiquido()); | ||
contracheque.setTotalDescontos(getTotalDescontos()); | ||
contracheque.setLancamentos(lancamentos); | ||
return contracheque; | ||
} | ||
|
||
private double getSalarioLiquido() { | ||
lancamentos = getLancamentos(); | ||
double salarioLiquido = funcionario.getSalarioBruto() + getTotalDescontos(); | ||
return salarioLiquido; | ||
} | ||
|
||
private double getTotalDescontos() { | ||
lancamentos = getLancamentos(); | ||
if( totalDescontos == 0){ | ||
for (Lancamento lancamento : lancamentos) { | ||
if(lancamento.getTipoLancamento() == TipoLancamento.DESCONTO){ | ||
totalDescontos -= lancamento.getValor(); | ||
} | ||
} | ||
} | ||
return totalDescontos; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/stone/apicontracheques/domain/Contracheque.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.stone.apicontracheques.domain; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.stone.apicontracheques.domain.lancamentos.Lancamento; | ||
|
||
public class Contracheque implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private Integer mesReferencia; | ||
private double totalDescontos; | ||
private double salarioBruto; | ||
private double salarioLiquido; | ||
private List<Lancamento> lancamentos = new ArrayList<>(); | ||
|
||
public Contracheque() { | ||
} | ||
|
||
public Contracheque(Integer mesReferencia, double totalDescontos, double salarioBruto, double salarioLiquido, | ||
List<Lancamento> lancamentos) { | ||
this.mesReferencia = mesReferencia; | ||
this.totalDescontos = totalDescontos; | ||
this.salarioBruto = salarioBruto; | ||
this.salarioLiquido = salarioLiquido; | ||
this.lancamentos = lancamentos; | ||
} | ||
|
||
public Integer getMesReferencia() { | ||
return mesReferencia; | ||
} | ||
|
||
public void setMesReferencia(Integer i) { | ||
this.mesReferencia = i; | ||
} | ||
|
||
public double getTotalDescontos() { | ||
return totalDescontos; | ||
} | ||
|
||
public void setTotalDescontos(double totalDescontos) { | ||
this.totalDescontos = totalDescontos; | ||
} | ||
|
||
public double getSalarioBruto() { | ||
return salarioBruto; | ||
} | ||
|
||
public void setSalarioBruto(double salarioBruto) { | ||
this.salarioBruto = salarioBruto; | ||
} | ||
|
||
public double getSalarioLiquido() { | ||
return salarioLiquido; | ||
} | ||
|
||
public void setSalarioLiquido(double salarioLiquido) { | ||
this.salarioLiquido = salarioLiquido; | ||
} | ||
|
||
public void setLancamentos(List<Lancamento> lancamentos) { | ||
this.lancamentos = lancamentos; | ||
} | ||
|
||
public void addLancamentos(Lancamento lancamento) { | ||
this.lancamentos.add(lancamento); | ||
} | ||
|
||
public List<Lancamento> getLancamentos() { | ||
return this.lancamentos; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/stone/apicontracheques/domain/enums/TipoLancamento.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.stone.apicontracheques.domain.enums; | ||
|
||
public enum TipoLancamento { | ||
|
||
DESCONTO(1,"DESCONTO"), | ||
REMUNERACAO(2,"REMUNERACAO"); | ||
|
||
private Integer codigo; | ||
private String descricao; | ||
|
||
private TipoLancamento(int codigo, String descricao) { | ||
this.codigo = codigo; | ||
this.descricao = descricao; | ||
} | ||
|
||
public Integer getCodigo() { | ||
return this.codigo; | ||
} | ||
|
||
public String getDescricao() { | ||
return this.descricao; | ||
} | ||
|
||
public static PerfilAcesso toEnum(Integer codigo) { | ||
|
||
if ( codigo == null) { | ||
return null; | ||
} | ||
|
||
for (PerfilAcesso x: PerfilAcesso.values()) { | ||
if ( codigo == x.getCodigo()) { | ||
return x; | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException("Tipo de remuneração inválido:" + codigo); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/stone/apicontracheques/domain/interfaces/IAplicavel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.stone.apicontracheques.domain.interfaces; | ||
|
||
public interface IAplicavel { | ||
boolean aplicavel(); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/stone/apicontracheques/domain/interfaces/ICalculavel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.stone.apicontracheques.domain.interfaces; | ||
|
||
public interface ICalculavel { | ||
double calcular(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/stone/apicontracheques/domain/lancamentos/FGTS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.stone.apicontracheques.domain.lancamentos; | ||
|
||
import com.stone.apicontracheques.domain.Funcionario; | ||
import com.stone.apicontracheques.domain.enums.TipoLancamento; | ||
|
||
public class FGTS extends Lancamento { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public FGTS(Funcionario funcionario) { | ||
super(TipoLancamento.DESCONTO, 0, "FGTS",funcionario); | ||
} | ||
|
||
@Override | ||
public boolean aplicavel() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public double calcular() { | ||
return funcionario.getSalarioBruto() * 0.08; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/stone/apicontracheques/domain/lancamentos/INSS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.stone.apicontracheques.domain.lancamentos; | ||
|
||
import com.stone.apicontracheques.domain.Funcionario; | ||
import com.stone.apicontracheques.domain.enums.TipoLancamento; | ||
|
||
public class INSS extends Lancamento { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public INSS(Funcionario funcionario) { | ||
super(TipoLancamento.DESCONTO, 0, "INSS",funcionario); | ||
} | ||
|
||
@Override | ||
public boolean aplicavel() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public double calcular() { | ||
double valorDesconto = 0; | ||
if (funcionario.getSalarioBruto() <= 1045) { | ||
valorDesconto = funcionario.getSalarioBruto() * 0.075; | ||
} else if (funcionario.getSalarioBruto() <= 2089) { | ||
valorDesconto = funcionario.getSalarioBruto() * 0.09; | ||
} else if (funcionario.getSalarioBruto() <= 3134.40) { | ||
valorDesconto = funcionario.getSalarioBruto() * 0.12; | ||
} else { | ||
valorDesconto = Math.min(funcionario.getSalarioBruto() * 0.14, 713.09); | ||
} | ||
return valorDesconto; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/stone/apicontracheques/domain/lancamentos/ImpostoDeRenda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.stone.apicontracheques.domain.lancamentos; | ||
|
||
import com.stone.apicontracheques.domain.Funcionario; | ||
import com.stone.apicontracheques.domain.enums.TipoLancamento; | ||
|
||
public class ImpostoDeRenda extends Lancamento { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ImpostoDeRenda(Funcionario funcionario) { | ||
super(TipoLancamento.DESCONTO, 0, "Imposto De Renda",funcionario); | ||
} | ||
|
||
@Override | ||
public boolean aplicavel() { | ||
return funcionario.getSalarioBruto() > 1903.98; | ||
} | ||
|
||
@Override | ||
public double calcular() { | ||
double valorDesconto = 0; | ||
if (funcionario.getSalarioBruto() <= 1903.98) { | ||
valorDesconto = 0; | ||
}else if (funcionario.getSalarioBruto() <= 2826.65) { | ||
valorDesconto = funcionario.getSalarioBruto() * 0.075; | ||
} else if (funcionario.getSalarioBruto() <= 3751.05) { | ||
valorDesconto = funcionario.getSalarioBruto() * 0.15; | ||
} else if (funcionario.getSalarioBruto() <= 4664.68) { | ||
valorDesconto = funcionario.getSalarioBruto() * 0.225; | ||
} else { | ||
valorDesconto = Math.min(funcionario.getSalarioBruto() * 0.275, 869.36); | ||
} | ||
return valorDesconto; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/stone/apicontracheques/domain/lancamentos/Lancamento.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.stone.apicontracheques.domain.lancamentos; | ||
|
||
import java.io.Serializable; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.stone.apicontracheques.domain.Funcionario; | ||
import com.stone.apicontracheques.domain.enums.TipoLancamento; | ||
import com.stone.apicontracheques.domain.interfaces.IAplicavel; | ||
import com.stone.apicontracheques.domain.interfaces.ICalculavel; | ||
|
||
public abstract class Lancamento implements Serializable, IAplicavel, ICalculavel { | ||
private static final long serialVersionUID = 1L; | ||
|
||
protected TipoLancamento tipoLancamento; | ||
protected double valor; | ||
protected String descricao; | ||
@JsonIgnore | ||
protected Funcionario funcionario; | ||
|
||
public Lancamento() { | ||
} | ||
|
||
public Lancamento(TipoLancamento tipoLancamento, double valor, String descricao, Funcionario funcionario) { | ||
this.tipoLancamento = tipoLancamento; | ||
this.valor = valor; | ||
this.descricao = descricao; | ||
this.funcionario = funcionario; | ||
} | ||
|
||
public TipoLancamento getTipoLancamento() { | ||
return tipoLancamento; | ||
} | ||
|
||
public void setTipoLancamento(TipoLancamento tipoLancamento) { | ||
this.tipoLancamento = tipoLancamento; | ||
} | ||
|
||
public double getValor() { | ||
return this.calcular(); | ||
} | ||
|
||
public void setValor(double valor) { | ||
this.valor = valor; | ||
} | ||
|
||
public String getDescricao() { | ||
return descricao; | ||
} | ||
|
||
public void setDescricao(String descricao) { | ||
this.descricao = descricao; | ||
} | ||
|
||
public Funcionario getFuncionario() { | ||
return funcionario; | ||
} | ||
|
||
public void setFuncionario(Funcionario funcionario) { | ||
this.funcionario = funcionario; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/stone/apicontracheques/domain/lancamentos/PlanoDeSaude.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.stone.apicontracheques.domain.lancamentos; | ||
|
||
import com.stone.apicontracheques.domain.Funcionario; | ||
import com.stone.apicontracheques.domain.enums.TipoLancamento; | ||
|
||
public class PlanoDeSaude extends Lancamento { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public PlanoDeSaude(Funcionario funcionario) { | ||
super(TipoLancamento.DESCONTO, 0, "Plano De Saude",funcionario); | ||
} | ||
|
||
@Override | ||
public boolean aplicavel() { | ||
return funcionario.isDescontaPlanoDeSaude(); | ||
} | ||
|
||
@Override | ||
public double calcular() { | ||
return 10; | ||
} | ||
|
||
} |
Oops, something went wrong.