daniel.zauli 2015-07-02 14:13:47 +00:00
parent 6bd11e8cc5
commit d6fcc018cc
6 changed files with 159 additions and 34 deletions

View File

@ -15,6 +15,7 @@ public interface TarifaOficialDAO extends GenericDAO<TarifaOficial, Integer>{
*/
public Integer gerarTarifaPorCoeficiente(Integer ruta, Integer usuarioId, Integer orgaoConcedenteId, Integer empresaId);
public Integer gerarTarifaArtesp(Integer ruta, Integer usuarioId, Integer orgaoConcedenteId, Integer empresaId);
public Integer gerarTabelaZerada(Integer ruta, Integer usuarioId, Integer orgaoConcedenteId, Integer empresaId);

View File

@ -39,6 +39,16 @@ public class TarifaOficialHibernateDAO extends GenericHibernateDAO<TarifaOficial
return qtd;
}
@Override
public Integer gerarTarifaArtesp(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId, Integer emrpesaId) {
String sql = sqlBuilder.getSQLGerarTarifaOficialArtesp(rutaId, usuarioId, orgaoConcedenteId, emrpesaId);
int qtd = getSession().createSQLQuery(sql).executeUpdate();
return qtd;
}
@Override
public Integer gerarTabelaZerada(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId, Integer emrpesaId) {

View File

@ -23,6 +23,9 @@ public interface SQLBuilder {
public String getSQLGerarTabelaZerada(Integer codRuta, Integer usuarioId, Integer orgaoConcedenteId, Integer empresaId);
public String getSQLAtualizarTarifaOficial(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId);
public String getSQLGerarTarifaOficialArtesp( Integer codRuta, Integer usuarioId,
Integer orgaoConcedenteId, Integer empresaId);
public String getAtualizarTaxaEmbarquePorKmParada(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId);

View File

@ -112,6 +112,131 @@ public class SQLBuilderOracle implements SQLBuilder {
return sb.toString();
}
@Override
public String getSQLGerarTarifaOficialArtesp(final Integer codRuta, final Integer usuarioId,
final Integer orgaoConcedenteId, final Integer empresaId)
{
StringBuilder sb = new StringBuilder();
sb.append(" INSERT ");
sb.append(" INTO ");
sb.append(" TARIFA_OFICIAL ");
sb.append(" ( ");
sb.append(" TARIFAOFICIAL_ID, ");
sb.append(" PRECIO, ");
sb.append(" PRECIOORIGINAL, ");
sb.append(" TRAMO_ID, ");
sb.append(" MARCA_ID, ");
sb.append(" CLASESERVICIO_ID, ");
sb.append(" PRECIOREDABIERTO, ");
sb.append(" MONEDA_ID, ");
sb.append(" VIGENCIATARIFA_ID, ");
sb.append(" STATUSTARIFA, ");
sb.append(" IMPORTETAXAEMBARQUE, ");
sb.append(" IMPORTEPEDAGIO, ");
sb.append(" IMPORTEOUTROS, ");
sb.append(" IMPORTESEGURO, ");
sb.append(" ORGAOCONCEDENTE_ID, ");
sb.append(" RUTA_ID, ");
sb.append(" ACTIVO, ");
sb.append(" FECMODIF, ");
sb.append(" USUARIO_ID, ");
sb.append(" ORIGEN_ID, ");
sb.append(" DESTINO_ID ");
sb.append(" ) ");
sb.append(" select ");
sb.append(" ");
sb.append(" TARIFA_OFICIAL_SEQ.NEXTVAL, ");
sb.append(" ROUND( ");
sb.append(" (");
sb.append(" ");
sb.append(" case ( coalesce((select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= t.cantkmreal and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 )) when 0 then");
sb.append(" (select max( tkm.valortaxa ) from Tarifa_km tkm where tkm.CLASESERVICIO_ID = r.CLASESERVICIO_ID and tkm.activo = 1)");
sb.append(" else");
sb.append(" (select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= t.cantkmreal and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) end");
// sb.append(" * "); ARTESP não tem ICMS ou ja é calculado na tabela de referencia em pdf da artesp
// sb.append(" (case when e.icms is null then 1 else (1/(1-e.icms/100)) end)");
sb.append(" ) ");
sb.append(" ,2), ");
sb.append(" ROUND( ");
sb.append(" (");
sb.append(" ");
sb.append(" case ( coalesce((select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= t.cantkmreal and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 )) when 0 then");
sb.append(" (select max( tkm.valortaxa ) from Tarifa_km tkm where tkm.CLASESERVICIO_ID = r.CLASESERVICIO_ID and tkm.activo = 1)");
sb.append(" else");
sb.append(" (select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= t.cantkmreal and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) end");
sb.append(" ) ");
sb.append(" ,2), ");
sb.append(" t.tramo_id, ");
sb.append(" mc.marca_id, ");
sb.append(" r.CLASESERVICIO_ID, ");
sb.append(" null, ");
sb.append(" m.moneda_id, ");
sb.append(" null, ");
sb.append(" 'A', ");
sb.append(" null, ");
sb.append(" null, ");
sb.append(" null, ");
sb.append(" null, ");
sb.append(" oc.orgaoconcedente_id, ");
sb.append(" r.ruta_id, ");
sb.append(" 1, ");
sb.append(" ").append(DBUtil.getInstance().dbSysdate()).append(", ");
sb.append(" ").append(usuarioId).append(", ");
sb.append(" po.parada_id, ");
sb.append(" pd.parada_id ");
sb.append(" ");
sb.append("from ");
sb.append(" ruta_combinacion rc ");
sb.append(" inner join ruta r on r.ruta_id = rc.ruta_id ");
sb.append(" inner join ruta_empresa re on r.ruta_id = re.ruta_id ");
sb.append(" inner join marca ma on ma.empresa_id = re.empresa_id ");
//sb.append(" and tc.CLASESERVICIO_ID = r.CLASESERVICIO_ID and tc.activo =1 ");
sb.append(" inner join orgao_concedente oc on oc.orgaoconcedente_id =r.orgaoconcedente_id ");
sb.append(" inner join tramo t on t.tramo_id = rc.tramo_id and t.activo =1");//adicionei isso t.activo =1");
// sb.append(" inner join orgao_tramo tc on tc.tramo_id = rc.tramo_id ");//
sb.append(" inner join parada po on po.parada_id = t.origen_id ");
sb.append(" inner join parada pd on pd.parada_id = t.destino_id ");
sb.append(" inner join ciudad c on c.ciudad_id = po.ciudad_id ");
sb.append(" inner join estado e on e.estado_id = c.estado_id ");
sb.append(" inner join MARCA_CLASESERVICIO mc on ");
sb.append(" mc.CLASESERVICIO_ID = r.CLASESERVICIO_ID and ma.marca_id = mc.marca_id, ");
sb.append(" moneda m ");
sb.append(" ");
sb.append("where ");
sb.append(" rc.activo = 1 ");
if (codRuta != null) {
sb.append(" and r.ruta_id = ").append(codRuta);
}
sb.append(" and r.activo = 1 ");
// sb.append(" and tc.activo = 1 ");
sb.append(" and mc.marca_id <> -1 ");
sb.append(" and mc.activo = 1 ");
sb.append(" and re.activo = 1 ");
sb.append(" and r.orgaoconcedente_id = 21 ");
if (empresaId != null) {
sb.append(" and re.empresa_id = ").append(empresaId);
}
sb.append(" and m.moneda_id = 1 ");
if (orgaoConcedenteId != null) {
sb.append(" and oc.orgaoconcedente_id = ").append(orgaoConcedenteId);
}
sb.append(" and ");
sb.append(" (t.tramo_id, ");
sb.append(" mc.marca_id, ");
sb.append(" r.CLASESERVICIO_ID, ");
sb.append(" m.moneda_id, ");
sb.append(" oc.orgaoconcedente_id, r.ruta_id) ");
sb.append(" not in (select tao.tramo_id,tao.marca_id,tao.CLASESERVICIO_ID, ");
sb.append(" tao.moneda_id,tao.orgaoconcedente_id, tao.ruta_id ");
sb.append(" from tarifa_oficial tao where tao.activo = 1) ");
return sb.toString();
}
@Override
public String getSQLGerarTarifaOficial(final Integer codRuta, final Integer usuarioId,
final Integer orgaoConcedenteId, final Integer empresaId) {
@ -147,49 +272,17 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" ");
sb.append(" TARIFA_OFICIAL_SEQ.NEXTVAL, ");
sb.append("(case (r.orgaoconcedente_id) when 21 then ");
sb.append(" ROUND( ");
sb.append(" ( ");
sb.append(" ");
sb.append(" case (( coalesce((select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente1 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) ) + ( coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente2 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 )) +(coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente3 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) ) ) when 0 then ");
sb.append(" (select max( tkm.valortaxa ) from Tarifa_km tkm where tkm.CLASESERVICIO_ID = tc.CLASESERVICIO_ID and tkm.activo = 1) ");
sb.append(" else ");
sb.append(" (( coalesce((select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente1 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) ) ");
sb.append(" +( coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente2 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 )) ");
sb.append(" +(coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente3 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) )) end ");
// sb.append(" * "); ARTESP usa uma tabela(tarifa_km) que terá valores os quais ja têm icms calculado
// sb.append(" (case when e.icms is null then 1 else (1/(1-e.icms/100)) end) ");
sb.append(" ) ");
sb.append(" ,2) ");
sb.append(" else ");
sb.append(" ROUND( ");
sb.append(" (coalesce(ct1.coeficiente,0) * coalesce(tc.kmcoeficiente1,0) + ");
sb.append(" coalesce(ct2.coeficiente,0) * coalesce(tc.kmcoeficiente2,0) + ");
sb.append(" coalesce(ct3.coeficiente,0) * coalesce(tc.kmcoeficiente3,0)) * ");
sb.append(" case when e.icms is null then 1 else (1/(1-e.icms/100)) end ,2) ");
sb.append(" end ), ");
sb.append(" case when e.icms is null then 1 else (1/(1-e.icms/100)) end ,2) ,");
sb.append("(case (r.orgaoconcedente_id) when 21 then "); //ARTESP = 21
sb.append(" ROUND( ");
sb.append(" (");
sb.append(" ");
sb.append(" case (( coalesce((select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente1 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) ) + ( coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente2 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 )) +(coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente3 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) ) ) when 0 then");
sb.append(" (select max( tkm.valortaxa ) from Tarifa_km tkm where tkm.CLASESERVICIO_ID = tc.CLASESERVICIO_ID and tkm.activo = 1)");
sb.append(" else");
sb.append(" (( coalesce((select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente1 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) )");
sb.append(" +( coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente2 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ))");
sb.append(" +(coalesce(( select min( tkm.valortaxa ) from Tarifa_km tkm where tkm.kmate >= tc.kmcoeficiente3 and r.CLASESERVICIO_ID = tkm.CLASESERVICIO_ID and tkm.activo = 1) , 0 ) )) end");
// sb.append(" * "); ARTESP não tem ICMS
// sb.append(" (case when e.icms is null then 1 else (1/(1-e.icms/100)) end)");
sb.append(" ) ");
sb.append(" ,2) ");
sb.append(" else ");
sb.append(" ROUND( ");
sb.append(" (coalesce(ct1.coeficiente,0) * coalesce(tc.kmcoeficiente1,0) + ");
sb.append(" coalesce(ct2.coeficiente,0) * coalesce(tc.kmcoeficiente2,0) + ");
sb.append(" coalesce(ct3.coeficiente,0) * coalesce(tc.kmcoeficiente3,0)) * ");
sb.append(" case when e.icms is null then 1 else (1/(1-e.icms/100)) end ,2) ");
sb.append(" end ), ");
sb.append(" case when e.icms is null then 1 else (1/(1-e.icms/100)) end ,2) ,");
sb.append(" t.tramo_id, ");
sb.append(" mc.marca_id, ");
@ -242,6 +335,7 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" and mc.marca_id <> -1 ");
sb.append(" and mc.activo = 1 ");
sb.append(" and re.activo = 1 ");
sb.append(" and r.orgaoconcedente_id <> 21 ");
if (empresaId != null) {
sb.append(" and re.empresa_id = ").append(empresaId);
}

View File

@ -126,4 +126,8 @@ public interface TarifaOficialService {
public Integer gerarTabelaZerada(Integer rutaId, Integer orgaoConcedenteId, Integer empresaId);
public void gerarAtualizarTarifaArtesp(Integer rudaId, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException;
public Integer gerarTarifaArtesp(Integer rutaId, Integer orgaoConcedenteId, Integer empresaId);
}

View File

@ -35,6 +35,12 @@ public class TarifaOficialServiceImpl implements TarifaOficialService {
return tarifaOficialDAO.gerarTarifaPorCoeficiente(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId);
}
@Override
@Transactional
public Integer gerarTarifaArtesp(Integer rutaId, Integer orgaoConcedenteId, Integer empresaId) {
return tarifaOficialDAO.gerarTarifaArtesp(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId);
}
@Override
@Transactional
public Integer gerarTabelaZerada(Integer rutaId, Integer orgaoConcedenteId, Integer empresaId) {
@ -63,6 +69,13 @@ public class TarifaOficialServiceImpl implements TarifaOficialService {
}
@Override
@Transactional(rollbackFor = BusinessException.class)
public void gerarAtualizarTarifaArtesp(Integer rudaId, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException
{
gerarTarifaArtesp(rudaId, orgaoConcedenteId, empresaId);
}
@Override
@Transactional(rollbackFor = BusinessException.class)
public void gerarAtualizarTabelaZerada(Integer rudaId, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException {