|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|