MIFOSX-2184 - Add ability to disable backdating of penalties

This commit is contained in:
Sander van der Heijden
2015-11-26 16:12:09 +01:00
parent 3cdf64fa16
commit 883ca09346
7 changed files with 44 additions and 9 deletions
@@ -49,4 +49,5 @@ public interface ConfigurationDomainService {
int getRoundingMode(); int getRoundingMode();
boolean isBackdatePenaltiesEnabled();
} }
@@ -187,10 +187,18 @@ public class ConfigurationDomainServiceJpa implements ConfigurationDomainService
final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName);
if (property.isEnabled()) { if (property.isEnabled()) {
int value = property.getValue().intValue(); int value = property.getValue().intValue();
if (value < 0 || value > 6) { return defaultValue; } if (value < 0 || value > 6) {
return defaultValue;
}
return value; return value;
} }
return defaultValue; return defaultValue;
} }
public boolean isBackdatePenaltiesEnabled() {
final String propertyName = "backdate-penalties-enabled";
final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName);
return property.isEnabled();
}
} }
@@ -76,7 +76,7 @@ public interface LoanReadPlatformService {
* result overdue installments with this charge already applied are not * result overdue installments with this charge already applied are not
* returned. * returned.
*/ */
Collection<OverdueLoanScheduleData> retrieveAllLoansWithOverdueInstallments(final Long penaltyWaitPeriod); Collection<OverdueLoanScheduleData> retrieveAllLoansWithOverdueInstallments(final Long penaltyWaitPeriod, final Boolean backdatePenalties);
Integer retriveLoanCounter(Long groupId, Integer loanType, Long productId); Integer retriveLoanCounter(Long groupId, Integer loanType, Long productId);
@@ -17,8 +17,11 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.Days; import org.joda.time.Days;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
@@ -1465,12 +1468,31 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public Collection<OverdueLoanScheduleData> retrieveAllLoansWithOverdueInstallments(final Long penaltyWaitPeriod) { public Collection<OverdueLoanScheduleData> retrieveAllLoansWithOverdueInstallments(final Long penaltyWaitPeriod, final Boolean backdatePenalties) {
final MusoniOverdueLoanScheduleMapper rm = new MusoniOverdueLoanScheduleMapper(); final MusoniOverdueLoanScheduleMapper rm = new MusoniOverdueLoanScheduleMapper();
final String sql = "select " + rm.schema() + " where DATE_SUB(CURDATE(),INTERVAL ? DAY) > ls.duedate "
+ " and ls.completed_derived <> 1 and mc.charge_applies_to_enum =1 " final StringBuilder sqlBuilder = new StringBuilder(400);
+ " and mc.charge_time_enum = 9 and ml.loan_status_id = 300 "; sqlBuilder
return this.jdbcTemplate.query(sql, rm, new Object[] { penaltyWaitPeriod }); .append("select ")
.append(rm.schema())
.append(" where DATE_SUB(CURDATE(),INTERVAL ? DAY) > ls.duedate ")
.append( " and ls.completed_derived <> 1 and mc.charge_applies_to_enum =1 ")
.append(" and mc.charge_time_enum = 9 and ml.loan_status_id = 300 ");
if(backdatePenalties)
{
return this.jdbcTemplate.query(sqlBuilder.toString(), rm, new Object[] { penaltyWaitPeriod });
}
else
{
// Only apply for duedate = yesterday (so that we don't apply penalties on the duedate itself)
sqlBuilder.append(" and ls.duedate >= DATE_SUB(CURDATE(),INTERVAL (? + 1) DAY)");
return this.jdbcTemplate.query(sqlBuilder.toString(), rm, new Object[] { penaltyWaitPeriod, penaltyWaitPeriod });
}
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -49,8 +49,9 @@ public class LoanSchedularServiceImpl implements LoanSchedularService {
public void applyChargeForOverdueLoans() throws JobExecutionException { public void applyChargeForOverdueLoans() throws JobExecutionException {
final Long penaltyWaitPeriodValue = this.configurationDomainService.retrievePenaltyWaitPeriod(); final Long penaltyWaitPeriodValue = this.configurationDomainService.retrievePenaltyWaitPeriod();
final Boolean backdatePenalties = this.configurationDomainService.isBackdatePenaltiesEnabled();
final Collection<OverdueLoanScheduleData> overdueLoanScheduledInstallments = this.loanReadPlatformService final Collection<OverdueLoanScheduleData> overdueLoanScheduledInstallments = this.loanReadPlatformService
.retrieveAllLoansWithOverdueInstallments(penaltyWaitPeriodValue); .retrieveAllLoansWithOverdueInstallments(penaltyWaitPeriodValue,backdatePenalties);
if (!overdueLoanScheduledInstallments.isEmpty()) { if (!overdueLoanScheduledInstallments.isEmpty()) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
@@ -2441,7 +2441,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
} }
} }
@Override
@Transactional @Transactional
public void applyOverdueChargesForLoan(final Long loanId, Collection<OverdueLoanScheduleData> overdueLoanScheduleDatas) { public void applyOverdueChargesForLoan(final Long loanId, Collection<OverdueLoanScheduleData> overdueLoanScheduleDatas) {
@@ -0,0 +1,4 @@
INSERT INTO `c_configuration` ( `name`, `value`, `enabled`, `description`)
VALUES
( 'backdate-penalties-enabled', 0, 1, 'If this parameter is disabled penalties will only be added to instalments due moving forward, any old overdue instalments will not be affected.');