Example usage for org.joda.time LocalDate LocalDate

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

Introduction

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

Prototype

public LocalDate() 

Source Link

Document

Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Usage

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

License:Apache License

public void makeChargePayment(final Long chargeId, final LoanLifecycleStateMachine loanLifecycleStateMachine,
        final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds,
        final HolidayDetailDTO holidayDetailDTO, final LoanTransaction paymentTransaction,
        final Integer installmentNumber) {

    validateAccountStatus(LoanEvent.LOAN_CHARGE_PAYMENT);
    validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_CHARGE_PAYMENT,
            paymentTransaction.getTransactionDate());
    validateActivityNotBeforeLastTransactionDate(LoanEvent.LOAN_CHARGE_PAYMENT,
            paymentTransaction.getTransactionDate());
    validateRepaymentDateIsOnHoliday(paymentTransaction.getTransactionDate(),
            holidayDetailDTO.isAllowTransactionsOnHoliday(), holidayDetailDTO.getHolidays());
    validateRepaymentDateIsOnNonWorkingDay(paymentTransaction.getTransactionDate(),
            holidayDetailDTO.getWorkingDays(), holidayDetailDTO.isAllowTransactionsOnNonWorkingDay());

    if (paymentTransaction.getTransactionDate().isAfter(new LocalDate())) {
        final String errorMessage = "The date on which a loan charge paid cannot be in the future.";
        throw new InvalidLoanStateTransitionException("charge.payment", "cannot.be.a.future.date", errorMessage,
                paymentTransaction.getTransactionDate());
    }//from   w w  w .  j av a  2 s . c o  m
    existingTransactionIds.addAll(findExistingTransactionIds());
    existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
    LoanCharge charge = null;
    for (final LoanCharge loanCharge : this.charges) {
        if (loanCharge.isActive() && chargeId.equals(loanCharge.getId())) {
            charge = loanCharge;
        }
    }
    handleChargePaidTransaction(charge, paymentTransaction, loanLifecycleStateMachine, installmentNumber);
}

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

License:Apache License

public LocalDate possibleNextRepaymentDate() {
    LocalDate earliestUnpaidInstallmentDate = new LocalDate();
    List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();
    for (final LoanRepaymentScheduleInstallment installment : installments) {
        if (installment.isNotFullyPaidOff()) {
            earliestUnpaidInstallmentDate = installment.getDueDate();
            break;
        }//from  w w  w .  j  a  v  a2  s .  c  o m
    }

    LocalDate lastTransactionDate = null;
    for (final LoanTransaction transaction : this.loanTransactions) {
        if (transaction.isRepayment() && transaction.isNonZero()) {
            lastTransactionDate = transaction.getTransactionDate();
        }
    }

    LocalDate possibleNextRepaymentDate = earliestUnpaidInstallmentDate;
    if (lastTransactionDate != null && lastTransactionDate.isAfter(earliestUnpaidInstallmentDate)) {
        possibleNextRepaymentDate = lastTransactionDate;
    }

    return possibleNextRepaymentDate;
}

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

License:Apache License

public LoanTransaction deriveDefaultInterestWaiverTransaction(final LocalDateTime createdDate,
        final AppUser currentUser) {

    final Money totalInterestOutstanding = getTotalInterestOutstandingOnLoan();
    Money possibleInterestToWaive = totalInterestOutstanding.copy();
    LocalDate transactionDate = new LocalDate();

    if (totalInterestOutstanding.isGreaterThanZero()) {
        // find earliest known instance of overdue interest and default to
        // that/*from w  w  w.j  a va 2 s.co m*/
        List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();
        for (final LoanRepaymentScheduleInstallment scheduledRepayment : installments) {

            final Money outstandingForPeriod = scheduledRepayment.getInterestOutstanding(loanCurrency());
            if (scheduledRepayment.isOverdueOn(new LocalDate()) && scheduledRepayment.isNotFullyPaidOff()
                    && outstandingForPeriod.isGreaterThanZero()) {
                transactionDate = scheduledRepayment.getDueDate();
                possibleInterestToWaive = outstandingForPeriod;
                break;
            }
        }
    }

    return LoanTransaction.waiver(getOffice(), this, possibleInterestToWaive, transactionDate,
            possibleInterestToWaive, possibleInterestToWaive.zero(), createdDate, currentUser);
}

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

