Example usage for org.joda.time LocalDate toDate

List of usage examples for org.joda.time LocalDate toDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDate.

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:com.gst.portfolio.loanaccount.domain.LoanTransaction.java

License:Apache License

public static LoanTransaction approveTransfer(final Office office, final Loan loan,
        final LocalDate transferDate, final LocalDateTime createdDate, final AppUser appUser) {
    return new LoanTransaction(loan, office, LoanTransactionType.APPROVE_TRANSFER.getValue(),
            transferDate.toDateTimeAtStartOfDay().toDate(), loan.getSummary().getTotalOutstanding(),
            loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary().getTotalInterestOutstanding(),
            loan.getSummary().getTotalFeeChargesOutstanding(),
            loan.getSummary().getTotalPenaltyChargesOutstanding(), null, false, null, null, createdDate,
            appUser);//from w  ww.  j  a v  a  2s  . c o m
}

From source file:com.gst.portfolio.loanaccount.domain.LoanTransaction.java

License:Apache License

public static LoanTransaction withdrawTransfer(final Office office, final Loan loan,
        final LocalDate transferDate, final LocalDateTime createdDate, final AppUser appUser) {
    return new LoanTransaction(loan, office, LoanTransactionType.WITHDRAW_TRANSFER.getValue(),
            transferDate.toDateTimeAtStartOfDay().toDate(), loan.getSummary().getTotalOutstanding(),
            loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary().getTotalInterestOutstanding(),
            loan.getSummary().getTotalFeeChargesOutstanding(),
            loan.getSummary().getTotalPenaltyChargesOutstanding(), null, false, null, null, createdDate,
            appUser);/* w  w  w . j av a2  s.c o m*/
}

From source file:com.gst.portfolio.loanaccount.domain.LoanTransaction.java

License:Apache License

private LoanTransaction(final Loan loan, final Office office, final LoanTransactionType type,
        final BigDecimal amount, final LocalDate date, final String externalId, final LocalDateTime createdDate,
        final AppUser appUser) {
    this.loan = loan;
    this.typeOf = type.getValue();
    this.amount = amount;
    this.dateOf = date.toDateTimeAtStartOfDay().toDate();
    this.externalId = externalId;
    this.office = office;
    this.submittedOnDate = DateUtils.getDateOfTenant();
    this.createdDate = createdDate.toDate();
    this.appUser = appUser;
}

From source file:com.gst.portfolio.loanaccount.domain.LoanTransaction.java

License:Apache License

private LoanTransaction(final Loan loan, final Office office, final LoanTransactionType type,
        final PaymentDetail paymentDetail, final BigDecimal amount, final LocalDate date,
        final String externalId, final LocalDateTime createdDate, final AppUser appUser) {
    this.loan = loan;
    this.typeOf = type.getValue();
    this.paymentDetail = paymentDetail;
    this.amount = amount;
    this.dateOf = date.toDateTimeAtStartOfDay().toDate();
    this.externalId = externalId;
    this.office = office;
    this.submittedOnDate = DateUtils.getDateOfTenant();
    this.createdDate = createdDate.toDate();
    this.appUser = appUser;
}

From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

License:Apache License

