fixes bug #8170
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@62214 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
02e940f183
commit
5c2b83e93f
|
@ -8,7 +8,7 @@ import com.rjconsultores.ventaboletos.entidad.Ruta;
|
||||||
public interface CalcularPeajeDAO {
|
public interface CalcularPeajeDAO {
|
||||||
public List<Object> buscarCasetasPeajeWithinTramo(Ruta ruta);
|
public List<Object> buscarCasetasPeajeWithinTramo(Ruta ruta);
|
||||||
|
|
||||||
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao);
|
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao, boolean usaICMS);
|
||||||
|
|
||||||
public List<Ruta> buscarRutaWithCasetaPeajeFromOrgao(OrgaoConcedente oc);
|
public List<Ruta> buscarRutaWithCasetaPeajeFromOrgao(OrgaoConcedente oc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
||||||
}
|
}
|
||||||
|
|
||||||
// pra cada ruta obter as combinacoes de tramos, cada tramo com sua lista de casetaPeaje
|
// pra cada ruta obter as combinacoes de tramos, cada tramo com sua lista de casetaPeaje
|
||||||
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao) {
|
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao, boolean usaICMS) {
|
||||||
List<PeajeVO> peajes = new ArrayList<PeajeVO>();
|
List<PeajeVO> peajes = new ArrayList<PeajeVO>();
|
||||||
orgao = orgaoConcedenteService.obtenerID(orgao.getOrgaoConcedenteId());
|
orgao = orgaoConcedenteService.obtenerID(orgao.getOrgaoConcedenteId());
|
||||||
List<ClasseIndicePeaje> classeIndicePeajes = orgao.getClassesIndicePeaje();
|
List<ClasseIndicePeaje> classeIndicePeajes = orgao.getClassesIndicePeaje();
|
||||||
|
@ -138,7 +138,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
||||||
List<Object> lsObj = buscarCasetasPeajeWithinTramo(ruta);
|
List<Object> lsObj = buscarCasetasPeajeWithinTramo(ruta);
|
||||||
if (null != lsObj) {
|
if (null != lsObj) {
|
||||||
for (Object arrObj : lsObj) {
|
for (Object arrObj : lsObj) {
|
||||||
peajes.add(PeajeVO.create(ruta, orgao, (Object[]) arrObj, classeIndicePeajes));
|
peajes.add(PeajeVO.create(ruta, orgao, (Object[]) arrObj, classeIndicePeajes, usaICMS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,12 +179,14 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
||||||
ids.add(p.casetaPeajeId);
|
ids.add(p.casetaPeajeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Query query = getSession()
|
if(!ids.isEmpty()){
|
||||||
.createQuery("select c from CasetaPeaje c where c.casetaPeajeId in (:ids) ");
|
Query query = getSession()
|
||||||
query.setParameterList("ids", ids);
|
.createQuery("select c from CasetaPeaje c where c.casetaPeajeId in (:ids) ");
|
||||||
|
query.setParameterList("ids", ids);
|
||||||
|
|
||||||
for (CasetaPeaje c : (List<CasetaPeaje>) query.list()) {
|
for (CasetaPeaje c : (List<CasetaPeaje>) query.list()) {
|
||||||
casetas.put(c.getCasetaPeajeId(), c);
|
casetas.put(c.getCasetaPeajeId(), c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return casetas;
|
return casetas;
|
||||||
|
@ -303,7 +305,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
||||||
|
|
||||||
// ((importe * rutaCantEixos) / (indice * rutaCantAsientos)) / ( 1 - icms)
|
// ((importe * rutaCantEixos) / (indice * rutaCantAsientos)) / ( 1 - icms)
|
||||||
private static BigDecimal calculateImportePeajeANTT(BigDecimal importe, BigDecimal icms,
|
private static BigDecimal calculateImportePeajeANTT(BigDecimal importe, BigDecimal icms,
|
||||||
BigDecimal indice, BigDecimal rutaCantEixos, BigDecimal rutaCantAsientos) {
|
BigDecimal indice, BigDecimal rutaCantEixos, BigDecimal rutaCantAsientos, boolean usaICMS) {
|
||||||
|
|
||||||
if (ApplicationProperties.getInstance().calculoPeajeReunidasANTT()) {
|
if (ApplicationProperties.getInstance().calculoPeajeReunidasANTT()) {
|
||||||
// (importe * rutaCantEixos) / (indice)
|
// (importe * rutaCantEixos) / (indice)
|
||||||
|
@ -311,31 +313,43 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
||||||
.divide(indice, HIGH_PRECISION, RoundingMode.HALF_UP);
|
.divide(indice, HIGH_PRECISION, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return importe.multiply(rutaCantEixos)
|
if(!usaICMS){
|
||||||
.divide(indice.multiply(rutaCantAsientos), HIGH_PRECISION, RoundingMode.HALF_UP)
|
return importe.multiply(rutaCantEixos)
|
||||||
.divide(BigDecimal.ONE.subtract(icms), HIGH_PRECISION, RoundingMode.HALF_UP);
|
.divide(indice.multiply(rutaCantAsientos), HIGH_PRECISION, RoundingMode.HALF_UP);
|
||||||
|
}else{
|
||||||
|
return importe.multiply(rutaCantEixos)
|
||||||
|
.divide(indice.multiply(rutaCantAsientos), HIGH_PRECISION, RoundingMode.HALF_UP)
|
||||||
|
.divide(BigDecimal.ONE.subtract(icms), HIGH_PRECISION, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ((importe * rutaCantEixos) / (indice)) / ( 1 - icms)
|
// ((importe * rutaCantEixos) / (indice)) / ( 1 - icms)
|
||||||
private static BigDecimal calculateImportePeajeARTESP(BigDecimal importe, BigDecimal icms,
|
private static BigDecimal calculateImportePeajeARTESP(BigDecimal importe, BigDecimal icms,
|
||||||
BigDecimal indice, BigDecimal rutaCantEixos) {
|
BigDecimal indice, BigDecimal rutaCantEixos, boolean usaICMS) {
|
||||||
return importe.multiply(rutaCantEixos)
|
if(!usaICMS){
|
||||||
.divide(indice, HIGH_PRECISION, RoundingMode.HALF_UP)
|
return importe.multiply(rutaCantEixos)
|
||||||
.divide(BigDecimal.ONE.subtract(icms), HIGH_PRECISION, RoundingMode.HALF_UP);
|
.divide(indice, HIGH_PRECISION, RoundingMode.HALF_UP);
|
||||||
|
}else{
|
||||||
|
return importe.multiply(rutaCantEixos)
|
||||||
|
.divide(indice, HIGH_PRECISION, RoundingMode.HALF_UP)
|
||||||
|
.divide(BigDecimal.ONE.subtract(icms), HIGH_PRECISION, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BigDecimal calculateImportePeaje(Ruta ruta, OrgaoConcedente orgao, Object[] obj, BigDecimal indicePeaje) {
|
private static BigDecimal calculateImportePeaje(Ruta ruta, OrgaoConcedente orgao, Object[] obj, BigDecimal indicePeaje, boolean usaICMS) {
|
||||||
BigDecimal rutaCantEixos = getCantEixos(ruta);
|
BigDecimal rutaCantEixos = getCantEixos(ruta);
|
||||||
BigDecimal indice = indicePeaje;
|
BigDecimal indice = indicePeaje;
|
||||||
BigDecimal importe = getImporte(ruta, obj);
|
BigDecimal importe = getImporte(ruta, obj);
|
||||||
BigDecimal icms = getIcms(ruta, obj);
|
BigDecimal icms = usaICMS ? getIcms(ruta, obj) : null;
|
||||||
|
|
||||||
if (Constantes.ORGAOS_CONCEDENTES_CALCULO_ARTESP.contains(orgao.getOrgaoConcedenteId())) {
|
if (Constantes.ORGAOS_CONCEDENTES_CALCULO_ARTESP.contains(orgao.getOrgaoConcedenteId())) {
|
||||||
return calculateImportePeajeARTESP(importe, icms, indice, rutaCantEixos);
|
return calculateImportePeajeARTESP(importe, icms, indice, rutaCantEixos, usaICMS);
|
||||||
}
|
}
|
||||||
if (Constantes.ORGAOS_CONCEDENTES_CALCULO_ANTT.contains(orgao.getOrgaoConcedenteId())) {
|
if (Constantes.ORGAOS_CONCEDENTES_CALCULO_ANTT.contains(orgao.getOrgaoConcedenteId())) {
|
||||||
return calculateImportePeajeANTT(importe, icms, indice, rutaCantEixos, getRutaCantAsientos(ruta));
|
return calculateImportePeajeANTT(importe, icms, indice, rutaCantEixos, getRutaCantAsientos(ruta), usaICMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BigDecimal.ZERO; // TODO throw an exception? como calcular quando é outro orgao concendente?
|
return BigDecimal.ZERO; // TODO throw an exception? como calcular quando é outro orgao concendente?
|
||||||
|
@ -353,7 +367,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PeajeVO create(Ruta ruta, OrgaoConcedente orgao,
|
private static PeajeVO create(Ruta ruta, OrgaoConcedente orgao,
|
||||||
Object[] obj, List<ClasseIndicePeaje> lsClasseIndicePeaje) {
|
Object[] obj, List<ClasseIndicePeaje> lsClasseIndicePeaje, boolean usaICMS) {
|
||||||
|
|
||||||
PeajeVO pvo = new PeajeVO();
|
PeajeVO pvo = new PeajeVO();
|
||||||
|
|
||||||
|
@ -365,7 +379,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO<String, Strin
|
||||||
pvo.orgaoId = orgao.getOrgaoConcedenteId();
|
pvo.orgaoId = orgao.getOrgaoConcedenteId();
|
||||||
pvo.casetaPeajeId = Integer.parseInt(obj[20].toString());
|
pvo.casetaPeajeId = Integer.parseInt(obj[20].toString());
|
||||||
pvo.indicePeaje = getIndicePeaje(ruta.getClaseServicio(), orgao, lsClasseIndicePeaje);
|
pvo.indicePeaje = getIndicePeaje(ruta.getClaseServicio(), orgao, lsClasseIndicePeaje);
|
||||||
pvo.importePeaje = calculateImportePeaje(ruta, orgao, obj, pvo.indicePeaje);
|
pvo.importePeaje = calculateImportePeaje(ruta, orgao, obj, pvo.indicePeaje, usaICMS);
|
||||||
|
|
||||||
pvo.activo = 1;
|
pvo.activo = 1;
|
||||||
pvo.fecmodif = new Date();
|
pvo.fecmodif = new Date();
|
||||||
|
|
|
@ -8,5 +8,5 @@ import com.rjconsultores.ventaboletos.entidad.Ruta;
|
||||||
public interface CalcularPeajeService {
|
public interface CalcularPeajeService {
|
||||||
public List<Object> buscarCasetasPeajeWithinTramo(Ruta ruta);
|
public List<Object> buscarCasetasPeajeWithinTramo(Ruta ruta);
|
||||||
public List<Ruta> buscarRutaWithCasetaPeajeFromOrgao(OrgaoConcedente oc);
|
public List<Ruta> buscarRutaWithCasetaPeajeFromOrgao(OrgaoConcedente oc);
|
||||||
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao);
|
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao, boolean usaICMS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class CalcularPeajeServiceImpl implements CalcularPeajeService{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = BusinessException.class)
|
@Transactional(rollbackFor = BusinessException.class)
|
||||||
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao){
|
public int[] gerarSQLInserirPeajes(List<Ruta> lsRuta, OrgaoConcedente orgao, boolean usaICMS){
|
||||||
return calcularPeajeDAO.gerarSQLInserirPeajes(lsRuta, orgao);
|
return calcularPeajeDAO.gerarSQLInserirPeajes(lsRuta, orgao, usaICMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue