From dc7f18803861e9b9a85c82e89b79826f980a952c Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Sat, 12 Aug 2017 19:53:31 +0200 Subject: [PATCH] Fixed #145 - report: show month budget --- .../logic/report/ReportGenerator.java | 37 +++++++++++++++---- .../ui/controller/ReportController.java | 10 ++++- .../budgetmaster/ui/fxml/ReportTab.fxml | 1 + 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/de/deadlocker8/budgetmaster/logic/report/ReportGenerator.java b/src/de/deadlocker8/budgetmaster/logic/report/ReportGenerator.java index 0bdce3d28..27cd67b46 100644 --- a/src/de/deadlocker8/budgetmaster/logic/report/ReportGenerator.java +++ b/src/de/deadlocker8/budgetmaster/logic/report/ReportGenerator.java @@ -24,6 +24,7 @@ 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.CategoryBudget; import de.deadlocker8.budgetmaster.logic.utils.Helpers; @@ -32,33 +33,35 @@ public class ReportGenerator private ArrayList<ReportItem> reportItems; private ArrayList<CategoryBudget> categoryBudgets; private ColumnOrder columnOrder; + private boolean includeBudget; private boolean splitTable; private boolean includeCategoryBudgets; private File savePath; private String currency; private DateTime date; + private Budget budget; - public ReportGenerator(ArrayList<ReportItem> reportItems, ArrayList<CategoryBudget> categoryBudgets, ColumnOrder columnOrder, boolean splitTable, boolean includeCategoryBudgets, File savePath, String currency, DateTime date) + public ReportGenerator(ArrayList<ReportItem> reportItems, ArrayList<CategoryBudget> categoryBudgets, ColumnOrder columnOrder, boolean includeBudget, boolean splitTable, boolean includeCategoryBudgets, File savePath, String currency, DateTime date, Budget budget) { this.reportItems = reportItems; this.categoryBudgets = categoryBudgets; this.columnOrder = columnOrder; + this.includeBudget = includeBudget; this.splitTable = splitTable; this.includeCategoryBudgets = includeCategoryBudgets; this.savePath = savePath; this.currency = currency; this.date = date; + this.budget = budget; } private Chapter generateHeader() { - Font chapterFont = new Font(FontFamily.HELVETICA, 16, Font.BOLDITALIC); - Font paragraphFont = new Font(FontFamily.HELVETICA, 12, Font.NORMAL); + Font chapterFont = new Font(FontFamily.HELVETICA, 16, Font.BOLDITALIC); Chunk chunk = new Chunk("Monatsbericht - " + date.toString("MMMM yyyy"), chapterFont); Chapter chapter = new Chapter(new Paragraph(chunk), 1); chapter.setNumberDepth(0); - chapter.add(Chunk.NEWLINE); - chapter.add(new Paragraph("Buchungsübersicht", paragraphFont)); + chapter.add(Chunk.NEWLINE); return chapter; } @@ -153,14 +156,32 @@ public class ReportGenerator writer.setPageEvent(new HeaderFooterPageEvent()); document.open(); document.setMargins(50, 45, 50, 70); + Font headerFont = new Font(FontFamily.HELVETICA, 14, Font.BOLD); + Font smallHeaderFont = new Font(FontFamily.HELVETICA, 12, Font.BOLD); Font paragraphFont = new Font(FontFamily.HELVETICA, 12, Font.NORMAL); document.add(generateHeader()); document.add(Chunk.NEWLINE); + + if(includeBudget) + { + Font fontGreen = new Font(FontFamily.HELVETICA, 12, Font.NORMAL, new BaseColor(36, 122, 45)); + Font fontRed = new Font(FontFamily.HELVETICA, 12, Font.NORMAL, BaseColor.RED); + Font fontBlack = new Font(FontFamily.HELVETICA, 12, Font.BOLD); + document.add(new Paragraph("Budget", headerFont)); + document.add(Chunk.NEWLINE); + document.add(new Paragraph("Einnahmen: " + Helpers.getCurrencyString(budget.getIncomeSum(), currency), fontGreen)); + document.add(new Paragraph("Ausgaben: " + Helpers.getCurrencyString(budget.getPaymentSum(), currency), fontRed)); + document.add(new Paragraph("Restbudget: " + Helpers.getCurrencyString(budget.getIncomeSum()-budget.getPaymentSum(), currency), fontBlack)); + document.add(Chunk.NEWLINE); + } + + document.add(new Paragraph("Buchungsübersicht", headerFont)); + document.add(Chunk.NEWLINE); if(splitTable) { - document.add(new Paragraph("Einnahmen", paragraphFont)); + document.add(new Paragraph("Einnahmen", smallHeaderFont)); document.add(Chunk.NEWLINE); PdfPTable table = generateTable(100, AmountType.INCOME); if(table != null) @@ -169,7 +190,7 @@ public class ReportGenerator } document.add(Chunk.NEWLINE); - document.add(new Paragraph("Ausgaben", paragraphFont)); + document.add(new Paragraph("Ausgaben", smallHeaderFont)); document.add(Chunk.NEWLINE); table = generateTable(100, AmountType.PAYMENT); if(table != null) @@ -189,7 +210,7 @@ public class ReportGenerator if(includeCategoryBudgets) { document.add(Chunk.NEWLINE); - document.add(new Paragraph("Verbrauch nach Kategorien", paragraphFont)); + document.add(new Paragraph("Verbrauch nach Kategorien", headerFont)); document.add(Chunk.NEWLINE); PdfPTable table = generateCategoryBudgets(); if(table != null) diff --git a/src/de/deadlocker8/budgetmaster/ui/controller/ReportController.java b/src/de/deadlocker8/budgetmaster/ui/controller/ReportController.java index 030e59c11..9d4852397 100644 --- a/src/de/deadlocker8/budgetmaster/ui/controller/ReportController.java +++ b/src/de/deadlocker8/budgetmaster/ui/controller/ReportController.java @@ -11,6 +11,7 @@ import java.util.Optional; import org.joda.time.DateTime; +import de.deadlocker8.budgetmaster.logic.Budget; import de.deadlocker8.budgetmaster.logic.FilterSettings; import de.deadlocker8.budgetmaster.logic.Payment; import de.deadlocker8.budgetmaster.logic.RepeatingPaymentEntry; @@ -62,6 +63,7 @@ public class ReportController implements Refreshable @FXML private AnchorPane anchorPaneMain; @FXML private Label labelPayments; @FXML private Label labelFilterActive; + @FXML private CheckBox checkBoxIncludeBudget; @FXML private CheckBox checkBoxSplitTable; @FXML private CheckBox checkBoxIncludeCategoryBudgets; @FXML private Button buttonFilter; @@ -87,6 +89,7 @@ public class ReportController implements Refreshable labelFilterActive.setStyle("-fx-text-fill: " + controller.getBundle().getString("color.text")); buttonFilter.setStyle("-fx-background-color: #2E79B9; -fx-text-fill: white; -fx-font-weight: bold; -fx-font-size: 16;"); buttonGenerate.setStyle("-fx-background-color: #2E79B9; -fx-text-fill: white; -fx-font-weight: bold; -fx-font-size: 16;"); + checkBoxIncludeBudget.setStyle("-fx-text-fill: " + controller.getBundle().getString("color.text") + "; -fx-font-size: 14;"); checkBoxSplitTable.setStyle("-fx-text-fill: " + controller.getBundle().getString("color.text") + "; -fx-font-size: 14;"); checkBoxIncludeCategoryBudgets.setStyle("-fx-text-fill: " + controller.getBundle().getString("color.text") + "; -fx-font-size: 14;"); @@ -536,14 +539,19 @@ public class ReportController implements Refreshable if(file != null) { reportPath = file; + + Budget budget = new Budget(controller.getPaymentHandler().getPayments()); + ReportGenerator reportGenerator = new ReportGenerator(new ArrayList<ReportItem>(tableView.getItems()), controller.getCategoryBudgets(), columnOrder, + checkBoxIncludeBudget.isSelected(), checkBoxSplitTable.isSelected(), checkBoxIncludeCategoryBudgets.isSelected(), file, controller.getSettings().getCurrency(), - controller.getCurrentDate()); + controller.getCurrentDate(), + budget); Stage modalStage = Helpers.showModal("Vorgang läuft", "Der Monatsbericht wird erstellt, bitte warten...", controller.getStage(), controller.getIcon()); diff --git a/src/de/deadlocker8/budgetmaster/ui/fxml/ReportTab.fxml b/src/de/deadlocker8/budgetmaster/ui/fxml/ReportTab.fxml index ab291d656..35239f67f 100644 --- a/src/de/deadlocker8/budgetmaster/ui/fxml/ReportTab.fxml +++ b/src/de/deadlocker8/budgetmaster/ui/fxml/ReportTab.fxml @@ -39,6 +39,7 @@ <children> <VBox spacing="10.0"> <children> + <CheckBox fx:id="checkBoxIncludeBudget" mnemonicParsing="false" text="Budgetkalkulation hinzufügen" /> <CheckBox fx:id="checkBoxSplitTable" mnemonicParsing="false" text="Einnahmen und Ausgaben als getrennte Tabellen" /> <CheckBox fx:id="checkBoxIncludeCategoryBudgets" mnemonicParsing="false" text="Verbrauch nach Kategorien hinzufügen" /> </children> -- GitLab