License:Apache License

@SuppressWarnings("unused")
private Money getTotalInterestOverdueOnLoan() {
    Money cumulativeInterestOverdue = Money.zero(this.loanRepaymentScheduleDetail.getPrincipal().getCurrency());
    List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();
    for (final LoanRepaymentScheduleInstallment scheduledRepayment : installments) {

        final Money interestOutstandingForPeriod = scheduledRepayment.getInterestOutstanding(loanCurrency());
        if (scheduledRepayment.isOverdueOn(new LocalDate())) {
            cumulativeInterestOverdue = cumulativeInterestOverdue.plus(interestOutstandingForPeriod);
        }//  ww  w  .j  av a 2 s .  c om
    }

    return cumulativeInterestOverdue;
}

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

License:Apache License

public LocalDate possibleNextRefundDate() {

    final LocalDate now = new LocalDate();

    LocalDate lastTransactionDate = null;
    for (final LoanTransaction transaction : this.loanTransactions) {
        if ((transaction.isRepayment() || transaction.isRefundForActiveLoan()) && transaction.isNonZero()) {
            lastTransactionDate = transaction.getTransactionDate();
        }//  w  w  w  .ja  va  2 s . co  m
    }

    return lastTransactionDate == null ? now : lastTransactionDate;
}

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

License:Apache License

public LocalDate getNextPossibleRepaymentDateForRescheduling() {
    List<LoanDisbursementDetails> loanDisbursementDetails = this.disbursementDetails;
    LocalDate nextRepaymentDate = new LocalDate();
    for (LoanDisbursementDetails loanDisbursementDetail : loanDisbursementDetails) {
        if (loanDisbursementDetail.actualDisbursementDate() == null) {
            List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();
            for (final LoanRepaymentScheduleInstallment installment : installments) {
                if (installment.getDueDate()
                        .isEqual(loanDisbursementDetail.expectedDisbursementDateAsLocalDate())
                        || installment.getDueDate()
                                .isAfter(loanDisbursementDetail.expectedDisbursementDateAsLocalDate())
                                && installment.isNotFullyPaidOff()) {
                    nextRepaymentDate = installment.getDueDate();
                    break;
                }/*from   www  .java 2 s  . c om*/
            }
            break;
        }
    }
    return nextRepaymentDate;
}

From source file:com.gst.portfolio.loanaccount.loanschedule.data.LoanSchedulePeriodData.java

License:Apache License

