diff --git a/src/main/java/info/bukova/isspst/reporting/DefinitionFiller.java b/src/main/java/info/bukova/isspst/reporting/DefinitionFiller.java deleted file mode 100644 index 9ab25c62..00000000 --- a/src/main/java/info/bukova/isspst/reporting/DefinitionFiller.java +++ /dev/null @@ -1,44 +0,0 @@ -package info.bukova.isspst.reporting; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; - -public class DefinitionFiller { - - @Autowired - ReportDefinition definition; - - @SuppressWarnings("unchecked") - private void setData(Object data) { - if (data instanceof List) { - definition.setDataSet((List)data); - } else { - definition.setSingleObject(data); - } - } - - public void fillDefinition(Report report, Object data) { - definition.clear(); - definition.setReport(report); - setData(data); - } - - public void fillDefinition(Report report, Object data, Map params) { - fillDefinition(report, data); - definition.setParams(params); - } - - public void fillDefinition(Report report, Object data, String[] columns) { - fillDefinition(report, data); - definition.setFieldsToPrint(Arrays.asList(columns)); - } - - public void fillDefinition(Report report, Object data, String[] columns, Map params) { - fillDefinition(report, data, params); - definition.setFieldsToPrint(Arrays.asList(columns)); - } - -} diff --git a/src/main/java/info/bukova/isspst/reporting/ParamFiller.java b/src/main/java/info/bukova/isspst/reporting/ParamFiller.java new file mode 100644 index 00000000..ae17f290 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/ParamFiller.java @@ -0,0 +1,54 @@ +package info.bukova.isspst.reporting; + +import info.bukova.isspst.data.AuthItem; +import info.bukova.isspst.data.TripBill; +import info.bukova.isspst.data.User; +import info.bukova.isspst.data.UserSettingsData; +import info.bukova.isspst.services.requirement.TripRequirementService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.storage.FileStorage; + +import org.springframework.beans.factory.annotation.Autowired; + +public class ParamFiller { + + @Autowired + private ReportDefinition definition; + @Autowired + private UserService userService; + @Autowired + private FileStorage storage; + @Autowired + private TripRequirementService tripReqService; + + public void fill() { + if (definition.getDataSet() == null || definition.getDataSet().isEmpty()) { + return; + } + + if ((definition.getDataSet().get(0) instanceof TripBill) + && definition.getReport().isSingleRecord()) { + if (userService.getUserSettings().getSignatureFile() != null + && !userService.getUserSettings().getSignatureFile().isEmpty()) { + definition.setParam("P_USER_SIGNATURE", storage.serverPath(userService.getUserSettings().getSignatureFile())); + } + + TripBill tb = (TripBill)definition.getDataSet().get(0); + tripReqService.loadAuthItems(tb.getRequirement()); + AuthItem lastAuth = tb.getRequirement().getAuthorization().get(tb.getRequirement().getAuthorization().size() - 1); + + definition.setParam("P_APPROVE_DATE", lastAuth.getAuthDate()); + + User u = lastAuth.getApprover(); + + UserSettingsData approverSettings = userService.getUserSettings(u); + + if (approverSettings != null + && approverSettings.getSignatureFile() != null + && !approverSettings.getSignatureFile().isEmpty()) { + definition.setParam("P_APPROVER_SIGNATURE", storage.serverPath(approverSettings.getSignatureFile())); + } + } + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/ReportController.java b/src/main/java/info/bukova/isspst/reporting/ReportController.java index 18888238..5e06b347 100644 --- a/src/main/java/info/bukova/isspst/reporting/ReportController.java +++ b/src/main/java/info/bukova/isspst/reporting/ReportController.java @@ -6,6 +6,8 @@ import java.io.OutputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -17,7 +19,10 @@ public class ReportController { private ReportDefinition reportDefinition; @Autowired private GeneratorFactory factory; + @Autowired + private ParamFiller paramFiller; private static final String ERROR_MESSAGE = "Generator returned no data!
%s"; + private final static Logger logger = LoggerFactory.getLogger(ReportController.class); private void writeError(OutputStream stream, Throwable e) { writeError(stream, e.toString()); @@ -45,6 +50,7 @@ public class ReportController { throw new ReportException("Definition is null"); } + paramFiller.fill(); Generator gen = factory.createGenerator(reportDefinition); byte[] data = gen.generate(); response.setContentType(contentType); @@ -54,13 +60,13 @@ public class ReportController { os.flush(); os.close(); } catch (IOException e) { - e.printStackTrace(); + logger.error("I/O error: " + e.getMessage()); } catch (ReportException e) { + logger.error("Report generation error: " + e.getMessage()); writeError(os, e); } finally { if (os != null) { try { - os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/webapp/WEB-INF/reports/tripBill.jasper b/src/main/webapp/WEB-INF/reports/tripBill.jasper index ddf3e513..3777829c 100644 Binary files a/src/main/webapp/WEB-INF/reports/tripBill.jasper and b/src/main/webapp/WEB-INF/reports/tripBill.jasper differ diff --git a/src/main/webapp/WEB-INF/reports/tripBill.jrxml b/src/main/webapp/WEB-INF/reports/tripBill.jrxml index 5c39e24a..6c2c48b6 100644 --- a/src/main/webapp/WEB-INF/reports/tripBill.jrxml +++ b/src/main/webapp/WEB-INF/reports/tripBill.jrxml @@ -1,11 +1,12 @@ - - + + + @@ -360,6 +361,19 @@ tuzemské pracovní cesty]]> + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/reports/tripRequirement.jasper b/src/main/webapp/WEB-INF/reports/tripRequirement.jasper index 2362b89f..fb065a35 100644 Binary files a/src/main/webapp/WEB-INF/reports/tripRequirement.jasper and b/src/main/webapp/WEB-INF/reports/tripRequirement.jasper differ diff --git a/src/main/webapp/WEB-INF/reports/tripRequirement.jrxml b/src/main/webapp/WEB-INF/reports/tripRequirement.jrxml index 4a5d74e4..460059d6 100644 --- a/src/main/webapp/WEB-INF/reports/tripRequirement.jrxml +++ b/src/main/webapp/WEB-INF/reports/tripRequirement.jrxml @@ -2,7 +2,7 @@ - +