adamsaghy commented on code in PR #5937:
URL: https://github.com/apache/fineract/pull/5937#discussion_r3389744529


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/calc/ProjectedAmortizationScheduleModel.java:
##########
@@ -273,6 +274,20 @@ public void applyPayment(final LocalDate paymentDate, 
final BigDecimal amount) {
         rebuildPayments();
     }
 
+    public void undoPayment(final LocalDate paymentDate, final BigDecimal 
amount) {
+        Objects.requireNonNull(paymentDate, "paymentDate");
+        Objects.requireNonNull(amount, "amount");
+        final int firstPeriodDayOffset = hasDisbursementDatePayment() || 
paymentDate.equals(expectedDisbursementDate) ? 0 : 1;
+        final LocalDate allocationDate = calculateAllocationDate(paymentDate, 
firstPeriodDayOffset);
+        Optional<ActualPayment> first = actualPayments.stream()
+                .filter(p -> p.date.equals(allocationDate) && 
p.amount.getAmount().compareTo(amount) == 0).findFirst();
+        if (first.isEmpty()) {
+            throw new IllegalStateException("payment not found: date=" + 
paymentDate + " with amount=" + amount);
+        }
+        actualPayments.remove(first.get());
+        rebuildPayments();

Review Comment:
   No need to rebuild everything... just the things after this operation...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to