final List<EntryDTO> result = new ArrayList<EntryDTO>();
final Map<Installment, Money> amountsByInstallment =
getPaymentPlan(event).calculateInstallmentRemainingAmounts(event, when, getDiscountPercentage(event));
for (final Installment installment : getPaymentPlan(event).getInstallmentsSortedByEndDate()) {
final Money installmentAmount = amountsByInstallment.get(installment);
if (installmentAmount == null || !installmentAmount.isPositive()) {
continue;
}
result.add(new EntryWithInstallmentDTO(EntryType.GRATUITY_FEE, event, installmentAmount, event
.getDescriptionForEntryType(getEntryType()), installment));
}
if (needsTotalAmountEntry(getPaymentPlan(event), result, event, when)) {
final Money amountToPay = event.calculateAmountToPay(when);
result.add(new EntryDTO(EntryType.GRATUITY_FEE, event, amountToPay, event.getPayedAmount(), amountToPay, event
.getDescriptionForEntryType(getEntryType()), amountToPay));
}
return result;