Skip to content

Commit

Permalink
Update annual vacation days from last year to next year
Browse files Browse the repository at this point in the history
fix #3623
  • Loading branch information
honnel committed Jan 24, 2023
1 parent 886a78e commit 1e5eaf3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void updateRemainingVacationDays(int year, Person person) {
final Account changedHolidaysAccount = holidaysAccount.get();
final Account nextYearsHolidaysAccount = nextYearsHolidaysAccountOptional.get();

updateRemainingVacationDays(nextYearsHolidaysAccount, changedHolidaysAccount);
updateVacationDays(nextYearsHolidaysAccount, changedHolidaysAccount);

LOG.info("Updated remaining vacation days of holidays account: {}", nextYearsHolidaysAccount);

Expand Down Expand Up @@ -181,7 +181,7 @@ public Account autoCreateOrUpdateNextYearsHolidaysAccount(Account referenceAccou
final Optional<Account> nextYearAccountOptional = accountService.getHolidaysAccount(nextYear, referenceAccount.getPerson());
if (nextYearAccountOptional.isPresent()) {
final Account nextYearAccount = nextYearAccountOptional.get();
updateRemainingVacationDays(nextYearAccount, referenceAccount);
updateVacationDays(nextYearAccount, referenceAccount);

LOG.info("Updated existing holidays account for {}: {}", nextYear, nextYearAccount);

Expand Down Expand Up @@ -218,12 +218,13 @@ private BigDecimal getRemainingVacationDaysForThisYear(LocalDate today, Integer
}

/**
* Updates the remaining vacation days of the given new account by using data of the given last account.
* Updates the remaining and annual vacation days of the given new account by using data of the given
* last account.
*
* @param newAccount to calculate and update remaining vacation days for
* @param lastAccount as reference to be used for calculation of remaining vacation days
* @param newAccount to calculate and update remaining and annual vacation days for
* @param lastAccount as reference to be used for calculation of remaining and annual vacation days
*/
private void updateRemainingVacationDays(Account newAccount, Account lastAccount) {
private void updateVacationDays(Account newAccount, Account lastAccount) {

final BigDecimal leftVacationDays = vacationDaysService.calculateTotalLeftVacationDays(lastAccount);
newAccount.setRemainingVacationDays(leftVacationDays);
Expand All @@ -233,6 +234,8 @@ private void updateRemainingVacationDays(Account newAccount, Account lastAccount
newAccount.setRemainingVacationDaysNotExpiring(leftVacationDays);
}

newAccount.setAnnualVacationDays(lastAccount.getAnnualVacationDays());

accountService.save(newAccount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,33 @@ void ensureUpdatesRemainingVacationDaysOfHolidaysAccountIfAlreadyExists() {
verify(accountService).getHolidaysAccount(nextYear, person);
}

@Test
void ensureUpdatesAnnualVacationDaysOfHolidaysAccountIfAlreadyExists() {
final Person person = new Person("muster", "Muster", "Marlene", "muster@example.org");

final int year = 2014;
final int nextYear = 2015;

final LocalDate startDate = LocalDate.of(year, JANUARY, 1);
final LocalDate endDate = LocalDate.of(year, OCTOBER, 31);
final LocalDate expiryDateNew = LocalDate.of(year, APRIL, 2);
final BigDecimal leftDays = BigDecimal.valueOf(7);

final Account referenceAccount = new Account(person, startDate, endDate, false, expiryDateNew, BigDecimal.valueOf(30),
ZERO, ZERO, "");

final LocalDate expiryDateOld = LocalDate.of(year, APRIL, 1);
final Account nextYearAccount = new Account(person, LocalDate.of(nextYear, 1, 1), LocalDate.of(
nextYear, 10, 31), true, expiryDateOld, BigDecimal.valueOf(28), ZERO, ZERO, "");

when(accountService.getHolidaysAccount(nextYear, person)).thenReturn(Optional.of(nextYearAccount));
when(vacationDaysService.calculateTotalLeftVacationDays(referenceAccount)).thenReturn(leftDays);

final Account account = sut.autoCreateOrUpdateNextYearsHolidaysAccount(referenceAccount);
assertThat(account.getAnnualVacationDays()).isEqualTo(referenceAccount.getAnnualVacationDays());
}


@Test
void createHolidaysAccount() {
final Person person = new Person("muster", "Muster", "Marlene", "muster@example.org");
Expand Down

0 comments on commit 1e5eaf3

Please sign in to comment.