Skip to content
Permalink
Browse files
retrofitted loan repqyment to respect wanted payment size
  • Loading branch information
mgeiss committed Aug 23, 2017
1 parent 4cb25fe commit 9e3347588fda9718febc8c8a18a8d0e324b4a616
Showing 2 changed files with 16 additions and 12 deletions.
@@ -49,7 +49,9 @@ public PortfolioTransactionHandler(@Qualifier(ServiceConstants.LOGGER_NAME) fina
public TellerTransactionCosts getTellerTransactionCosts(final TellerTransaction tellerTransaction) {
final List<Charge> charges =
this.portfolioService.getCharges(
tellerTransaction.getProductIdentifier(), tellerTransaction.getProductCaseIdentifier()
tellerTransaction.getProductIdentifier(),
tellerTransaction.getProductCaseIdentifier(),
tellerTransaction.getAmount()
);

final TellerTransactionCosts tellerTransactionCosts = new TellerTransactionCosts();
@@ -70,7 +72,8 @@ public void processRepayment(final String tellerCode, final TellerTransaction te
this.portfolioService.processRepayment(
tellerTransaction.getProductIdentifier(),
tellerTransaction.getProductCaseIdentifier(),
tellerEntity.getTellerAccountIdentifier()
tellerEntity.getTellerAccountIdentifier(),
tellerTransaction.getAmount()
);

} else {
@@ -15,6 +15,7 @@
*/
package io.mifos.teller.service.internal.service.helper;

import com.google.common.collect.Sets;
import io.mifos.core.api.util.NotFoundException;
import io.mifos.core.lang.ServiceException;
import io.mifos.individuallending.api.v1.domain.product.AccountDesignators;
@@ -51,13 +52,16 @@ public PortfolioService(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger lo
this.portfolioManager = portfolioManager;
}

public List<Charge> getCharges(final String productIdentifier, final String caseIdentifier) {
public List<Charge> getCharges(final String productIdentifier, final String caseIdentifier, final Double paymentSize) {

final List<Charge> charges = new ArrayList<>();

try {
//TODO switch CostComponent to PlannedPayment once avail
final List<CostComponent> costComponentsForAction =
this.portfolioManager.getCostComponentsForAction(productIdentifier, caseIdentifier, Action.ACCEPT_PAYMENT.name());
this.portfolioManager.getCostComponentsForAction(
productIdentifier, caseIdentifier, Action.ACCEPT_PAYMENT.name(), Sets.newHashSet(),
BigDecimal.valueOf(paymentSize));

costComponentsForAction.forEach(costComponent -> {
final ChargeDefinition chargeDefinition =
@@ -78,19 +82,16 @@ public List<Charge> getCharges(final String productIdentifier, final String case
return charges;
}

public void processRepayment(final String productIdentifier, final String caseIdentifier, final String tellerAccount) {
public void processRepayment(final String productIdentifier, final String caseIdentifier, final String tellerAccount,
final Double paymentSize) {

try {
final List<CostComponent> costComponentsForAction =
this.portfolioManager.getCostComponentsForAction(productIdentifier, caseIdentifier, Action.ACCEPT_PAYMENT.name());

final Command repaymentCommand = new Command();
repaymentCommand.setOneTimeAccountAssignments(this.getAccountAssignments(tellerAccount));
repaymentCommand.setPaymentSize(BigDecimal.valueOf(
costComponentsForAction.stream().mapToDouble(value -> value.getAmount().doubleValue()).sum())
);
repaymentCommand.setPaymentSize(BigDecimal.valueOf(paymentSize));

portfolioManager.executeCaseCommand(productIdentifier, caseIdentifier, Action.ACCEPT_PAYMENT.name(), repaymentCommand);
portfolioManager.executeCaseCommand(productIdentifier, caseIdentifier, Action.ACCEPT_PAYMENT.name(),
repaymentCommand);
} catch (final NotFoundException | BadRequestException ex) {
throw ServiceException.internalError(
"Could not process repayment, reason: {0}", ex.getCause() + " - " + ex.getMessage()

0 comments on commit 9e33475

Please sign in to comment.