merge Nayan's work around weekly charges

This commit is contained in:
Vishwas Babu A J
2014-06-22 15:04:47 -07:00
8 changed files with 72 additions and 30 deletions
@@ -467,6 +467,10 @@ public class Charge extends AbstractPersistable<Long> {
public Integer getChargePaymentMode() {
return this.chargePaymentMode;
}
public Integer getFeeInterval(){
return this.feeInterval;
}
public boolean isMonthlyFee() {
return ChargeTimeType.fromInt(this.chargeTime).isMonthlyFee();
@@ -20,7 +20,8 @@ public enum ChargeTimeType {
INSTALMENT_FEE(8, "chargeTimeType.instalmentFee"), // only for loan charges
OVERDUE_INSTALLMENT(9, "chargeTimeType.overdueInstallment"), // only for
// loan charges
OVERDRAFT_FEE(10, "chargeTimeType.overdraftFee");// only for savings
OVERDRAFT_FEE(10, "chargeTimeType.overdraftFee"),// only for savings
WEEKLY_FEE(11, "chargeTimeType.weeklyFee"); // only for savings
private final Integer value;
private final String code;
@@ -51,7 +52,7 @@ public enum ChargeTimeType {
public static Object[] validSavingsValues() {
return new Integer[] { ChargeTimeType.SPECIFIED_DUE_DATE.getValue(), ChargeTimeType.SAVINGS_ACTIVATION.getValue(),
ChargeTimeType.SAVINGS_CLOSURE.getValue(), ChargeTimeType.WITHDRAWAL_FEE.getValue(), ChargeTimeType.ANNUAL_FEE.getValue(),
ChargeTimeType.MONTHLY_FEE.getValue(), ChargeTimeType.OVERDRAFT_FEE.getValue() };
ChargeTimeType.MONTHLY_FEE.getValue(), ChargeTimeType.OVERDRAFT_FEE.getValue(), ChargeTimeType.WEEKLY_FEE.getValue() };
}
public static ChargeTimeType fromInt(final Integer chargeTime) {
@@ -88,6 +89,9 @@ public enum ChargeTimeType {
case 10:
chargeTimeType = OVERDRAFT_FEE;
break;
case 11:
chargeTimeType = WEEKLY_FEE;
break;
default:
chargeTimeType = INVALID;
break;
@@ -123,7 +127,11 @@ public enum ChargeTimeType {
public boolean isMonthlyFee() {
return this.value.equals(ChargeTimeType.MONTHLY_FEE.getValue());
}
public boolean isWeeklyFee() {
return this.value.equals(ChargeTimeType.WEEKLY_FEE.getValue());
}
public boolean isInstalmentFee() {
return this.value.equals(ChargeTimeType.INSTALMENT_FEE.getValue());
}
@@ -138,7 +146,7 @@ public enum ChargeTimeType {
public boolean isAllowedSavingsChargeTime() {
return isOnSpecifiedDueDate() || isSavingsActivation() || isSavingsClosure() || isWithdrawalFee() || isAnnualFee()
|| isMonthlyFee() || isOverdraftFee();
|| isMonthlyFee() || isWeeklyFee() || isOverdraftFee();
}
public boolean isOverdraftFee() {
@@ -113,6 +113,12 @@ public final class ChargeDefinitionCommandFromApiJsonDeserializer {
}
final ChargeTimeType ctt = ChargeTimeType.fromInt(chargeTimeType);
if (ctt.isWeeklyFee()) {
final String monthDay = this.fromApiJsonHelper.extractStringNamed("feeOnMonthDay", element);
baseDataValidator.reset().parameter("feeOnMonthDay").value(monthDay).mustBeBlankWhenParameterProvidedIs("chargeTimeType", chargeTimeType);
}
if (ctt.isMonthlyFee()) {
final MonthDay monthDay = this.fromApiJsonHelper.extractMonthDayNamed("feeOnMonthDay", element);
baseDataValidator.reset().parameter("feeOnMonthDay").value(monthDay).notNull();
@@ -84,6 +84,7 @@ public class ChargeDropdownReadPlatformServiceImpl implements ChargeDropdownRead
return Arrays.asList(chargeTimeType(ChargeTimeType.SPECIFIED_DUE_DATE), chargeTimeType(ChargeTimeType.SAVINGS_ACTIVATION),
// chargeTimeType(ChargeTimeType.SAVINGS_CLOSURE),
chargeTimeType(ChargeTimeType.WITHDRAWAL_FEE), chargeTimeType(ChargeTimeType.ANNUAL_FEE),
chargeTimeType(ChargeTimeType.MONTHLY_FEE), chargeTimeType(ChargeTimeType.OVERDRAFT_FEE));
chargeTimeType(ChargeTimeType.MONTHLY_FEE), chargeTimeType(ChargeTimeType.WEEKLY_FEE),
chargeTimeType(ChargeTimeType.OVERDRAFT_FEE));
}
}
@@ -48,6 +48,10 @@ public class ChargeEnumerations {
optionData = new EnumOptionData(ChargeTimeType.MONTHLY_FEE.getValue().longValue(), ChargeTimeType.MONTHLY_FEE.getCode(),
"Monthly Fee");
break;
case WEEKLY_FEE:
optionData = new EnumOptionData(ChargeTimeType.WEEKLY_FEE.getValue().longValue(), ChargeTimeType.WEEKLY_FEE.getCode(),
"Weekly Fee");
break;
case INSTALMENT_FEE:
optionData = new EnumOptionData(ChargeTimeType.INSTALMENT_FEE.getValue().longValue(),
ChargeTimeType.INSTALMENT_FEE.getCode(), "Instalment Fee");
@@ -241,7 +241,7 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
MonthDay feeOnMonthDay = null;
final Integer feeOnMonth = JdbcSupport.getInteger(rs, "feeOnMonth");
final Integer feeOnDay = JdbcSupport.getInteger(rs, "feeOnDay");
if (feeOnDay != null) {
if (feeOnDay != null && feeOnMonth != null) {
feeOnMonthDay = new MonthDay(feeOnMonth, feeOnDay);
}
final BigDecimal minCap = rs.getBigDecimal("minCap");
@@ -108,14 +108,20 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
public static SavingsAccountCharge createNewFromJson(final SavingsAccount savingsAccount, final Charge chargeDefinition,
final JsonCommand command) {
final BigDecimal amount = command.bigDecimalValueOfParameterNamed(amountParamName);
BigDecimal amount = command.bigDecimalValueOfParameterNamed(amountParamName);
final LocalDate dueDate = command.localDateValueOfParameterNamed(dueAsOfDateParamName);
final MonthDay feeOnMonthDay = command.extractMonthDayNamed(feeOnMonthDayParamName);
final Integer feeInterval = command.integerValueOfParameterNamed(feeIntervalParamName);
MonthDay feeOnMonthDay = command.extractMonthDayNamed(feeOnMonthDayParamName);
Integer feeInterval = command.integerValueOfParameterNamed(feeIntervalParamName);
final ChargeTimeType chargeTime = null;
final ChargeCalculationType chargeCalculation = null;
final boolean status = true;
// If these values is not sent as parameter, then derive from Charge
// definition
amount = (amount == null) ? chargeDefinition.getAmount() : amount;
feeOnMonthDay = (feeOnMonthDay == null) ? chargeDefinition.getFeeOnMonthDay() : feeOnMonthDay;
feeInterval = (feeInterval == null) ? chargeDefinition.getFeeInterval() : feeInterval;
return new SavingsAccountCharge(savingsAccount, chargeDefinition, amount, chargeTime, chargeCalculation, dueDate, status,
feeOnMonthDay, feeInterval);
}
@@ -149,6 +155,14 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
}
if (isWeeklyFee()) {
if (dueDate == null) {
final String defaultUserMessage = "Savings Account charge is missing due date.";
throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName,
defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName());
}
}
if (isAnnualFee() || isMonthlyFee()) {
feeOnMonthDay = (feeOnMonthDay == null) ? chargeDefinition.getFeeOnMonthDay() : feeOnMonthDay;
if (feeOnMonthDay == null) {
@@ -160,10 +174,8 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
this.feeOnMonth = feeOnMonthDay.getMonthOfYear();
this.feeOnDay = feeOnMonthDay.getDayOfMonth();
if (isMonthlyFee()) {
this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval;
}
} else if (isMonthlyFee() || isWeeklyFee()) {
this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval;
} else {
this.feeOnDay = null;
this.feeOnMonth = null;
@@ -195,7 +207,7 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
}
public void resetPropertiesForRecurringFees() {
if (isMonthlyFee() || isAnnualFee()) {
if (isMonthlyFee() || isAnnualFee() || isWeeklyFee()) {
// FIXME: AA: If charge is percentage of x amount then need to
// update amount outstanding accordingly.
// Right now annual and monthly charges supports charge calculation
@@ -630,6 +642,10 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
return ChargeTimeType.fromInt(this.chargeTime).isMonthlyFee();
}
public boolean isWeeklyFee() {
return ChargeTimeType.fromInt(this.chargeTime).isWeeklyFee();
}
public boolean hasCurrencyCodeOf(final String matchingCurrencyCode) {
if (this.currencyCode() == null || matchingCurrencyCode == null) { return false; }
return this.currencyCode().equalsIgnoreCase(matchingCurrencyCode);
@@ -670,26 +686,26 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
}
public void updateToNextDueDateFrom(final LocalDate startingDate) {
if (isAnnualFee() || isMonthlyFee()) {
LocalDate nextDueLocalDate = startingDate.withMonthOfYear(this.feeOnMonth);
int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth();
int newDayOfMonth = (this.feeOnDay.intValue() <= maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth;
nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth);
while (startingDate.isAfter(nextDueLocalDate)) {
if (isAnnualFee()) {
nextDueLocalDate = nextDueLocalDate.plusYears(1);
} else if (isMonthlyFee()) {
nextDueLocalDate = nextDueLocalDate.plusMonths(this.feeInterval);
}
if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
LocalDate nextDueLocalDate = null;
if (isAnnualFee()) {
nextDueLocalDate = startingDate.withMonthOfYear(this.feeOnMonth).plusYears(1);
} else if (isMonthlyFee()) {
nextDueLocalDate = startingDate.plusMonths(this.feeInterval);
int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth();
int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth;
nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth);
} else if (isWeeklyFee()) {
nextDueLocalDate = startingDate.plusDays(7 * this.feeInterval);
}
this.dueDate = nextDueLocalDate.toDate();
}
}
public void updateNextDueDateForRecurringFees() {
if (isAnnualFee() || isMonthlyFee()) {
if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
LocalDate nextDueLocalDate = new LocalDate(dueDate);
int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth();
int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth;
@@ -699,19 +715,22 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
nextDueLocalDate = nextDueLocalDate.withMonthOfYear(this.feeOnMonth).plusYears(1);
} else if (isMonthlyFee()) {
nextDueLocalDate = nextDueLocalDate.plusMonths(this.feeInterval);
} else if (isWeeklyFee()) {
nextDueLocalDate = nextDueLocalDate.plusDays(7 * this.feeInterval);
}
this.dueDate = nextDueLocalDate.toDate();
}
}
public void updateToPreviousDueDate() {
if (isAnnualFee() || isMonthlyFee()) {
if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
LocalDate nextDueLocalDate = new LocalDate(dueDate);
if (isAnnualFee()) {
nextDueLocalDate = nextDueLocalDate.withMonthOfYear(this.feeOnMonth).minusYears(1);
} else if (isMonthlyFee()) {
nextDueLocalDate = nextDueLocalDate.minusMonths(this.feeInterval);
} else if (isWeeklyFee()) {
nextDueLocalDate = nextDueLocalDate.minusDays(7 * this.feeInterval);
}
// set day of month
@@ -112,7 +112,7 @@ public class SavingsAccountChargeReadPlatformServiceImpl implements SavingsAccou
MonthDay feeOnMonthDay = null;
final Integer feeOnMonth = JdbcSupport.getInteger(rs, "feeOnMonth");
final Integer feeOnDay = JdbcSupport.getInteger(rs, "feeOnDay");
if (feeOnDay != null) {
if (feeOnDay != null && feeOnMonth != null) {
feeOnMonthDay = new MonthDay(feeOnMonth, feeOnDay);
}