private LoanSchedulePeriodData(final Integer periodNumber, final LocalDate fromDate, final LocalDate dueDate,
        final BigDecimal principalDisbursed, final BigDecimal chargesDueAtTimeOfDisbursement,
        final boolean isDisbursed) {
    this.period = periodNumber;
    this.fromDate = fromDate;
    this.dueDate = dueDate;
    this.obligationsMetOnDate = null;
    this.complete = null;
    if (fromDate != null) {
        this.daysInPeriod = Days.daysBetween(this.fromDate, this.dueDate).getDays();
    } else {//w w w .  j  a  va2 s  .c  om
        this.daysInPeriod = null;
    }
    this.principalDisbursed = principalDisbursed;
    this.principalOriginalDue = null;
    this.principalDue = null;
    this.principalPaid = null;
    this.principalWrittenOff = null;
    this.principalOutstanding = null;
    this.principalLoanBalanceOutstanding = principalDisbursed;

    this.interestOriginalDue = null;
    this.interestDue = null;
    this.interestPaid = null;
    this.interestWaived = null;
    this.interestWrittenOff = null;
    this.interestOutstanding = null;

    this.feeChargesDue = chargesDueAtTimeOfDisbursement;
    if (isDisbursed) {
        this.feeChargesPaid = chargesDueAtTimeOfDisbursement;
        this.feeChargesWaived = null;
        this.feeChargesWrittenOff = null;
        this.feeChargesOutstanding = null;
    } else {
        this.feeChargesPaid = null;
        this.feeChargesWaived = null;
        this.feeChargesWrittenOff = null;
        this.feeChargesOutstanding = chargesDueAtTimeOfDisbursement;
    }

    this.penaltyChargesDue = null;
    this.penaltyChargesPaid = null;
    this.penaltyChargesWaived = null;
    this.penaltyChargesWrittenOff = null;
    this.penaltyChargesOutstanding = null;

    this.totalOriginalDueForPeriod = chargesDueAtTimeOfDisbursement;
    this.totalDueForPeriod = chargesDueAtTimeOfDisbursement;
    this.totalPaidForPeriod = this.feeChargesPaid;
    this.totalPaidInAdvanceForPeriod = null;
    this.totalPaidLateForPeriod = null;
    this.totalWaivedForPeriod = null;
    this.totalWrittenOffForPeriod = null;
    this.totalOutstandingForPeriod = this.feeChargesOutstanding;
    this.totalActualCostOfLoanForPeriod = this.feeChargesDue;
    this.totalInstallmentAmountForPeriod = null;
    if (dueDate.isBefore(new LocalDate())) {
        this.totalOverdue = this.totalOutstandingForPeriod;
    } else {
        this.totalOverdue = null;
    }
}

From source file:com.gst.portfolio.loanaccount.loanschedule.data.LoanSchedulePeriodData.java

License:Apache License

private LoanSchedulePeriodData(final Integer periodNumber, final LocalDate fromDate, final LocalDate dueDate,
        final BigDecimal principalOriginalDue, final BigDecimal principalOutstanding,
        final BigDecimal interestDueOnPrincipalOutstanding, final BigDecimal feeChargesDueForPeriod,
        final BigDecimal penaltyChargesDueForPeriod, final BigDecimal totalDueForPeriod,
        BigDecimal totalInstallmentAmountForPeriod) {
    this.period = periodNumber;
    this.fromDate = fromDate;
    this.dueDate = dueDate;
    this.obligationsMetOnDate = null;
    this.complete = null;
    if (fromDate != null) {
        this.daysInPeriod = Days.daysBetween(this.fromDate, this.dueDate).getDays();
    } else {/*ww w.j av  a 2 s  .c om*/
        this.daysInPeriod = null;
    }
    this.principalDisbursed = null;
    this.principalOriginalDue = principalOriginalDue;
    this.principalDue = principalOriginalDue;
    this.principalPaid = null;
    this.principalWrittenOff = null;
    this.principalOutstanding = principalOriginalDue;
    this.principalLoanBalanceOutstanding = principalOutstanding;

    this.interestOriginalDue = interestDueOnPrincipalOutstanding;
    this.interestDue = interestDueOnPrincipalOutstanding;
    this.interestPaid = null;
    this.interestWaived = null;
    this.interestWrittenOff = null;
    this.interestOutstanding = interestDueOnPrincipalOutstanding;

    this.feeChargesDue = feeChargesDueForPeriod;
    this.feeChargesPaid = null;
    this.feeChargesWaived = null;
    this.feeChargesWrittenOff = null;
    this.feeChargesOutstanding = null;

    this.penaltyChargesDue = penaltyChargesDueForPeriod;
    this.penaltyChargesPaid = null;
    this.penaltyChargesWaived = null;
    this.penaltyChargesWrittenOff = null;
    this.penaltyChargesOutstanding = null;

    this.totalOriginalDueForPeriod = totalDueForPeriod;
    this.totalDueForPeriod = totalDueForPeriod;
    this.totalPaidForPeriod = BigDecimal.ZERO;
    this.totalPaidInAdvanceForPeriod = null;
    this.totalPaidLateForPeriod = null;
    this.totalWaivedForPeriod = null;
    this.totalWrittenOffForPeriod = null;
    this.totalOutstandingForPeriod = totalDueForPeriod;
    this.totalActualCostOfLoanForPeriod = interestDueOnPrincipalOutstanding.add(feeChargesDueForPeriod);
    this.totalInstallmentAmountForPeriod = totalInstallmentAmountForPeriod;

    if (dueDate.isBefore(new LocalDate())) {
        this.totalOverdue = this.totalOutstandingForPeriod;
    } else {
        this.totalOverdue = null;
    }
}

