if (hasAlreadyPayedAnyAmount(event, when)) {
final Money totalFinalAmount = event.getPayedAmount().add(amountToAdd);
if (!(totalFinalAmount.greaterOrEqualThan(calculateTotalAmountToPay(event, when)) || totalFinalAmount
.equals(getPartialPaymentAmount(event, when)))) {
throw new DomainExceptionWithLabelFormatter(
"error.accounting.postingRules.gratuity.SpecializationDegreeGratuityPR.amount.being.payed.must.be.equal.to.amout.in.debt",
event.getDescriptionForEntryType(getEntryType()));
}
} else {
if (!isPayingTotalAmount(event, when, amountToAdd) && !isPayingPartialAmount(event, when, amountToAdd)) {
final LabelFormatter percentageLabelFormatter = new LabelFormatter();
percentageLabelFormatter.appendLabel(getSpecializationDegreePartialAcceptedPercentage().multiply(
BigDecimal.valueOf(100)).toString());
throw new DomainExceptionWithLabelFormatter(
"error.accounting.postingRules.gratuity.SpecializationDegreeGratuityPR.invalid.partial.payment.value",
event.getDescriptionForEntryType(getEntryType()), percentageLabelFormatter);
}
}
}