private LoanApplicationTerms assembleLoanApplicationTermsFrom(final JsonElement element,
        final LoanProduct loanProduct) {

    final MonetaryCurrency currency = loanProduct.getCurrency();
    final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository
            .findOneWithNotFoundDetection(currency);

    // loan terms
    final Integer loanTermFrequency = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("loanTermFrequency",
            element);/*from  w w  w .j a  v a 2s  . c  o  m*/
    final Integer loanTermFrequencyType = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("loanTermFrequencyType", element);
    final PeriodFrequencyType loanTermPeriodFrequencyType = PeriodFrequencyType.fromInt(loanTermFrequencyType);

    final Integer numberOfRepayments = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("numberOfRepayments", element);
    final Integer repaymentEvery = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentEvery",
            element);
    final Integer repaymentFrequencyType = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("repaymentFrequencyType", element);
    final PeriodFrequencyType repaymentPeriodFrequencyType = PeriodFrequencyType
            .fromInt(repaymentFrequencyType);
    final Integer nthDay = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentFrequencyNthDayType",
            element);
    final Integer dayOfWeek = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("repaymentFrequencyDayOfWeekType", element);
    final DayOfWeekType weekDayType = DayOfWeekType.fromInt(dayOfWeek);

    final Integer amortizationType = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("amortizationType",
            element);
    final AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(amortizationType);

    // interest terms
    final Integer interestType = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("interestType", element);
    final InterestMethod interestMethod = InterestMethod.fromInt(interestType);

    final Integer interestCalculationPeriodType = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("interestCalculationPeriodType", element);
    final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod
            .fromInt(interestCalculationPeriodType);
    Boolean allowPartialPeriodInterestCalcualtion = this.fromApiJsonHelper
            .extractBooleanNamed(LoanProductConstants.allowPartialPeriodInterestCalcualtionParamName, element);
    if (allowPartialPeriodInterestCalcualtion == null) {
        allowPartialPeriodInterestCalcualtion = loanProduct.getLoanProductRelatedDetail()
                .isAllowPartialPeriodInterestCalcualtion();
    }

    final BigDecimal interestRatePerPeriod = this.fromApiJsonHelper
            .extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element);
    final PeriodFrequencyType interestRatePeriodFrequencyType = loanProduct.getInterestPeriodFrequencyType();

    BigDecimal annualNominalInterestRate = BigDecimal.ZERO;
    if (interestRatePerPeriod != null) {
        annualNominalInterestRate = this.aprCalculator.calculateFrom(interestRatePeriodFrequencyType,
                interestRatePerPeriod);
    }

    // disbursement details
    final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element);
    final Money principalMoney = Money.of(currency, principal);

    final LocalDate expectedDisbursementDate = this.fromApiJsonHelper
            .extractLocalDateNamed("expectedDisbursementDate", element);
    final LocalDate repaymentsStartingFromDate = this.fromApiJsonHelper
            .extractLocalDateNamed("repaymentsStartingFromDate", element);
    LocalDate calculatedRepaymentsStartingFromDate = repaymentsStartingFromDate;

    final Boolean synchDisbursement = this.fromApiJsonHelper.extractBooleanNamed("syncDisbursementWithMeeting",
            element);
    final Long calendarId = this.fromApiJsonHelper.extractLongNamed("calendarId", element);
    Calendar calendar = null;

    final String loanTypeParameterName = "loanType";
    final String loanTypeStr = this.fromApiJsonHelper.extractStringNamed(loanTypeParameterName, element);

    final AccountType loanType = AccountType.fromName(loanTypeStr);

    /*
     * If it is JLG loan/Group Loan then make sure loan frequency is same as
     * Group/Center meeting frequency or multiple of it. TODO: Check should
     * be either same frequency or loan freq is multiple of center/group
     * meeting freq multiples
     */
    if ((loanType.isJLGAccount() || loanType.isGroupAccount()) && calendarId != null) {
        calendar = this.calendarRepository.findOne(calendarId);
        if (calendar == null) {
            throw new CalendarNotFoundException(calendarId);
        }
        final PeriodFrequencyType meetingPeriodFrequency = CalendarUtils
                .getMeetingPeriodFrequencyType(calendar.getRecurrence());
        validateRepaymentFrequencyIsSameAsMeetingFrequency(meetingPeriodFrequency.getValue(),
                repaymentFrequencyType, CalendarUtils.getInterval(calendar.getRecurrence()), repaymentEvery);
    } else {
        if (repaymentPeriodFrequencyType == PeriodFrequencyType.MONTHS && nthDay != null
                && nthDay != NthDayType.INVALID.getValue()) {
            LocalDate calendarStartDate = repaymentsStartingFromDate;
            if (calendarStartDate == null)
                calendarStartDate = expectedDisbursementDate;
            calendar = createLoanCalendar(calendarStartDate, repaymentEvery, CalendarFrequencyType.MONTHLY,
                    dayOfWeek, nthDay);
        }
    }

    /*
     * If user has not passed the first repayments date then then derive the
     * same based on loan type.
     */
    if (calculatedRepaymentsStartingFromDate == null) {
        calculatedRepaymentsStartingFromDate = deriveFirstRepaymentDate(loanType, repaymentEvery,
                expectedDisbursementDate, repaymentPeriodFrequencyType,
                loanProduct.getMinimumDaysBetweenDisbursalAndFirstRepayment(), calendar);
    }

    /*
     * If it is JLG loan/Group Loan synched with a meeting, then make sure
     * first repayment falls on meeting date
     */
    final Long groupId = this.fromApiJsonHelper.extractLongNamed("groupId", element);
    Group group = null;
    if (groupId != null) {
        group = this.groupRepository.findOneWithNotFoundDetection(groupId);
    }

    Boolean isSkipMeetingOnFirstDay = false;
    Integer numberOfDays = 0;
    boolean isSkipRepaymentOnFirstMonthEnabled = configurationDomainService
            .isSkippingMeetingOnFirstDayOfMonthEnabled();
    if (isSkipRepaymentOnFirstMonthEnabled) {
        isSkipMeetingOnFirstDay = this.loanUtilService.isLoanRepaymentsSyncWithMeeting(group, calendar);
        if (isSkipMeetingOnFirstDay) {
            numberOfDays = configurationDomainService.retreivePeroidInNumberOfDaysForSkipMeetingDate()
                    .intValue();
        }
    }
    if ((loanType.isJLGAccount() || loanType.isGroupAccount()) && calendar != null) {
        validateRepaymentsStartDateWithMeetingDates(calculatedRepaymentsStartingFromDate, calendar,
                isSkipMeetingOnFirstDay, numberOfDays);

        /*
         * If disbursement is synced on meeting, make sure disbursement date
         * is on a meeting date
         */
        if (synchDisbursement != null && synchDisbursement.booleanValue()) {
            validateDisbursementDateWithMeetingDates(expectedDisbursementDate, calendar,
                    isSkipMeetingOnFirstDay, numberOfDays);
        }
    }

    validateMinimumDaysBetweenDisbursalAndFirstRepayment(expectedDisbursementDate,
            calculatedRepaymentsStartingFromDate,
            loanProduct.getMinimumDaysBetweenDisbursalAndFirstRepayment());

    // grace details
    final Integer graceOnPrincipalPayment = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("graceOnPrincipalPayment", element);
    final Integer recurringMoratoriumOnPrincipalPeriods = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("recurringMoratoriumOnPrincipalPeriods", element);
    final Integer graceOnInterestPayment = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("graceOnInterestPayment", element);
    final Integer graceOnInterestCharged = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("graceOnInterestCharged", element);
    final LocalDate interestChargedFromDate = this.fromApiJsonHelper
            .extractLocalDateNamed("interestChargedFromDate", element);
    final Boolean isInterestChargedFromDateSameAsDisbursalDateEnabled = this.configurationDomainService
            .isInterestChargedFromDateSameAsDisbursementDate();

    final Integer graceOnArrearsAgeing = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed(LoanProductConstants.graceOnArrearsAgeingParameterName, element);

    // other
    final BigDecimal inArrearsTolerance = this.fromApiJsonHelper
            .extractBigDecimalWithLocaleNamed("inArrearsTolerance", element);
    final Money inArrearsToleranceMoney = Money.of(currency, inArrearsTolerance);

    final BigDecimal emiAmount = this.fromApiJsonHelper
            .extractBigDecimalWithLocaleNamed(LoanApiConstants.emiAmountParameterName, element);
    final BigDecimal maxOutstandingBalance = this.fromApiJsonHelper
            .extractBigDecimalWithLocaleNamed(LoanApiConstants.maxOutstandingBalanceParameterName, element);

    final List<DisbursementData> disbursementDatas = fetchDisbursementData(element.getAsJsonObject());

    /**
     * Interest recalculation settings copy from product definition
     */
    final DaysInMonthType daysInMonthType = loanProduct.fetchDaysInMonthType();

    final DaysInYearType daysInYearType = loanProduct.fetchDaysInYearType();

    final boolean isInterestRecalculationEnabled = loanProduct.isInterestRecalculationEnabled();
    RecalculationFrequencyType recalculationFrequencyType = null;
    CalendarInstance restCalendarInstance = null;
    RecalculationFrequencyType compoundingFrequencyType = null;
    CalendarInstance compoundingCalendarInstance = null;
    InterestRecalculationCompoundingMethod compoundingMethod = null;
    boolean allowCompoundingOnEod = false;
    if (isInterestRecalculationEnabled) {
        LoanProductInterestRecalculationDetails loanProductInterestRecalculationDetails = loanProduct
                .getProductInterestRecalculationDetails();
        recalculationFrequencyType = loanProductInterestRecalculationDetails.getRestFrequencyType();
        Integer repeatsOnDay = null;
        Integer recalculationFrequencyNthDay = loanProductInterestRecalculationDetails.getRestFrequencyOnDay();
        if (recalculationFrequencyNthDay == null) {
            recalculationFrequencyNthDay = loanProductInterestRecalculationDetails.getRestFrequencyNthDay();
            repeatsOnDay = loanProductInterestRecalculationDetails.getRestFrequencyWeekday();
        }
        Integer frequency = loanProductInterestRecalculationDetails.getRestInterval();
        if (recalculationFrequencyType.isSameAsRepayment()) {
            restCalendarInstance = createCalendarForSameAsRepayment(repaymentEvery,
                    repaymentPeriodFrequencyType, expectedDisbursementDate);
        } else {
            LocalDate calendarStartDate = expectedDisbursementDate;
            restCalendarInstance = createInterestRecalculationCalendarInstance(calendarStartDate,
                    recalculationFrequencyType, frequency, recalculationFrequencyNthDay, repeatsOnDay);
        }
        compoundingMethod = InterestRecalculationCompoundingMethod
                .fromInt(loanProductInterestRecalculationDetails.getInterestRecalculationCompoundingMethod());
        if (compoundingMethod.isCompoundingEnabled()) {
            Integer compoundingRepeatsOnDay = null;
            Integer recalculationCompoundingFrequencyNthDay = loanProductInterestRecalculationDetails
                    .getCompoundingFrequencyOnDay();
            if (recalculationCompoundingFrequencyNthDay == null) {
                recalculationCompoundingFrequencyNthDay = loanProductInterestRecalculationDetails
                        .getCompoundingFrequencyNthDay();
                compoundingRepeatsOnDay = loanProductInterestRecalculationDetails
                        .getCompoundingFrequencyWeekday();
            }
            compoundingFrequencyType = loanProductInterestRecalculationDetails.getCompoundingFrequencyType();
            if (compoundingFrequencyType.isSameAsRepayment()) {
                compoundingCalendarInstance = createCalendarForSameAsRepayment(repaymentEvery,
                        repaymentPeriodFrequencyType, expectedDisbursementDate);
            } else {
                LocalDate calendarStartDate = expectedDisbursementDate;
                compoundingCalendarInstance = createInterestRecalculationCalendarInstance(calendarStartDate,
                        compoundingFrequencyType,
                        loanProductInterestRecalculationDetails.getCompoundingInterval(),
                        recalculationCompoundingFrequencyNthDay, compoundingRepeatsOnDay);
            }
            allowCompoundingOnEod = loanProductInterestRecalculationDetails.allowCompoundingOnEod();
        }
    }

    final BigDecimal principalThresholdForLastInstalment = loanProduct
            .getPrincipalThresholdForLastInstallment();

    final Integer installmentAmountInMultiplesOf = loanProduct.getInstallmentAmountInMultiplesOf();

    List<LoanTermVariationsData> loanTermVariations = new ArrayList<>();
    if (loanProduct.isLinkedToFloatingInterestRate()) {
        final BigDecimal interestRateDiff = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
                LoanApiConstants.interestRateDifferentialParameterName, element);
        final Boolean isFloatingInterestRate = this.fromApiJsonHelper
                .extractBooleanNamed(LoanApiConstants.isFloatingInterestRateParameterName, element);
        List<FloatingRatePeriodData> baseLendingRatePeriods = null;
        try {
            baseLendingRatePeriods = this.floatingRatesReadPlatformService.retrieveBaseLendingRate()
                    .getRatePeriods();
        } catch (final FloatingRateNotFoundException ex) {
            // Do not do anything
        }
        FloatingRateDTO floatingRateDTO = new FloatingRateDTO(isFloatingInterestRate, expectedDisbursementDate,
                interestRateDiff, baseLendingRatePeriods);
        Collection<FloatingRatePeriodData> applicableRates = loanProduct.fetchInterestRates(floatingRateDTO);

        LocalDate interestRateStartDate = DateUtils.getLocalDateOfTenant();
        final LocalDate dateValue = null;
        final boolean isSpecificToInstallment = false;
        for (FloatingRatePeriodData periodData : applicableRates) {
            LoanTermVariationsData loanTermVariation = new LoanTermVariationsData(
                    LoanEnumerations.loanvariationType(LoanTermVariationType.INTEREST_RATE),
                    periodData.getFromDateAsLocalDate(), periodData.getInterestRate(), dateValue,
                    isSpecificToInstallment);
            if (!interestRateStartDate.isBefore(periodData.getFromDateAsLocalDate())) {
                interestRateStartDate = periodData.getFromDateAsLocalDate();
                annualNominalInterestRate = periodData.getInterestRate();
            }
            loanTermVariations.add(loanTermVariation);
        }
    }

    final Long clientId = this.fromApiJsonHelper.extractLongNamed("clientId", element);
    Client client = null;
    Long officeId = null;
    if (clientId != null) {
        client = this.clientRepository.findOneWithNotFoundDetection(clientId);
        officeId = client.getOffice().getId();
    } else if (groupId != null) {
        group = this.groupRepository.findOneWithNotFoundDetection(groupId);
        officeId = group.getOffice().getId();
    }
    final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
    final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId,
            expectedDisbursementDate.toDate(), HolidayStatusType.ACTIVE.getValue());
    final WorkingDays workingDays = this.workingDaysRepository.findOne();
    HolidayDetailDTO detailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays);
    return LoanApplicationTerms.assembleFrom(applicationCurrency, loanTermFrequency,
            loanTermPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentPeriodFrequencyType,
            nthDay, weekDayType, amortizationMethod, interestMethod, interestRatePerPeriod,
            interestRatePeriodFrequencyType, annualNominalInterestRate, interestCalculationPeriodMethod,
            allowPartialPeriodInterestCalcualtion, principalMoney, expectedDisbursementDate,
            repaymentsStartingFromDate, calculatedRepaymentsStartingFromDate, graceOnPrincipalPayment,
            recurringMoratoriumOnPrincipalPeriods, graceOnInterestPayment, graceOnInterestCharged,
            interestChargedFromDate, inArrearsToleranceMoney, loanProduct.isMultiDisburseLoan(), emiAmount,
            disbursementDatas, maxOutstandingBalance, graceOnArrearsAgeing, daysInMonthType, daysInYearType,
            isInterestRecalculationEnabled, recalculationFrequencyType, restCalendarInstance, compoundingMethod,
            compoundingCalendarInstance, compoundingFrequencyType, principalThresholdForLastInstalment,
            installmentAmountInMultiplesOf, loanProduct.preCloseInterestCalculationStrategy(), calendar,
            BigDecimal.ZERO, loanTermVariations, isInterestChargedFromDateSameAsDisbursalDateEnabled,
            numberOfDays, isSkipMeetingOnFirstDay, detailDTO, allowCompoundingOnEod);
}

