Opraveno duplicitní vkládání záznamů do agendy Fakturace požadavků, v případě, že se požadavek upraví a znovu schválí.

closes #252
Verze_3.0
Josef Rokos 9 years ago
parent cd6a6cf5a6
commit 768d3ee874

@ -1,7 +1,7 @@
package info.bukova.isspst.data; package info.bukova.isspst.data;
import java.math.BigDecimal; import org.hibernate.annotations.LazyCollection;
import java.util.List; import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
@ -11,16 +11,15 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import java.math.BigDecimal;
import org.hibernate.annotations.LazyCollection; import java.util.List;
import org.hibernate.annotations.LazyCollectionOption;
@Entity @Entity
@Table(name = "INVOICING") @Table(name = "INVOICING")
public class Invoicing extends BaseData implements Cloneable public class Invoicing extends BaseData implements Cloneable
{ {
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "REQUIREMENT_ID") @JoinColumn(name = "REQUIREMENT_ID")
private Requirement requirement; private Requirement requirement;

@ -1,6 +1,7 @@
package info.bukova.isspst.services.invoicing; package info.bukova.isspst.services.invoicing;
import info.bukova.isspst.data.Invoicing; import info.bukova.isspst.data.Invoicing;
import info.bukova.isspst.data.Requirement;
import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.Service; import info.bukova.isspst.services.Service;
@ -20,4 +21,6 @@ public interface InvoicingService extends Service<Invoicing> {
public List<Invoicing> getPendingList(); public List<Invoicing> getPendingList();
public List<Invoicing> getArchiveList(); public List<Invoicing> getArchiveList();
public Invoicing getForRequirement(Requirement req);
} }

@ -2,18 +2,18 @@ package info.bukova.isspst.services.invoicing;
import info.bukova.isspst.data.Invoicing; import info.bukova.isspst.data.Invoicing;
import info.bukova.isspst.data.InvoicingItem; import info.bukova.isspst.data.InvoicingItem;
import info.bukova.isspst.data.Requirement;
import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.AbstractOwnedService;
import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.LazyLoader;
import java.math.BigDecimal;
import java.util.List;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.List;
public class InvoicingServiceImpl extends AbstractOwnedService<Invoicing> implements public class InvoicingServiceImpl extends AbstractOwnedService<Invoicing> implements
InvoicingService { InvoicingService {
@ -92,4 +92,13 @@ public class InvoicingServiceImpl extends AbstractOwnedService<Invoicing> 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"); 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(); 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();
}
} }

@ -11,8 +11,8 @@ import info.bukova.isspst.data.Workflow;
import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.LazyLoader;
import info.bukova.isspst.services.invoicing.InvoicingService; import info.bukova.isspst.services.invoicing.InvoicingService;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -244,11 +244,19 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
@Override @Override
@Transactional @Transactional
public BigDecimal getInvoicedAmount(Requirement req) { public BigDecimal getInvoicedAmount(Requirement req) {
Query query = dao.getQuery("select invoice from Invoicing invoice join invoice.requirement rq where rq.id = :reqId"); Invoicing inv = invoicingService.getForRequirement(req);
query.setParameter("reqId", req.getId()); return inv != null ? inv.getTotalInvoiced() : null;
}
Invoicing inv = (Invoicing) query.uniqueResult(); @Override
@Transactional
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
public void update(Requirement entity) {
super.update(entity);
Invoicing inv = invoicingService.getForRequirement(entity);
return inv != null ? inv.getTotalInvoiced() : null; if (inv != null) {
invoicingService.delete(inv);
}
} }
} }

Loading…
Cancel
Save