diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/NewLoanScheduleData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/NewLoanScheduleData.java new file mode 100644 index 000000000..a0bede38e --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/NewLoanScheduleData.java @@ -0,0 +1,72 @@ +package org.mifosng.platform.api; + +import java.math.BigDecimal; + +/** + * Immutable data object to represent aspects of a loan schedule such as: + * + *
principalDisbursed and totalCostOfLoan.
+ */
+ private final BigDecimal totalExpectedRepayment;
+ private final BigDecimal totalInArrears;
+
+ public NewLoanScheduleData() {
+ this.principalDisbursed = null;
+ this.principalPaid = null;
+ this.principalOutstanding = null;
+
+ this.interestExpected = null;
+ this.interestPaid = null;
+ this.interestWaived = null;
+ this.interestOutstanding = null;
+
+ this.chargesToDate = null;
+ this.chargesPaid = null;
+ this.chargesOutstanding = null;
+
+ this.totalCostOfLoan = null;
+
+ this.totalExpectedRepayment = null;
+ this.totalInArrears = null;
+ }
+}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanSchedulePeriodData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanSchedulePeriodData.java
new file mode 100644
index 000000000..d1695baad
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanSchedulePeriodData.java
@@ -0,0 +1,8 @@
+package org.mifosng.platform.api.data;
+
+/**
+ * Immutable data object that represents a period of a loan schedule.
+ */
+public class LoanSchedulePeriodData {
+
+}
diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanProductRelatedDetailAssembler.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanProductRelatedDetailAssembler.java
new file mode 100644
index 000000000..1b4f968da
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanProductRelatedDetailAssembler.java
@@ -0,0 +1,63 @@
+package org.mifosng.platform.loan.service;
+
+import java.math.BigDecimal;
+
+import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
+import org.mifosng.platform.currency.domain.MonetaryCurrency;
+import org.mifosng.platform.exceptions.LoanProductNotFoundException;
+import org.mifosng.platform.loan.domain.AmortizationMethod;
+import org.mifosng.platform.loan.domain.InterestCalculationPeriodMethod;
+import org.mifosng.platform.loan.domain.InterestMethod;
+import org.mifosng.platform.loan.domain.LoanProduct;
+import org.mifosng.platform.loan.domain.LoanProductRelatedDetail;
+import org.mifosng.platform.loan.domain.LoanProductRepository;
+import org.mifosng.platform.loan.domain.PeriodFrequencyType;
+import org.mifosng.platform.loanschedule.domain.AprCalculator;
+import org.springframework.stereotype.Service;
+
+@Service
+public class LoanProductRelatedDetailAssembler {
+
+ private final LoanProductRepository loanProductRepository;
+ private final AprCalculator aprCalculator;
+
+ public LoanProductRelatedDetailAssembler(
+ final LoanProductRepository loanProductRepository,
+ final AprCalculator aprCalculator) {
+ this.loanProductRepository = loanProductRepository;
+ this.aprCalculator = aprCalculator;
+ }
+
+ public LoanProductRelatedDetail assembleFrom(final CalculateLoanScheduleCommand command) {
+
+ final BigDecimal principalAmount = command.getPrincipal();
+ final BigDecimal defaultNominalInterestRatePerPeriod = command.getInterestRatePerPeriod();
+ final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyType());
+ final InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestType());
+ final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodType());
+
+ final Integer defaultNumberOfInstallments = command.getNumberOfRepayments();
+ final Integer repayEvery = command.getRepaymentEvery();
+ final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequencyType());
+
+ final AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationType());
+
+ final BigDecimal defaultAnnualNominalInterestRate = this.aprCalculator.calculateFrom(interestPeriodFrequencyType, defaultNominalInterestRatePerPeriod);
+
+ final LoanProduct loanProduct = this.loanProductRepository.findOne(command.getProductId());
+ if (loanProduct == null) {
+ throw new LoanProductNotFoundException(command.getProductId());
+ }
+
+ final MonetaryCurrency currency = loanProduct.getCurrency();
+
+ // in arrerars tolerance isnt relevant when auto-calculating a loan schedule
+ final BigDecimal inArrearsTolerance = BigDecimal.ZERO;
+
+ return new LoanProductRelatedDetail(currency, principalAmount,
+ defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate,
+ interestMethod, interestCalculationPeriodMethod,
+ repayEvery, repaymentFrequencyType, defaultNumberOfInstallments, amortizationMethod,
+ inArrearsTolerance);
+ }
+}
\ No newline at end of file