From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

License:Apache License

public LoanScheduleModel assembleLoanScheduleFrom(final JsonElement element) {
    // This method is getting called from calculate loan schedule.
    final LoanApplicationTerms loanApplicationTerms = assembleLoanTerms(element);
    // Get holiday details
    final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();

    final Long clientId = this.fromApiJsonHelper.extractLongNamed("clientId", element);
    final Long groupId = this.fromApiJsonHelper.extractLongNamed("groupId", element);

    Client client = null;/*  www .j a v  a  2 s . c o  m*/
    Group group = null;
    Long officeId = null;
    if (clientId != null) {
        client = this.clientRepository.findOneWithNotFoundDetection(clientId);
        officeId = client.getOffice().getId();
    } else if (groupId != null) {
        group = this.groupRepository.findOneWithNotFoundDetection(groupId);
        officeId = group.getOffice().getId();
    }

    final LocalDate expectedDisbursementDate = this.fromApiJsonHelper
            .extractLocalDateNamed("expectedDisbursementDate", element);
    final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId,
            expectedDisbursementDate.toDate(), HolidayStatusType.ACTIVE.getValue());
    final WorkingDays workingDays = this.workingDaysRepository.findOne();

    validateDisbursementDateIsOnNonWorkingDay(loanApplicationTerms.getExpectedDisbursementDate(), workingDays);
    validateDisbursementDateIsOnHoliday(loanApplicationTerms.getExpectedDisbursementDate(), isHolidayEnabled,
            holidays);

    List<LoanDisbursementDetails> loanDisbursementDetails = this.loanUtilService
            .fetchDisbursementData(element.getAsJsonObject());

    return assembleLoanScheduleFrom(loanApplicationTerms, isHolidayEnabled, holidays, workingDays, element,
            loanDisbursementDetails);
}

