janez89 commented on code in PR #4099:
URL: https://github.com/apache/fineract/pull/4099#discussion_r1801460953


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/RepaymentPeriod.java:
##########
@@ -0,0 +1,176 @@
+/**
+ * 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.
+ */
+package org.apache.fineract.portfolio.loanaccount.loanschedule.data;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.fineract.infrastructure.core.service.MathUtil;
+import org.apache.fineract.organisation.monetary.domain.Money;
+
+@ToString
+@EqualsAndHashCode(exclude = { "previous", "next" })
+public class RepaymentPeriod {
+
+    @ToString.Exclude
+    private final RepaymentPeriod previous;
+    @Getter
+    private final LocalDate fromDate;
+    @Getter
+    private final LocalDate dueDate;
+    @Getter
+    private final List<InterestPeriod> interestPeriods;
+    @Setter
+    @ToString.Exclude
+    private RepaymentPeriod next;
+    @Setter
+    @Getter
+    private Money emi;
+    @Getter
+    private Money paidPrincipal;
+    @Getter
+    private Money paidInterest;
+
+    public RepaymentPeriod(RepaymentPeriod previous, LocalDate fromDate, 
LocalDate dueDate, Money emi) {
+        this.previous = previous;
+        if (previous != null) {
+            previous.setNext(this);
+        }
+        this.fromDate = fromDate;
+        this.dueDate = dueDate;
+        this.emi = emi;
+        this.interestPeriods = new ArrayList<>();
+        // There is always at least 1 interest period, by default with same 
from-due date as repayment period
+        getInterestPeriods().add(new InterestPeriod(this, getFromDate(), 
getDueDate(), BigDecimal.ZERO, getZero(), getZero(), getZero()));
+        this.paidInterest = getZero();
+        this.paidPrincipal = getZero();
+    }
+
+    public RepaymentPeriod(RepaymentPeriod previous, RepaymentPeriod 
repaymentPeriod) {
+        this.previous = previous;
+        if (previous != null) {
+            previous.setNext(this);
+        }
+        this.fromDate = repaymentPeriod.fromDate;
+        this.dueDate = repaymentPeriod.dueDate;
+        this.emi = repaymentPeriod.emi;
+        this.interestPeriods = new ArrayList<>();
+        this.paidPrincipal = repaymentPeriod.paidPrincipal;
+        this.paidInterest = repaymentPeriod.paidInterest;
+        // There is always at least 1 interest period, by default with same 
from-due date as repayment period
+        for (InterestPeriod interestPeriod : repaymentPeriod.interestPeriods) {
+            interestPeriods.add(new InterestPeriod(this, interestPeriod));
+        }
+    }
+
+    public void addInterestPeriod(InterestPeriod interestPeriod) {
+        interestPeriods.add(interestPeriod);
+        Collections.sort(interestPeriods);

Review Comment:
   No, sort is not needed anymore. It was part of old logic, I remove it.



-- 
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