From 9d202192ee4020c0888a528a3eecd777fcc0b761 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 24 Apr 2015 14:00:36 +0200 Subject: [PATCH] =?UTF-8?q?Zm=C4=9Bn=C4=9Bn=20zp=C5=AFsob=20p=C5=99enosu?= =?UTF-8?q?=20vy=C3=BA=C4=8Dtov=C3=A1n=C3=AD=20ke=20spolucestuj=C3=ADc?= =?UTF-8?q?=C3=ADm:=20v=C3=BD=C3=BA=C4=8Dtov=C3=A1n=C3=AD=20se=20p=C5=99en?= =?UTF-8?q?ese=20pouze=20v=20p=C5=99=C3=ADpad=C4=9B,=20kdy=C5=BE=20ho=20je?= =?UTF-8?q?=C5=A1t=C4=9B=20spolucestuj=C3=ADc=C3=AD=20needitoval.=20Do=20z?= =?UTF-8?q?editovan=C3=A9ho=20vy=C3=BA=C4=8Dtov=C3=A1n=C3=AD=20se=20vy?= =?UTF-8?q?=C3=BA=C4=8Dtov=C3=A1n=C3=AD=20=C5=BEadatele=20u=C5=BE=20nep?= =?UTF-8?q?=C5=99en=C3=A1=C5=A1=C3=AD.=20Vy=C3=BA=C4=8Dtov=C3=A1n=C3=AD=20?= =?UTF-8?q?spolucestuj=C3=ADc=C3=ADch=20se=20schvaluj=C3=AD=20ka=C5=BEd?= =?UTF-8?q?=C3=A9=20zvl=C3=A1=C5=A1=C5=A5.=20refs=20#212?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/data/TripBill.java | 34 ++++--- .../isspst/services/AbstractService.java | 4 + .../services/tripbill/TripBillService.java | 11 ++- .../tripbill/TripBillServiceImpl.java | 41 ++++---- .../info/bukova/isspst/ui/FormWithUpload.java | 7 +- .../requirement/TripRequirementListAll.java | 2 +- .../TripRequirementListCentre.java | 2 +- .../TripRequirementListWorkgroup.java | 2 +- .../isspst/ui/tripbill/TripBillForm.java | 19 ++-- .../isspst/ui/tripbill/TripBillSummaryVM.java | 6 +- .../trips/requirements/tripBillSummary.zul | 93 +++++++------------ .../requirements/tripBillSummaryMaster.zul | 38 ++++++++ 12 files changed, 151 insertions(+), 108 deletions(-) create mode 100644 src/main/webapp/main/trips/requirements/tripBillSummaryMaster.zul diff --git a/src/main/java/info/bukova/isspst/data/TripBill.java b/src/main/java/info/bukova/isspst/data/TripBill.java index f5fc295e..cc352b1b 100644 --- a/src/main/java/info/bukova/isspst/data/TripBill.java +++ b/src/main/java/info/bukova/isspst/data/TripBill.java @@ -1,11 +1,13 @@ package info.bukova.isspst.data; import info.bukova.isspst.storage.EntityWithAttachment; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; +import org.hibernate.search.annotations.Analyze; +import org.hibernate.search.annotations.Field; +import org.hibernate.search.annotations.Index; +import org.hibernate.search.annotations.Indexed; +import org.hibernate.search.annotations.IndexedEmbedded; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -16,14 +18,10 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; - -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; -import org.hibernate.search.annotations.Analyze; -import org.hibernate.search.annotations.Field; -import org.hibernate.search.annotations.Index; -import org.hibernate.search.annotations.Indexed; -import org.hibernate.search.annotations.IndexedEmbedded; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; @Entity @Table(name = "TRIP_BILL") @@ -65,6 +63,8 @@ public class TripBill extends BaseData implements EntityWithAttachment { @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "APPROVAL_ID") private TripBillApproval approval; + @Column(name = "SAVED") + private Boolean saved; public TripBill() { billItems = new ArrayList(); @@ -178,4 +178,12 @@ public class TripBill extends BaseData implements EntityWithAttachment { public void setApproval(TripBillApproval approval) { this.approval = approval; } + + public Boolean getSaved() { + return saved; + } + + public void setSaved(Boolean saved) { + this.saved = saved; + } } diff --git a/src/main/java/info/bukova/isspst/services/AbstractService.java b/src/main/java/info/bukova/isspst/services/AbstractService.java index 86e9bfcd..613a57e8 100644 --- a/src/main/java/info/bukova/isspst/services/AbstractService.java +++ b/src/main/java/info/bukova/isspst/services/AbstractService.java @@ -274,6 +274,10 @@ public abstract class AbstractService implements Service @Override @Transactional public void loadLazyData(String group, T entity) { + if (entity == null) { + return; + } + Method[] methods = this.getClass().getMethods(); for (Method m : methods) { diff --git a/src/main/java/info/bukova/isspst/services/tripbill/TripBillService.java b/src/main/java/info/bukova/isspst/services/tripbill/TripBillService.java index d73d7278..1630ed81 100644 --- a/src/main/java/info/bukova/isspst/services/tripbill/TripBillService.java +++ b/src/main/java/info/bukova/isspst/services/tripbill/TripBillService.java @@ -1,11 +1,11 @@ package info.bukova.isspst.services.tripbill; -import java.util.List; - import info.bukova.isspst.data.TripBill; import info.bukova.isspst.data.TripRequirement; import info.bukova.isspst.services.Service; +import java.util.List; + public interface TripBillService extends Service { public TripBill createTripBill(TripRequirement requirement); @@ -15,4 +15,11 @@ public interface TripBillService extends Service { public void loadOwner(TripBill bill); public void loadPassengers(TripBill bill); + /** + * Uloží vyúčtování a nastaví příznak přenosu vyúčtování od žadatele + * + * @param bill + */ + public void updateOwned(TripBill bill); + } diff --git a/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java b/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java index 6c7784f8..9c0ddd27 100644 --- a/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java @@ -199,6 +199,14 @@ public class TripBillServiceImpl extends AbstractOwnedService implemen bill.getRequirement().setPassengers(tr.getPassengers()); } + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())") + public void updateOwned(TripBill bill) { + bill.setSaved(true); + update(bill); + } + @Override @Transactional @PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())") @@ -206,26 +214,27 @@ public class TripBillServiceImpl extends AbstractOwnedService implemen super.update(entity); TripRequirement req = entity.getRequirement(); - Query q = dao.getQuery("from TripBill where requirement = :req and id != :id"); - q.setParameter("req", req); - q.setParameter("id", entity.getId()); - List bills = q.list(); - for (TripBill tb : bills) { - tb.getBillItems().clear(); + if (req.getOwnedBy().equals(entity.getOwnedBy())) { + Query q = dao.getQuery("from TripBill where requirement = :req and id != :id and (saved = false or saved is null)"); + q.setParameter("req", req); + q.setParameter("id", entity.getId()); - for (TripBillItem item : entity.getBillItems()) { - tb.getBillItems().add(new TripBillItem(item)); - } + List bills = q.list(); + for (TripBill tb : bills) { + tb.getBillItems().clear(); - tb.setFreeCarfare(entity.isFreeCarfare()); - tb.setFreeHousing(entity.isFreeHousing()); - tb.setFreeMeals(entity.isFreeMeals()); - tb.setApproval(entity.getApproval()); - calculate(tb); - super.update(tb); - } + for (TripBillItem item : entity.getBillItems()) { + tb.getBillItems().add(new TripBillItem(item)); + } + tb.setFreeCarfare(entity.isFreeCarfare()); + tb.setFreeHousing(entity.isFreeHousing()); + tb.setFreeMeals(entity.isFreeMeals()); + calculate(tb); + super.update(tb); + } + } } @Override diff --git a/src/main/java/info/bukova/isspst/ui/FormWithUpload.java b/src/main/java/info/bukova/isspst/ui/FormWithUpload.java index 4c543d16..ac6eee2d 100644 --- a/src/main/java/info/bukova/isspst/ui/FormWithUpload.java +++ b/src/main/java/info/bukova/isspst/ui/FormWithUpload.java @@ -62,11 +62,14 @@ public class FormWithUpload extends FormViewModel { @Override protected void doSave() { + maintainAttachment(); + super.doSave(); + } + + protected void maintainAttachment() { for (FileMetainfo info : forDelete) { documentStorage.removeFile(info); } - - super.doSave(); } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java index 8fe4bba5..266bcc5f 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java @@ -83,7 +83,7 @@ public class TripRequirementListAll extends RequirementSubpage tripBillService.loadLazyData(tb); Map params = new HashMap(); params.put("bill", tb); - Window win = (Window) Executions.createComponents("tripBillSummary.zul", null, params); + Window win = (Window) Executions.createComponents("tripBillSummaryMaster.zul", null, params); win.doModal(); } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java index f92e1ba5..ba6b9a71 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java @@ -80,7 +80,7 @@ public class TripRequirementListCentre extends RequirementSubpage params = new HashMap(); params.put("bill", tb); - Window win = (Window) Executions.createComponents("tripBillSummary.zul", null, params); + Window win = (Window) Executions.createComponents("tripBillSummaryMaster.zul", null, params); win.doModal(); } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java index fc053e6b..30f91122 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java @@ -87,7 +87,7 @@ public class TripRequirementListWorkgroup extends RequirementSubpage params = new HashMap(); params.put("bill", tb); - Window win = (Window) Executions.createComponents("tripBillSummary.zul", null, params); + Window win = (Window) Executions.createComponents("tripBillSummaryMaster.zul", null, params); win.doModal(); } diff --git a/src/main/java/info/bukova/isspst/ui/tripbill/TripBillForm.java b/src/main/java/info/bukova/isspst/ui/tripbill/TripBillForm.java index 6d03e144..0b7fb013 100644 --- a/src/main/java/info/bukova/isspst/ui/tripbill/TripBillForm.java +++ b/src/main/java/info/bukova/isspst/ui/tripbill/TripBillForm.java @@ -8,10 +8,6 @@ import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.tripbill.TripBillApprovalService; import info.bukova.isspst.services.tripbill.TripBillService; import info.bukova.isspst.ui.FormWithUpload; - -import java.util.ArrayList; -import java.util.List; - import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; @@ -22,6 +18,9 @@ import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Window; +import java.util.ArrayList; +import java.util.List; + public class TripBillForm extends FormWithUpload { @WireVariable @@ -50,11 +49,7 @@ public class TripBillForm extends FormWithUpload { } public boolean isBillDisabled() { - if (getDataBean().getRequirement().getBillForPassengers() != null - && getDataBean().getRequirement().getBillForPassengers() - && !getDataBean().getOwnedBy().equals(getDataBean().getRequirement().getOwnedBy())) { - return true; - } else if (getDataBean().getApproval() != null) { + if (getDataBean().getApproval() != null) { return true; } @@ -93,4 +88,10 @@ public class TripBillForm extends FormWithUpload { } } + + @Override + protected void doSave() { + maintainAttachment(); + tripBillService.updateOwned(getDataBean()); + } } diff --git a/src/main/java/info/bukova/isspst/ui/tripbill/TripBillSummaryVM.java b/src/main/java/info/bukova/isspst/ui/tripbill/TripBillSummaryVM.java index 1b430b91..c2a01d9d 100644 --- a/src/main/java/info/bukova/isspst/ui/tripbill/TripBillSummaryVM.java +++ b/src/main/java/info/bukova/isspst/ui/tripbill/TripBillSummaryVM.java @@ -49,13 +49,17 @@ public class TripBillSummaryVM extends RequirementSubpage { return bill; } - public void setBill(TripBill bill) { + @Command + @NotifyChange({"bill", "dataBean", "canApprove"}) + public void setBill(@BindingParam("bill") TripBill bill) { this.bill = bill; + setDataBean(bill.getApproval()); } public List getBills() { List bills = new ArrayList(); + bills.add(this.bill); for (TripBill b : tripRequirementService.getBills(bill.getRequirement())) { if (b.getId() != bill.getId()) { tripBillService.loadLazyData(b); diff --git a/src/main/webapp/main/trips/requirements/tripBillSummary.zul b/src/main/webapp/main/trips/requirements/tripBillSummary.zul index 4937b4ff..556b6e00 100644 --- a/src/main/webapp/main/trips/requirements/tripBillSummary.zul +++ b/src/main/webapp/main/trips/requirements/tripBillSummary.zul @@ -5,68 +5,37 @@ xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> - - - - -