From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

License:Apache License

private void extractLoanTermVariations(final Loan loan, final String dateFormat, final Locale locale,
        final JsonArray modificationsArray, final boolean isInsertInstallment,
        final boolean isDeleteInstallment, final List<LoanTermVariations> loanTermVariations) {
    for (int i = 1; i <= modificationsArray.size(); i++) {
        final JsonObject arrayElement = modificationsArray.get(i - 1).getAsJsonObject();
        BigDecimal decimalValue = null;
        LoanTermVariationType decimalValueVariationType = LoanTermVariationType.INVALID;
        if (loan.getLoanProductRelatedDetail().getAmortizationMethod().isEqualInstallment()
                && loan.getLoanProductRelatedDetail().getInterestMethod().isDecliningBalnce()) {
            decimalValue = this.fromApiJsonHelper
                    .extractBigDecimalNamed(LoanApiConstants.installmentAmountParamName, arrayElement, locale);
            decimalValueVariationType = LoanTermVariationType.EMI_AMOUNT;
        } else {// www.  j a v  a 2 s  .  c  o  m
            decimalValue = this.fromApiJsonHelper.extractBigDecimalNamed(LoanApiConstants.principalParamName,
                    arrayElement, locale);
            decimalValueVariationType = LoanTermVariationType.PRINCIPAL_AMOUNT;
        }

        LocalDate duedateLocalDate = this.fromApiJsonHelper
                .extractLocalDateNamed(LoanApiConstants.dueDateParamName, arrayElement, dateFormat, locale);
        Date dueDate = duedateLocalDate.toDate();

        LocalDate modifiedDuedateLocalDate = this.fromApiJsonHelper.extractLocalDateNamed(
                LoanApiConstants.modifiedDueDateParamName, arrayElement, dateFormat, locale);
        Date modifiedDuedate = null;
        if (modifiedDuedateLocalDate != null) {
            modifiedDuedate = modifiedDuedateLocalDate.toDate();
        }
        boolean isSpecificToInstallment = true;
        if (isInsertInstallment) {
            LoanTermVariations data = new LoanTermVariations(
                    LoanTermVariationType.INSERT_INSTALLMENT.getValue(), dueDate, decimalValue, modifiedDuedate,
                    isSpecificToInstallment, loan);
            loanTermVariations.add(data);
        } else if (isDeleteInstallment) {
            LoanTermVariations data = new LoanTermVariations(
                    LoanTermVariationType.DELETE_INSTALLMENT.getValue(), dueDate, decimalValue, modifiedDuedate,
                    isSpecificToInstallment, loan);
            loanTermVariations.add(data);
        } else {
            if (modifiedDuedate != null) {
                BigDecimal amountData = null;
                LoanTermVariations data = new LoanTermVariations(LoanTermVariationType.DUE_DATE.getValue(),
                        dueDate, amountData, modifiedDuedate, isSpecificToInstallment, loan);
                loanTermVariations.add(data);
            }
            if (decimalValue != null) {
                if (modifiedDuedate == null) {
                    modifiedDuedate = dueDate;
                }
                Date date = null;
                LoanTermVariations data = new LoanTermVariations(decimalValueVariationType.getValue(),
                        modifiedDuedate, decimalValue, date, isSpecificToInstallment, loan);
                loanTermVariations.add(data);
            }
        }

    }
}

