public void updateLoanApplicationAttributes()

in fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java [1240:1476]


    public void updateLoanApplicationAttributes(JsonCommand command, Loan loan, Map<String, Object> changes) {
        final String localeAsInput = command.locale();

        final String principalParamName = "principal";
        LoanProductRelatedDetail loanProductRelatedDetail = loan.getLoanRepaymentScheduleDetail();
        if (command.isChangeInBigDecimalParameterNamed(principalParamName, loanProductRelatedDetail.getPrincipal().getAmount())) {
            final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(principalParamName);
            changes.put(principalParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setPrincipal(newValue);
        }

        final String repaymentEveryParamName = "repaymentEvery";
        if (command.isChangeInIntegerParameterNamed(repaymentEveryParamName, loanProductRelatedDetail.getRepayEvery())) {
            final Integer newValue = command.integerValueOfParameterNamed(repaymentEveryParamName);
            changes.put(repaymentEveryParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setRepayEvery(newValue);
        }

        final String repaymentFrequencyTypeParamName = "repaymentFrequencyType";
        if (command.isChangeInIntegerParameterNamed(repaymentFrequencyTypeParamName,
                loanProductRelatedDetail.getRepaymentPeriodFrequencyType().getValue())) {
            Integer newValue = command.integerValueOfParameterNamed(repaymentFrequencyTypeParamName);
            changes.put(repaymentFrequencyTypeParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setRepaymentPeriodFrequencyType(PeriodFrequencyType.fromInt(newValue));
        }
        if (PeriodFrequencyType.MONTHS.equals(loanProductRelatedDetail.getRepaymentPeriodFrequencyType())) {
            final String repaymentFrequencyNthDayTypeParamName = "repaymentFrequencyNthDayType";
            Integer newValue = command.integerValueOfParameterNamed(repaymentFrequencyNthDayTypeParamName);
            changes.put(repaymentFrequencyNthDayTypeParamName, newValue);

            final String repaymentFrequencyDayOfWeekTypeParamName = "repaymentFrequencyDayOfWeekType";
            newValue = command.integerValueOfParameterNamed(repaymentFrequencyDayOfWeekTypeParamName);
            changes.put(repaymentFrequencyDayOfWeekTypeParamName, newValue);
            changes.put("locale", localeAsInput);
        }

        final String numberOfRepaymentsParamName = "numberOfRepayments";
        if (command.isChangeInIntegerParameterNamed(numberOfRepaymentsParamName, loanProductRelatedDetail.getNumberOfRepayments())) {
            final Integer newValue = command.integerValueOfParameterNamed(numberOfRepaymentsParamName);
            changes.put(numberOfRepaymentsParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setNumberOfRepayments(newValue);
        }

        final String amortizationTypeParamName = "amortizationType";
        if (command.isChangeInIntegerParameterNamed(amortizationTypeParamName,
                loanProductRelatedDetail.getAmortizationMethod().getValue())) {
            final Integer newValue = command.integerValueOfParameterNamed(amortizationTypeParamName);
            changes.put(amortizationTypeParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setAmortizationMethod(AmortizationMethod.fromInt(newValue));
        }

        final String inArrearsToleranceParamName = "inArrearsTolerance";
        if (command.isChangeInBigDecimalParameterNamed(inArrearsToleranceParamName,
                loanProductRelatedDetail.getInArrearsTolerance().getAmount())) {
            final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(inArrearsToleranceParamName);
            changes.put(inArrearsToleranceParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setInArrearsTolerance(newValue);
        }

        final String interestRatePerPeriodParamName = "interestRatePerPeriod";
        if (command.isChangeInBigDecimalParameterNamed(interestRatePerPeriodParamName,
                loanProductRelatedDetail.getNominalInterestRatePerPeriod())) {
            final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(interestRatePerPeriodParamName);
            changes.put(interestRatePerPeriodParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setNominalInterestRatePerPeriod(newValue);
            relatedDetailUpdateUtil.updateInterestRateDerivedFields(loanProductRelatedDetail, aprCalculator);
        }

        final String interestRateFrequencyTypeParamName = "interestRateFrequencyType";
        final int interestPeriodFrequencyType = loanProductRelatedDetail.getInterestPeriodFrequencyType() == null
                ? PeriodFrequencyType.INVALID.getValue()
                : loanProductRelatedDetail.getInterestPeriodFrequencyType().getValue();
        if (command.isChangeInIntegerParameterNamed(interestRateFrequencyTypeParamName, interestPeriodFrequencyType)) {
            final Integer newValue = command.integerValueOfParameterNamed(interestRateFrequencyTypeParamName);
            changes.put(interestRateFrequencyTypeParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setInterestPeriodFrequencyType(PeriodFrequencyType.fromInt(newValue));
            relatedDetailUpdateUtil.updateInterestRateDerivedFields(loanProductRelatedDetail, aprCalculator);
        }

        final String interestTypeParamName = "interestType";
        if (command.isChangeInIntegerParameterNamed(interestTypeParamName, loanProductRelatedDetail.getInterestMethod().getValue())) {
            final Integer newValue = command.integerValueOfParameterNamed(interestTypeParamName);
            changes.put(interestTypeParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setInterestMethod(InterestMethod.fromInt(newValue));
        }

        final String interestCalculationPeriodTypeParamName = "interestCalculationPeriodType";
        if (command.isChangeInIntegerParameterNamed(interestCalculationPeriodTypeParamName,
                loanProductRelatedDetail.getInterestCalculationPeriodMethod().getValue())) {
            final Integer newValue = command.integerValueOfParameterNamed(interestCalculationPeriodTypeParamName);
            changes.put(interestCalculationPeriodTypeParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setInterestCalculationPeriodMethod(InterestCalculationPeriodMethod.fromInt(newValue));
        }

        if (command.isChangeInBooleanParameterNamed(LoanProductConstants.ALLOW_PARTIAL_PERIOD_INTEREST_CALCUALTION_PARAM_NAME,
                loanProductRelatedDetail.isAllowPartialPeriodInterestCalcualtion())) {
            final boolean newValue = command
                    .booleanPrimitiveValueOfParameterNamed(LoanProductConstants.ALLOW_PARTIAL_PERIOD_INTEREST_CALCUALTION_PARAM_NAME);
            changes.put(LoanProductConstants.ALLOW_PARTIAL_PERIOD_INTEREST_CALCUALTION_PARAM_NAME, newValue);
            loanProductRelatedDetail.setAllowPartialPeriodInterestCalcualtion(newValue);
        }

        if (loanProductRelatedDetail.getInterestCalculationPeriodMethod().isDaily()) {
            loanProductRelatedDetail.setAllowPartialPeriodInterestCalcualtion(false);
        }

        final String graceOnPrincipalPaymentParamName = "graceOnPrincipalPayment";
        if (command.isChangeInIntegerParameterNamed(graceOnPrincipalPaymentParamName,
                loanProductRelatedDetail.getGraceOnPrincipalPayment())) {
            final Integer newValue = command.integerValueOfParameterNamed(graceOnPrincipalPaymentParamName);
            changes.put(graceOnPrincipalPaymentParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setGraceOnPrincipalPayment(newValue);
        }

        final String recurringMoratoriumOnPrincipalPeriodsParamName = "recurringMoratoriumOnPrincipalPeriods";
        if (command.isChangeInIntegerParameterNamed(recurringMoratoriumOnPrincipalPeriodsParamName,
                loanProductRelatedDetail.getRecurringMoratoriumOnPrincipalPeriods())) {
            final Integer newValue = command.integerValueOfParameterNamed(recurringMoratoriumOnPrincipalPeriodsParamName);
            changes.put(recurringMoratoriumOnPrincipalPeriodsParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setRecurringMoratoriumOnPrincipalPeriods(newValue);
        }

        final String graceOnInterestPaymentParamName = "graceOnInterestPayment";
        if (command.isChangeInIntegerParameterNamed(graceOnInterestPaymentParamName,
                loanProductRelatedDetail.getGraceOnInterestPayment())) {
            final Integer newValue = command.integerValueOfParameterNamed(graceOnInterestPaymentParamName);
            changes.put(graceOnInterestPaymentParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setGraceOnInterestPayment(newValue);
        }

        final String graceOnInterestChargedParamName = "graceOnInterestCharged";
        if (command.isChangeInIntegerParameterNamed(graceOnInterestChargedParamName,
                loanProductRelatedDetail.getGraceOnInterestCharged())) {
            final Integer newValue = command.integerValueOfParameterNamed(graceOnInterestChargedParamName);
            changes.put(graceOnInterestChargedParamName, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setGraceOnInterestCharged(newValue);
        }

        if (command.isChangeInIntegerParameterNamed(LoanProductConstants.GRACE_ON_ARREARS_AGEING_PARAMETER_NAME,
                loanProductRelatedDetail.getGraceOnArrearsAgeing())) {
            final Integer newValue = command.integerValueOfParameterNamed(LoanProductConstants.GRACE_ON_ARREARS_AGEING_PARAMETER_NAME);
            changes.put(LoanProductConstants.GRACE_ON_ARREARS_AGEING_PARAMETER_NAME, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setGraceOnArrearsAgeing(newValue);
        }

        if (command.isChangeInIntegerParameterNamed(LoanProductConstants.DAYS_IN_MONTH_TYPE_PARAMETER_NAME,
                loanProductRelatedDetail.fetchDaysInMonthType().getValue())) {
            final Integer newValue = command.integerValueOfParameterNamed(LoanProductConstants.DAYS_IN_MONTH_TYPE_PARAMETER_NAME);
            changes.put(LoanProductConstants.DAYS_IN_MONTH_TYPE_PARAMETER_NAME, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setDaysInMonthType(newValue);
        }

        if (command.isChangeInIntegerParameterNamed(LoanProductConstants.DAYS_IN_YEAR_TYPE_PARAMETER_NAME,
                loanProductRelatedDetail.fetchDaysInYearType().getValue())) {
            final Integer newValue = command.integerValueOfParameterNamed(LoanProductConstants.DAYS_IN_YEAR_TYPE_PARAMETER_NAME);
            changes.put(LoanProductConstants.DAYS_IN_YEAR_TYPE_PARAMETER_NAME, newValue);
            changes.put("locale", localeAsInput);
            loanProductRelatedDetail.setDaysInYearType(newValue);
        }

        if (command.isChangeInBooleanParameterNamed(LoanProductConstants.IS_INTEREST_RECALCULATION_ENABLED_PARAMETER_NAME,
                loanProductRelatedDetail.isInterestRecalculationEnabled())) {
            final boolean newValue = command
                    .booleanPrimitiveValueOfParameterNamed(LoanProductConstants.IS_INTEREST_RECALCULATION_ENABLED_PARAMETER_NAME);
            changes.put(LoanProductConstants.IS_INTEREST_RECALCULATION_ENABLED_PARAMETER_NAME, newValue);
            loanProductRelatedDetail.setInterestRecalculationEnabled(newValue);
        }

        if (command.isChangeInBooleanParameterNamed(LoanProductConstants.IS_EQUAL_AMORTIZATION_PARAM,
                loanProductRelatedDetail.isEqualAmortization())) {
            final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(LoanProductConstants.IS_EQUAL_AMORTIZATION_PARAM);
            changes.put(LoanProductConstants.IS_EQUAL_AMORTIZATION_PARAM, newValue);
            loanProductRelatedDetail.setEqualAmortization(newValue);
        }

        if (command.isChangeInBooleanParameterNamed(LoanProductConstants.ENABLE_DOWN_PAYMENT,
                loanProductRelatedDetail.isEnableDownPayment())) {
            final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(LoanProductConstants.ENABLE_DOWN_PAYMENT);
            changes.put(LoanProductConstants.ENABLE_DOWN_PAYMENT, newValue);
            loanProductRelatedDetail.setEnableDownPayment(newValue);
            if (!newValue) {
                loanProductRelatedDetail.setEnableAutoRepaymentForDownPayment(false);
                loanProductRelatedDetail.setDisbursedAmountPercentageForDownPayment(null);
            }
        }

        if (loanProductRelatedDetail.isEnableDownPayment()) {
            Boolean enableAutoRepaymentForDownPayment = loan.loanProduct().getLoanProductRelatedDetail()
                    .isEnableAutoRepaymentForDownPayment();
            if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.ENABLE_AUTO_REPAYMENT_DOWN_PAYMENT, command.parsedJson())) {
                if (command.isChangeInBooleanParameterNamed(LoanProductConstants.ENABLE_AUTO_REPAYMENT_DOWN_PAYMENT,
                        loanProductRelatedDetail.isEnableAutoRepaymentForDownPayment())) {
                    enableAutoRepaymentForDownPayment = command
                            .booleanObjectValueOfParameterNamed(LoanProductConstants.ENABLE_AUTO_REPAYMENT_DOWN_PAYMENT);
                    changes.put(LoanProductConstants.ENABLE_AUTO_REPAYMENT_DOWN_PAYMENT, enableAutoRepaymentForDownPayment);
                }
            }
            loanProductRelatedDetail.setEnableAutoRepaymentForDownPayment(enableAutoRepaymentForDownPayment);

            BigDecimal disbursedAmountPercentageDownPayment = loan.loanProduct().getLoanProductRelatedDetail()
                    .getDisbursedAmountPercentageForDownPayment();
            if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.DISBURSED_AMOUNT_PERCENTAGE_DOWN_PAYMENT,
                    command.parsedJson())) {
                if (command.isChangeInBigDecimalParameterNamed(LoanProductConstants.DISBURSED_AMOUNT_PERCENTAGE_DOWN_PAYMENT,
                        loanProductRelatedDetail.getDisbursedAmountPercentageForDownPayment())) {
                    disbursedAmountPercentageDownPayment = command
                            .bigDecimalValueOfParameterNamed(LoanProductConstants.DISBURSED_AMOUNT_PERCENTAGE_DOWN_PAYMENT);
                    changes.put(LoanProductConstants.DISBURSED_AMOUNT_PERCENTAGE_DOWN_PAYMENT, disbursedAmountPercentageDownPayment);
                }
            }
            loanProductRelatedDetail.setDisbursedAmountPercentageForDownPayment(disbursedAmountPercentageDownPayment);
        }

        if (command.isChangeInBooleanParameterNamed(LoanProductConstants.INTEREST_RECOGNITION_ON_DISBURSEMENT_DATE,
                loanProductRelatedDetail.isInterestRecognitionOnDisbursementDate())) {
            final boolean newValue = command
                    .booleanPrimitiveValueOfParameterNamed(LoanProductConstants.INTEREST_RECOGNITION_ON_DISBURSEMENT_DATE);
            changes.put(LoanProductConstants.INTEREST_RECOGNITION_ON_DISBURSEMENT_DATE, newValue);
            loanProductRelatedDetail.updateInterestRecognitionOnDisbursementDate(newValue);
        }
    }