diff --git a/src/com/rjconsultores/ventaboletos/dao/ConfigRestriccionPagoDAO.java b/src/com/rjconsultores/ventaboletos/dao/ConfigRestriccionPagoDAO.java index 4fcf2d176..67d5749b1 100644 --- a/src/com/rjconsultores/ventaboletos/dao/ConfigRestriccionPagoDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/ConfigRestriccionPagoDAO.java @@ -5,6 +5,7 @@ package com.rjconsultores.ventaboletos.dao; import com.rjconsultores.ventaboletos.entidad.ConfigRestriccionPago; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.FormaPago; import com.rjconsultores.ventaboletos.entidad.RestriccionPago; import java.util.List; @@ -17,7 +18,7 @@ import java.util.Map; public interface ConfigRestriccionPagoDAO extends GenericDAO { public List buscar(FormaPago formaPago, - RestriccionPago restriccionPago); + RestriccionPago restriccionPago, Empresa empresa); public Map buscar(FormaPago formaPago); diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/ConfigRestriccionPagoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/ConfigRestriccionPagoHibernateDAO.java index 73c1cf39f..ee6042804 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/ConfigRestriccionPagoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/ConfigRestriccionPagoHibernateDAO.java @@ -4,21 +4,24 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; -import com.rjconsultores.ventaboletos.dao.ConfigRestriccionPagoDAO; -import com.rjconsultores.ventaboletos.entidad.ConfigRestriccionPago; -import com.rjconsultores.ventaboletos.entidad.FormaPago; -import com.rjconsultores.ventaboletos.entidad.RestriccionPago; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + import org.hibernate.Criteria; import org.hibernate.SessionFactory; -import org.hibernate.criterion.Order; +import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; +import com.rjconsultores.ventaboletos.dao.ConfigRestriccionPagoDAO; +import com.rjconsultores.ventaboletos.entidad.ConfigRestriccionPago; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.FormaPago; +import com.rjconsultores.ventaboletos.entidad.RestriccionPago; + /** * * @author Administrador @@ -42,12 +45,22 @@ public class ConfigRestriccionPagoHibernateDAO } public List buscar(FormaPago formaPago, - RestriccionPago restriccionPago) { + RestriccionPago restriccionPago, Empresa empresa) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("restriccion", restriccionPago)); c.add(Restrictions.eq("formaPago", formaPago)); + + Criterion empresaNull = Restrictions.isNull("empresa"); + Criterion empresaMenosUm = Restrictions.eq("empresa", new Empresa(-1)); + + if(empresa != null) { + Criterion empresaIgual = Restrictions.eq("empresa", empresa); + c.add(Restrictions.or(Restrictions.or(empresaNull, empresaMenosUm), empresaIgual)); + } else { + c.add(Restrictions.or(empresaNull, empresaMenosUm)); + } return c.list(); } diff --git a/src/com/rjconsultores/ventaboletos/entidad/ConfigRestriccionPago.java b/src/com/rjconsultores/ventaboletos/entidad/ConfigRestriccionPago.java index 1e8fa5dc1..927ec24b3 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/ConfigRestriccionPago.java +++ b/src/com/rjconsultores/ventaboletos/entidad/ConfigRestriccionPago.java @@ -47,6 +47,9 @@ public class ConfigRestriccionPago implements Serializable { @JoinColumn(name = "FORMAPAGO_ID", referencedColumnName = "FORMAPAGO_ID") @ManyToOne private FormaPago formaPago; + @JoinColumn(name = "EMPRESA_ID", referencedColumnName = "EMPRESA_ID") + @ManyToOne + private Empresa empresa; public ConfigRestriccionPago() { } @@ -106,7 +109,7 @@ public class ConfigRestriccionPago implements Serializable { @Override public int hashCode() { int hash = 0; - hash += (configrestriccionId != null ? configrestriccionId.hashCode() : 0); + hash += (getConfigrestriccionId() != null ? getConfigrestriccionId().hashCode() : 0); return hash; } @@ -117,7 +120,7 @@ public class ConfigRestriccionPago implements Serializable { return false; } ConfigRestriccionPago other = (ConfigRestriccionPago) object; - if ((this.configrestriccionId == null && other.configrestriccionId != null) || (this.configrestriccionId != null && !this.configrestriccionId.equals(other.configrestriccionId))) { + if ((this.getConfigrestriccionId() == null && other.getConfigrestriccionId() != null) || (this.getConfigrestriccionId() != null && !this.getConfigrestriccionId().equals(other.getConfigrestriccionId()))) { return false; } return true; @@ -127,4 +130,12 @@ public class ConfigRestriccionPago implements Serializable { public String toString() { return "com.rjconsultores.ventaboletos.entidad.ConfigRestriccionPago[configrestriccionId=" + configrestriccionId + "]"; } + + public Empresa getEmpresa() { + return empresa; + } + + public void setEmpresa(Empresa empresa) { + this.empresa = empresa; + } } diff --git a/src/com/rjconsultores/ventaboletos/service/ConfigRestriccionPagoService.java b/src/com/rjconsultores/ventaboletos/service/ConfigRestriccionPagoService.java index 55c899544..a21b70870 100644 --- a/src/com/rjconsultores/ventaboletos/service/ConfigRestriccionPagoService.java +++ b/src/com/rjconsultores/ventaboletos/service/ConfigRestriccionPagoService.java @@ -5,6 +5,7 @@ package com.rjconsultores.ventaboletos.service; import com.rjconsultores.ventaboletos.entidad.ConfigRestriccionPago; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.FormaPago; import com.rjconsultores.ventaboletos.entidad.RestriccionPago; import java.util.List; @@ -17,7 +18,7 @@ public interface ConfigRestriccionPagoService extends GenericService { public List buscar(FormaPago formaPago, - RestriccionPago restriccionPago); + RestriccionPago restriccionPago, Empresa empresa); /** * Verifica se puede dar de alta en el registro. diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ConfigRestriccionPagoServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ConfigRestriccionPagoServiceImpl.java index cc480a7fc..7fb63fd17 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/ConfigRestriccionPagoServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/ConfigRestriccionPagoServiceImpl.java @@ -6,6 +6,7 @@ package com.rjconsultores.ventaboletos.service.impl; import com.rjconsultores.ventaboletos.dao.ConfigRestriccionPagoDAO; import com.rjconsultores.ventaboletos.entidad.ConfigRestriccionPago; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.FormaPago; import com.rjconsultores.ventaboletos.entidad.RestriccionPago; import com.rjconsultores.ventaboletos.service.ConfigRestriccionPagoService; @@ -70,8 +71,8 @@ public class ConfigRestriccionPagoServiceImpl implements ConfigRestriccionPagoSe } public List buscar(FormaPago formaPago, - RestriccionPago restriccionPago) { - return configRestriccionPagoDAO.buscar(formaPago, restriccionPago); + RestriccionPago restriccionPago, Empresa empresa) { + return configRestriccionPagoDAO.buscar(formaPago, restriccionPago, empresa); } public boolean puedoDarDeAlta(ConfigRestriccionPago configRestriccionPago) { @@ -89,7 +90,7 @@ public class ConfigRestriccionPagoServiceImpl implements ConfigRestriccionPagoSe Collection values = mapConsulta.values(); Integer restriccionId = null; for (ConfigRestriccionPago c : values) { - if ((c.equals(configRestriccionPago)) && (!c.getRestriccion().getRestriccionId().equals(configRestriccionPago.getRestriccion().getRestriccionId()))) { + if (c.equals(configRestriccionPago) || (!c.getRestriccion().getRestriccionId().equals(configRestriccionPago.getRestriccion().getRestriccionId()))) { restriccionId = c.getRestriccion().getRestriccionId().intValue(); } } @@ -99,39 +100,39 @@ public class ConfigRestriccionPagoServiceImpl implements ConfigRestriccionPagoSe } if ((configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_CANCELABLE.shortValue()) - && (mapConsulta.get(RESTRICCION_NO_CANCELABLE) != null)) + && (mapConsulta.get(RESTRICCION_NO_CANCELABLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_NO_CANCELABLE))) || (configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_NO_CANCELABLE.shortValue()) - && (mapConsulta.get(RESTRICCION_CANCELABLE) != null))) { + && (mapConsulta.get(RESTRICCION_CANCELABLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_CANCELABLE)))) { return false; } if ((configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_TRANSFERIBLE.shortValue()) - && (mapConsulta.get(RESTRICCION_NO_TRANSFERIBLE) != null)) + && (mapConsulta.get(RESTRICCION_NO_TRANSFERIBLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_NO_TRANSFERIBLE))) || (configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_NO_TRANSFERIBLE.shortValue()) - && (mapConsulta.get(RESTRICCION_TRANSFERIBLE) != null))) { + && (mapConsulta.get(RESTRICCION_TRANSFERIBLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_TRANSFERIBLE)))) { return false; } if ((configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_RESERVABLE.shortValue()) - && (mapConsulta.get(RESTRICCION_NO_RESERVABLE) != null)) + && (mapConsulta.get(RESTRICCION_NO_RESERVABLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_NO_RESERVABLE))) || (configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_NO_RESERVABLE.shortValue()) - && (mapConsulta.get(RESTRICCION_RESERVABLE) != null))) { + && (mapConsulta.get(RESTRICCION_RESERVABLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_RESERVABLE)))) { return false; } if (configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_RESERVABLE.shortValue()) - && (mapConsulta.get(RESTRICCION_RESERVABLE) != null)) { + && (mapConsulta.get(RESTRICCION_RESERVABLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_RESERVABLE))) { return false; } if (configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_TRANSFERIBLE.shortValue()) - && (mapConsulta.get(RESTRICCION_TRANSFERIBLE) != null)) { + && (mapConsulta.get(RESTRICCION_TRANSFERIBLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_TRANSFERIBLE))) { return false; } if (configRestriccionPago.getRestriccion().getRestriccionId().equals(RESTRICCION_CANCELABLE.shortValue()) - && (mapConsulta.get(RESTRICCION_CANCELABLE) != null)) { + && (mapConsulta.get(RESTRICCION_CANCELABLE) != null) && isMesmaEmpresaOrEmpresaTodas(configRestriccionPago, mapConsulta.get(RESTRICCION_CANCELABLE))) { return false; } @@ -140,5 +141,13 @@ public class ConfigRestriccionPagoServiceImpl implements ConfigRestriccionPagoSe return true; } + private boolean isMesmaEmpresaOrEmpresaTodas(ConfigRestriccionPago configRestriccionPago, ConfigRestriccionPago configRestriccionPagoExistente) { + return configRestriccionPagoExistente.getEmpresa() == null || + configRestriccionPagoExistente.getEmpresa().getEmpresaId() == -1 || + configRestriccionPago.getEmpresa() == null || + configRestriccionPago.getEmpresa().getEmpresaId() == -1 || + configRestriccionPago.getEmpresa().equals(configRestriccionPagoExistente.getEmpresa()); + } + }