Advertisement
MX37S

FacturaCabeceraDao

Aug 25th, 2021
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 21.71 KB | None | 0 0
  1. package tca.fe.dao;
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.ArrayList;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.List;
  8. import org.hibernate.SQLQuery;
  9. import org.hibernate.Session;
  10. import org.hibernate.SessionFactory;
  11. import org.hibernate.criterion.DetachedCriteria;
  12. import org.hibernate.criterion.Restrictions;
  13. import org.hibernate.transform.Transformers;
  14. import org.hibernate.type.StandardBasicTypes;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Repository;
  17. import tca.fe.entity.FacturaCabecera;
  18. import tca.fe.model.ClienteFactura;
  19. import tca.fe.model.DataFactura;
  20.  
  21. @Repository
  22. public class FacturaCabeceraDao extends DaoHibernate<FacturaCabecera>{
  23.  
  24.     private final Long ESTADO_MAIL_ENVIADO = 4L;
  25.     private static final int CUENTA_CORRIENTE  = 2;
  26.     private static final int DEBITO_AUTOMATICO = 3;
  27.     private static final int INTERBANKING      = 4;
  28.    
  29.     @Autowired
  30.     public FacturaCabeceraDao(SessionFactory sessionFactory) {
  31.         setSessionFactory(sessionFactory);
  32.     }
  33.    
  34.     @Override
  35.     protected Class<FacturaCabecera> getTypeClass() {
  36.         return FacturaCabecera.class;
  37.     }
  38.    
  39.     public int updateCabeceras(Long codEstado, List<String> facturas,String tabla, String columnaId) {
  40.         String query = null;
  41.         query = "update "+tabla +" set estado = "+codEstado+" where estado <> "+2L+" and "+columnaId+" in( ";
  42.        
  43.         for(String item : facturas){
  44.             if(!item.equals(facturas.get(facturas.size()-1))){
  45.                 query = query + item +" , ";
  46.             }else{
  47.                 query = query +item + ")";
  48.             }
  49.         }
  50.         return  getHibernateTemplate().bulkUpdate(query);
  51.     }  
  52.    
  53.    
  54.     public String obtengoIdGuia(String prefijo, String nguia, Session session){
  55.            
  56.         try {
  57.             logger.info("ingresa a obtengoIdGuia");
  58.        
  59.             String sql = "select to_char(sguia) from sgui where cprefijo = '"+prefijo+"' and nguia = '"+nguia+"'";
  60.        
  61.             SQLQuery query = session.createSQLQuery(sql);
  62.        
  63.             if (query.list().size() > 0){
  64.                 return (String) query.list().get(0);
  65.             }
  66.             else{
  67.                 return "-1";
  68.             }
  69.            
  70.         } catch (Exception e) {
  71.             return null;
  72.         }
  73.  
  74.     }
  75.  
  76.     public int updateCabecerasPorAfipAprobado(String tabla, Long codEstado,String sfactura,String observacion ){
  77.        
  78.         boolean isWhitespace = observacion.matches("^\\s*$");
  79.        
  80.         String query = null;
  81.         if(isWhitespace){
  82.              query = "update "+tabla +" set estado = "+codEstado+" where sfactura = "+sfactura;
  83.         }else{
  84.              query = "update "+tabla +" set estado = "+codEstado+" , observaciones = "+"'"+observacion+"'" +
  85.              " where sfactura = "+sfactura;
  86.         }
  87.        
  88.         return getHibernateTemplate().bulkUpdate(query);
  89.     }
  90.    
  91.     public int updateCabecerasPorAfipRechazo(String tabla, Long codEstado,String sfactura, String observacion ){
  92.        
  93.         boolean isWhitespace = observacion.matches("^\\s*$");
  94.        
  95.         String query = null;
  96.         if(isWhitespace){
  97.             query = "update "+tabla +" set estado = "+codEstado+
  98.              " where sfactura = "+sfactura;
  99.         }else{
  100.             query = "update "+tabla +" set estado = "+codEstado+" , observaciones = "+"'"+observacion+"'" +
  101.              " where sfactura = "+sfactura;
  102.         }
  103.        
  104.          return getHibernateTemplate().bulkUpdate(query);
  105.     }
  106.    
  107.     public int updateCabecerasConError(Long codEstado, List<String> comprobantesError,String tabla,String columnaId) {
  108.        
  109.         String query = "update " + tabla + " set estado = " + codEstado + " where estado <> "
  110.                         + 2L + " and " + columnaId + " in( ";
  111.  
  112.         for (String comprobante : comprobantesError) {
  113.             if (!comprobante.equals(comprobantesError.get(comprobantesError.size() - 1))) {
  114.                 query = query + comprobante + " , ";
  115.             } else {
  116.                 query = query + comprobante + ")";
  117.             }
  118.         }
  119.         return getHibernateTemplate().bulkUpdate(query);
  120.     }  
  121.    
  122.     public FacturaCabecera findFacturasbyNroPv
  123.     (Long nroFactura, Long pv,String letra, String tipoFormulario){
  124.        
  125.         DetachedCriteria dc = createCriteria();
  126.         dc.add(Restrictions.eq("nroFactura",nroFactura))
  127.         .add(Restrictions.eq("pv", pv))
  128.     //  .add( Restrictions.in("tipoFormulario", new String[] {"FA","NC","ND" }))
  129.         .add(Restrictions.eq("letra",letra))
  130.         .add(Restrictions.eq("tipoFormulario",tipoFormulario));
  131.        
  132.         @SuppressWarnings("unchecked")
  133.         List<FacturaCabecera> list = getHibernateTemplate().findByCriteria(dc);
  134.        
  135.         if (list.size() > 0) {
  136.             return list.get(0);
  137.         } else {
  138.             return null;
  139.         }
  140.     }
  141.    
  142.     private String queryCCFindIdResponsableFacturados() {
  143.         return "select"+
  144.                 " scli_cliente as scli_cliente," +
  145.                 " ccli.email as email," +
  146.                 " ccli.dnomyap as dnomyap" +
  147.                 " from(" +
  148.                 " select distinct" +
  149.                 " decode" +
  150.                 " (a.scli_despachante, null," +
  151.                 " a.scli_responsable," +  
  152.                 " decode((select distinct sddt.csecobra" +
  153.                 " from fcfi b, fsei, sddt" +
  154.                 " where" +
  155.                 " b.sfactura = fsei.sfactura" +
  156.                 " and b.sfactura = a.sfactura" +
  157.                 " and fsei.sdctodest = sddt.sdctodest),1," +
  158.                 " a.scli_responsable, a.scli_despachante)) as scli_cliente" +
  159.                 " from fcfi a" +
  160.                 " where" +
  161.                 " a.cconvta = 2" +
  162.                 " and a.ctpcomprobante in ('FA','NC','ND')" +
  163.                 " and a.caea_estado = 2" +
  164.                 " and a.fhemision>=:fechaMinima),ccli" +
  165.                 " where" +
  166.                 " ccli.scli = scli_cliente" +
  167.                 " and ccli.email is not null";
  168.     }
  169.    
  170.     private String queryDAFindIdResponsableFacturados(){
  171.         return " select distinct" +
  172.                 " decode(cctadeb_responsable,null, scli_despachante,scli_responsable) as scli_cliente," +
  173.                 " cdeb.email as email,"+
  174.                 " decode(cctadeb_responsable,null, dnomyap_despachante,dnomyap) as dnomyap" +
  175.                 " FROM fcfi, cdeb" +
  176.                 " WHERE" +
  177.                 " fhemision >=:fechaMinima" +
  178.                 " and (cctadeb_responsable =  cdeb.cctadeb or cctadeb_despachante =  cdeb.cctadeb )"+
  179.                 " and (csuc_responsable = cdeb.csuc or csuc_despachante = cdeb.csuc )"+
  180.                 " and (cbco_responsable = cdeb.cbco or cbco_despachante = cdeb.cbco )"+
  181.                 " and cdeb.email is not null"+
  182.                 " and cconvta = 3"+
  183.                 " and ctpcomprobante in('FA','NC','ND')"+
  184.                 " and caea_estado = 2";
  185.     }
  186.    
  187.     private String queryINTERBFindIdResponsableFacturados() {
  188.         return "select distinct"
  189.                 + " decode(ccta_responsable,null,scli_despachante,scli_responsable) as scli_cliente,"
  190.                 + " ccli.email as email,"
  191.                 + " decode(fcfi.ccta_responsable,null,fcfi.dnomyap_despachante,fcfi.dnomyap) as dnomyap"
  192.                 + " FROM"
  193.                 + " ccli INNER JOIN"
  194.                 + " fcfi ON"
  195.                 + " ccli.scli = fcfi.scli_responsable"
  196.                 + " WHERE"
  197.                 + " ctpcomprobante in('FA','NC','ND')"
  198.                 + " and cconvta = 4"
  199.                 + " and fhemision>=:fechaMinima"
  200.                 + " and caea_estado = 2"
  201.                 + " and ccli.email is not null";
  202.     }
  203.  
  204.     @SuppressWarnings("unchecked")
  205.     public List<ClienteFactura> findIdResponsableFacturados(Integer diasBuscar, Integer payMethod){
  206.        
  207.         Session session = getSessionFactory().openSession();
  208.         Calendar cal = Calendar.getInstance();
  209.         cal.set(Calendar.HOUR,0);
  210.         cal.set(Calendar.AM_PM,0);
  211.         cal.set(Calendar.MINUTE,0);
  212.         cal.set(Calendar.SECOND,0);
  213.         cal.set(Calendar.MILLISECOND,0);
  214.         cal.add(Calendar.DATE, diasBuscar);
  215.        
  216.         try {
  217.                 logger.info("ingresa a findIdResponsableFacturados");
  218.                 SQLQuery  query = null;
  219.            
  220.                 switch (payMethod) {
  221.                     case CUENTA_CORRIENTE:
  222.                         query = session.createSQLQuery(queryCCFindIdResponsableFacturados());
  223.                         break;
  224.                              
  225.                     case DEBITO_AUTOMATICO:
  226.                          query= session.createSQLQuery(queryDAFindIdResponsableFacturados());
  227.                          break;
  228.                              
  229.                     case INTERBANKING:
  230.                          query= session.createSQLQuery(queryINTERBFindIdResponsableFacturados());
  231.                          break;
  232.                 }
  233.            
  234.                 query.setDate("fechaMinima", cal.getTime());
  235.                
  236.                 query.addScalar("scli_cliente", StandardBasicTypes.STRING)
  237.                 .addScalar("email", StandardBasicTypes.STRING)
  238.                 .addScalar("dnomyap", StandardBasicTypes.STRING)
  239.                 .setResultTransformer(Transformers.aliasToBean(ClienteFactura.class));
  240.                
  241.                          
  242.                 if (query.list().size() > 0){
  243.                     return query.list();
  244.                 }
  245.                 else{
  246.                     return null;
  247.                 }
  248.             }
  249.        
  250.             catch (Exception e) {
  251.                 return null;
  252.             }finally {
  253.                 session.close();
  254.             }
  255.     }
  256.    
  257.     private String queryCCFindFacturasAprobadasByCliente(Long idCliente) {
  258.         return "select *"+
  259.                 " from( select sfactura as idFactura,"+
  260.                 " ctpcomprobante as tipoComprobante,"+
  261.                 " ctpcomprobante||'-'||caea_ptovta||'-'||ctiplet||'-'||nfactura as nroFactura,"+
  262.                 " dnomyap_despachante as despachante,"+
  263.                 " dnomyap as importador,"+
  264.                 " fhemision as fechaEmision,"+
  265.                 " decode (fcfi.scli_despachante,"+
  266.                 " null,"+
  267.                 " decode( fcfi.scli_responsable,"+idCliente+",  'CLIENTE_OK', null),"+
  268.                 " decode(("+
  269.                 " select distinct sddt.csecobra"+
  270.                 " from fcfi b, fsei, sddt"+
  271.                 " where"+
  272.                 " b.sfactura = fsei.sfactura"+
  273.                 " and b.sfactura = fcfi.sfactura"+
  274.                 " and fsei.sdctodest = sddt.sdctodest), 1,"+
  275.                 " decode( fcfi.scli_responsable,"+idCliente+",  'CLIENTE_OK', null),"+
  276.                 " decode( fcfi.scli_despachante,"+idCliente+",  'CLIENTE_OK', null))) clienteCobrado"+
  277.                 " from fcfi"+
  278.                 " where"+
  279.                 " caea_estado = 2"+
  280.                 " and fhemision >=:fechaMinima"+
  281.                 " and  cconvta = 2"+
  282.                 " and ctpcomprobante in('FA','NC','ND')"+
  283.                 " and ((scli_despachante = "+idCliente+" )"+
  284.                 " or (scli_responsable = "+idCliente+")))";//+
  285.                 //" where";+
  286.                 //" clienteCobrado is not null";
  287.     }
  288.    
  289.     private String queryDAFindFacturasAprobadasByCliente(Long idCliente) {
  290.         return "select sfactura as idFactura," +
  291.                 " ctpcomprobante as tipoComprobante,"+
  292.                 " ctpcomprobante||'-'||caea_ptovta||'-'||ctiplet||'-'||nfactura as nroFactura,"+
  293.                 " dnomyap_despachante as despachante,"+
  294.                 " dnomyap as importador,"+
  295.                 " fhemision as fechaEmision"+
  296.                 " from fcfi"+
  297.                 " where"+
  298.                 " caea_estado = 2"+
  299.                 " and fhemision >=:fechaMinima"+
  300.                 " and  cconvta = 3"+
  301.                 " and ctpcomprobante in('FA','NC','ND')"+
  302.                 " and ((scli_despachante = "+ idCliente+" and cctadeb_despachante is not null)" +
  303.                 " or (scli_responsable = "+idCliente+" and cctadeb_responsable is not null))";
  304.     }
  305.    
  306.     private String queryINTERBFindFacturasAprobadasByCliente(Long idCliente) {
  307.         return "select sfactura as idFactura, "
  308.                 + "ctpcomprobante as tipoComprobante, "
  309.                 + "ctpcomprobante||'-'||caea_ptovta||'-'||ctiplet||'-'||nfactura as nroFactura, "
  310.                 + "dnomyap_despachante as despachante, "
  311.                 + "dnomyap as importador, "
  312.                 + "fhemision as fechaEmision "
  313.                 + "from fcfi "
  314.                 + "where "
  315.                 + "caea_estado = 2 "
  316.                 + "and fhemision >=:fechaMinima "
  317.                 + "and cconvta = 4 "
  318.                 + "and ctpcomprobante in('FA','NC','ND') "
  319.                 + "and ((scli_despachante = "+idCliente+" and ccta_despachante is not null) "
  320.                 + "or (scli_responsable = "+idCliente+" and ccta_responsable is not null));";
  321.     }
  322.    
  323.    
  324.     @SuppressWarnings("unchecked")
  325.     public List<DataFactura> findFacturasAprobadasByCliente(Long idCliente, Integer diasBuscar, Integer payMethod){
  326.        
  327.         Session session = getSessionFactory().openSession();
  328.         Calendar cal = Calendar.getInstance();
  329.         cal.set(Calendar.HOUR,0);
  330.         cal.set(Calendar.AM_PM,0);
  331.         cal.set(Calendar.MINUTE,0);
  332.         cal.set(Calendar.SECOND,0);
  333.         cal.set(Calendar.MILLISECOND,0);
  334.        
  335.         cal.add(Calendar.DATE, diasBuscar);
  336.         try {
  337.             logger.info("ingresa a findFacturasAprobadasByCliente");
  338.            
  339.             SQLQuery  query = null;
  340.            
  341.             switch (payMethod) {
  342.                 case CUENTA_CORRIENTE:
  343.                     query= session.createSQLQuery(queryCCFindFacturasAprobadasByCliente(idCliente));
  344.                     break;
  345.                    
  346.                 case DEBITO_AUTOMATICO:
  347.                     query= session.createSQLQuery(queryDAFindFacturasAprobadasByCliente(idCliente));
  348.                     break;
  349.                    
  350.                 case INTERBANKING:
  351.                     query= session.createSQLQuery(queryINTERBFindFacturasAprobadasByCliente(idCliente));
  352.                     break;
  353.             }
  354.                
  355.             query.setDate("fechaMinima", cal.getTime());
  356.                      
  357.             query.addScalar("idFactura", StandardBasicTypes.STRING)
  358.             .addScalar("tipoComprobante", StandardBasicTypes.STRING)
  359.             .addScalar("nroFactura", StandardBasicTypes.STRING)
  360.             .addScalar("despachante", StandardBasicTypes.STRING)
  361.             .addScalar("importador", StandardBasicTypes.STRING)
  362.             .addScalar("fechaEmision", StandardBasicTypes.DATE)
  363.             .setResultTransformer(Transformers.aliasToBean(DataFactura.class));
  364.                
  365.             if (query.list().size() > 0){
  366.                 return query.list();
  367.             }
  368.             else{
  369.                 return null;
  370.             }
  371.            
  372.         } catch (Exception e) {
  373.             logger.info("error select "+e.getMessage());
  374.             e.printStackTrace();
  375.             return null;
  376.         }
  377.         finally {
  378.             session.close();
  379.         }
  380.        
  381.     }
  382.    
  383.     private String queryCCFindFacturasAprobadasByClientePortalNoNull(Long idCliente){
  384.         return "select *"+
  385.                 " from(select distinct fcfi.sfactura as idFactura,"+
  386.                 " fcfi.ctpcomprobante as tipoComprobante,"+
  387.                 " fcfi.ctpcomprobante||'-'||fcfi.caea_ptovta||'-'||fcfi.ctiplet||'-'||fcfi.nfactura as nroFactura,"+
  388.                 " fcfi.dnomyap_despachante as despachante,"+
  389.                 " fcfi.dnomyap as importador,"+
  390.                 " 'IMPO' as sucursal,"+
  391.                 " fcfi.fhemision as fechaEmision,"+
  392.                 " decode (fcfi.scli_despachante,"+
  393.                 " null,"+
  394.                 " decode( fcfi.scli_responsable,"+idCliente+", 'CLIENTE_OK', null),"+
  395.                 " decode(("+
  396.                 " select distinct sddt.csecobra"+
  397.                 " from fcfi b, fsei, sddt"+
  398.                 " where"+
  399.                 " b.sfactura = fsei.sfactura"+
  400.                 " and b.sfactura = fcfi.sfactura"+
  401.                 " and fsei.sdctodest = sddt.sdctodest), 1,"+
  402.                 " decode( fcfi.scli_responsable,"+idCliente+",  'CLIENTE_OK', null),"+
  403.                 " decode( fcfi.scli_despachante,"+idCliente+",  'CLIENTE_OK', null))) clienteCobrado"+
  404.                 " from fcfi"+
  405.                 " where"+
  406.                 " fcfi.caea_estado in (2,4)"+
  407.                 " and fcfi.fhemision >= :fechaMinima"+
  408.                 " and fcfi.fhemision <= :fechaMaxima"+
  409.                 " and fcfi.cconvta in(1,2)"+
  410.                 " and fcfi.ctpcomprobante in('FA','NC','ND')"+
  411.                 " and ((fcfi.scli_despachante = "+idCliente+" )"+
  412.                 " or (fcfi.scli_responsable = "+idCliente+")))";//+
  413.                 //" where"+
  414.                 //" clienteCobrado is not null";
  415.     }
  416.    
  417.     private String queryCCFindFacturasAprobadasByClientePortalNull(){
  418.         return " select distinct fcfi.sfactura as idFactura,"+
  419.                 " fcfi.ctpcomprobante as tipoComprobante,"+
  420.                 " fcfi.ctpcomprobante||'-'||caea_ptovta||'-'||ctiplet||'-'||nfactura as nroFactura,"+
  421.                 " fcfi.dnomyap_despachante as despachante,"+
  422.                 " fcfi.dnomyap as importador,"+
  423.                 " 'IMPO' as sucursal,"+
  424.                 " fcfi.fhemision as fechaEmision"+
  425.                 " from fcfi"+
  426.                 " where"+
  427.                 " fcfi.caea_estado in (2,4)"+
  428.                 " and fcfi.fhemision >= :fechaMinima"+
  429.                 " and fcfi.fhemision <= :fechaMaxima"+
  430.                 " and fcfi.cconvta in(1, 2)"+
  431.                 " and fcfi.ctpcomprobante in('FA','NC','ND')";
  432.     }
  433.    
  434.     private String queryDAFindFacturasAprobadasByClientePortalNull(){
  435.         return "select DISTINCT fcfi.sfactura as idFactura," +
  436.                   " fcfi.ctpcomprobante as tipoComprobante," +
  437.                   " fcfi.ctpcomprobante||'-'||fcfi.caea_ptovta||'-'||fcfi.ctiplet||'-'||fcfi.nfactura as nroFactura," +
  438.                   " fcfi.dnomyap_despachante as despachante," +
  439.                   " fcfi.dnomyap as importador," +
  440.                   " 'IMPO' as sucursal," +
  441.                   " fcfi.fhemision as fechaEmision" +
  442.                   " from fcfi "+
  443.                   " where fcfi.caea_estado in (2,4)" +
  444.                   " and fcfi.fhemision >= :fechaMinima" +
  445.                   " and fcfi.fhemision <= :fechaMaxima" +
  446.                   " and fcfi.cconvta = 3" +
  447.                   " and fcfi.ctpcomprobante in('FA','NC','ND')";
  448.     }
  449.    
  450.     private String queryDAFindFacturasAprobadasByClientePortalNoNullAux(Long idCliente){
  451.         return " and ((fcfi.scli_despachante = "+ idCliente+
  452.                 " and fcfi.cctadeb_despachante is not null)" +
  453.                 " or (fcfi.scli_responsable = "+idCliente+
  454.                 " and fcfi.cctadeb_responsable is not null))";
  455.     }
  456.    
  457.     private String queryINTERBFindFacturasAprobadasByClientePortalNull() {
  458.         return "select DISTINCT fcfi.sfactura as idFactura, "
  459.                 + "fcfi.ctpcomprobante as tipoComprobante, "
  460.                 + "fcfi.ctpcomprobante||'-'||fcfi.caea_ptovta||'-'||fcfi.ctiplet||'-'||fcfi.nfactura as nroFactura, "
  461.                 + "fcfi.dnomyap_despachante as despachante, "
  462.                 + "fcfi.dnomyap as importador, "
  463.                 + "'IMPO' as sucursal, "
  464.                 + "fcfi.fhemision as fechaEmision "
  465.                 + "from fcfi "
  466.                 + "where fcfi.caea_estado in (2,4) "
  467.                 + "and fcfi.fhemision >= :fechaMinima "
  468.                 + "and fcfi.fhemision <= :fechaMaxima "
  469.                 + "and fcfi.cconvta = 4 "
  470.                 + "and fcfi.ctpcomprobante in('FA','NC','ND')";
  471.     }
  472.    
  473.     private String queryINTERBFindFacturasAprobadasByClientePortalNoNullAux(Long idCliente){
  474.         return " and ((fcfi.scli_despachante = "+idCliente
  475.                 + " and fcfi.ccta_despachante is not null)"
  476.                 + " or (fcfi.scli_responsable = "+idCliente
  477.                 + " and fcfi.ccta_responsable is not null))";
  478.     }
  479.  
  480.     //para solicitud desde portal
  481.     @SuppressWarnings("unchecked")
  482.     public List<DataFactura> findFacturasAprobadasByClientePortal(Long idCliente,Date fechaMinima,Date fechaMaxima, String prefijo, String nguia, Integer payMethod){
  483.        
  484.         Session session = getSessionFactory().openSession();
  485.        
  486.         try {
  487.             logger.info("ingresa a findFacturasAprobadasByClientePortal");
  488.            
  489.             SQLQuery  query;
  490.             String    queryString = null;
  491.             String    sguia = "";      
  492.             int       q_cliente = 0;
  493.            
  494.             switch (payMethod) {
  495.            
  496.                 case CUENTA_CORRIENTE:
  497.                     if(idCliente != null){
  498.                         queryString = queryCCFindFacturasAprobadasByClientePortalNoNull(idCliente);
  499.                         q_cliente = 1;     
  500.                     }
  501.                     else{
  502.                         queryString = queryCCFindFacturasAprobadasByClientePortalNull();
  503.                     }
  504.                     break;
  505.                    
  506.                 case DEBITO_AUTOMATICO:
  507.                     queryString = queryDAFindFacturasAprobadasByClientePortalNull();       
  508.                
  509.                     if(idCliente != null)
  510.                       queryString=queryString+queryDAFindFacturasAprobadasByClientePortalNoNullAux(idCliente);
  511.                     break;
  512.                    
  513.                 case INTERBANKING:
  514.                     queryString = queryINTERBFindFacturasAprobadasByClientePortalNull();       
  515.                    
  516.                     if(idCliente != null)
  517.                       queryString=queryString+queryINTERBFindFacturasAprobadasByClientePortalNoNullAux(idCliente);
  518.                     break;
  519.             }
  520.        
  521.             // Si el usuario ingreso el numero de guia y el prefijo busco la guia
  522.             if((!prefijo.isEmpty() || prefijo.length() > 0) && (!nguia.isEmpty() || nguia.length() > 0)){
  523.                 // Busco el id de la guia
  524.                 sguia = obtengoIdGuia(prefijo,nguia,session);
  525.                 // Si el sguia es (-1) significa que no encontro la guia
  526.                 if(sguia.equals("-1")){
  527.                     return new ArrayList<DataFactura>();
  528.                 } else {
  529.                     if(q_cliente == 0){
  530.                         queryString = queryString + " and fcfi.sfactura in (select distinct sfactura from fdfi where sguia = "+sguia+")";
  531.                     } else {
  532.                         queryString += " and idFactura in (select distinct sfactura from fdfi where sguia = "+sguia+")";
  533.                     }
  534.                 }
  535.                
  536.             }
  537.            
  538.             query= session.createSQLQuery(queryString);
  539.             query.setDate("fechaMinima", fechaMinima);
  540.             query.setDate("fechaMaxima", fechaMaxima);   
  541.                        
  542.             query.addScalar("idFactura", StandardBasicTypes.STRING)
  543.             .addScalar("tipoComprobante", StandardBasicTypes.STRING)
  544.             .addScalar("nroFactura", StandardBasicTypes.STRING)
  545.             .addScalar("despachante", StandardBasicTypes.STRING)
  546.             .addScalar("importador", StandardBasicTypes.STRING)
  547.             .addScalar("sucursal", StandardBasicTypes.STRING)
  548.             .addScalar("fechaEmision", StandardBasicTypes.DATE)
  549.             .setResultTransformer(Transformers.aliasToBean(DataFactura.class));
  550.            
  551.             if (query.list().size() > 0){
  552.                 return query.list();
  553.             }
  554.             else{
  555.                 return new ArrayList<DataFactura>();
  556.             }
  557.            
  558.         } catch (Exception e) {
  559.             logger.info("error select "+e.getMessage());
  560.             e.printStackTrace();
  561.             return new ArrayList<DataFactura>();
  562.            
  563.         } finally {
  564.             session.close();
  565.         }
  566.     }
  567.    
  568.     public String findFacturaById(BigDecimal idFactura){
  569.        
  570.         Session session = getSessionFactory().openSession();
  571.        
  572.         try {
  573.             logger.info("ingresa a findFacturasAprobadasByCliente");
  574.        
  575.             String sql = "SELECT CTPCOMPROBANTE||'-'||CTIPLET||'-'||CAEA_PTOVTA||'-'||NFACTURA FROM FCFI WHERE SFACTURA = "+idFactura;
  576.            
  577.             SQLQuery query = session.createSQLQuery(sql);
  578.            
  579.             if (query.list().size() > 0){
  580.                 return (String) query.list().get(0);
  581.             }
  582.             else{
  583.                 return null;
  584.             }
  585.              
  586.         } catch (Exception e) {
  587.         return null;
  588.            
  589.         } finally {
  590.             session.close();
  591.         }
  592.     }
  593.    
  594.     public void updateCabecerasPorEnvioMail(String sfactura, String tabla){
  595.         String query = "update "+tabla+" set estado = "+ESTADO_MAIL_ENVIADO +
  596.         " where sfactura = "+sfactura;
  597.         getHibernateTemplate().bulkUpdate(query);
  598.     //  getHibernateTemplate().update(query);
  599.     }
  600. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement