@Override public String value(WrappedBooking input) { return String.valueOf(input.getAmount()); } },
private static BigDecimal ermittleMittelwert(List<WrappedBooking> umsaetze) { BigDecimal summe = BigDecimal.ZERO; for (WrappedBooking umsatz : umsaetze) { summe = summe.add(umsatz.getAmount()); } return summe.divide(new BigDecimal(umsaetze.size()), RoundingMode.CEILING) .setScale(0, RoundingMode.CEILING).setScale(2, RoundingMode.UNNECESSARY); }
private static BigDecimal calcAmountTwoBookings(List<WrappedBooking> sortierteUmsaetze, int umsatzAnzahl) { // Wenn mehr als ein Umsatz in der Liste List<WrappedBooking> letzteZweiUmsaetze = sortierteUmsaetze.subList(umsatzAnzahl - 2, umsatzAnzahl); // Prüfe, ob die zwei letzten Transaktionen einer sonstigen Fixkostenzahlung den gleichen Betrag hatten // (last_transaction.amount = second_last_transaction.amount) final boolean letzteZweiBetraegeGleich = // Hinweis: Hier könnte eine NPE auftreten, falls der Betrag beim (0) null ist. letzteZweiUmsaetze.get(0).getAmount().compareTo(letzteZweiUmsaetze.get(1).getAmount()) == 0; if (letzteZweiBetraegeGleich) { // Dann setze diesen Betrag als zu erwartenden Betrag für die nächste Transaktion return letzteZweiUmsaetze.get(0).getAmount(); } // sollten nur zwei Transaktionen vorliegen, // dann soll daraus der auf volle Euro aufgerundete Mittelwert berechnet werden return ermittleMittelwert(letzteZweiUmsaetze); }
public static BigDecimal calcAmount(List<WrappedBooking> bookings) { if (bookings == null || bookings.isEmpty()) { return null; } List<WrappedBooking> sortedBookings = bookings.stream() .sorted(Comparator.comparing(WrappedBooking::getExecutionDate).reversed()) .collect(Collectors.toList()); final int countBookings = sortedBookings.size(); if (countBookings <= 1) { // Default, nimm den letzten Betrag. Deckt den Fall mit nur einem jährlichen Umsatz ab. return sortedBookings.get(countBookings - 1).getAmount(); } if (countBookings == 2) { return calcAmountTwoBookings(sortedBookings, countBookings); } List<BigDecimal> lastThreeAmounts = sortedBookings.stream() .map(booking -> booking.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP)) .limit(3) .collect(Collectors.toList()); BigDecimal twoSame = checkTwoSameAmount(lastThreeAmounts); if (twoSame != null) { return twoSame; } return new BigDecimal(sortedBookings.stream() .mapToDouble(value -> value.getAmount().doubleValue()) .average().getAsDouble()); }
private boolean evalNonRecurrentGroup(BookingGroup bookingGroup, List<WrappedBooking> bookings, List<BookingPeriod> bookingPeriods) { if (bookings.isEmpty()) { return false; } int indexCurrentPeriod = bookingPeriods.indexOf(filterPeriod(bookingPeriods, LocalDate.now())); BookingPeriod lastPeriod = indexCurrentPeriod > 0 ? bookingPeriods.get(indexCurrentPeriod - 1) : null; BookingPeriod secondLastPeriod = indexCurrentPeriod > 1 ? bookingPeriods.get(indexCurrentPeriod - 2) : null; BigDecimal amountLastPeriod = bookings.stream() .filter(booking -> dateInPeriod(booking.getExecutionDate(), lastPeriod)) .map(value -> value.getAmount()) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal amountSecondLastPeriod = bookings.stream() .filter(booking -> dateInPeriod(booking.getExecutionDate(), secondLastPeriod)) .map(value -> value.getAmount()) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal amount; if (amountLastPeriod.compareTo(BigDecimal.ZERO) != 0 && amountSecondLastPeriod.compareTo(BigDecimal.ZERO) != 0) { amount = amountLastPeriod.add(amountSecondLastPeriod).divide(new BigDecimal(2)); } else if (amountLastPeriod.compareTo(BigDecimal.ZERO) != 0) { amount = amountLastPeriod; } else { amount = BigDecimal.ZERO; } if (amount.compareTo(BigDecimal.ZERO) == 0) { return false; } bookingGroup.setAmount(amount); return true; }
private BookingGroup handleOtherIncomeBookings(List<WrappedBooking> otherBookings, List<BookingPeriod> bookingPeriods) { BookingGroup otherIncomeGroup = new BookingGroup(null, null, Group.Type.OTHER_INCOME.toString(), Group.Type.OTHER_INCOME); List<WrappedBooking> otherIncomeBookings = otherBookings .stream() .filter(wrappedBooking -> wrappedBooking.getAmount().compareTo(BigDecimal.ZERO) >= 0) .collect(Collectors.toList()); if (!otherIncomeBookings.isEmpty()) { evalNonRecurrentGroup(otherIncomeGroup, otherIncomeBookings, bookingPeriods); List<BookingPeriod> groupPeriods = createGroupPeriods(bookingPeriods, otherIncomeBookings); if (groupPeriods.size() > 0) { otherIncomeGroup.setBookingPeriods(groupPeriods); } return otherIncomeGroup; } return null; }
/** * Assert if the given booking is a recurrent non sepa booking. * <p> * If a blacklist is defined each entry will be matched with the given input. * If all non null attribute values of the blacklist entry matches the booking will be refused. * * @param booking the booking to be asserted * @param blacklist booking templates to be false * @return true if the booking is a recurrent non sepa booking otherwise false. */ public static boolean isRecurrent(WrappedBooking booking, List<Matcher> blacklist) { // should only have negative amount if (booking.getAmount() == null || booking.getAmount().compareTo(BigDecimal.ZERO) >= 0) { return false; } // should have a purpose if (booking.getPurpose() == null) { return false; } // should not have a valid creditorId if (booking.getCreditorId() != null) { return false; } for (Matcher backlistEntry : blacklist) { if (backlistEntry.match(booking)) { return false; } } return true; }
private BookingGroup handleOtherExpenseBookings(List<WrappedBooking> otherBookings, List<BookingPeriod> bookingPeriods) { BookingGroup otherExpensesGroup = new BookingGroup(null, null, Group.Type.OTHER_EXPENSES.toString(), Group.Type.OTHER_EXPENSES); List<WrappedBooking> otherExpensesBookings = otherBookings .stream() .filter(wrappedBooking -> wrappedBooking.getAmount().compareTo(BigDecimal.ZERO) < 0) .collect(Collectors.toList()); if (!otherExpensesBookings.isEmpty()) { evalNonRecurrentGroup(otherExpensesGroup, otherExpensesBookings, bookingPeriods); List<BookingPeriod> groupPeriods = createGroupPeriods(bookingPeriods, otherExpensesBookings); if (groupPeriods.size() > 0) { otherExpensesGroup.setBookingPeriods(groupPeriods); } return otherExpensesGroup; } return null; }
/** * Assert if the given booking is a recurrent income booking. * * @param booking the booking to be asserted * @return true if the booking is a recurrent income booking otherwise false. */ public static boolean isRecurrent(WrappedBooking booking) { // should only have positive amount if (booking.getAmount() == null || booking.getAmount().compareTo(BigDecimal.ZERO) < 0) { return false; } // should have a purpose if (booking.getPurpose() == null) { return false; } // should not have a valid bank connection return booking.getIban() != null || (booking.getBankCode() != null && booking.getAccountNumber() != null) || booking.getReferenceName() != null; }
@Override public BookingGroup createGroup(WrappedBooking booking) { if (booking == null) { return null; } if (booking.getRuleIds() != null) { return new BookingGroup(booking.getBankConnection(), booking.getRuleIds().toString(), getGroupName(), getGroupType()); } else if (booking.getAmount() != null) { return new BookingGroup(booking.getBankConnection(), booking.getAmount().toPlainString(), getGroupName(), getGroupType()); } return null; }
@Override public BookingGroup createGroup(WrappedBooking booking) { BookingGroup bookingGroup; if (booking.getCreditorId() != null && booking.getMandateReference() != null) { log.trace("interpreted as standing order booking with kref & mref"); bookingGroup = new BookingGroup(booking.getCreditorId(), booking.getMandateReference(), getGroupName(), getGroupType()); } else if (booking.getIban() != null) { log.trace("interpreted as standing order booking with iban"); bookingGroup = new BookingGroup(booking.getIban(), booking.getAmount().toPlainString(), getGroupName(), getGroupType()); } else { log.trace("interpreted as non sepa booking with amount"); bookingGroup = new BookingGroup(booking.getReferenceName(), booking.getAmount().toPlainString(), getGroupName(), getGroupType()); } return bookingGroup; }