From source file:com.gst.portfolio.loanaccount.loanschedule.data.LoanSchedulePeriodData.java

License:Apache License

private LoanSchedulePeriodData(final Integer periodNumber, final LocalDate fromDate, final LocalDate dueDate,
        final LocalDate obligationsMetOnDate, final boolean complete, final BigDecimal principalOriginalDue,
        final BigDecimal principalPaid, final BigDecimal principalWrittenOff,
        final BigDecimal principalOutstanding, final BigDecimal principalLoanBalanceOutstanding,
        final BigDecimal interestDueOnPrincipalOutstanding, final BigDecimal interestPaid,
        final BigDecimal interestWaived, final BigDecimal interestWrittenOff,
        final BigDecimal interestOutstanding, final BigDecimal feeChargesDue, final BigDecimal feeChargesPaid,
        final BigDecimal feeChargesWaived, final BigDecimal feeChargesWrittenOff,
        final BigDecimal feeChargesOutstanding, final BigDecimal penaltyChargesDue,
        final BigDecimal penaltyChargesPaid, final BigDecimal penaltyChargesWaived,
        final BigDecimal penaltyChargesWrittenOff, final BigDecimal penaltyChargesOutstanding,
        final BigDecimal totalDueForPeriod, final BigDecimal totalPaid,
        final BigDecimal totalPaidInAdvanceForPeriod, final BigDecimal totalPaidLateForPeriod,
        final BigDecimal totalWaived, final BigDecimal totalWrittenOff, final BigDecimal totalOutstanding,
        final BigDecimal totalActualCostOfLoanForPeriod, final BigDecimal totalInstallmentAmountForPeriod) {
    this.period = periodNumber;
    this.fromDate = fromDate;
    this.dueDate = dueDate;
    this.obligationsMetOnDate = obligationsMetOnDate;
    this.complete = complete;
    if (fromDate != null) {
        this.daysInPeriod = Days.daysBetween(this.fromDate, this.dueDate).getDays();
    } else {/*  ww w .jav  a 2  s . c o  m*/
        this.daysInPeriod = null;
    }
    this.principalDisbursed = null;
    this.principalOriginalDue = principalOriginalDue;
    this.principalDue = principalOriginalDue;
    this.principalPaid = principalPaid;
    this.principalWrittenOff = principalWrittenOff;
    this.principalOutstanding = principalOutstanding;
    this.principalLoanBalanceOutstanding = principalLoanBalanceOutstanding;

    this.interestOriginalDue = interestDueOnPrincipalOutstanding;
    this.interestDue = interestDueOnPrincipalOutstanding;
    this.interestPaid = interestPaid;
    this.interestWaived = interestWaived;
    this.interestWrittenOff = interestWrittenOff;
    this.interestOutstanding = interestOutstanding;

    this.feeChargesDue = feeChargesDue;
    this.feeChargesPaid = feeChargesPaid;
    this.feeChargesWaived = feeChargesWaived;
    this.feeChargesWrittenOff = feeChargesWrittenOff;
    this.feeChargesOutstanding = feeChargesOutstanding;

    this.penaltyChargesDue = penaltyChargesDue;
    this.penaltyChargesPaid = penaltyChargesPaid;
    this.penaltyChargesWaived = penaltyChargesWaived;
    this.penaltyChargesWrittenOff = penaltyChargesWrittenOff;
    this.penaltyChargesOutstanding = penaltyChargesOutstanding;

    this.totalOriginalDueForPeriod = totalDueForPeriod;
    this.totalDueForPeriod = totalDueForPeriod;
    this.totalPaidForPeriod = totalPaid;
    this.totalPaidInAdvanceForPeriod = totalPaidInAdvanceForPeriod;
    this.totalPaidLateForPeriod = totalPaidLateForPeriod;
    this.totalWaivedForPeriod = totalWaived;
    this.totalWrittenOffForPeriod = totalWrittenOff;
    this.totalOutstandingForPeriod = totalOutstanding;
    this.totalActualCostOfLoanForPeriod = totalActualCostOfLoanForPeriod;
    this.totalInstallmentAmountForPeriod = totalInstallmentAmountForPeriod;

    if (dueDate.isBefore(new LocalDate())) {
        this.totalOverdue = this.totalOutstandingForPeriod;
    } else {
        this.totalOverdue = null;
    }
}

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

