diff --git a/src/main/java/info/bukova/isspst/data/Invoicing.java b/src/main/java/info/bukova/isspst/data/Invoicing.java index f6d81b8c..19dfdfb5 100644 --- a/src/main/java/info/bukova/isspst/data/Invoicing.java +++ b/src/main/java/info/bukova/isspst/data/Invoicing.java @@ -1,7 +1,7 @@ package info.bukova.isspst.data; -import java.math.BigDecimal; -import java.util.List; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -11,16 +11,15 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; - -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; +import java.math.BigDecimal; +import java.util.List; @Entity @Table(name = "INVOICING") public class Invoicing extends BaseData implements Cloneable { - @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "REQUIREMENT_ID") private Requirement requirement; diff --git a/src/main/java/info/bukova/isspst/services/invoicing/InvoicingService.java b/src/main/java/info/bukova/isspst/services/invoicing/InvoicingService.java index 84583cc9..414ed36f 100644 --- a/src/main/java/info/bukova/isspst/services/invoicing/InvoicingService.java +++ b/src/main/java/info/bukova/isspst/services/invoicing/InvoicingService.java @@ -1,6 +1,7 @@ package info.bukova.isspst.services.invoicing; import info.bukova.isspst.data.Invoicing; +import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.Service; @@ -20,4 +21,6 @@ public interface InvoicingService extends Service { public List getPendingList(); public List getArchiveList(); + + public Invoicing getForRequirement(Requirement req); } diff --git a/src/main/java/info/bukova/isspst/services/invoicing/InvoicingServiceImpl.java b/src/main/java/info/bukova/isspst/services/invoicing/InvoicingServiceImpl.java index 98124d3d..7386188c 100644 --- a/src/main/java/info/bukova/isspst/services/invoicing/InvoicingServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/invoicing/InvoicingServiceImpl.java @@ -2,18 +2,18 @@ package info.bukova.isspst.services.invoicing; import info.bukova.isspst.data.Invoicing; import info.bukova.isspst.data.InvoicingItem; +import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; - -import java.math.BigDecimal; -import java.util.List; - import org.hibernate.Hibernate; import org.hibernate.Query; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; +import java.util.List; + public class InvoicingServiceImpl extends AbstractOwnedService implements InvoicingService { @@ -92,4 +92,13 @@ public class InvoicingServiceImpl extends AbstractOwnedService implem Query q = dao.getQuery("select inv from Invoicing as inv join fetch inv.requirement rq join fetch rq.ownedBy where inv.completed = true order by rq.numser"); return q.list(); } + + @Override + @Transactional + public Invoicing getForRequirement(Requirement req) { + Query query = dao.getQuery("select invoice from Invoicing invoice join invoice.requirement rq where rq.id = :reqId"); + query.setParameter("reqId", req.getId()); + + return (Invoicing) query.uniqueResult(); + } } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java index 857857b0..a1dc8aa5 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -11,8 +11,8 @@ import info.bukova.isspst.data.Workflow; import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.invoicing.InvoicingService; import org.hibernate.Hibernate; -import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; @@ -244,11 +244,19 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl