Merge pull request #969 from pramodn02/MIFOSX-1353

MIFOSX-1353 : corrected monthly charge calculation
This commit is contained in:
Vishwas Babu A J
2014-06-23 15:12:22 -07:00
@@ -174,14 +174,16 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
this.feeOnMonth = feeOnMonthDay.getMonthOfYear(); this.feeOnMonth = feeOnMonthDay.getMonthOfYear();
this.feeOnDay = feeOnMonthDay.getDayOfMonth(); this.feeOnDay = feeOnMonthDay.getDayOfMonth();
} else if (isMonthlyFee() || isWeeklyFee()) {
this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval;
} else { } else {
this.feeOnDay = null; this.feeOnDay = null;
this.feeOnMonth = null; this.feeOnMonth = null;
this.feeInterval = null; this.feeInterval = null;
} }
if (isMonthlyFee() || isWeeklyFee()) {
this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval;
}
this.dueDate = (dueDate == null) ? null : dueDate.toDate(); this.dueDate = (dueDate == null) ? null : dueDate.toDate();
this.chargeCalculation = chargeDefinition.getChargeCalculation(); this.chargeCalculation = chargeDefinition.getChargeCalculation();
@@ -688,15 +690,14 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
public void updateToNextDueDateFrom(final LocalDate startingDate) { public void updateToNextDueDateFrom(final LocalDate startingDate) {
if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
LocalDate nextDueLocalDate = null; LocalDate nextDueLocalDate = null;
if (isAnnualFee()) { if (isAnnualFee() || isMonthlyFee()) {
nextDueLocalDate = startingDate.withMonthOfYear(this.feeOnMonth).plusYears(1); nextDueLocalDate = startingDate.withMonthOfYear(this.feeOnMonth);
} else if (isMonthlyFee()) { nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
nextDueLocalDate = startingDate.plusMonths(this.feeInterval); while (startingDate.isAfter(nextDueLocalDate)) {
int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth(); nextDueLocalDate = calculateNextDueDate(nextDueLocalDate);
int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth; }
nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth); } else {
} else if (isWeeklyFee()) { nextDueLocalDate = calculateNextDueDate(startingDate);
nextDueLocalDate = startingDate.plusDays(7 * this.feeInterval);
} }
this.dueDate = nextDueLocalDate.toDate(); this.dueDate = nextDueLocalDate.toDate();
@@ -704,20 +705,31 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
} }
private LocalDate calculateNextDueDate(final LocalDate date) {
LocalDate nextDueLocalDate = null;
if (isAnnualFee()) {
nextDueLocalDate = date.withMonthOfYear(this.feeOnMonth).plusYears(1);
nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
} else if (isMonthlyFee()) {
nextDueLocalDate = date.plusMonths(this.feeInterval);
nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
} else if (isWeeklyFee()) {
nextDueLocalDate = date.plusDays(7 * this.feeInterval);
}
return nextDueLocalDate;
}
private LocalDate setDayOfMonth(LocalDate nextDueLocalDate) {
int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth();
int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth;
nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth);
return nextDueLocalDate;
}
public void updateNextDueDateForRecurringFees() { public void updateNextDueDateForRecurringFees() {
if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
LocalDate nextDueLocalDate = new LocalDate(dueDate); LocalDate nextDueLocalDate = new LocalDate(dueDate);
int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth(); nextDueLocalDate = calculateNextDueDate(nextDueLocalDate);
int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth;
nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth);
if (isAnnualFee()) {
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(); this.dueDate = nextDueLocalDate.toDate();
} }
} }
@@ -733,10 +745,7 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
nextDueLocalDate = nextDueLocalDate.minusDays(7 * this.feeInterval); nextDueLocalDate = nextDueLocalDate.minusDays(7 * this.feeInterval);
} }
// set day of month nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth();
int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth;
nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth);
this.dueDate = nextDueLocalDate.toDate(); this.dueDate = nextDueLocalDate.toDate();
} }