diff --git a/src/main/java/info/bukova/isspst/data/TripBill.java b/src/main/java/info/bukova/isspst/data/TripBill.java index a819d286..369de0e2 100644 --- a/src/main/java/info/bukova/isspst/data/TripBill.java +++ b/src/main/java/info/bukova/isspst/data/TripBill.java @@ -60,7 +60,7 @@ public class TripBill extends BaseData implements EntityWithAttachment { @LazyCollection(LazyCollectionOption.TRUE) @IndexedEmbedded private List attachedFiles; - @OneToOne(fetch = FetchType.EAGER) + @OneToOne(fetch = FetchType.EAGER, orphanRemoval = true) @JoinColumn(name = "APPROVAL_ID") private TripBillApproval approval; @Column(name = "SAVED") diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java index a022da7a..d58f9f0e 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -131,7 +131,8 @@ public abstract class RequirementBaseServiceImpl exte } protected void postAdd(T entity) { - if (canApprove(entity)) { + Workflow wf = getNextWorkflow(entity); + if (canApprove(entity) && (wf.getSignature() == null || !wf.getSignature())) { approve(entity); } else { this.sendToApprovers(entity); @@ -280,7 +281,7 @@ public abstract class RequirementBaseServiceImpl exte if (signedPdf != null) { saveSignedDoc(e, signedPdf); - } else if (wf.getSignature() != null && wf.getSignature()) { + } else if (wf.getSignature() != null && wf.getSignature() && !signatureNotRequired(wf)) { throw new ApproveException("ErrApproveMustBeSigned"); } @@ -310,6 +311,15 @@ public abstract class RequirementBaseServiceImpl exte postApprove(e); } + /** + * Check pro automatické schválení, kdy není třeba podepisovat- nadlimitní nákupy se neautorizují... + * @param wf Další krok schválení + * @return true pokud není potřeba podepisovat. Zde vrací vždy false, v případě potřeby nutno překrýt. + */ + protected boolean signatureNotRequired(Workflow wf) { + return false; + } + protected void approve(T entity, User user) { approve(entity, user, new Date(), null); } @@ -549,11 +559,7 @@ public abstract class RequirementBaseServiceImpl exte public void update(T entity) { entity.getAuthorization().clear(); entity.setState(RequirementState.NEW); - - SignedDocument doc = signedDocumentService.getForEntity(entity); - if (doc != null) { - signedDocumentService.delFromApprove(doc); - } + signedDocumentService.deleteForEntity(entity); super.update(entity); sendToApprovers(entity); 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 a1dc8aa5..7ebad845 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -67,6 +67,16 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl { SignedDocumentItem getItem(DataModel entity, long reportId); void addFromApprove(SignedDocument document); void delFromApprove(SignedDocument document); + void deleteForEntity(DataModel entity); } diff --git a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java index 4a6c0f86..f2cfea1c 100644 --- a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java @@ -83,5 +83,14 @@ public class SignedDocumentServiceImpl extends AbstractOwnedService { public TripBillApproval createApproval(TripBill bill); + public void cancelApproval(TripBill bill); } diff --git a/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java b/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java index 3610e997..4f3410f3 100644 --- a/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java @@ -9,6 +9,7 @@ import info.bukova.isspst.data.TripBillApproval; import info.bukova.isspst.services.IsspstException; import info.bukova.isspst.services.requirement.RequirementBaseServiceImpl; import info.bukova.isspst.services.requirement.RequirementTypeService; +import info.bukova.isspst.services.signeddocs.SignedDocumentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -22,6 +23,10 @@ public class TripBillApprovalServiceImpl extends RequirementBaseServiceImpl { @GlobalCommand @NotifyChange("dataBean") public void reload() { - setDataBean(tripBillApprovalService.getById(bill.getApproval().getId())); + if (bill.getApproval() != null) { + setDataBean(tripBillApprovalService.getById(bill.getApproval().getId())); + } } public Map getSelTab() { return selTab; } + + @Command + public void cancelApproval() { + Messagebox.show(StringUtils.localize("TripBillCancelApprovalQuestion"), StringUtils.localize("TripBillCancelApprovalTitle"), Messagebox.YES + | Messagebox.NO, Messagebox.QUESTION, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + if (((Integer) event.getData()).intValue() == Messagebox.YES) { + tripBillApprovalService.cancelApproval(bill); + setDataBean(null); + BindUtils.postNotifyChange(null, null, TripBillSummaryVM.this, "bill"); + BindUtils.postNotifyChange(null, null, TripBillSummaryVM.this, "dataBean"); + BindUtils.postNotifyChange(null, null, TripBillSummaryVM.this, "canApprove"); + } + } + }); + } } diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 1df6aba3..d1af6cac 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -241,6 +241,9 @@ TripBillBack=Zpět TripBillTotal=Celkem TripBillSaveApprove=Jestliže máte vše vyplněno, pošlete vyúčtování ke schválení. Vyúčtování zaslané ke schválení už nelze dále upravovat. Odeslat ke schválení? TripBillSave=Odeslat ke schválení? +TripBillCancelApproval=Zrušit schválení a povolit úpravy +TripBillCancelApprovalQuestion=Opravdu zrušít schválení tohoto vyúčtování? +TripBillCancelApprovalTitle=Zrušit schválení TripBillSummaryDetail=Detail diff --git a/src/main/webapp/main/trips/requirements/tripBillSummary.zul b/src/main/webapp/main/trips/requirements/tripBillSummary.zul index 556b6e00..38c39a31 100644 --- a/src/main/webapp/main/trips/requirements/tripBillSummary.zul +++ b/src/main/webapp/main/trips/requirements/tripBillSummary.zul @@ -35,6 +35,7 @@ +