License:Apache License

@Override
@Transactional//ww w.  j  av  a  2  s  . c  o m
public CommandProcessingResult approve(JsonCommand jsonCommand) {

    try {
        final Long loanRescheduleRequestId = jsonCommand.entityId();

        final LoanRescheduleRequest loanRescheduleRequest = this.loanRescheduleRequestRepository
                .findOne(loanRescheduleRequestId);

        if (loanRescheduleRequest == null) {
            throw new LoanRescheduleRequestNotFoundException(loanRescheduleRequestId);
        }

        // validate the request in the JsonCommand object passed as
        // parameter
        this.loanRescheduleRequestDataValidator.validateForApproveAction(jsonCommand, loanRescheduleRequest);

        final AppUser appUser = this.platformSecurityContext.authenticatedUser();
        final Map<String, Object> changes = new LinkedHashMap<>();

        LocalDate approvedOnDate = jsonCommand.localDateValueOfParameterNamed("approvedOnDate");
        final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(jsonCommand.dateFormat())
                .withLocale(jsonCommand.extractLocale());

        changes.put("locale", jsonCommand.locale());
        changes.put("dateFormat", jsonCommand.dateFormat());
        changes.put("approvedOnDate", approvedOnDate.toString(dateTimeFormatter));
        changes.put("approvedByUserId", appUser.getId());

        Loan loan = loanRescheduleRequest.getLoan();
        final List<Long> existingTransactionIds = new ArrayList<>(loan.findExistingTransactionIds());
        final List<Long> existingReversedTransactionIds = new ArrayList<>(
                loan.findExistingReversedTransactionIds());

        ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan,
                loanRescheduleRequest.getRescheduleFromDate());

        Collection<LoanRepaymentScheduleHistory> loanRepaymentScheduleHistoryList = this.loanScheduleHistoryWritePlatformService
                .createLoanScheduleArchive(loan.getRepaymentScheduleInstallments(), loan,
                        loanRescheduleRequest);

        final LoanApplicationTerms loanApplicationTerms = loan
                .constructLoanApplicationTerms(scheduleGeneratorDTO);

        LocalDate rescheduleFromDate = null;
        Set<LoanTermVariations> activeLoanTermVariations = loan.getActiveLoanTermVariations();
        LoanTermVariations dueDateVariationInCurrentRequest = loanRescheduleRequest
                .getDueDateTermVariationIfExists();
        if (dueDateVariationInCurrentRequest != null && activeLoanTermVariations != null) {
            LocalDate fromScheduleDate = dueDateVariationInCurrentRequest.fetchTermApplicaDate();
            LocalDate currentScheduleDate = fromScheduleDate;
            LocalDate modifiedScheduleDate = dueDateVariationInCurrentRequest.fetchDateValue();
            Map<LocalDate, LocalDate> changeMap = new HashMap<>();
            changeMap.put(currentScheduleDate, modifiedScheduleDate);
            for (LoanTermVariations activeLoanTermVariation : activeLoanTermVariations) {
                if (activeLoanTermVariation.getTermType().isDueDateVariation() && activeLoanTermVariation
                        .fetchDateValue().equals(dueDateVariationInCurrentRequest.fetchTermApplicaDate())) {
                    activeLoanTermVariation.markAsInactive();
                    rescheduleFromDate = activeLoanTermVariation.fetchTermApplicaDate();
                    dueDateVariationInCurrentRequest.setTermApplicableFrom(rescheduleFromDate.toDate());
                } else if (!activeLoanTermVariation.fetchTermApplicaDate().isBefore(fromScheduleDate)) {
                    while (currentScheduleDate.isBefore(activeLoanTermVariation.fetchTermApplicaDate())) {
                        currentScheduleDate = this.scheduledDateGenerator.generateNextRepaymentDate(
                                currentScheduleDate, loanApplicationTerms, false,
                                loanApplicationTerms.getHolidayDetailDTO());
                        modifiedScheduleDate = this.scheduledDateGenerator.generateNextRepaymentDate(
                                modifiedScheduleDate, loanApplicationTerms, false,
                                loanApplicationTerms.getHolidayDetailDTO());
                        changeMap.put(currentScheduleDate, modifiedScheduleDate);
                    }
                    if (changeMap.containsKey(activeLoanTermVariation.fetchTermApplicaDate())) {
                        activeLoanTermVariation.setTermApplicableFrom(
                                changeMap.get(activeLoanTermVariation.fetchTermApplicaDate()).toDate());
                    }
                }
            }
        }
        if (rescheduleFromDate == null) {
            rescheduleFromDate = loanRescheduleRequest.getRescheduleFromDate();
        }
        for (LoanRescheduleRequestToTermVariationMapping mapping : loanRescheduleRequest
                .getLoanRescheduleRequestToTermVariationMappings()) {
            mapping.getLoanTermVariations().updateIsActive(true);
        }
        BigDecimal annualNominalInterestRate = null;
        List<LoanTermVariationsData> loanTermVariations = new ArrayList<>();
        loan.constructLoanTermVariations(scheduleGeneratorDTO.getFloatingRateDTO(), annualNominalInterestRate,
                loanTermVariations);
        loanApplicationTerms.getLoanTermVariations().setExceptionData(loanTermVariations);

        /*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);
            }
        }
        }*/

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

        loan.updateLoanSchedule(loanSchedule.getInstallments(), appUser);
        loan.recalculateAllCharges();
        ChangedTransactionDetail changedTransactionDetail = loan.processTransactions();

        for (LoanRepaymentScheduleHistory loanRepaymentScheduleHistory : loanRepaymentScheduleHistoryList) {
            this.loanRepaymentScheduleHistoryRepository.save(loanRepaymentScheduleHistory);
        }

        loan.updateRescheduledByUser(appUser);
        loan.updateRescheduledOnDate(new LocalDate());

        // update the status of the request
        loanRescheduleRequest.approve(appUser, approvedOnDate);

        // update the loan object
        saveAndFlushLoanWithDataIntegrityViolationChecks(loan);

        if (changedTransactionDetail != null) {
            for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail
                    .getNewTransactionMappings().entrySet()) {
                this.loanTransactionRepository.save(mapEntry.getValue());
                // update loan with references to the newly created
                // transactions
                loan.addLoanTransaction(mapEntry.getValue());
                this.accountTransfersWritePlatformService.updateLoanTransaction(mapEntry.getKey(),
                        mapEntry.getValue());
            }
        }
        postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);

        this.loanAccountDomainService.recalculateAccruals(loan, true);

        return new CommandProcessingResultBuilder().withCommandId(jsonCommand.commandId())
                .withEntityId(loanRescheduleRequestId).withLoanId(loanRescheduleRequest.getLoan().getId())
                .with(changes).build();
    }

    catch (final DataIntegrityViolationException dve) {
        // handle the data integrity violation
        handleDataIntegrityViolation(dve);

        // return an empty command processing result object
        return CommandProcessingResult.empty();
    }
}