if (isCancelled()) {
throw new DomainException("error.accounting.Event.cannot.calculatePayedAmount.on.invalid.events");
}
final DateTime now = new DateTime();
Money result = Money.ZERO;
for (final Installment installment : getGratuityPaymentPlan().getInstallmentsSet()) {
if (!getGratuityPaymentPlan().isInstallmentInDebt(installment, this, now, BigDecimal.ZERO)) {
result = result.add(installment.getAmount());
}
}
if (result.isPositive()) {
result = result.subtract(getTotalDiscount());
}
return result.isPositive() ? result.add(getPayedAmountLessInstallments()) : getPayedAmountLessInstallments();
}