diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 1d17da2c..28724080 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -136,7 +136,7 @@ public class Constants { new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresní karty", "address")), new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresa", "address", false, true)), new ReportMapping(MOD_TRIPBILL, new Report("Žádost", "tripRequirement", false, true)), - new ReportMapping(MOD_TRIPBILL, new Report("Vyúčtování", "tripBill", false, true)), + new ReportMapping(MOD_TRIPBILL, new Report("Vyúčtování", "tripBill", false, true, true)), new ReportMapping(MOD_ORDER, new Report("Objednávka", "order", true, true)), new ReportMapping(MOD_REQUIREMENTS, new Report("Požadavky", "requirements")) }; diff --git a/src/main/java/info/bukova/isspst/dao/TripBillApprovalDao.java b/src/main/java/info/bukova/isspst/dao/TripBillApprovalDao.java new file mode 100644 index 00000000..bbc5a3ac --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/TripBillApprovalDao.java @@ -0,0 +1,9 @@ +package info.bukova.isspst.dao; + +import info.bukova.isspst.data.TripBillApproval; + +/** + * @author Pepa Rokos + */ +public interface TripBillApprovalDao extends BaseDao { +} diff --git a/src/main/java/info/bukova/isspst/dao/jpa/TripBillApprovalDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/TripBillApprovalDaoJPA.java new file mode 100644 index 00000000..a4c9a956 --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/jpa/TripBillApprovalDaoJPA.java @@ -0,0 +1,11 @@ +package info.bukova.isspst.dao.jpa; + +import info.bukova.isspst.dao.TripBillApprovalDao; +import info.bukova.isspst.data.TripBillApproval; + +/** + * @author Pepa Rokos + */ +public class TripBillApprovalDaoJPA extends BaseDaoJPA implements TripBillApprovalDao { + +} diff --git a/src/main/java/info/bukova/isspst/data/TripBill.java b/src/main/java/info/bukova/isspst/data/TripBill.java index cee4c8ac..0f75f7aa 100644 --- a/src/main/java/info/bukova/isspst/data/TripBill.java +++ b/src/main/java/info/bukova/isspst/data/TripBill.java @@ -11,6 +11,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; @@ -51,6 +52,9 @@ public class TripBill extends BaseData implements EntityWithAttachment { @LazyCollection(LazyCollectionOption.TRUE) @IndexedEmbedded private List attachedFiles; + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "APPROVAL_ID") + private TripBillApproval approval; public TripBill() { billItems = new ArrayList(); @@ -147,4 +151,11 @@ public class TripBill extends BaseData implements EntityWithAttachment { this.attachedFiles = attachedFiles; } + public TripBillApproval getApproval() { + return approval; + } + + public void setApproval(TripBillApproval approval) { + this.approval = approval; + } } diff --git a/src/main/java/info/bukova/isspst/data/TripBillApproval.java b/src/main/java/info/bukova/isspst/data/TripBillApproval.java new file mode 100644 index 00000000..bb1bd627 --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/TripBillApproval.java @@ -0,0 +1,14 @@ +package info.bukova.isspst.data; + +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * @author Pepa Rokos + */ + +@Entity +@Table(name = "TRIP_BILL_APPROVAL") +public class TripBillApproval extends RequirementBase { + +} diff --git a/src/main/java/info/bukova/isspst/reporting/Report.java b/src/main/java/info/bukova/isspst/reporting/Report.java index 19b2a757..606626b9 100644 --- a/src/main/java/info/bukova/isspst/reporting/Report.java +++ b/src/main/java/info/bukova/isspst/reporting/Report.java @@ -8,10 +8,12 @@ public class Report { private String jasperFile; private boolean hasSettings; private boolean singleRecord; + private boolean hasCondition; public Report() { hasSettings = false; singleRecord = false; + hasCondition = false; } /** @@ -46,6 +48,19 @@ public class Report { this.singleRecord = singleRecord; } + /** + * + * @param name + * @param jasperFile + * @param hasSettings + * @param singleRecord + * @param hasCondition + */ + public Report(String name, String jasperFile, boolean hasSettings, boolean singleRecord, boolean hasCondition) { + this(name, jasperFile, hasSettings, singleRecord); + this.hasCondition = hasCondition; + } + public ReportType getType() { return type; } @@ -86,4 +101,11 @@ public class Report { this.singleRecord = singleRecord; } + public boolean isHasCondition() { + return hasCondition; + } + + public void setHasCondition(boolean hasCondition) { + this.hasCondition = hasCondition; + } } diff --git a/src/main/java/info/bukova/isspst/security/AbstractRequirementEvaluator.java b/src/main/java/info/bukova/isspst/security/AbstractRequirementEvaluator.java index 4fff0edc..1cf1a01b 100644 --- a/src/main/java/info/bukova/isspst/security/AbstractRequirementEvaluator.java +++ b/src/main/java/info/bukova/isspst/security/AbstractRequirementEvaluator.java @@ -24,14 +24,16 @@ public abstract class AbstractRequirementEvaluator extends AbstractModuleEvaluat return false; } - RequirementBase req = (RequirementBase) targetDomainObject; - - if (permission.equals(Constants.PERM_EDIT_NEW)) { - return req.getState() == RequirementState.NEW; - } - - if (permission.equals(Constants.PERM_DELETE_NEW)) { - return req.getState() == RequirementState.NEW; + if (targetDomainObject instanceof RequirementBase) { + RequirementBase req = (RequirementBase) targetDomainObject; + + if (permission.equals(Constants.PERM_EDIT_NEW)) { + return req.getState() == RequirementState.NEW; + } + + if (permission.equals(Constants.PERM_DELETE_NEW)) { + return req.getState() == RequirementState.NEW; + } } return true; diff --git a/src/main/java/info/bukova/isspst/services/AbstractService.java b/src/main/java/info/bukova/isspst/services/AbstractService.java index 3b633670..86e9bfcd 100644 --- a/src/main/java/info/bukova/isspst/services/AbstractService.java +++ b/src/main/java/info/bukova/isspst/services/AbstractService.java @@ -296,4 +296,9 @@ public abstract class AbstractService implements Service } } } + + @Override + public boolean canPrintRecord(T entity) { + return true; + } } diff --git a/src/main/java/info/bukova/isspst/services/Service.java b/src/main/java/info/bukova/isspst/services/Service.java index cac39c05..8285e0ec 100644 --- a/src/main/java/info/bukova/isspst/services/Service.java +++ b/src/main/java/info/bukova/isspst/services/Service.java @@ -22,5 +22,6 @@ public interface Service { public List filterList(List sourceList, Filter filter); public Module getModule(); public List getReports(); + public boolean canPrintRecord(T entity); } 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 afef01a3..f8e30263 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -75,11 +75,7 @@ public abstract class RequirementBaseServiceImpl exte super.add(entity); - if (canApprove(entity)) { - approve(entity); - } else { - this.sendToApprovers(entity); - } + this.postAdd(entity); } private void checkEnable() { @@ -103,6 +99,14 @@ public abstract class RequirementBaseServiceImpl exte } } + protected void postAdd(T entity) { + if (canApprove(entity)) { + approve(entity); + } else { + this.sendToApprovers(entity); + } + } + protected void addWorkflow(T entity) { if (entity.getType() == null) { return; diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java index 7897c302..fde257d6 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java @@ -50,6 +50,7 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl { + + public TripBillApproval createApproval(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 new file mode 100644 index 00000000..eee282ab --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java @@ -0,0 +1,51 @@ +package info.bukova.isspst.services.tripbill; + +import info.bukova.isspst.Constants; +import info.bukova.isspst.data.RequirementState; +import info.bukova.isspst.data.TripBill; +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 org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; + +/** + * @author Pepa Rokos + */ +public class TripBillApprovalServiceImpl extends RequirementBaseServiceImpl implements TripBillApprovalService { + + @Autowired + private RequirementTypeService reqTypeService; + + @Override + public TripBillApproval createApproval(TripBill bill) { + if (bill.getApproval() != null) { + throw new IsspstException("Approval already exists"); + } + + TripBillApproval approval = new TripBillApproval(); + approval.setCentre(bill.getRequirement().getCentre()); + approval.setWorkgroup(bill.getRequirement().getWorkgroup()); + approval.setReqDate(new Date()); + approval.setType(reqTypeService.getTypeById(Constants.REQTYPE_BUSINESSTRIP)); + approval.setState(RequirementState.NEW); + bill.setApproval(approval); + return approval; + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_ADD')") + public void add(TripBillApproval entity) { + entity.setCreated(new Date()); + entity.setOwnedBy(getLoggedInUser()); + addWorkflow(entity); + dao.add(entity); + + postAdd(entity); + } +} 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 5c7deac1..6c7784f8 100644 --- a/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java @@ -1,5 +1,6 @@ package info.bukova.isspst.services.tripbill; +import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.SettingsData; import info.bukova.isspst.data.TripBill; import info.bukova.isspst.data.TripBillItem; @@ -220,9 +221,19 @@ public class TripBillServiceImpl extends AbstractOwnedService implemen tb.setFreeCarfare(entity.isFreeCarfare()); tb.setFreeHousing(entity.isFreeHousing()); tb.setFreeMeals(entity.isFreeMeals()); + tb.setApproval(entity.getApproval()); calculate(tb); super.update(tb); } } + + @Override + public boolean canPrintRecord(TripBill entity) { + if (entity.getApproval() != null && entity.getApproval().getState() == RequirementState.APPROVED) { + return true; + } + + return false; + } } diff --git a/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java index 08086e7d..0fd9a4b3 100644 --- a/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java +++ b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java @@ -5,9 +5,6 @@ import info.bukova.isspst.reporting.ReportDefinition; import info.bukova.isspst.reporting.ReportType; import info.bukova.isspst.services.Service; import info.bukova.isspst.ui.DocumentViewModel; - -import java.util.List; - import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.ExecutionArgParam; @@ -17,6 +14,8 @@ import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; +import java.util.List; + public class ReportDialogVM extends DocumentViewModel { @@ -94,4 +93,12 @@ public class ReportDialogVM extends DocumentViewModel this.reportDefinition = reportDefinition; } + public boolean isCanPrint() { + if (singleObject != null) { + return reportDefinition.getService().canPrintRecord(singleObject); + } + + return true; + } + } 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 4709b651..8fe4bba5 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java @@ -82,8 +82,8 @@ public class TripRequirementListAll extends RequirementSubpage TripBill tb = tripRequirementService.getTripBill(getDataBean()); tripBillService.loadLazyData(tb); Map params = new HashMap(); - params.put("selected", tb); - Window win = (Window) Executions.createComponents("tripBill.zul", null, params); + params.put("bill", tb); + Window win = (Window) Executions.createComponents("tripBillSummary.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 f0857290..f92e1ba5 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java @@ -79,8 +79,8 @@ public class TripRequirementListCentre extends RequirementSubpage params = new HashMap(); - params.put("selected", tb); - Window win = (Window) Executions.createComponents("tripBill.zul", null, params); + params.put("bill", tb); + Window win = (Window) Executions.createComponents("tripBillSummary.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 4a883718..fc053e6b 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java @@ -86,8 +86,8 @@ public class TripRequirementListWorkgroup extends RequirementSubpage params = new HashMap(); - params.put("selected", tb); - Window win = (Window) Executions.createComponents("tripBill.zul", null, params); + params.put("bill", tb); + Window win = (Window) Executions.createComponents("tripBillSummary.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 91f4420b..94102475 100644 --- a/src/main/java/info/bukova/isspst/ui/tripbill/TripBillForm.java +++ b/src/main/java/info/bukova/isspst/ui/tripbill/TripBillForm.java @@ -1,14 +1,22 @@ package info.bukova.isspst.ui.tripbill; +import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.TripBill; +import info.bukova.isspst.data.TripBillApproval; import info.bukova.isspst.data.Vehicle; 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 org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; 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; @@ -20,6 +28,8 @@ public class TripBillForm extends FormWithUpload { private List vehicles; @WireVariable private GlobalSettingsService settingsService; + @WireVariable + private TripBillApprovalService tripBillApprovalService; @Init(superclass = true) public void init() { @@ -43,9 +53,35 @@ public class TripBillForm extends FormWithUpload { && getDataBean().getRequirement().getBillForPassengers() && !getDataBean().getOwnedBy().equals(getDataBean().getRequirement().getOwnedBy())) { return true; + } else if (getDataBean().getApproval() != null) { + return true; } return false; } + @Override + @Command + @NotifyChange("errMessages") + public void save(@BindingParam("window") Window win) { + final Window editWin = win; + if (getDataBean().getApproval() == null && !isBillDisabled()) { + Messagebox.show(StringUtils.localize("TripBillSaveApprove"), StringUtils.localize("TripBillSave"), Messagebox.YES + | Messagebox.NO, Messagebox.QUESTION, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + if (((Integer) event.getData()).intValue() == Messagebox.YES) { + TripBillApproval approval = tripBillApprovalService.createApproval(getDataBean()); + tripBillApprovalService.add(approval); + TripBillForm.super.save(editWin); + } else { + TripBillForm.super.save(editWin); + } + } + }); + } else { + super.save(win); + } + + } } diff --git a/src/main/java/info/bukova/isspst/ui/tripbill/TripBillSummaryVM.java b/src/main/java/info/bukova/isspst/ui/tripbill/TripBillSummaryVM.java new file mode 100644 index 00000000..1b430b91 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/tripbill/TripBillSummaryVM.java @@ -0,0 +1,83 @@ +package info.bukova.isspst.ui.tripbill; + +import info.bukova.isspst.data.TripBill; +import info.bukova.isspst.data.TripBillApproval; +import info.bukova.isspst.services.requirement.TripRequirementService; +import info.bukova.isspst.services.tripbill.TripBillApprovalService; +import info.bukova.isspst.services.tripbill.TripBillService; +import info.bukova.isspst.ui.requirement.RequirementSubpage; +import org.zkoss.bind.annotation.BindingParam; +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.ExecutionArgParam; +import org.zkoss.bind.annotation.GlobalCommand; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.select.annotation.WireVariable; +import org.zkoss.zul.Window; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Pepa Rokos + */ +public class TripBillSummaryVM extends RequirementSubpage { + + @WireVariable + private TripBillApprovalService tripBillApprovalService; + @WireVariable + private TripBillService tripBillService; + @WireVariable + private TripRequirementService tripRequirementService; + private TripBill bill; + + @Init(superclass = true) + public void initBillSummary(@ExecutionArgParam("bill") TripBill bill) { + service = tripBillApprovalService; + + if (bill.getApproval() != null) { + setDataBean(bill.getApproval()); + } + + this.bill = bill; + } + + public TripBill getBill() { + return bill; + } + + public void setBill(TripBill bill) { + this.bill = bill; + } + + public List getBills() { + List bills = new ArrayList(); + + for (TripBill b : tripRequirementService.getBills(bill.getRequirement())) { + if (b.getId() != bill.getId()) { + tripBillService.loadLazyData(b); + bills.add(b); + } + } + + return bills; + } + + @Command + public void showBill(@BindingParam("bill") TripBill bill) { + Map params = new HashMap(); + params.put("selected", bill); + Window win = (Window) Executions.createComponents("tripBill.zul", null, params); + win.doModal(); + } + + @Override + @GlobalCommand + @NotifyChange("dataBean") + public void reload() { + setDataBean(tripBillApprovalService.getById(bill.getApproval().getId())); + } +} diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 95356639..5cf14ec5 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -35,5 +35,6 @@ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 33a75b22..95202f5f 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -229,6 +229,10 @@ TripBillInKc=v Kč TripBillTo=Tam 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í? + +TripBillSummaryDetail=Detail TripRequirement=Požadavek na služební cestu ShowTripBill=Zobrazit vyúčtování diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index 9bce01b1..b97b8ec8 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -103,6 +103,7 @@ + @@ -267,6 +268,10 @@ + + + + @@ -443,5 +448,9 @@ + + + + diff --git a/src/main/webapp/app/reporting/reportDialog.zul b/src/main/webapp/app/reporting/reportDialog.zul index 85a40846..a55be370 100644 --- a/src/main/webapp/app/reporting/reportDialog.zul +++ b/src/main/webapp/app/reporting/reportDialog.zul @@ -8,7 +8,7 @@ diff --git a/src/main/webapp/main/trips/bill/tripBillGrid.zul b/src/main/webapp/main/trips/bill/tripBillGrid.zul index 7f7561ef..52bb87cd 100644 --- a/src/main/webapp/main/trips/bill/tripBillGrid.zul +++ b/src/main/webapp/main/trips/bill/tripBillGrid.zul @@ -1,5 +1,7 @@ - + -->