Skip to content

Commit

Permalink
Merge branch 'v2_13_0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Jan 22, 2023
2 parents 69df705 + c391fca commit b5554c9
Show file tree
Hide file tree
Showing 128 changed files with 3,121 additions and 294 deletions.
22 changes: 17 additions & 5 deletions BudgetMasterServer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BudgetMaster</artifactId>
<groupId>de.deadlocker8</groupId>
<version>2.12.0</version>
<version>2.13.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -27,19 +27,20 @@
<jlibs.version>3.2.0</jlibs.version>
<versionizer.version>3.0.1</versionizer.version>
<webjars-locator.version>0.46</webjars-locator.version>
<jquery.version>3.6.1</jquery.version>
<jquery.version>3.6.3</jquery.version>
<materializecss.version>1.0.0</materializecss.version>
<fontawesome.version>6.2.0</fontawesome.version>
<fontawesome.version>6.2.1</fontawesome.version>
<sortablejs.version>1.15.0</sortablejs.version>
<mousetrap.version>1.6.5</mousetrap.version>
<codemirror.version>5.62.2</codemirror.version>
<selenium.version>4.7.1</selenium.version>
<assertj-core.version>3.23.1</assertj-core.version>
<selenium.version>4.7.2</selenium.version>
<jgit.version>6.4.0.202211300538-r</jgit.version>
<natorder.version>1.1.3</natorder.version>
<itextpdf.version>5.5.13.3</itextpdf.version>
<vanilla-picker.version>2.12.1</vanilla-picker.version>
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<opencsv.version>5.7.1</opencsv.version>
<datatables.version>1.13.1</datatables.version>

<project.outputDirectory>${project.build.directory}/../build/${project.version}</project.outputDirectory>
<project.artifactName>${project.artifactId}-v${project.version}</project.artifactName>
Expand Down Expand Up @@ -137,6 +138,12 @@
<version>${natorder.version}</version>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
</dependency>

