diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java index 0fa0bd062..b288456bf 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java @@ -96,7 +96,8 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" coalesce(ei.indtxembarqueestadual,0) as indtxembarqueestadual, "); sql.append(" coalesce(ei.indpedagioestdual,0) as indpedagioestdual "); sql.append("from boleto c "); - sql.append(" join bpe bpe on c.boleto_id = bpe.boleto_id and bpe.activo = 1 "); + sql.append(" join bpe bpe on c.boleto_id = bpe.boleto_id "); + sql.append(" and bpe.activo = (case when c.motivocancelacion_id = 17 and c.boletooriginal_id is null then 0 else 1 end) "); sql.append(" join estado e on e.codibge = bpe.uf "); sql.append(" join marca ma on c.marca_id = ma.marca_id "); sql.append(" join empresa ep on ma.empresa_id = ep.empresa_id "); @@ -112,8 +113,8 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" left join empresa_imposto ei on ei.empresa_id = ep.empresa_id and ei.estado_id = e.estado_id "); sql.append("where c.activo = 1 and e.activo = 1 and ei.activo = 1 "); sql.append(" and bpe.tipoamb = 1 and ep.activo = 1 "); - sql.append(" and bpe.codstat in (100,101,102,135,150) "); - sql.append(" and (bpe.tipoevento <> 110115 or bpe.tipoevento is null) "); + sql.append(" and bpe.codstat in ('-1','100','101','102','135','150') "); + sql.append(" and (bpe.tipoevento <> '110115' or bpe.tipoevento is null) "); sql.append(" and c.feccreacion >= to_date(?,'DD/MM/YYYY HH24:MI:SS') "); sql.append(" and c.feccreacion <= to_date(?,'DD/MM/YYYY HH24:MI:SS') "); sql.append(" and ep.empresa_id = ? "); @@ -248,7 +249,7 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" from bpe bpe "); sql.append(" where bpe.activo = 1 "); sql.append(" and bpe.tipoamb = 1 "); - sql.append(" and bpe.codstat in (100) "); + sql.append(" and bpe.codstat in ('100','150') "); sql.append(" and bpe.chbpe = ? "); try { @@ -608,9 +609,10 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000, 3001) as xml_bpe_2, "); sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000, 6001) as xml_bpe_3 "); sql.append("from boleto c "); - sql.append(" join bpe bpe on c.boleto_id = bpe.boleto_id and bpe.activo = 1 "); - sql.append(" left join bpe bpecan on bpecan.chbpe = bpe.chbpe and bpecan.codstat in (101,135) and bpe.codstat = 100 "); - sql.append(" and (bpecan.tipoevento = 110111 or bpecan.tipoevento is null) and bpecan.activo = 1 "); + sql.append(" join bpe bpe on c.boleto_id = bpe.boleto_id "); + sql.append(" and bpe.activo = (case when c.motivocancelacion_id = 17 and c.boletooriginal_id is null then 0 else 1 end) "); + sql.append(" left join bpe bpecan on bpecan.chbpe = bpe.chbpe and bpecan.codstat in ('101','135') and bpe.codstat = '100' "); + sql.append(" and (bpecan.tipoevento = '110111' or bpecan.tipoevento is null) and bpecan.activo = 1 "); sql.append(" join estado e on e.codibge = bpe.uf "); sql.append(" join marca ma on c.marca_id = ma.marca_id "); sql.append(" join empresa ep on ma.empresa_id = ep.empresa_id "); @@ -624,11 +626,9 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" inner join ciudad cd on d.ciudad_id = cd.ciudad_id "); sql.append(" inner join estado ed on ed.estado_id = cd.estado_id "); sql.append(" left join empresa_imposto ei on ei.empresa_id = ep.empresa_id and ei.estado_id = e.estado_id and ei.activo = 1 "); - sql.append("where c.activo = 1 and bpe.tipoamb = 1 and bpe.codstat in (100,102,150) "); + sql.append("where c.activo = 1 and bpe.tipoamb = 1 and bpe.codstat in ('-1','100','102','150') "); sql.append(" and (bpe.fecmodif < (case when (to_char(bpe.fecmodif, 'mm/yyyy') <> to_char(bpecan.fecmodif, 'mm/yyyy') ) "); sql.append(" then bpecan.fecmodif else bpe.fecmodif end) or bpecan.fecmodif is null) "); -// sql.append(" and (case when ei.indtribviagem = 1 then c.fechorviaje else c.feccreacion end) >= :DATE_INICIO "); -// sql.append(" and (case when ei.indtribviagem = 1 then c.fechorviaje else c.feccreacion end) <= :DATE_FIM "); sql.append(" and c.feccreacion >= :DATE_INICIO "); sql.append(" and c.feccreacion <= :DATE_FIM "); sql.append(" and ep.empresa_id = :EMPRESA_ID "); @@ -677,9 +677,11 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append("from boleto bori "); sql.append(" inner join marca m on m.marca_id = bori.marca_id and m.activo = 1 "); sql.append(" inner join empresa e on e.empresa_id = m.empresa_id "); - sql.append(" inner join bpe bpe on bpe.boleto_id = bori.boleto_id and bpe.activo = 1 "); + sql.append(" inner join bpe bpe on bpe.boleto_id = bori.boleto_id "); + sql.append(" and bpe.activo = (case when bori.motivocancelacion_id = 17 and bori.boletooriginal_id is null then 0 else 1 end) "); sql.append(" inner join estado est_bpe on bpe.uf = est_bpe.codibge "); - sql.append(" left join bpe bpeori on bpeori.chbpe = bpe.chbpe_substituicao and bpeori.activo = 1 "); + sql.append(" left join bpe bpeori on bpeori.chbpe = bpe.chbpe_substituicao "); + sql.append(" and bpeori.activo = (case when bori.motivocancelacion_id = 17 and bori.boletooriginal_id is null then 0 else 1 end) "); sql.append(" left join boleto b on b.boleto_id = bpeori.boleto_id "); sql.append(" inner join punto_venta ptv on ptv.puntoventa_id = b.puntoventa_id "); sql.append(" inner join parada ori on (b.origen_id = ori.parada_id ) "); @@ -705,10 +707,10 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" left join boleto bant on bant.boleto_id = (case when bpeori.tipoevento is not null then coalesce(b.boletoanterior_id, b.boletooriginal_id) else null end) "); sql.append(" left join bpe bpeant on bpeant.boleto_id = bant.boleto_id "); sql.append(" left join punto_venta ptvo on ptvo.puntoventa_id = coalesce(bant.puntoventa_id, bori.puntoventa_id,b.ptovtaventa_id) "); - sql.append("where ( (bpe.codstat in (100,101,102,135,150) and bpe.chbpe_substituicao is not null) "); - sql.append(" or (bpe.codstat in (101,135) and to_char(b.feccreacion, 'mm/yyyy') < to_char(bori.feccreacion, 'mm/yyyy')) ) "); - sql.append(" and (bpe.codstat in (100,101,102,135,150) and bpe.tipoevento <> 110115 or bpe.tipoevento is null) "); - sql.append(" and (bpeori.codstat in (100,101,102,135,150) and bpeori.tipoevento <> 110115 or bpeori.tipoevento is null) "); + sql.append("where ( (bpe.codstat in ('-1','100','101','102','135','150') and bpe.chbpe_substituicao is not null) "); + sql.append(" or (bpe.codstat in ('101','135') and to_char(b.feccreacion, 'mm/yyyy') < to_char(bori.feccreacion, 'mm/yyyy')) ) "); + sql.append(" and (bpe.codstat in ('-1','100','101','102','135','150') and bpe.tipoevento <> '110115' or bpe.tipoevento is null) "); + sql.append(" and (bpeori.codstat in ('-1','100','101','102','135','150') and bpeori.tipoevento <> '110115' or bpeori.tipoevento is null) "); sql.append(" and bori.feccreacion >= :DATE_INICIO "); sql.append(" and bori.feccreacion <= :DATE_FIM "); sql.append(" and est_bpe.cveestado in ( ").append(ufs).append(" ) "); @@ -753,10 +755,12 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append("from boleto bori "); sql.append(" inner join marca m on m.marca_id = bori.marca_id and m.activo = 1 "); sql.append(" inner join empresa e on e.empresa_id = m.empresa_id "); - sql.append(" inner join bpe bpe on bpe.boleto_id = bori.boleto_id and bpe.activo = 1 "); + sql.append(" inner join bpe bpe on bpe.boleto_id = bori.boleto_id "); + sql.append(" and bpe.activo = (case when bori.motivocancelacion_id = 17 and bori.boletooriginal_id is null then 0 else 1 end) "); sql.append(" inner join estado est_bpe on bpe.uf = est_bpe.codibge "); sql.append(" left join boleto b on b.boleto_id = (case when bori.motivocancelacion_id = 99 then bori.boletoanterior_id else bori.boletooriginal_id end) "); - sql.append(" left join bpe bpeori on b.boleto_id = bpeori.boleto_id and bpeori.activo = 1 "); + sql.append(" left join bpe bpeori on b.boleto_id = bpeori.boleto_id "); + sql.append(" and bpeori.activo = (case when bori.motivocancelacion_id = 17 and bori.boletooriginal_id is null then 0 else 1 end) "); sql.append(" inner join punto_venta ptv on ptv.puntoventa_id = bori.puntoventa_id "); sql.append(" inner join parada ori on (b.origen_id = ori.parada_id ) "); sql.append(" inner join parada des on (b.destino_id = des.parada_id ) "); @@ -780,11 +784,12 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append("left join estado esaidf on esaidf.estado_id = aidf.estado_id "); sql.append("left join boleto bant on bant.boleto_id = (case when bpeori.tipoevento is not null then coalesce(b.boletoanterior_id, b.boletooriginal_id) else null end) "); sql.append("left join bpe bpeant on bpeant.boleto_id = bant.boleto_id "); + sql.append(" and bpeant.activo = (case when bori.motivocancelacion_id = 17 and bori.boletooriginal_id is null then 0 else 1 end) "); sql.append("left join punto_venta ptvo on ptvo.puntoventa_id = coalesce(bant.puntoventa_id, bori.puntoventa_id,b.ptovtaventa_id) "); sql.append("where "); - sql.append(" (bpe.codstat in (101,135) and to_char(b.feccreacion, 'mm/yyyy') < to_char(bori.feccreacion, 'mm/yyyy')) "); - sql.append(" and (bpe.codstat in (100,101,102,135,150) and bpe.tipoevento <> 110115 or bpe.tipoevento is null) "); - sql.append(" and (bpeori.codstat in (100,101,102,135,150) and bpeori.tipoevento <> 110115 or bpeori.tipoevento is null) "); + sql.append(" (bpe.codstat in ('101','135') and to_char(b.feccreacion, 'mm/yyyy') < to_char(bori.feccreacion, 'mm/yyyy')) "); + sql.append(" and (bpe.codstat in ('-1','100','101','102','135','150') and bpe.tipoevento <> '110115' or bpe.tipoevento is null) "); + sql.append(" and (bpeori.codstat in ('-1','100','101','102','135','150') and bpeori.tipoevento <> '110115' or bpeori.tipoevento is null) "); sql.append(" and bori.feccreacion >= :DATE_INICIO "); sql.append(" and bori.feccreacion <= :DATE_FIM "); sql.append(" and est_bpe.cveestado in ( ").append(ufs).append(" ) ");