Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,18 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.class
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.6
9 changes: 9 additions & 0 deletions comissoes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORRETOR;01/01/2014;0.02
CORRETOR;01/01/2015;0.03
CORRETOR;01/01/2016;0.05
CORRETORA;01/01/2014;0.05
CORRETORA;01/01/2015;0.04
CORRETORA;01/01/2016;0.02
GERENTE;01/01/2014;0.03
GERENTE;01/01/2015;0.03
GERENTE;01/01/2016;0.05
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<version>0.0.1-SNAPSHOT</version>

<properties>
<java.version>1.7</java.version>
<java.version>1.6</java.version>
</properties>
<dependencies>
<dependency>
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/br/com/akato/comissaovenda/CalculadoraDeComissao.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
package br.com.akato.comissaovenda;

import java.util.Calendar;

import java.math.BigDecimal;
import java.util.Date;

public class CalculadoraDeComissao {

private Date dataDoCalculo;

public CalculadoraDeComissao(){
this.dataDoCalculo = new Date(Calendar.getInstance().getTimeInMillis());
public CalculadoraDeComissao(Date dataDeCalculo){
this.dataDoCalculo = dataDeCalculo;
}

public double calcularComissaoPorVenda(Venda venda, Funcionario funcionario){
double comissao = 0.0;

public BigDecimal calcularComissaoPorVenda(Venda venda, Funcionario funcionario){
BigDecimal porcentagemComissao = new BigDecimal("0.00");
BigDecimal valorVenda = new BigDecimal("0.00");
BigDecimal comissaoDaVenda = new BigDecimal("0.00");
try {
if(verificaSePoderaReceberComissao(venda)){
if(venda!=null && venda.getValorVenda()>0){
if(venda!=null && venda.getValorVenda().doubleValue()>0.0){

double valorComissao = funcionario.getPerfil().comissaoDoAno(venda.getAnoDeVenda());
double valorVenda = venda.getValorVenda();
comissao = valorComissao * valorVenda;
porcentagemComissao = funcionario.getComissaoPorData(venda.getDataVenda());
valorVenda = venda.getValorVenda();
comissaoDaVenda = porcentagemComissao.multiply(valorVenda);

}
}

funcionario.adicionaCommisao(venda, comissao);
} catch (Exception e) {
e.printStackTrace();
}
return comissao;
return comissaoDaVenda;
}

public Date getDataDoCalculo() {
return dataDoCalculo;
}

public void setDataDoCalculo(Date dataDoCalculo) {
this.dataDoCalculo = dataDoCalculo;
}

private boolean verificaSePoderaReceberComissao(Venda venda){

return (quantidadeDeDiasEntreVendaEDataDeCalculo(venda.getDataVenda()) >=60) ? true : false;
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/br/com/akato/comissaovenda/Comissionado.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package br.com.akato.comissaovenda;


import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Set;

public abstract class Comissionado {

protected Map<Date, BigDecimal> comissoes;

protected BigDecimal commissaoPorData(Date data) {

return comissoes.get(buscaComissao(data));
}

/*
*
* CORRETOR;31/01/2014;0.03
*/

protected void carregarComissoes(Perfil perfil) {
LeitorDeTabelaDeComissao leitorDeComissoes = new LeitorDeTabelaDeComissao();
try {
Collection<String> comissoes = leitorDeComissoes.lerComissoes();
for (String linhaDecomissao : comissoes) {
String[] dados = linhaDecomissao.split(";");
String perfilDoComissionado = dados[0];
Date dataLimiteComissao = new SimpleDateFormat("dd/MM/yyyy")
.parse(dados[1]);
BigDecimal valorComissao = new BigDecimal(dados[2]);
if (perfilDoComissionado.equals(perfil.toString())) {
this.adicionaComissao(dataLimiteComissao, valorComissao);
}
}
} catch (ParseException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

}

protected void adicionaComissao(Date dataLimite, BigDecimal comissao) {
this.comissoes.put(dataLimite, comissao);
}

protected BigDecimal getComissaoPorData(Date dataDeReferencia){
return this.buscaComissao(dataDeReferencia);
}

//lookup by date
protected BigDecimal buscaComissao(Date data) {
Set<Date> chavesPorData = this.comissoes.keySet();
Date dataEncontrada = new Date();
boolean encontrouComissao=false;
for(Date dataChave:chavesPorData){
if(data.getTime()>=dataChave.getTime()){
encontrouComissao = true;
dataEncontrada = dataChave;
}
}
return encontrouComissao?this.comissoes.get(dataEncontrada):null;
}

}
12 changes: 12 additions & 0 deletions src/main/java/br/com/akato/comissaovenda/Criador.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package br.com.akato.comissaovenda;

import static br.com.akato.comissaovenda.Perfil.CORRETOR;

public class Criador {
public static void main(String[]args){
Funcionario corretor = new Funcionario(CORRETOR);

// corretor.getAno(new Date());
// corretor.carregarComissoes(new Date(),new BigDecimal("0.03"));
}
}
22 changes: 0 additions & 22 deletions src/main/java/br/com/akato/comissaovenda/EnumPerfil.java

This file was deleted.

48 changes: 13 additions & 35 deletions src/main/java/br/com/akato/comissaovenda/Funcionario.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,22 @@
package br.com.akato.comissaovenda;

import static br.com.akato.comissaovenda.EnumPerfil.CORRETOR;
import static br.com.akato.comissaovenda.EnumPerfil.CORRETORA;
import static br.com.akato.comissaovenda.EnumPerfil.GERENTE;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Funcionario {
private Map<Venda,Double> comissoes;
private EnumPerfil perfil;

public class Funcionario extends Comissionado{

public Funcionario(String perfil){
this.perfil = identificaPerfil(perfil);
this.comissoes = new HashMap<Venda, Double>();
}

public Funcionario(){

};
public EnumPerfil getPerfil() {
return perfil;
}
private Perfil perfil;

public void adicionaCommisao(Venda venda, Double comissao){
this.comissoes.put(venda, comissao);
public Funcionario(Perfil perfil) {
this.perfil = perfil;
this.comissoes = new HashMap<Date,BigDecimal>();
this.carregarComissoes(this.perfil);
}

public Double getComissaoPorVenda(Venda venda){
return this.comissoes.get(venda);
}

private EnumPerfil identificaPerfil(String perfil) {
if (perfil.equalsIgnoreCase("gerente")) {
return GERENTE;
} else if (perfil.equalsIgnoreCase("corretora")) {
return CORRETORA;
} else {
return CORRETOR;
}

public Perfil getPerfil() {
return perfil;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package br.com.akato.comissaovenda;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;

public class LeitorDeTabelaDeComissao {
public Collection<String> lerComissoes() throws Exception {
String caminho = new File("comissoes.txt").getCanonicalPath();
InputStream is = new FileInputStream(caminho);
Collection<String> acoes = new ArrayList<String>();
String linha;
try {
@SuppressWarnings("resource")
BufferedReader bfr = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
while ((linha = bfr.readLine()) != null) {
acoes.add(linha);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
is.close();
}
return acoes;
}
}
19 changes: 19 additions & 0 deletions src/main/java/br/com/akato/comissaovenda/Perfil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package br.com.akato.comissaovenda;


import java.util.HashMap;
import java.util.Map;

public enum Perfil {
CORRETORA(), GERENTE(), CORRETOR();

static Map<String,Perfil> mapaDePerfil;

static{
mapaDePerfil = new HashMap<String,Perfil>();
mapaDePerfil.put("CORRETORA",CORRETORA);
mapaDePerfil.put("GERENTE",GERENTE);
mapaDePerfil.put("CORRETOR",CORRETOR);
}

}
Loading