List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public void updateLoanRepaymentScheduleDates(final LocalDate meetingStartDate, final String recuringRule, final boolean isHolidayEnabled, final List<Holiday> holidays, final WorkingDays workingDays, final boolean isSkipRepaymentonfirstdayofmonth, final Integer numberofDays) { // first repayment's from date is same as disbursement date. LocalDate tmpFromDate = getDisbursementDate(); final PeriodFrequencyType repaymentPeriodFrequencyType = this.loanRepaymentScheduleDetail .getRepaymentPeriodFrequencyType(); final Integer loanRepaymentInterval = this.loanRepaymentScheduleDetail.getRepayEvery(); final String frequency = CalendarUtils .getMeetingFrequencyFromPeriodFrequencyType(repaymentPeriodFrequencyType); LocalDate newRepaymentDate = null; LocalDate seedDate = meetingStartDate; LocalDate latestRepaymentDate = null; List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments(); for (final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : installments) { LocalDate oldDueDate = loanRepaymentScheduleInstallment.getDueDate(); // FIXME: AA this won't update repayment dates before current date. if (oldDueDate.isAfter(seedDate) && oldDueDate.isAfter(DateUtils.getLocalDateOfTenant())) { newRepaymentDate = CalendarUtils.getNewRepaymentMeetingDate(recuringRule, seedDate, oldDueDate, loanRepaymentInterval, frequency, workingDays, isSkipRepaymentonfirstdayofmonth, numberofDays);//from w w w . j a v a 2s . c om final LocalDate maxDateLimitForNewRepayment = getMaxDateLimitForNewRepayment( repaymentPeriodFrequencyType, loanRepaymentInterval, tmpFromDate); if (newRepaymentDate.isAfter(maxDateLimitForNewRepayment)) { newRepaymentDate = CalendarUtils.getNextRepaymentMeetingDate(recuringRule, seedDate, tmpFromDate, loanRepaymentInterval, frequency, workingDays, isSkipRepaymentonfirstdayofmonth, numberofDays); } if (isHolidayEnabled) { newRepaymentDate = HolidayUtil.getRepaymentRescheduleDateToIfHoliday(newRepaymentDate, holidays); } if (latestRepaymentDate == null || latestRepaymentDate.isBefore(newRepaymentDate)) { latestRepaymentDate = newRepaymentDate; } loanRepaymentScheduleInstallment.updateDueDate(newRepaymentDate); // reset from date to get actual daysInPeriod loanRepaymentScheduleInstallment.updateFromDate(tmpFromDate); tmpFromDate = newRepaymentDate;// update with new repayment // date } else { tmpFromDate = oldDueDate; } } if (latestRepaymentDate != null) { this.expectedMaturityDate = latestRepaymentDate.toDate(); } }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public void applyHolidayToRepaymentScheduleDates(final Holiday holiday) { // first repayment's from date is same as disbursement date. LocalDate tmpFromDate = getDisbursementDate(); // Loop through all loanRepayments List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments(); for (final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : installments) { final LocalDate oldDueDate = loanRepaymentScheduleInstallment.getDueDate(); // update from date if it's not same as previous installament's due // date.//from www .j av a2 s.c o m if (!loanRepaymentScheduleInstallment.getFromDate().isEqual(tmpFromDate)) { loanRepaymentScheduleInstallment.updateFromDate(tmpFromDate); } if (oldDueDate.isAfter(holiday.getToDateLocalDate())) { break; } if (oldDueDate.equals(holiday.getFromDateLocalDate()) || oldDueDate.equals(holiday.getToDateLocalDate()) || oldDueDate.isAfter(holiday.getFromDateLocalDate()) && oldDueDate.isBefore(holiday.getToDateLocalDate())) { // FIXME: AA do we need to apply non-working days. // Assuming holiday's repayment reschedule to date cannot be // created on a non-working day. final LocalDate newRepaymentDate = holiday.getRepaymentsRescheduledToLocalDate(); loanRepaymentScheduleInstallment.updateDueDate(newRepaymentDate); } tmpFromDate = loanRepaymentScheduleInstallment.getDueDate(); } }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void validateActivityNotBeforeClientOrGroupTransferDate(final LoanEvent event, final LocalDate activityDate) { if (this.client != null && this.client.getOfficeJoiningLocalDate() != null) { final LocalDate clientOfficeJoiningDate = this.client.getOfficeJoiningLocalDate(); if (activityDate.isBefore(clientOfficeJoiningDate)) { String errorMessage = null; String action = null; String postfix = null; switch (event) { case LOAN_CREATED: errorMessage = "The date on which a loan is submitted cannot be earlier than client's transfer date to this office"; action = "submittal"; postfix = "cannot.be.before.client.transfer.date"; break; case LOAN_APPROVED: errorMessage = "The date on which a loan is approved cannot be earlier than client's transfer date to this office"; action = "approval"; postfix = "cannot.be.before.client.transfer.date"; break; case LOAN_APPROVAL_UNDO: errorMessage = "The date on which a loan is approved cannot be earlier than client's transfer date to this office"; action = "approval"; postfix = "cannot.be.undone.before.client.transfer.date"; break; case LOAN_DISBURSED: errorMessage = "The date on which a loan is disbursed cannot be earlier than client's transfer date to this office"; action = "disbursal"; postfix = "cannot.be.before.client.transfer.date"; break; case LOAN_DISBURSAL_UNDO: errorMessage = "Cannot undo a disbursal done in another branch"; action = "disbursal"; postfix = "cannot.be.undone.before.client.transfer.date"; break; case LOAN_REPAYMENT_OR_WAIVER: errorMessage = "The date on which a repayment or waiver is made cannot be earlier than client's transfer date to this office"; action = "repayment.or.waiver"; postfix = "cannot.be.made.before.client.transfer.date"; break; case LOAN_REJECTED: errorMessage = "The date on which a loan is rejected cannot be earlier than client's transfer date to this office"; action = "reject"; postfix = "cannot.be.before.client.transfer.date"; break; case LOAN_WITHDRAWN: errorMessage = "The date on which a loan is withdrawn cannot be earlier than client's transfer date to this office"; action = "withdraw"; postfix = "cannot.be.before.client.transfer.date"; break; case WRITE_OFF_OUTSTANDING: errorMessage = "The date on which a write off is made cannot be earlier than client's transfer date to this office"; action = "writeoff"; postfix = "cannot.be.undone.before.client.transfer.date"; break; case REPAID_IN_FULL: errorMessage = "The date on which the loan is repaid in full cannot be earlier than client's transfer date to this office"; action = "close"; postfix = "cannot.be.undone.before.client.transfer.date"; break; case LOAN_CHARGE_PAYMENT: errorMessage = "The date on which a charge payment is made cannot be earlier than client's transfer date to this office"; action = "charge.payment"; postfix = "cannot.be.made.before.client.transfer.date"; break; case LOAN_REFUND: errorMessage = "The date on which a refund is made cannot be earlier than client's transfer date to this office"; action = "refund"; postfix = "cannot.be.made.before.client.transfer.date"; break; case LOAN_DISBURSAL_UNDO_LAST: errorMessage = "Cannot undo a last disbursal in another branch"; action = "disbursal"; postfix = "cannot.be.undone.before.client.transfer.date"; break; default: break; }/* w w w .j a va 2s. co m*/ throw new InvalidLoanStateTransitionException(action, postfix, errorMessage, clientOfficeJoiningDate); } } }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public LocalDate getLastUserTransactionDate() { LocalDate currentTransactionDate = getDisbursementDate(); for (final LoanTransaction previousTransaction : this.loanTransactions) { if (!(previousTransaction.isReversed() || previousTransaction.isAccrual() || previousTransaction.isIncomePosting())) { if (currentTransactionDate.isBefore(previousTransaction.getTransactionDate())) { currentTransactionDate = previousTransaction.getTransactionDate(); }//w w w . j a va 2 s . c o m } } return currentTransactionDate; }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public LocalDate getLastRepaymentDate() { LocalDate currentTransactionDate = getDisbursementDate(); for (final LoanTransaction previousTransaction : this.loanTransactions) { if (previousTransaction.isRepayment()) { if (currentTransactionDate.isBefore(previousTransaction.getTransactionDate())) { currentTransactionDate = previousTransaction.getTransactionDate(); }// ww w . j a v a 2s . c om } } return currentTransactionDate; }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public void regenerateRepaymentScheduleWithInterestRecalculation(final ScheduleGeneratorDTO generatorDTO, final AppUser currentUser) { LocalDate lastTransactionDate = getLastUserTransactionDate(); final LoanScheduleDTO loanSchedule = getRecalculatedSchedule(generatorDTO); if (loanSchedule == null) { return;/* w w w . j a va 2s .c om*/ } updateLoanSchedule(loanSchedule.getInstallments(), currentUser); this.interestRecalculatedOn = DateUtils.getDateOfTenant(); LocalDate lastRepaymentDate = this.getLastRepaymentPeriodDueDate(true); Set<LoanCharge> charges = this.charges(); for (LoanCharge loanCharge : charges) { if (!loanCharge.isDueAtDisbursement()) { updateOverdueScheduleInstallment(loanCharge); if (loanCharge.getDueLocalDate() == null || (!lastRepaymentDate.isBefore(loanCharge.getDueLocalDate()))) { if (!loanCharge.isWaived() && (loanCharge.getDueLocalDate() == null || !lastTransactionDate.isAfter(loanCharge.getDueLocalDate()))) { recalculateLoanCharge(loanCharge, generatorDTO.getPenaltyWaitPeriod()); loanCharge.updateWaivedAmount(getCurrency()); } } else { loanCharge.setActive(false); } } } processPostDisbursementTransactions(); processIncomeTransactions(currentUser); }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void validateRefundDateIsAfterLastRepayment(final LocalDate refundTransactionDate) { final LocalDate possibleNextRefundDate = possibleNextRefundDate(); if (possibleNextRefundDate == null || refundTransactionDate.isBefore(possibleNextRefundDate)) { throw new InvalidRefundDateException(refundTransactionDate.toString()); }// w w w . ja va2 s .c om }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private ChangedTransactionDetail handleRefundTransaction(final LoanTransaction loanTransaction, final LoanLifecycleStateMachine loanLifecycleStateMachine, final LoanTransaction adjustedTransaction) { ChangedTransactionDetail changedTransactionDetail = null; final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_REFUND, LoanStatus.fromInt(this.loanStatus)); this.loanStatus = statusEnum.getValue(); loanTransaction.updateLoan(this); // final boolean isTransactionChronologicallyLatest = // isChronologicallyLatestRefund(loanTransaction, // this.loanTransactions); if (status().isOverpaid() || status().isClosed()) { final String errorMessage = "This refund option is only for active loans "; throw new InvalidLoanStateTransitionException("transaction", "is.exceeding.overpaid.amount", errorMessage, this.totalOverpaid, loanTransaction.getAmount(getCurrency()).getAmount()); } else if (this.getTotalPaidInRepayments().isZero()) { final String errorMessage = "Cannot refund when no payment has been made"; throw new InvalidLoanStateTransitionException("transaction", "no.payment.yet.made.for.loan", errorMessage);/*from w w w . ja v a 2 s . com*/ } if (loanTransaction.isNotZero(loanCurrency())) { addLoanTransaction(loanTransaction); } if (loanTransaction.isNotRefundForActiveLoan()) { final String errorMessage = "A transaction of type refund was expected but not received."; throw new InvalidLoanTransactionTypeException("transaction", "is.not.a.refund.transaction", errorMessage); } final LocalDate loanTransactionDate = loanTransaction.getTransactionDate(); if (loanTransactionDate.isBefore(getDisbursementDate())) { final String errorMessage = "The transaction date cannot be before the loan disbursement date: " + getApprovedOnDate().toString(); throw new InvalidLoanStateTransitionException("transaction", "cannot.be.before.disbursement.date", errorMessage, loanTransactionDate, getDisbursementDate()); } if (loanTransactionDate.isAfter(DateUtils.getLocalDateOfTenant())) { final String errorMessage = "The transaction date cannot be in the future."; throw new InvalidLoanStateTransitionException("transaction", "cannot.be.a.future.date", errorMessage, loanTransactionDate); } if (this.loanProduct.isMultiDisburseLoan() && adjustedTransaction == null) { BigDecimal totalDisbursed = getDisbursedAmount(); if (totalDisbursed.compareTo(this.summary.getTotalPrincipalRepaid()) < 0) { final String errorMessage = "The transaction cannot be done before the loan disbursement: " + getApprovedOnDate().toString(); throw new InvalidLoanStateTransitionException("transaction", "cannot.be.done.before.disbursement", errorMessage); } } final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory .determineProcessor(this.transactionProcessingStrategy); // If is a refund if (adjustedTransaction == null) { loanRepaymentScheduleTransactionProcessor.handleRefund(loanTransaction, getCurrency(), getRepaymentScheduleInstallments(), charges()); } else { final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement(); changedTransactionDetail = loanRepaymentScheduleTransactionProcessor.handleTransaction( getDisbursementDate(), allNonContraTransactionsPostDisbursement, getCurrency(), getRepaymentScheduleInstallments(), charges()); for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail .getNewTransactionMappings().entrySet()) { mapEntry.getValue().updateLoan(this); } } updateLoanSummaryDerivedFields(); doPostLoanTransactionChecks(loanTransaction.getTransactionDate(), loanLifecycleStateMachine); return changedTransactionDetail; }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public Map<String, Object> undoLastDisbursal(ScheduleGeneratorDTO scheduleGeneratorDTO, List<Long> existingTransactionIds, List<Long> existingReversedTransactionIds, AppUser currentUser, Loan loan) {//from w w w . j a v a 2 s. co m validateAccountStatus(LoanEvent.LOAN_DISBURSAL_UNDO_LAST); existingTransactionIds.addAll(findExistingTransactionIds()); existingReversedTransactionIds.addAll(findExistingReversedTransactionIds()); final Map<String, Object> actualChanges = new LinkedHashMap<>(); validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_DISBURSAL_UNDO_LAST, getDisbursementDate()); LocalDate actualDisbursementDate = null; LocalDate lastTransactionDate = getDisbursementDate(); List<LoanTransaction> loanTransactions = retreiveListOfTransactionsExcludeAccruals(); Collections.reverse(loanTransactions); for (final LoanTransaction previousTransaction : loanTransactions) { if (lastTransactionDate.isBefore(previousTransaction.getTransactionDate())) { if (previousTransaction.isRepayment() || previousTransaction.isWaiver() || previousTransaction.isChargePayment()) { throw new UndoLastTrancheDisbursementException(previousTransaction.getId()); } } if (previousTransaction.isDisbursement()) { lastTransactionDate = previousTransaction.getTransactionDate(); break; } } actualDisbursementDate = lastTransactionDate; updateLoanToLastDisbursalState(actualDisbursementDate); for (Iterator<LoanTermVariations> iterator = this.loanTermVariations.iterator(); iterator.hasNext();) { LoanTermVariations loanTermVariations = iterator.next(); if (loanTermVariations.getTermType().isDueDateVariation() && loanTermVariations.fetchDateValue().isAfter(actualDisbursementDate) || loanTermVariations.getTermType().isEMIAmountVariation() && loanTermVariations.getTermApplicableFrom().equals(actualDisbursementDate.toDate()) || loanTermVariations.getTermApplicableFrom().after(actualDisbursementDate.toDate())) { iterator.remove(); } } reverseExistingTransactionsTillLastDisbursal(actualDisbursementDate); loan.recalculateScheduleFromLastTransaction(scheduleGeneratorDTO, existingTransactionIds, existingReversedTransactionIds, currentUser); actualChanges.put("undolastdisbursal", "true"); actualChanges.put("disbursedAmount", this.getDisbursedAmount()); updateLoanSummaryDerivedFields(); return actualChanges; }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
/** * Reverse only disbursement, accruals, and repayments at disbursal * transactions/*from w w w.j av a2s.com*/ * * @param actualDisbursementDate * @return */ public List<LoanTransaction> reverseExistingTransactionsTillLastDisbursal(LocalDate actualDisbursementDate) { final List<LoanTransaction> reversedTransactions = new ArrayList<>(); for (final LoanTransaction transaction : this.loanTransactions) { if ((actualDisbursementDate.equals(transaction.getTransactionDate()) || actualDisbursementDate.isBefore(transaction.getTransactionDate())) && transaction.isAllowTypeTransactionAtTheTimeOfLastUndo()) { reversedTransactions.add(transaction); transaction.reverse(); } } return reversedTransactions; }