From source file:com.gst.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest.java

License:Apache License

/** 
 * change the status of the loan reschedule request to approved, also updating the 
 * approvedByUser and approvedOnDate properties 
 * //from   w  ww . j a  v  a  2  s .c  o m
 * @param approvedByUser the user who approved the request
 * @param approvedOnDate the date of the approval
 * @return void
 **/
public void approve(final AppUser approvedByUser, final LocalDate approvedOnDate) {

    if (approvedOnDate != null) {
        this.approvedByUser = approvedByUser;
        this.approvedOnDate = approvedOnDate.toDate();
        this.statusEnum = LoanStatus.APPROVED.getValue();
    }
}

From source file:com.gst.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest.java

License:Apache License

/** 
 * change the status of the loan reschedule request to rejected, also updating the 
 * approvedByUser and approvedOnDate properties 
 * /* w ww .  j  ava2 s  .c om*/
 * @param approvedByUser the user who approved the request
 * @param approvedOnDate the date of the approval
 * @return void
 **/
public void reject(final AppUser approvedByUser, final LocalDate approvedOnDate) {

    if (approvedOnDate != null) {
        this.rejectedByUser = approvedByUser;
        this.rejectedOnDate = approvedOnDate.toDate();
        this.statusEnum = LoanStatus.REJECTED.getValue();
    }
}

