diff --git a/pom.xml b/pom.xml index 8a7f23a14037fe513eae1e30ace182a34177112d..3f8acfa99ba2f70867152e812006f8569c790ecb 100644 --- a/pom.xml +++ b/pom.xml @@ -143,6 +143,12 @@ <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> + + <dependency> + <groupId>com.itextpdf</groupId> + <artifactId>itextpdf</artifactId> + <version>5.5.13</version> + </dependency> </dependencies> <build> diff --git a/src/main/java/de/deadlocker8/budgetmaster/controller/ReportController.java b/src/main/java/de/deadlocker8/budgetmaster/controller/ReportController.java index 5241ff2c426c34c43776c6ae11816c741a0bec06..5935d9e87a00eb80ebcb17408660d592c1243c44 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/controller/ReportController.java +++ b/src/main/java/de/deadlocker8/budgetmaster/controller/ReportController.java @@ -1,13 +1,17 @@ package de.deadlocker8.budgetmaster.controller; +import de.deadlocker8.budgetmaster.reports.ReportSettings; import de.deadlocker8.budgetmaster.repositories.SettingsRepository; import de.deadlocker8.budgetmaster.services.HelpersService; import org.joda.time.DateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; @Controller @@ -24,16 +28,23 @@ public class ReportController extends BaseController { DateTime date = helpers.getDateTimeFromCookie(cookieDate); + ReportSettings reportSettings = new ReportSettings(); + + model.addAttribute("reportSettings", reportSettings); model.addAttribute("currentDate", date); return "reports/reports"; } - @RequestMapping("/reports/generate") - public String generate(Model model, @CookieValue(value = "currentDate", required = false) String cookieDate) + @RequestMapping(value = "/reports/generate", method = RequestMethod.POST) + public String post(Model model, + @CookieValue(value = "currentDate", required = false) String cookieDate, + @ModelAttribute("NewReportSettings") ReportSettings reportSettings, + BindingResult bindingResult) { DateTime date = helpers.getDateTimeFromCookie(cookieDate); - model.addAttribute("currentDate", date); - return "reports/reports"; + System.out.println(reportSettings); + + return "redirect:/reports"; } } \ No newline at end of file diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/AmountType.java b/src/main/java/de/deadlocker8/budgetmaster/reports/AmountType.java new file mode 100644 index 0000000000000000000000000000000000000000..328fea5966d485b8e5f2867a086becf404e65f88 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/AmountType.java @@ -0,0 +1,6 @@ +package de.deadlocker8.budgetmaster.reports; + +public enum AmountType +{ + INCOME, PAYMENT, BOTH +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/ColumnType.java b/src/main/java/de/deadlocker8/budgetmaster/reports/ColumnType.java new file mode 100644 index 0000000000000000000000000000000000000000..89d417eabaadb5ff68a6a484a81436f692fcb676 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/ColumnType.java @@ -0,0 +1,38 @@ +package de.deadlocker8.budgetmaster.reports; + + +import de.deadlocker8.budgetmaster.utils.Strings; +import de.thecodelabs.utils.util.Localization; + +public enum ColumnType +{ + POSITION(Strings.REPORT_POSITION, 1), + DATE(Strings.REPORT_DATE, 2), + REPEATING(Strings.REPORT_REPEATING, 1), + CATEGORY(Strings.REPORT_CATEGORY, 3), + NAME(Strings.REPORT_NAME, 3), + DESCRIPTION(Strings.REPORT_DESCRIPTION, 3), + TAGS(Strings.REPORT_TAGS, 3), + ACCOUNT(Strings.REPORT_ACCOUNT, 2), + RATING(Strings.REPORT_RATING, 1), + AMOUNT(Strings.REPORT_AMOUNT, 2); + + private String name; + private float proportion; + + private ColumnType(String name, float proportion) + { + this.name = name; + this.proportion = proportion; + } + + public String getName() + { + return Localization.getString(name); + } + + public float getProportion() + { + return proportion; + } +} \ No newline at end of file diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/Fonts.java b/src/main/java/de/deadlocker8/budgetmaster/reports/Fonts.java new file mode 100644 index 0000000000000000000000000000000000000000..81c7a9c02087b82d4a5fc7fb00fd7059a345caae --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/Fonts.java @@ -0,0 +1,6 @@ +package de.deadlocker8.budgetmaster.reports; + +public class Fonts +{ + public static final String OPEN_SANS = "fonts/OpenSans-Regular.ttf"; +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/HeaderFooterPageEvent.java b/src/main/java/de/deadlocker8/budgetmaster/reports/HeaderFooterPageEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..d6a7e482de9d78d592c1f6aad02df1613f3e3f26 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/HeaderFooterPageEvent.java @@ -0,0 +1,28 @@ +package de.deadlocker8.budgetmaster.reports; + +import com.itextpdf.text.*; +import com.itextpdf.text.pdf.BaseFont; +import com.itextpdf.text.pdf.ColumnText; +import com.itextpdf.text.pdf.PdfPageEventHelper; +import com.itextpdf.text.pdf.PdfWriter; +import de.deadlocker8.budgetmaster.utils.Strings; +import de.thecodelabs.utils.util.Localization; +import org.joda.time.DateTime; + + +public class HeaderFooterPageEvent extends PdfPageEventHelper +{ + public void onStartPage(PdfWriter writer, Document document) + { + + } + + public void onEndPage(PdfWriter writer, Document document) + { + Font font = FontFactory.getFont(Fonts.OPEN_SANS, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 8, Font.NORMAL, BaseColor.BLACK); + + ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(Localization.getString(Strings.REPORT_FOOTER_LEFT), font), 100, 25, 0); + ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(Localization.getString(Strings.REPORT_FOOTER_CENTER, document.getPageNumber()), font), 300, 25, 0); + ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(DateTime.now().toString("dd.MM.YYYY"), font), 500, 25, 0); + } +} \ No newline at end of file diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/ReportColumn.java b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportColumn.java new file mode 100644 index 0000000000000000000000000000000000000000..55cb047131da93596166529ea1aac1539a191d94 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportColumn.java @@ -0,0 +1,36 @@ +package de.deadlocker8.budgetmaster.reports; + +public class ReportColumn +{ + private boolean activated; + private int position; + + public boolean isActivated() + { + return activated; + } + + public void setActivated(boolean activated) + { + this.activated = activated; + } + + public int getPosition() + { + return position; + } + + public void setPosition(int position) + { + this.position = position; + } + + @Override + public String toString() + { + return "ReportColumn{" + + "activated=" + activated + + ", position=" + position + + '}'; + } +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/ReportGenerator.java b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..d015ac81ed43d393b77c6037813fb52599c35e80 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportGenerator.java @@ -0,0 +1,297 @@ +package de.deadlocker8.budgetmaster.reports; + +//import java.awt.Color; +//import java.io.File; +//import java.io.FileNotFoundException; +//import java.io.FileOutputStream; +//import java.util.ArrayList; +// +//import org.joda.time.DateTime; +//import org.joda.time.format.DateTimeFormat; +// +//import com.itextpdf.text.BaseColor; +//import com.itextpdf.text.Chapter; +//import com.itextpdf.text.Chunk; +//import com.itextpdf.text.Document; +//import com.itextpdf.text.DocumentException; +//import com.itextpdf.text.Element; +//import com.itextpdf.text.Font; +//import com.itextpdf.text.FontFactory; +//import com.itextpdf.text.Paragraph; +//import com.itextpdf.text.Phrase; +//import com.itextpdf.text.pdf.BaseFont; +//import com.itextpdf.text.pdf.GrayColor; +//import com.itextpdf.text.pdf.PdfPCell; +//import com.itextpdf.text.pdf.PdfPTable; +//import com.itextpdf.text.pdf.PdfWriter; +// +//import de.deadlocker8.budgetmaster.logic.Budget; +//import de.deadlocker8.budgetmaster.logic.category.CategoryBudget; +//import de.deadlocker8.budgetmaster.logic.utils.Fonts; +//import de.deadlocker8.budgetmaster.logic.utils.Helpers; +//import de.deadlocker8.budgetmaster.logic.utils.Strings; +//import tools.Localization; + +public class ReportGenerator +{ +// private ArrayList<ReportItem> reportItems; +// private ArrayList<CategoryBudget> categoryBudgets; +// private ReportPreferences reportPreferences; +// private File savePath; +// private String currency; +// private DateTime date; +// private Budget budget; +// private final String FONT = Fonts.OPEN_SANS; +// +// public ReportGenerator(ArrayList<ReportItem> reportItems, ArrayList<CategoryBudget> categoryBudgets, ReportPreferences reportPreferences, File savePath, String currency, DateTime date, Budget budget) +// { +// this.reportItems = reportItems; +// this.categoryBudgets = categoryBudgets; +// this.reportPreferences = reportPreferences; +// this.savePath = savePath; +// this.currency = currency; +// this.date = date; +// this.budget = budget; +// } +// +// private Chapter generateHeader() +// { +// Font font = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16, Font.BOLDITALIC, BaseColor.BLACK); +// Chunk chunk = new Chunk(Localization.getString(Strings.REPORT_HEADLINE, date.toString("MMMM yyyy")), font); +// Chapter chapter = new Chapter(new Paragraph(chunk), 1); +// chapter.setNumberDepth(0); +// chapter.add(Chunk.NEWLINE); +// return chapter; +// } +// +// private PdfPTable generateTable(int tableWidth, AmountType amountType) +// { +// int numberOfColumns = reportPreferences.getColumnOrder().getColumns().size(); +// int totalIncome = 0; +// int totalPayment = 0; +// +// if(numberOfColumns > 0) +// { +// float[] proportions = new float[numberOfColumns]; +// for(int i = 0; i < reportPreferences.getColumnOrder().getColumns().size(); i++) +// { +// proportions[i] = reportPreferences.getColumnOrder().getColumns().get(i).getProportion(); +// } +// +// PdfPTable table = new PdfPTable(proportions); +// table.setWidthPercentage(tableWidth); +// Font font = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 8, Font.NORMAL, GrayColor.BLACK); +// +// for(ColumnType column : reportPreferences.getColumnOrder().getColumns()) +// { +// PdfPCell cell = new PdfPCell(new Phrase(column.getName(), font)); +// cell.setBackgroundColor(GrayColor.LIGHT_GRAY); +// cell.setHorizontalAlignment(Element.ALIGN_CENTER); +// cell.setVerticalAlignment(Element.ALIGN_MIDDLE); +// table.addCell(cell); +// } +// +// for(ReportItem currentItem : reportItems) +// { +// if(currentItem.getAmount() > 0) +// { +// totalIncome += currentItem.getAmount(); +// if(amountType == AmountType.PAYMENT) +// { +// continue; +// } +// } +// else +// { +// totalPayment += currentItem.getAmount(); +// if(amountType == AmountType.INCOME) +// { +// continue; +// } +// } +// +// for(ColumnType column : reportPreferences.getColumnOrder().getColumns()) +// { +// PdfPCell cell = new PdfPCell(new Phrase(getProperty(currentItem, column), font)); +// cell.setBackgroundColor(new BaseColor(Color.WHITE)); +// cell.setHorizontalAlignment(Element.ALIGN_CENTER); +// cell.setVerticalAlignment(Element.ALIGN_MIDDLE); +// table.addCell(cell); +// } +// } +// +// PdfPCell cellTotal; +// String total = ""; +// switch(amountType) +// { +// case BOTH: +// String totalIncomeString = Helpers.getCurrencyString(totalIncome, currency); +// String totalPaymentString = Helpers.getCurrencyString(totalPayment, currency); +// total = Localization.getString(Strings.REPORT_SUM_TOTAL, totalIncomeString, totalPaymentString); +// break; +// case INCOME: +// total = Localization.getString(Strings.REPORT_SUM, Helpers.getCurrencyString(totalIncome, currency)); +// break; +// case PAYMENT: +// total = Localization.getString(Strings.REPORT_SUM, Helpers.getCurrencyString(totalPayment, currency)); +// break; +// default: +// break; +// } +// +// cellTotal = new PdfPCell(new Phrase(total, font)); +// cellTotal.setBackgroundColor(new BaseColor(Color.WHITE)); +// cellTotal.setColspan(numberOfColumns); +// cellTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); +// cellTotal.setVerticalAlignment(Element.ALIGN_MIDDLE); +// table.addCell(cellTotal); +// +// return table; +// } +// return null; +// } +// +// public void generate() throws FileNotFoundException, DocumentException +// { +// Document document = new Document(); +// PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(savePath)); +// writer.setPageEvent(new HeaderFooterPageEvent()); +// document.open(); +// document.setMargins(50, 45, 50, 70); +// Font headerFont = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 14, Font.BOLD, BaseColor.BLACK); +// Font smallHeaderFont = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12, Font.BOLD, BaseColor.BLACK); +// +// document.add(generateHeader()); +// document.add(Chunk.NEWLINE); +// +// if(reportPreferences.isIncludeBudget()) +// { +// Font fontGreen = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12, Font.NORMAL, new BaseColor(36, 122, 45)); +// Font fontRed = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12, Font.NORMAL, BaseColor.RED); +// Font fontBlack = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12, Font.BOLD, BaseColor.BLACK); +// +// document.add(new Paragraph(Localization.getString(Strings.REPORT_BUDGET), headerFont)); +// document.add(Chunk.NEWLINE); +// document.add(new Paragraph(Localization.getString(Strings.REPORT_INCOMES) + Helpers.getCurrencyString(budget.getIncomeSum(), currency), fontGreen)); +// document.add(new Paragraph(Localization.getString(Strings.REPORT_PAYMENTS) + Helpers.getCurrencyString(budget.getPaymentSum(), currency), fontRed)); +// document.add(new Paragraph(Localization.getString(Strings.REPORT_BUDGET_REST) + Helpers.getCurrencyString(budget.getIncomeSum() + budget.getPaymentSum(), currency), fontBlack)); +// document.add(Chunk.NEWLINE); +// } +// +// document.add(new Paragraph(Localization.getString(Strings.REPORT_HEADLINE_PAYMENTS_OVERVIEW), headerFont)); +// document.add(Chunk.NEWLINE); +// +// if(reportPreferences.isSplitTable()) +// { +// document.add(new Paragraph(Localization.getString(Strings.TITLE_INCOMES), smallHeaderFont)); +// document.add(Chunk.NEWLINE); +// +// PdfPTable table = generateTable(100, AmountType.INCOME); +// if(table != null) +// { +// document.add(table); +// } +// +// document.add(Chunk.NEWLINE); +// document.add(new Paragraph(Localization.getString(Strings.TITLE_PAYMENTS), smallHeaderFont)); +// document.add(Chunk.NEWLINE); +// +// table = generateTable(100, AmountType.PAYMENT); +// if(table != null) +// { +// document.add(table); +// } +// } +// else +// { +// PdfPTable table = generateTable(100, AmountType.BOTH); +// if(table != null) +// { +// document.add(table); +// } +// } +// +// if(reportPreferences.isIncludeCategoryBudgets()) +// { +// document.add(Chunk.NEWLINE); +// document.add(new Paragraph(Localization.getString(Strings.TITLE_CATEGORY_BUDGETS), smallHeaderFont)); +// document.add(Chunk.NEWLINE); +// +// PdfPTable table = generateCategoryBudgets(); +// if(table != null) +// { +// document.add(table); +// } +// } +// +// document.close(); +// } +// +// private PdfPTable generateCategoryBudgets() +// { +// PdfPTable table = new PdfPTable(2); +// table.setWidthPercentage(100); +// Font font = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 8, Font.NORMAL, BaseColor.BLACK); +// +// //header cells +// PdfPCell cellHeaderCategory = new PdfPCell(new Phrase(Localization.getString(Strings.TITLE_CATEGORY), font)); +// cellHeaderCategory.setBackgroundColor(GrayColor.LIGHT_GRAY); +// cellHeaderCategory.setHorizontalAlignment(Element.ALIGN_CENTER); +// table.addCell(cellHeaderCategory); +// PdfPCell cellHeaderAmount = new PdfPCell(new Phrase(Localization.getString(Strings.TITLE_AMOUNT), font)); +// cellHeaderAmount.setBackgroundColor(GrayColor.LIGHT_GRAY); +// cellHeaderAmount.setHorizontalAlignment(Element.ALIGN_CENTER); +// table.addCell(cellHeaderAmount); +// +// for(CategoryBudget budget : categoryBudgets) +// { +// PdfPCell cellName = new PdfPCell(new Phrase(budget.getCategory().getName(), font)); +// cellName.setBackgroundColor(new BaseColor(Color.WHITE)); +// cellName.setHorizontalAlignment(Element.ALIGN_CENTER); +// cellName.setVerticalAlignment(Element.ALIGN_MIDDLE); +// table.addCell(cellName); +// +// PdfPCell cellAmount = new PdfPCell(new Phrase(Helpers.getCurrencyString(budget.getBudget() / 100.0, currency), font)); +// cellAmount.setBackgroundColor(new BaseColor(Color.WHITE)); +// cellAmount.setHorizontalAlignment(Element.ALIGN_CENTER); +// cellAmount.setVerticalAlignment(Element.ALIGN_MIDDLE); +// table.addCell(cellAmount); +// } +// +// return table; +// } +// +// private String getProperty(ReportItem reportItem, ColumnType columnType) +// { +// switch(columnType) +// { +// case AMOUNT: +// return Helpers.getCurrencyString(reportItem.getAmount(), currency); +// case CATEGORY: +// return reportItem.getCategory().getName(); +// case DATE: +// return DateTime.parse(reportItem.getDate(), DateTimeFormat.forPattern("YYYY-MM-dd")).toString("dd.MM.YYYY"); +// case DESCRIPTION: +// return reportItem.getDescription(); +// case TAGS: +// return reportItem.getTags(); +// case NAME: +// return reportItem.getName(); +// case POSITION: +// return String.valueOf(reportItem.getPosition()); +// case RATING: +// return reportItem.getAmount() > 0 ? "+" : "-"; +// case REPEATING: +// if(reportItem.getRepeating()) +// { +// return Localization.getString(Strings.REPORT_REPEATING_YES); +// } +// else +// { +// return Localization.getString(Strings.REPORT_REPEATING_NO); +// } +// default: +// return null; +// } +// } +} \ No newline at end of file diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/ReportItem.java b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportItem.java new file mode 100644 index 0000000000000000000000000000000000000000..08ced7b10e18953f1ad662c298f2a3693ccae8d4 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportItem.java @@ -0,0 +1,107 @@ +package de.deadlocker8.budgetmaster.reports; + + +import de.deadlocker8.budgetmaster.entities.Category; + +public class ReportItem +{ + private int position; + private int amount; + private String date; + private Category category; + private String name; + private String description; + private String tags; + private boolean repeating; + + public ReportItem() + { + + } + + public int getPosition() + { + return position; + } + + public void setPosition(int position) + { + this.position = position; + } + + public int getAmount() + { + return amount; + } + + public void setAmount(int amount) + { + this.amount = amount; + } + + public String getDate() + { + return date; + } + + public void setDate(String date) + { + this.date = date; + } + + public Category getCategory() + { + return category; + } + + public void setCategory(Category category) + { + this.category = category; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getTags() + { + return tags; + } + + public void setTags(String tags) + { + this.tags = tags; + } + + public boolean getRepeating() + { + return repeating; + } + + public void setRepeating(boolean repeating) + { + this.repeating = repeating; + } + + @Override + public String toString() + { + return "ReportItem [position=" + position + ", amount=" + amount + ", date=" + date + ", category=" + category + ", name=" + name + ", description=" + description + ", tags=" + tags + ", repeating=" + repeating + "]"; + } +} \ No newline at end of file diff --git a/src/main/java/de/deadlocker8/budgetmaster/reports/ReportSettings.java b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportSettings.java new file mode 100644 index 0000000000000000000000000000000000000000..d6cab259e9fa697a67cbf3a86f3878fcb3296320 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/reports/ReportSettings.java @@ -0,0 +1,112 @@ +package de.deadlocker8.budgetmaster.reports; + +import org.joda.time.DateTime; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.HashMap; +import java.util.Map; + +public class ReportSettings +{ + @DateTimeFormat(pattern = "dd.MM.yyyy") + private DateTime date; + private boolean includeBudget; + private boolean splitTables; + private boolean includeCategoryBudgets; + + private Map<String, ReportColumn> columns; + + + public ReportSettings(DateTime date, boolean includeBudget, boolean splitTables, boolean includeCategoryBudgets) + { + this.date = date; + this.includeBudget = includeBudget; + this.splitTables = splitTables; + this.includeCategoryBudgets = includeCategoryBudgets; + + initColumns(); + } + + public ReportSettings() + { + initColumns(); + } + + private void initColumns() + { + this.columns = new HashMap<>(); + + this.columns.put("report.position", new ReportColumn()); + this.columns.put("report.date", new ReportColumn()); + this.columns.put("report.repeating", new ReportColumn()); + this.columns.put("report.name", new ReportColumn()); + this.columns.put("report.category", new ReportColumn()); + this.columns.put("report.description", new ReportColumn()); + this.columns.put("report.tags", new ReportColumn()); + this.columns.put("report.account", new ReportColumn()); + this.columns.put("report.rating", new ReportColumn()); + this.columns.put("report.amount", new ReportColumn()); + } + + public DateTime getDate() + { + return date; + } + + public void setDate(DateTime date) + { + this.date = date; + } + + public boolean isIncludeBudget() + { + return includeBudget; + } + + public void setIncludeBudget(boolean includeBudget) + { + this.includeBudget = includeBudget; + } + + public boolean isSplitTables() + { + return splitTables; + } + + public void setSplitTables(boolean splitTables) + { + this.splitTables = splitTables; + } + + public boolean isIncludeCategoryBudgets() + { + return includeCategoryBudgets; + } + + public void setIncludeCategoryBudgets(boolean includeCategoryBudgets) + { + this.includeCategoryBudgets = includeCategoryBudgets; + } + + public Map<String, ReportColumn> getColumns() + { + return this.columns; + } + + public void setColumns(Map<String, ReportColumn> columns) + { + this.columns = columns; + } + + @Override + public String toString() + { + return "ReportSettings{" + + "date=" + date + + ", includeBudget=" + includeBudget + + ", splitTables=" + splitTables + + ", includeCategoryBudgets=" + includeCategoryBudgets + + ", columns=" + columns + + '}'; + } +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/utils/Strings.java b/src/main/java/de/deadlocker8/budgetmaster/utils/Strings.java index 21a2cc56884e5af0878072e2ce52c6033328b0d6..23bb8956706fc87b5c92669bb51f396d2f86e066 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/utils/Strings.java +++ b/src/main/java/de/deadlocker8/budgetmaster/utils/Strings.java @@ -44,4 +44,29 @@ public class Strings public static final String WARNING_SETTINGS_PASSWORD_LENGTH = "warning.settings.password.length"; public static final String WARNING_SETTINGS_PASSWORD_CONFIRMATION_EMPTY = "warning.settings.password.confirmation.empty"; public static final String WARNING_SETTINGS_PASSWORD_CONFIRMATION_WRONG = "warning.settings.password.confirmation.wrong"; + + //REPORT + public static final String REPORT_FOOTER_LEFT = "report.footer.left"; + public static final String REPORT_FOOTER_CENTER = "report.footer.center"; + public static final String REPORT_POSITION = "report.position"; + public static final String REPORT_DATE = "report.date"; + public static final String REPORT_REPEATING = "report.repeating"; + public static final String REPORT_CATEGORY = "report.category"; + public static final String REPORT_NAME = "report.name"; + public static final String REPORT_DESCRIPTION = "report.description"; + public static final String REPORT_TAGS = "report.tags"; + public static final String REPORT_ACCOUNT = "report.account"; + public static final String REPORT_RATING = "report.rating"; + public static final String REPORT_AMOUNT = "report.amount"; + public static final String REPORT_HEADLINE = "report.headline"; + public static final String REPORT_HEADLINE_PAYMENTS_OVERVIEW = "report.headline.payments.overview"; + public static final String REPORT_SUM_TOTAL = "report.sum.total"; + public static final String REPORT_SUM = "report.sum"; + public static final String REPORT_REPEATING_YES ="report.repeating.yes"; + public static final String REPORT_REPEATING_NO ="report.repeating.no"; + public static final String REPORT_INITIAL_FILENAME ="report.initial.filename"; + public static final String REPORT_BUDGET = "report.budget"; + public static final String REPORT_INCOMES = "report.incomes"; + public static final String REPORT_PAYMENTS = "report.payments"; + public static final String REPORT_BUDGET_REST = "report.budget.rest"; } \ No newline at end of file diff --git a/src/main/resources/fonts/OpenSans-Regular.ttf b/src/main/resources/fonts/OpenSans-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2e31d02424ed50b9e05c19b5d82500699a6edbb0 Binary files /dev/null and b/src/main/resources/fonts/OpenSans-Regular.ttf differ diff --git a/src/main/resources/static/js/reports.js b/src/main/resources/static/js/reports.js index 8f2aa901196cc8c51a2b9d532a0565da6f98123a..e2d91c7f69bf95814e65cd768ecd2ae7ebb99230 100644 --- a/src/main/resources/static/js/reports.js +++ b/src/main/resources/static/js/reports.js @@ -12,7 +12,6 @@ $(document).ready(function () { $('.columnName-checkbox').each(function (i, obj) { updateRow(obj); }); - }); function updateRow(item) @@ -25,4 +24,14 @@ function updateRow(item) { $(item).parent().parent().addClass('columnName-disabled'); } +} + +function validateForm() +{ + $('.columnName-checkbox').each(function (i, obj) { + var positionInput = document.getElementsByName("columns['" + obj.dataset.key + "'].position")[0]; + positionInput.value = i; + }); + + return true; } \ No newline at end of file diff --git a/src/main/resources/templates/reports/reports.ftl b/src/main/resources/templates/reports/reports.ftl index 4a24ae25728b920d4855fc2f719c246cf45d50f7..36a200d2e86b56422051e4267c7a651ba4de7a93 100644 --- a/src/main/resources/templates/reports/reports.ftl +++ b/src/main/resources/templates/reports/reports.ftl @@ -17,121 +17,77 @@ <br> <div class="container"> - <#-- settings --> - <div class="row"> - <div class="col s12 center-align"> - <div class="headline-small">${locale.getString("report.settings")}</div> - </div> - </div> - <div class="row"> - <div class="col s12 m8 offset-m2"> - <div class="report-checkbox-container"> - <label> - <input type="checkbox" id="report-checkbox-include-budget"/> - <span class="columnName-label">${locale.getString('report.checkbox.include.budget')}</span> - </label> - </div> - <div class="report-checkbox-container"> - <label> - <input type="checkbox" id="report-checkbox-split-tables"> - <span class="columnName-label">${locale.getString('report.checkbox.split.tables')}</span> - </label> - </div> - <div class="report-checkbox-container"> - <label> - <input type="checkbox" id="report-checkbox-include-categorybudgets"/> - <span class="columnName-label">${locale.getString('report.checkbox.inclue.categorybudgets')}</span> - </label> - </div> - </div> - </div> - <br> + <form name="NewReportSettings" action="<@s.url '/reports/generate'/>" method="post" onsubmit="return validateForm()"> + <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> + <input type="hidden" name="date" value="${helpers.getLongDateString(currentDate)}"/> - <#-- columns --> - <div class="row no-margin"> - <div class="col s12 center-align"> - <div class="headline-small">${locale.getString("report.columns")}</div> - <table class="no-border-table table-advice"> - <tr> - <td><i class="material-icons">info_outline</i></td> - <td>${locale.getString("report.columns.advice")}</td> - </tr> - </table> + <#-- settings --> + <div class="row"> + <div class="col s12 center-align"> + <div class="headline-small">${locale.getString("report.settings")}</div> + </div> </div> - </div> - <div class="row"> - <div class="col s12 m8 offset-m2"> - <div id="columnNames"> - <div class="columnName"> - <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label">${locale.getString('report.position')}</span> - </label> - </div> - <div class="columnName"> + <div class="row"> + <div class="col s12 m8 offset-m2"> + <div class="report-checkbox-container"> <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label">${locale.getString('report.date')}</span> + <input type="checkbox" name="includeBudget" <#if reportSettings.includeBudget>checked="checked"</#if>> + <span class="columnName-label">${locale.getString('report.checkbox.include.budget')}</span> </label> </div> - <div class="columnName"> + <div class="report-checkbox-container"> <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label">${locale.getString('report.repeating')}</span> + <input type="checkbox" name="splitTables" <#if reportSettings.splitTables>checked="checked"</#if>> + <span class="columnName-label">${locale.getString('report.checkbox.split.tables')}</span> </label> </div> - <div class="columnName"> + <div class="report-checkbox-container"> <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label">${locale.getString('report.category')}</span> + <input type="checkbox" name="includeCategorybudgets" <#if reportSettings.includeCategoryBudgets>checked="checked"</#if>/> + <span class="columnName-label">${locale.getString('report.checkbox.inclue.categorybudgets')}</span> </label> </div> - <div class="columnName"> - <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label">${locale.getString('report.name')}</span> - </label> - </div> - <div class="columnName"> - <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label">${locale.getString('report.description')}</span> - </label> - </div> - <div class="columnName"> - <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label text-color">${locale.getString('report.tags')}</span> - </label> - </div> - <div class="columnName"> - <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label text-color">${locale.getString('report.account')}</span> - </label> - </div> - <div class="columnName"> - <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label text-color">${locale.getString('report.rating')}</span> - </label> - </div> - <div class="columnName"> - <label> - <input type="checkbox" class="columnName-checkbox"/> - <span class="columnName-label text-color">${locale.getString('report.amount')}</span> - </label> + </div> + </div> + <br> + + <#-- columns --> + <div class="row no-margin"> + <div class="col s12 center-align"> + <div class="headline-small">${locale.getString("report.columns")}</div> + <table class="no-border-table table-advice"> + <tr> + <td><i class="material-icons">info_outline</i></td> + <td>${locale.getString("report.columns.advice")}</td> + </tr> + </table> + </div> + </div> + <div class="row"> + <div class="col s12 m8 offset-m2"> + <div id="columnNames"> + <#list reportSettings.columns as key, value> + <div class="columnName"> + <label> + <input type="checkbox" class="columnName-checkbox" data-key="${key}" name="columns['${key}'].activated"/> + <span class="columnName-label">${locale.getString(key)}</span> + </label> + <input type="hidden" name="columns['${key}'].position" value=""/> + </div> + </#list> </div> </div> </div> - </div> - <#-- button new --> - <div class="row valign-wrapper"> - <div class="col s12 center-align"><a href="<@s.url '/reports/generate'/>" - class="waves-effect waves-light btn budgetmaster-blue"><i - class="material-icons left">save</i>${locale.getString("report.button.generate")}</a></div> - </div> + <#-- button new --> + <div class="row valign-wrapper"> + <div class="col s12 center-align"> + <button class="btn waves-effect waves-light budgetmaster-blue" type="submit" name="buttonSave"> + <i class="material-icons left">save</i>${locale.getString("report.button.generate")} + </button> + </div> + </div> + </form> </div> </div> </main>