<!--Webjars-->
<dependency>
<groupId>org.webjars</groupId>
Expand Down Expand Up @@ -178,6 +185,11 @@
<artifactId>vanilla-picker</artifactId>
<version>${vanilla-picker.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>datatables</artifactId>
<version>${datatables.version}</version>
</dependency>


<!-- selenium -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ public String index(Model model)
public String whatsNewModal(Model model)
{
final List<NewsEntry> newsEntries = new ArrayList<>();
newsEntries.add(NewsEntry.createWithLocalizationKey("clickableChartAreas"));
newsEntries.add(NewsEntry.createWithLocalizationKey("repeatingTransactionsWorkflow"));
newsEntries.add(NewsEntry.createWithLocalizationKey("searchForDateRange"));
newsEntries.add(NewsEntry.createWithLocalizationKey("removeDatabaseMigrator"));
newsEntries.add(NewsEntry.createWithLocalizationKey("fix.templateAmountInput"));
newsEntries.add(NewsEntry.createWithLocalizationKey("fix.searchHighlighting"));
newsEntries.add(NewsEntry.createWithLocalizationKey("fix.tomcatUpdateSearch"));
newsEntries.add(NewsEntry.createWithLocalizationKey("csvImport"));
newsEntries.add(NewsEntry.createWithLocalizationKey("recurringTransactionsOverview"));
newsEntries.add(NewsEntry.createWithLocalizationKey("improvedRestCalculation"));

model.addAttribute(ModelAttributes.NEWS_ENTRIES, newsEntries);
return ReturnValues.WHATS_NEW;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.google.gson.annotations.Expose;
import de.deadlocker8.budgetmaster.repeating.endoption.RepeatingEnd;
import de.deadlocker8.budgetmaster.repeating.endoption.RepeatingEndAfterXTimes;
import de.deadlocker8.budgetmaster.repeating.endoption.RepeatingEndDate;
import de.deadlocker8.budgetmaster.repeating.endoption.RepeatingEndNever;
import de.deadlocker8.budgetmaster.repeating.modifier.RepeatingModifier;
import de.deadlocker8.budgetmaster.transactions.Transaction;
import org.springframework.format.annotation.DateTimeFormat;
Expand Down Expand Up @@ -132,6 +135,35 @@ public List<LocalDate> getRepeatingDates(LocalDate dateFetchLimit)
return dates;
}

/***
* Returns whether this repeating option has ended before the given date.
*/
public boolean hasEndedBefore(LocalDate date)
{
if(endOption instanceof RepeatingEndNever)
{
return false;
}

if(endOption instanceof RepeatingEndDate)
{
final LocalDate endDate = (LocalDate) endOption.getValue();
return endDate.isBefore(date);
}

if(endOption instanceof RepeatingEndAfterXTimes)
{
// Use a date fetch limit far into future to really calculate all dates. The date calculation will finish
// as soon as the number of repetitions is reached and therefore never calculate dates until the year 3000.
final List<LocalDate> repeatingDates = getRepeatingDates(LocalDate.of(3000, 1, 1));
final LocalDate lastDate = repeatingDates.get(repeatingDates.size() - 1);

return lastDate.isBefore(date);
}

throw new UnsupportedOperationException("Unknown repeating end option type");
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Service
Expand Down Expand Up @@ -53,4 +54,24 @@ private boolean containsDate(List<Transaction> transactions, LocalDate date)

return false;
}

/**
* Returns all repeating transactions that have not ended before the given date.
*/
public List<Transaction> getActiveRepeatingTransactionsAfter(LocalDate date)
{
final List<RepeatingOption> repeatingOptions = repeatingOptionRepository.findAllByOrderByStartDateAsc();
final List<RepeatingOption> activeRepeatingOptions = repeatingOptions.stream()
.filter(repeatingOption -> !repeatingOption.hasEndedBefore(date))
.toList();

final List<Transaction> activeTransactions = new ArrayList<>();
for(RepeatingOption repeatingOption : activeRepeatingOptions)
{
final List<Transaction> transactions = transactionService.getRepository().findAllByRepeatingOption(repeatingOption);
activeTransactions.add(transactions.get(0));
}

return activeTransactions;
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
package de.deadlocker8.budgetmaster.reports;

public class Budget
public record Budget(int incomeSum, int expenditureSum)
{
private int incomeSum;
private int expenditureSum;

public Budget(int incomeSum, int expenditureSum)
{
this.incomeSum = incomeSum;
this.expenditureSum = expenditureSum;
}

public int getIncomeSum()
{
return incomeSum;
}

public int getExpenditureSum()
{
return expenditureSum;
}

public int getRest()
{
return incomeSum + expenditureSum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import de.deadlocker8.budgetmaster.reports.settings.ReportSettingsService;
import de.deadlocker8.budgetmaster.services.DateService;
import de.deadlocker8.budgetmaster.services.HelpersService;
import de.deadlocker8.budgetmaster.settings.SettingsService;
import de.deadlocker8.budgetmaster.transactions.Transaction;
import de.deadlocker8.budgetmaster.transactions.TransactionService;
import de.deadlocker8.budgetmaster.utils.Mappings;
Expand Down Expand Up @@ -48,7 +47,6 @@ private static class ReturnValues
public static final String ALL_ENTITIES = "reports/reports";
}

private final SettingsService settingsService;
private final ReportSettingsService reportSettingsService;
private final ReportGeneratorService reportGeneratorService;
private final TransactionService transactionService;
Expand All @@ -58,9 +56,8 @@ private static class ReturnValues
private final FilterHelpersService filterHelpers;

@Autowired
public ReportController(SettingsService settingsService, ReportSettingsService reportSettingsService, ReportGeneratorService reportGeneratorService, TransactionService transactionService, CategoryService categoryService, HelpersService helpers, DateService dateService, FilterHelpersService filterHelpers)
public ReportController(ReportSettingsService reportSettingsService, ReportGeneratorService reportGeneratorService, TransactionService transactionService, CategoryService categoryService, HelpersService helpers, DateService dateService, FilterHelpersService filterHelpers)
{
this.settingsService = settingsService;
this.reportSettingsService = reportSettingsService;
this.reportGeneratorService = reportGeneratorService;
this.transactionService = transactionService;
Expand Down Expand Up @@ -98,7 +95,7 @@ public void post(HttpServletRequest request, HttpServletResponse response,
}

FilterConfiguration filterConfiguration = filterHelpers.getFilterConfiguration(request);
List<Transaction> transactions = transactionService.getTransactionsForMonthAndYear(account, reportSettings.getDate().getMonthValue(), reportSettings.getDate().getYear(), settingsService.getSettings().isRestActivated(), filterConfiguration);
List<Transaction> transactions = transactionService.getTransactionsForMonthAndYear(account, reportSettings.getDate().getMonthValue(), reportSettings.getDate().getYear(), filterConfiguration);
Budget budget = helpers.getBudget(transactions, account);

ReportConfiguration reportConfiguration = new ReportConfigurationBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ private void createTotal(ReportConfiguration reportConfiguration, AmountType amo
{
PdfPCell cellTotal;
String total = "";
String totalIncomeString = currencyService.getCurrencyString(reportConfiguration.getBudget().getIncomeSum());
String totalExpenditureString = currencyService.getCurrencyString(reportConfiguration.getBudget().getExpenditureSum());
String totalIncomeString = currencyService.getCurrencyString(reportConfiguration.getBudget().incomeSum());
String totalExpenditureString = currencyService.getCurrencyString(reportConfiguration.getBudget().expenditureSum());
switch(amountType)
{
case BOTH:
Expand Down Expand Up @@ -189,11 +189,11 @@ public byte[] generate(ReportConfiguration reportConfiguration) throws DocumentE
Budget budget = reportConfiguration.getBudget();

Paragraph paragraph = new Paragraph();
paragraph.add(new Chunk(Localization.getString(Strings.REPORT_INCOMES) + currencyService.getCurrencyString(budget.getIncomeSum()), fontGreen));
paragraph.add(new Chunk(Localization.getString(Strings.REPORT_INCOMES) + currencyService.getCurrencyString(budget.incomeSum()), fontGreen));
paragraph.add(new Chunk(" "));
paragraph.add(new Chunk(Localization.getString(Strings.REPORT_PAYMENTS) + currencyService.getCurrencyString(budget.getExpenditureSum()), fontRed));
paragraph.add(new Chunk(Localization.getString(Strings.REPORT_PAYMENTS) + currencyService.getCurrencyString(budget.expenditureSum()), fontRed));
paragraph.add(new Chunk(" "));
paragraph.add(new Chunk(Localization.getString(Strings.REPORT_BUDGET_REST) + currencyService.getCurrencyString(budget.getIncomeSum() + budget.getExpenditureSum()), fontBlack));
paragraph.add(new Chunk(Localization.getString(Strings.REPORT_BUDGET_REST) + currencyService.getCurrencyString(budget.incomeSum() + budget.expenditureSum()), fontBlack));
paragraph.setAlignment(Element.ALIGN_JUSTIFIED);

final Paragraph paragraphBudgetHeadline = new Paragraph(Localization.getString(Strings.REPORT_BUDGET), headerFont);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public enum EntityType implements LocalizedEnum
ABOUT("info", "background-grey", ImportRequired.NONE, null, null),
TEMPLATE_GROUP("folder", "background-orange-dark", ImportRequired.OPTIONAL, "template groups", "template group"),
ICON("icon", "background-grey", ImportRequired.NONE, "icons", "icon"),
TRANSACTION_NAME_KEYWORD("transaction_name_keyword", "background-grey", ImportRequired.NONE, "keywords", "keyword");
TRANSACTION_NAME_KEYWORD("transaction_name_keyword", "background-grey", ImportRequired.NONE, "keywords", "keyword"),
RECURRING_TRANSACTIONS("repeat", "background-orange-dark", ImportRequired.NONE, "recurring", "recurring"),
TRANSACTION_IMPORT("fas fa-file-csv", "background-orange-dark", ImportRequired.NONE, "transactionImport", "transactionImport");

public enum ImportRequired
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import de.deadlocker8.budgetmaster.services.ImportResultItem;
import de.deadlocker8.budgetmaster.services.ImportService;
import de.deadlocker8.budgetmaster.settings.containers.*;
import de.deadlocker8.budgetmaster.settings.demo.DemoDateCreator;
import de.deadlocker8.budgetmaster.settings.demo.DemoDataCreator;
import de.deadlocker8.budgetmaster.transactions.keywords.TransactionNameKeyword;
import de.deadlocker8.budgetmaster.transactions.keywords.TransactionNameKeywordRepository;
import de.deadlocker8.budgetmaster.transactions.keywords.TransactionNameKeywordService;
Expand Down Expand Up @@ -101,12 +101,12 @@ private static class RequestAttributeNames
private final BackupService backupService;
private final HintService hintService;
private final TransactionNameKeywordService keywordService;
private final DemoDateCreator demoDateCreator;
private final DemoDataCreator demoDataCreator;

private final List<Integer> SEARCH_RESULTS_PER_PAGE_OPTIONS = Arrays.asList(10, 20, 25, 30, 50, 100);

@Autowired
public SettingsController(SettingsService settingsService, DatabaseService databaseService, CategoryService categoryService, ImportService importService, BudgetMasterUpdateService budgetMasterUpdateService, BackupService backupService, HintService hintService, TransactionNameKeywordService keywordService, DemoDateCreator demoDateCreator)
public SettingsController(SettingsService settingsService, DatabaseService databaseService, CategoryService categoryService, ImportService importService, BudgetMasterUpdateService budgetMasterUpdateService, BackupService backupService, HintService hintService, TransactionNameKeywordService keywordService, DemoDataCreator demoDataCreator)
{
this.settingsService = settingsService;
this.databaseService = databaseService;
Expand All @@ -116,7 +116,7 @@ public SettingsController(SettingsService settingsService, DatabaseService datab
this.backupService = backupService;
this.hintService = hintService;
this.keywordService = keywordService;
this.demoDateCreator = demoDateCreator;
this.demoDataCreator = demoDataCreator;
}

@GetMapping
Expand Down Expand Up @@ -479,7 +479,7 @@ public String testGit(@RequestParam(value = "autoBackupGitUrl") String autoBacku
@GetMapping("/database/createDemoData")
public String createDemoData(Model model)
{
demoDateCreator.createDemoData();
demoDataCreator.createDemoData();

prepareBasicModel(model, settingsService.getSettings());
return ReturnValues.ALL_ENTITIES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import static java.time.temporal.TemporalAdjusters.lastDayOfMonth;

@Component
public class DemoDateCreator
public class DemoDataCreator
{
private static final Logger LOGGER = LoggerFactory.getLogger(DemoDateCreator.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataCreator.class);

private final CategoryService categoryService;
private final IconService iconService;
Expand All @@ -40,7 +40,7 @@ public class DemoDateCreator
private Category categorySalary;

@Autowired
public DemoDateCreator(CategoryService categoryService, IconService iconService, AccountService accountService, TransactionService transactionService)
public DemoDataCreator(CategoryService categoryService, IconService iconService, AccountService accountService, TransactionService transactionService)
{
this.categoryService = categoryService;
this.iconService = iconService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import de.deadlocker8.budgetmaster.services.DateService;
import de.deadlocker8.budgetmaster.templategroup.TemplateGroupService;
import de.deadlocker8.budgetmaster.transactions.Transaction;
import de.deadlocker8.budgetmaster.transactions.TransactionImportController;
import de.deadlocker8.budgetmaster.transactions.TransactionService;
import de.deadlocker8.budgetmaster.transactions.csvimport.CsvTransaction;
import de.deadlocker8.budgetmaster.utils.Mappings;
import de.deadlocker8.budgetmaster.utils.ResourceNotFoundException;
import de.deadlocker8.budgetmaster.utils.WebRequestUtils;
Expand All @@ -22,6 +24,7 @@
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.server.ResponseStatusException;

Expand Down Expand Up @@ -134,7 +137,8 @@ public String deleteTemplate(WebRequest request, @PathVariable("ID") Integer ID)
}

@GetMapping("/{ID}/select")
public String selectTemplate(Model model,
public String selectTemplate(WebRequest request,
Model model,
@CookieValue("currentDate") String cookieDate,
@PathVariable("ID") Integer ID)
{
Expand Down Expand Up @@ -162,6 +166,8 @@ public String selectTemplate(Model model,
newTransaction.setIsExpenditure(true);
}

overrideFieldsFromCsvTransaction(request, newTransaction);

final LocalDate date = dateService.getDateTimeFromCookie(cookieDate);
transactionService.prepareModelNewOrEdit(model, false, date, false, newTransaction, accountService.getAllActivatedAccountsAsc());

Expand All @@ -172,6 +178,20 @@ public String selectTemplate(Model model,
return ReturnValues.NEW_TRANSACTION_NORMAL;
}

private void overrideFieldsFromCsvTransaction(WebRequest request, Transaction transaction)
{
final Object currentCsvTransaction = request.getAttribute(TransactionImportController.RequestAttributeNames.CURRENT_CSV_TRANSACTION, RequestAttributes.SCOPE_SESSION);
if(currentCsvTransaction != null)
{
final CsvTransaction csvTransaction = (CsvTransaction) currentCsvTransaction;

transaction.setDate(csvTransaction.getDate());
transaction.setAmount(csvTransaction.getAmount());
transaction.setIsExpenditure(csvTransaction.getAmount() <= 0);
transaction.setCategory(csvTransaction.getCategory());
}
}

@GetMapping("/newTemplate")
public String newTemplate(Model model)
{
Expand Down
Loading

0 comments on commit b5554c9

Please sign in to comment.