From source file:com.gst.portfolio.loanaccount.rescheduleloan.service.LoanReschedulePreviewPlatformServiceImpl.java

License:Apache License

@Override
public LoanScheduleModel previewLoanReschedule(Long requestId) {
    final LoanRescheduleRequest loanRescheduleRequest = this.loanRescheduleRequestRepository.findOne(requestId);

    if (loanRescheduleRequest == null) {
        throw new LoanRescheduleRequestNotFoundException(requestId);
    }//from  ww w . j  a va 2 s.c o  m

    Loan loan = loanRescheduleRequest.getLoan();

    ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan,
            loanRescheduleRequest.getRescheduleFromDate());
    LocalDate rescheduleFromDate = null;
    List<LoanTermVariationsData> removeLoanTermVariationsData = new ArrayList<>();
    final LoanApplicationTerms loanApplicationTerms = loan.constructLoanApplicationTerms(scheduleGeneratorDTO);
    LoanTermVariations dueDateVariationInCurrentRequest = loanRescheduleRequest
            .getDueDateTermVariationIfExists();
    if (dueDateVariationInCurrentRequest != null) {
        for (LoanTermVariationsData loanTermVariation : loanApplicationTerms.getLoanTermVariations()
                .getDueDateVariation()) {
            if (loanTermVariation.getDateValue()
                    .equals(dueDateVariationInCurrentRequest.fetchTermApplicaDate())) {
                rescheduleFromDate = loanTermVariation.getTermApplicableFrom();
                removeLoanTermVariationsData.add(loanTermVariation);
            }
        }
    }
    loanApplicationTerms.getLoanTermVariations().getDueDateVariation().removeAll(removeLoanTermVariationsData);
    if (rescheduleFromDate == null) {
        rescheduleFromDate = loanRescheduleRequest.getRescheduleFromDate();
    }
    List<LoanTermVariationsData> loanTermVariationsData = new ArrayList<>();
    LocalDate adjustedApplicableDate = null;
    Set<LoanRescheduleRequestToTermVariationMapping> loanRescheduleRequestToTermVariationMappings = loanRescheduleRequest
            .getLoanRescheduleRequestToTermVariationMappings();
    if (!loanRescheduleRequestToTermVariationMappings.isEmpty()) {
        for (LoanRescheduleRequestToTermVariationMapping loanRescheduleRequestToTermVariationMapping : loanRescheduleRequestToTermVariationMappings) {
            if (loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().getTermType()
                    .isDueDateVariation() && rescheduleFromDate != null) {
                adjustedApplicableDate = loanRescheduleRequestToTermVariationMapping.getLoanTermVariations()
                        .fetchDateValue();
                loanRescheduleRequestToTermVariationMapping.getLoanTermVariations()
                        .setTermApplicableFrom(rescheduleFromDate.toDate());
            }
            loanTermVariationsData
                    .add(loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().toData());
        }
    }

    for (LoanTermVariationsData loanTermVariation : loanApplicationTerms.getLoanTermVariations()
            .getDueDateVariation()) {
        if (rescheduleFromDate.isBefore(loanTermVariation.getTermApplicableFrom())) {
            LocalDate applicableDate = this.scheduledDateGenerator.generateNextRepaymentDate(rescheduleFromDate,
                    loanApplicationTerms, false, loanApplicationTerms.getHolidayDetailDTO());
            if (loanTermVariation.getTermApplicableFrom().equals(applicableDate)) {
                LocalDate adjustedDate = this.scheduledDateGenerator.generateNextRepaymentDate(
                        adjustedApplicableDate, loanApplicationTerms, false,
                        loanApplicationTerms.getHolidayDetailDTO());
                loanTermVariation.setApplicableFromDate(adjustedDate);
                loanTermVariationsData.add(loanTermVariation);
            }
        }
    }

    loanApplicationTerms.getLoanTermVariations().updateLoanTermVariationsData(loanTermVariationsData);
    final RoundingMode roundingMode = MoneyHelper.getRoundingMode();
    final MathContext mathContext = new MathContext(8, roundingMode);
    final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.loanRepaymentScheduleTransactionProcessorFactory
            .determineProcessor(loan.transactionProcessingStrategy());
    final LoanScheduleGenerator loanScheduleGenerator = this.loanScheduleFactory
            .create(loanApplicationTerms.getInterestMethod());
    final LoanLifecycleStateMachine loanLifecycleStateMachine = null;
    loan.setHelpers(loanLifecycleStateMachine, this.loanSummaryWrapper,
            this.loanRepaymentScheduleTransactionProcessorFactory);
    final LoanScheduleDTO loanSchedule = loanScheduleGenerator.rescheduleNextInstallments(mathContext,
            loanApplicationTerms, loan, loanApplicationTerms.getHolidayDetailDTO(),
            loanRepaymentScheduleTransactionProcessor, rescheduleFromDate);
    final LoanScheduleModel loanScheduleModel = loanSchedule.getLoanScheduleModel();
    LoanScheduleModel loanScheduleModels = LoanScheduleModel
            .withLoanScheduleModelPeriods(loanScheduleModel.getPeriods(), loanScheduleModel);

    return loanScheduleModels;
}