Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ public void createUndoResetAction() {
executeRescheduleAction(request);
}

@When("Admin creates WC delinquency reset action with start new period")
public void createResetActionWithStartNewPeriod() {
final PostWorkingCapitalLoansDelinquencyActionRequest request = new PostWorkingCapitalLoansDelinquencyActionRequest();
request.setAction("reset");
request.setLocale("en");
request.setStartNewPeriod(true);

executeRescheduleAction(request);
}

@When("Admin creates WC delinquency reschedule action with the following parameters:")
public void createRescheduleAction(final DataTable table) {
final Map<String, String> params = table.asMaps().get(0);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ private PostWorkingCapitalLoansDelinquencyActionRequest() {}
public String dateFormat;
@Schema(example = "en")
public String locale;
@Schema(example = "false")
public Boolean startNewPeriod;
}

@Schema(description = "PostWorkingCapitalLoansDelinquencyActionResponse")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ public class WorkingCapitalLoanDelinquencyAction extends AbstractAuditableWithUT
@Column(name = "frequency_type")
private DelinquencyFrequencyType frequencyType;

@Column(name = "start_new_period")
private Boolean startNewPeriod = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import org.apache.fineract.portfolio.workingcapitalloan.data.WorkingCapitalLoanDelinquencyRangeScheduleData;
import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoan;
import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanDelinquencyAction;
import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanDelinquencyRangeSchedule;

public interface WorkingCapitalLoanDelinquencyRangeScheduleService {

void generateInitialPeriod(WorkingCapitalLoan loan);

void generateNextPeriodIfNeeded(WorkingCapitalLoan loan, LocalDate businessDate);
List<WorkingCapitalLoanDelinquencyRangeSchedule> generateNextPeriodIfNeeded(WorkingCapitalLoan loan, LocalDate businessDate);

boolean hasSchedule(Long loanId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ public boolean hasSchedule(Long loanId) {
}

@Override
public void generateNextPeriodIfNeeded(WorkingCapitalLoan loan, LocalDate businessDate) {
public List<WorkingCapitalLoanDelinquencyRangeSchedule> generateNextPeriodIfNeeded(WorkingCapitalLoan loan, LocalDate businessDate) {
List<WorkingCapitalLoanDelinquencyRangeSchedule> result = new ArrayList<>();
final DelinquencyMinimumPaymentPeriodAndRule rule = getMinimumPaymentRule(loan);
if (rule == null) {
return;
return result;
}

final Optional<WorkingCapitalLoanDelinquencyRangeSchedule> latestPeriodOpt = loanDelinquencyRangeScheduleRepository
.findTopByLoanIdOrderByPeriodNumberDesc(loan.getId());
if (latestPeriodOpt.isEmpty() || latestPeriodOpt.get().getToDate().isAfter(businessDate)) {
return;
return result;
}

final EffectiveDelinquencyRescheduleParams params = resolveEffectiveRescheduleParams(loan.getId(), rule);
Expand All @@ -118,8 +119,10 @@ public void generateNextPeriodIfNeeded(WorkingCapitalLoan loan, LocalDate busine
applyRecordedPauses(nextPeriod, loan);

latestPeriod = loanDelinquencyRangeScheduleRepository.saveAndFlush(nextPeriod);
result.add(latestPeriod);
log.debug("Generated next delinquency range schedule period {} for WC loan {}", nextPeriod.getPeriodNumber(), loan.getId());
}
return result;
}

@Override
Expand Down Expand Up @@ -365,8 +368,16 @@ public void resetPeriods(WorkingCapitalLoan loan, WorkingCapitalLoanDelinquencyA
LocalDate resetDate = action.getStartDate();

final List<WorkingCapitalLoanDelinquencyRangeSchedule> periods = loanDelinquencyRangeScheduleRepository
.findByLoanIdAndResetIsNotAndToDateBeforeOrderByPeriodNumberAsc(loan.getId(), true, action.getStartDate());
periods.forEach(p1 -> resetPeriod(p1, resetDate));
.findByLoanIdOrderByPeriodNumberAsc(loan.getId());
if (action.getStartNewPeriod() != null && action.getStartNewPeriod()
&& !periods.getLast().getFromDate().isEqual(action.getStartDate())) {
periods.getLast().setToDate(action.getStartDate().minusDays(1));
List<WorkingCapitalLoanDelinquencyRangeSchedule> newPeriods = generateNextPeriodIfNeeded(loan, action.getStartDate());
periods.addAll(newPeriods);
}

periods.stream().filter(p -> !Objects.equals(p.getReset(), true) && p.getToDate().isBefore(action.getStartDate()))
.forEach(p1 -> resetPeriod(p1, resetDate));
}

private void resetPeriod(WorkingCapitalLoanDelinquencyRangeSchedule period, LocalDate resetDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class WorkingCapitalLoanDelinquencyActionParseAndValidator extends ParseA
private static final String MINIMUM_PAYMENT_TYPE = "minimumPaymentType";
private static final String FREQUENCY = "frequency";
private static final String FREQUENCY_TYPE = "frequencyType";
private static final String START_NEW_PERIOD = "startNewPeriod";

private final FromJsonHelper jsonHelper;
private final WorkingCapitalLoanDelinquencyRangeScheduleRepository rangeScheduleRepository;
Expand Down Expand Up @@ -271,6 +272,7 @@ private WorkingCapitalLoanDelinquencyAction parseCommand(final JsonCommand comma
action.setStartDate(extractDate(json, START_DATE));
} else if (DelinquencyAction.RESET.equals(action.getAction())) {
action.setStartDate(extractDate(json, START_DATE));
action.setStartNewPeriod(jsonHelper.extractBooleanNamed(START_NEW_PERIOD, json));
} else if (DelinquencyAction.UNDO_RESET.equals(action.getAction())) {
action.setStartDate(extractDate(json, START_DATE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@
<include relativeToChangelogFile="true" file="parts/0054_wc_loan_delinquency_reset.xml"/>
<include relativeToChangelogFile="true" file="parts/0055_wc_loan_charge_accrual_business_step.xml"/>
<include relativeToChangelogFile="true" file="parts/0056_wc_loan_delinquency_disable.xml"/>
<include relativeToChangelogFile="true" file="parts/0057_wc_loan_delinquency_reset_start_new_period.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">

<changeSet author="fineract" id="wcl-0057-1">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="m_wc_loan_delinquency_action" columnName="start_new_period"/>
</not>
</preConditions>
<addColumn tableName="m_wc_loan_delinquency_action">
<column name="start_new_period" type="BOOLEAN"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Loading