diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 33a650574..68310464b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -837,7 +837,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy"); - while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate())) { + while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate()) && savingsAccountCharge.isNotFullyPaid()) { payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java index d1ba2018e..6266d47bc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java @@ -5,6 +5,8 @@ */ package org.mifosplatform.scheduledjobs.service; +import org.mifosplatform.infrastructure.jobs.exception.JobExecutionException; + public interface ScheduledJobRunnerService { void updateLoanSummaryDetails(); @@ -15,5 +17,5 @@ public interface ScheduledJobRunnerService { void applyAnnualFeeForSavings(); - void applyDueChargesForSavings(); + void applyDueChargesForSavings() throws JobExecutionException; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java index 4b155ad1f..b695088ae 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java @@ -13,6 +13,7 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation import org.mifosplatform.infrastructure.core.service.RoutingDataSourceServiceFactory; import org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil; import org.mifosplatform.infrastructure.jobs.annotation.CronTarget; +import org.mifosplatform.infrastructure.jobs.exception.JobExecutionException; import org.mifosplatform.infrastructure.jobs.service.JobName; import org.mifosplatform.portfolio.savings.data.SavingsAccountAnnualFeeData; import org.mifosplatform.portfolio.savings.service.SavingsAccountChargeReadPlatformService; @@ -225,23 +226,32 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService @Override @CronTarget(jobName = JobName.PAY_DUE_SAVINGS_CHARGES) - public void applyDueChargesForSavings() { + public void applyDueChargesForSavings() throws JobExecutionException { final Collection chargesDueData = this.savingsAccountChargeReadPlatformService .retrieveChargesWithDue(); - + final StringBuilder errorMsg = new StringBuilder(); + for (final SavingsAccountAnnualFeeData savingsAccountReference : chargesDueData) { try { - this.savingsAccountWritePlatformService.applyChargeDue(savingsAccountReference.getId(), savingsAccountReference.getAccountId()); + this.savingsAccountWritePlatformService.applyChargeDue(savingsAccountReference.getId(), + savingsAccountReference.getAccountId()); } catch (final PlatformApiDataValidationException e) { final List errors = e.getErrors(); for (final ApiParameterError error : errors) { - logger.error("Apply Charges due for savings failed for account:" + savingsAccountReference.getAccountNo() + " with message " - + error.getDeveloperMessage()); + logger.error("Apply Charges due for savings failed for account:" + savingsAccountReference.getAccountNo() + + " with message " + error.getDeveloperMessage()); + errorMsg.append("Apply Charges due for savings failed for account:").append(savingsAccountReference.getAccountNo()) + .append(" with message ").append(error.getDeveloperMessage()); } } } - + logger.info(ThreadLocalContextUtil.getTenant().getName() + ": Savings accounts affected by update: " + chargesDueData.size()); + + /* + * throw exception if any charge payment fails. + */ + if (errorMsg.length() > 0) { throw new JobExecutionException(errorMsg.toString()); } } - + } \ No newline at end of file