List of usage examples for org.joda.time LocalDate minusDays
public LocalDate minusDays(int days)
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.AbstractLoanScheduleGenerator.java
License:Apache License
/** * Method returns the amount payable to close the loan account as of today. *//* w w w.ja v a 2 s. co m*/ @Override public LoanRepaymentScheduleInstallment calculatePrepaymentAmount(final MonetaryCurrency currency, final LocalDate onDate, final LoanApplicationTerms loanApplicationTerms, final MathContext mc, Loan loan, final HolidayDetailDTO holidayDetailDTO, final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor) { LocalDate calculateTill = onDate; if (loanApplicationTerms.getPreClosureInterestCalculationStrategy().calculateTillRestFrequencyEnabled()) { calculateTill = getNextRestScheduleDate(onDate.minusDays(1), loanApplicationTerms, holidayDetailDTO); } LoanScheduleDTO loanScheduleDTO = rescheduleNextInstallments(mc, loanApplicationTerms, loan, holidayDetailDTO, loanRepaymentScheduleTransactionProcessor, onDate, calculateTill); List<LoanTransaction> loanTransactions = loan.retreiveListOfTransactionsPostDisbursementExcludeAccruals(); loanRepaymentScheduleTransactionProcessor.handleTransaction( loanApplicationTerms.getExpectedDisbursementDate(), loanTransactions, currency, loanScheduleDTO.getInstallments(), loan.charges()); Money feeCharges = Money.zero(currency); Money penaltyCharges = Money.zero(currency); Money totalPrincipal = Money.zero(currency); Money totalInterest = Money.zero(currency); for (final LoanRepaymentScheduleInstallment currentInstallment : loanScheduleDTO.getInstallments()) { if (currentInstallment.isNotFullyPaidOff()) { totalPrincipal = totalPrincipal.plus(currentInstallment.getPrincipalOutstanding(currency)); totalInterest = totalInterest.plus(currentInstallment.getInterestOutstanding(currency)); feeCharges = feeCharges.plus(currentInstallment.getFeeChargesOutstanding(currency)); penaltyCharges = penaltyCharges.plus(currentInstallment.getPenaltyChargesOutstanding(currency)); } } final Set<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails = null; return new LoanRepaymentScheduleInstallment(null, 0, onDate, onDate, totalPrincipal.getAmount(), totalInterest.getAmount(), feeCharges.getAmount(), penaltyCharges.getAmount(), false, compoundingDetails); }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
@Override public LocalDate idealDisbursementDateBasedOnFirstRepaymentDate( final PeriodFrequencyType repaymentPeriodFrequencyType, final int repaidEvery, final LocalDate firstRepaymentDate, final Calendar loanCalendar, final HolidayDetailDTO holidayDetailDTO, final LoanApplicationTerms loanApplicationTerms) { LocalDate idealDisbursementDate = null; switch (repaymentPeriodFrequencyType) { case DAYS:/*from www . ja v a 2s.com*/ idealDisbursementDate = firstRepaymentDate.minusDays(repaidEvery); break; case WEEKS: idealDisbursementDate = firstRepaymentDate.minusWeeks(repaidEvery); break; case MONTHS: if (loanCalendar == null) { idealDisbursementDate = firstRepaymentDate.minusMonths(repaidEvery); } else { idealDisbursementDate = CalendarUtils.getNewRepaymentMeetingDate(loanCalendar.getRecurrence(), firstRepaymentDate.minusMonths(repaidEvery), firstRepaymentDate.minusMonths(repaidEvery), repaidEvery, CalendarUtils.getMeetingFrequencyFromPeriodFrequencyType(repaymentPeriodFrequencyType), holidayDetailDTO.getWorkingDays(), loanApplicationTerms.isSkipRepaymentOnFirstDayofMonth(), loanApplicationTerms.getNumberOfdays()); } break; case YEARS: idealDisbursementDate = firstRepaymentDate.minusYears(repaidEvery); break; case INVALID: break; } return idealDisbursementDate; }
From source file:com.gst.portfolio.loanaccount.service.LoanWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
public LoanOverdueDTO applyChargeToOverdueLoanInstallment(final Long loanId, final Long loanChargeId, final Integer periodNumber, final JsonCommand command, Loan loan, final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds) { boolean runInterestRecalculation = false; final Charge chargeDefinition = this.chargeRepository.findOneWithNotFoundDetection(loanChargeId); Collection<Integer> frequencyNumbers = loanChargeReadPlatformService .retrieveOverdueInstallmentChargeFrequencyNumber(loanId, chargeDefinition.getId(), periodNumber); Integer feeFrequency = chargeDefinition.feeFrequency(); final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator(); Map<Integer, LocalDate> scheduleDates = new HashMap<>(); final Long penaltyWaitPeriodValue = this.configurationDomainService.retrievePenaltyWaitPeriod(); final Long penaltyPostingWaitPeriodValue = this.configurationDomainService .retrieveGraceOnPenaltyPostingPeriod(); final LocalDate dueDate = command.localDateValueOfParameterNamed("dueDate"); Long diff = penaltyWaitPeriodValue + 1 - penaltyPostingWaitPeriodValue; if (diff < 0) { diff = 0L;/*from w ww. j a v a2s. c o m*/ } LocalDate startDate = dueDate.plusDays(penaltyWaitPeriodValue.intValue() + 1); Integer frequencyNunber = 1; if (feeFrequency == null) { scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue())); } else { while (DateUtils.getLocalDateOfTenant().isAfter(startDate)) { scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue())); LocalDate scheduleDate = scheduledDateGenerator.getRepaymentPeriodDate( PeriodFrequencyType.fromInt(feeFrequency), chargeDefinition.feeInterval(), startDate, null, null); startDate = scheduleDate; } } for (Integer frequency : frequencyNumbers) { scheduleDates.remove(frequency); } LoanRepaymentScheduleInstallment installment = null; LocalDate lastChargeAppliedDate = dueDate; if (!scheduleDates.isEmpty()) { if (loan == null) { loan = this.loanAssembler.assembleFrom(loanId); checkClientOrGroupActive(loan); existingTransactionIds.addAll(loan.findExistingTransactionIds()); existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds()); } installment = loan.fetchRepaymentScheduleInstallment(periodNumber); lastChargeAppliedDate = installment.getDueDate(); } LocalDate recalculateFrom = DateUtils.getLocalDateOfTenant(); if (loan != null) { this.businessEventNotifierService.notifyBusinessEventToBeExecuted( BUSINESS_EVENTS.LOAN_APPLY_OVERDUE_CHARGE, constructEntityMap(BUSINESS_ENTITY.LOAN, loan)); for (Map.Entry<Integer, LocalDate> entry : scheduleDates.entrySet()) { final LoanCharge loanCharge = LoanCharge.createNewFromJson(loan, chargeDefinition, command, entry.getValue()); LoanOverdueInstallmentCharge overdueInstallmentCharge = new LoanOverdueInstallmentCharge(loanCharge, installment, entry.getKey()); loanCharge.updateOverdueInstallmentCharge(overdueInstallmentCharge); boolean isAppliedOnBackDate = addCharge(loan, chargeDefinition, loanCharge); runInterestRecalculation = runInterestRecalculation || isAppliedOnBackDate; if (entry.getValue().isBefore(recalculateFrom)) { recalculateFrom = entry.getValue(); } if (entry.getValue().isAfter(lastChargeAppliedDate)) { lastChargeAppliedDate = entry.getValue(); } } } return new LoanOverdueDTO(loan, runInterestRecalculation, recalculateFrom, lastChargeAppliedDate); }
From source file:com.gst.portfolio.savings.domain.FixedDepositAccount.java
License:Apache License
public void updateMaturityDateAndAmount(final MathContext mc, final List<SavingsAccountTransaction> transactions, final boolean isPreMatureClosure, final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth) { final LocalDate maturityDate = calculateMaturityDate(); final LocalDate interestCalculationUpto = maturityDate.minusDays(1); // set end of day balance to maturity date for maturity interest // calculation this.resetAccountTransactionsEndOfDayBalances(transactions, maturityDate); final List<PostingPeriod> postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, transactions, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); // reset end of day balance back to today's date this.resetAccountTransactionsEndOfDayBalances(transactions, DateUtils.getLocalDateOfTenant()); Money totalInterestPayable = Money.zero(getCurrency()); for (PostingPeriod postingPeriod : postingPeriods) { totalInterestPayable = totalInterestPayable.plus(postingPeriod.getInterestEarned()); }/*ww w. j a v a2 s . c om*/ final Money depositAmount = Money.of(getCurrency(), this.accountTermAndPreClosure.depositAmount()); final Money maturityAmount = depositAmount.plus(totalInterestPayable); this.accountTermAndPreClosure.updateMaturityDetails(maturityAmount.getAmount(), maturityDate); }
From source file:com.gst.portfolio.savings.domain.FixedDepositAccount.java
License:Apache License
public void postPreMaturityInterest(final LocalDate accountCloseDate, final boolean isPreMatureClosure, final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth) { Money interestPostedToDate = totalInterestPosted(); // calculate interest before one day of closure date final LocalDate interestCalculatedToDate = accountCloseDate.minusDays(1); final Money interestOnMaturity = calculatePreMatureInterest(interestCalculatedToDate, retreiveOrderedNonInterestPostingTransactions(), isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); boolean recalucateDailyBalance = false; // post remaining interest final Money remainigInterestToBePosted = interestOnMaturity.minus(interestPostedToDate); if (!remainigInterestToBePosted.isZero()) { final boolean postInterestAsOn = false; final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(), accountCloseDate, remainigInterestToBePosted, postInterestAsOn); this.transactions.add(newPostingTransaction); recalucateDailyBalance = true;/* w ww. ja va 2 s. c o m*/ } recalucateDailyBalance = applyWithholdTaxForDepositAccounts(accountCloseDate, recalucateDailyBalance); if (recalucateDailyBalance) { // update existing transactions so derived balance fields are // correct. recalculateDailyBalances(Money.zero(this.currency), accountCloseDate); } this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); this.accountTermAndPreClosure.updateMaturityDetails(this.getAccountBalance(), accountCloseDate); }
From source file:com.gst.portfolio.savings.domain.FixedDepositAccount.java
License:Apache License
private LocalDate interestCalculatedUpto() { LocalDate uptoMaturityDate = calculateMaturityDate(); if (uptoMaturityDate != null) { // interest should not be calculated for maturity day uptoMaturityDate = uptoMaturityDate.minusDays(1); }// w w w .j a v a 2 s . com return uptoMaturityDate; }
From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java
License:Apache License
public void updateMaturityDateAndAmount(final MathContext mc, final boolean isPreMatureClosure, final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth) { final LocalDate maturityDate = calculateMaturityDate(); LocalDate interestCalculationUpto = null; List<SavingsAccountTransaction> allTransactions = null; if (maturityDate == null) { interestCalculationUpto = DateUtils.getLocalDateOfTenant(); allTransactions = getTransactions(interestCalculationUpto, false); } else {// ww w. j a va 2 s . c om interestCalculationUpto = maturityDate.minusDays(1); allTransactions = getTransactions(interestCalculationUpto, true); } final List<PostingPeriod> postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, allTransactions, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); Money totalInterestPayable = Money.zero(getCurrency()); Money totalDepositAmount = Money.zero(getCurrency()); for (PostingPeriod postingPeriod : postingPeriods) { totalInterestPayable = totalInterestPayable.plus(postingPeriod.getInterestEarned()); totalDepositAmount = totalDepositAmount.plus(postingPeriod.closingBalance()) .minus(postingPeriod.openingBalance()); } if (maturityDate == null) { this.accountTermAndPreClosure.updateDepositAmount(totalDepositAmount.getAmount()); } else { this.accountTermAndPreClosure.updateMaturityDetails(totalDepositAmount.getAmount(), totalInterestPayable.getAmount(), maturityDate); } }
From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java
License:Apache License
public void postMaturityInterest(final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth, final LocalDate closeDate) { LocalDate interestPostingUpToDate = maturityDate(); if (interestPostingUpToDate == null) { interestPostingUpToDate = closeDate; }//from w w w . j a v a 2 s. c o m final MathContext mc = MathContext.DECIMAL64; boolean isInterestTransfer = false; LocalDate postInterestOnDate = null; final List<PostingPeriod> postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate.minusDays(1), isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); Money interestPostedToDate = Money.zero(this.currency); boolean recalucateDailyBalanceDetails = false; for (final PostingPeriod interestPostingPeriod : postingPeriods) { LocalDate interestPostingTransactionDate = interestPostingPeriod.dateOfPostingTransaction(); interestPostingTransactionDate = interestPostingTransactionDate.isAfter(interestPostingUpToDate) ? interestPostingUpToDate : interestPostingTransactionDate; final Money interestEarnedToBePostedForPeriod = interestPostingPeriod.getInterestEarned(); interestPostedToDate = interestPostedToDate.plus(interestEarnedToBePostedForPeriod); final SavingsAccountTransaction postingTransaction = findInterestPostingTransactionFor( interestPostingTransactionDate); if (postingTransaction == null) { final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting( this, office(), interestPostingTransactionDate, interestEarnedToBePostedForPeriod, interestPostingPeriod.isUserPosting()); addTransaction(newPostingTransaction); recalucateDailyBalanceDetails = true; } else { final boolean correctionRequired = postingTransaction .hasNotAmount(interestEarnedToBePostedForPeriod); if (correctionRequired) { postingTransaction.reverse(); final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction .interestPosting(this, office(), interestPostingTransactionDate, interestEarnedToBePostedForPeriod, interestPostingPeriod.isUserPosting()); addTransaction(newPostingTransaction); recalucateDailyBalanceDetails = true; } } } applyWithholdTaxForDepositAccounts(interestPostingUpToDate, recalucateDailyBalanceDetails); if (recalucateDailyBalanceDetails) { // update existing transactions so derived balance fields are // correct. recalculateDailyBalances(Money.zero(this.currency), interestPostingUpToDate); } this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); }
From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java
License:Apache License
public void postPreMaturityInterest(final LocalDate accountCloseDate, final boolean isPreMatureClosure, final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth) { final Money interestPostedToDate = totalInterestPosted(); // calculate interest before one day of closure date final LocalDate interestCalculatedToDate = accountCloseDate.minusDays(1); final Money interestOnMaturity = calculatePreMatureInterest(interestCalculatedToDate, retreiveOrderedNonInterestPostingTransactions(), isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); boolean recalucateDailyBalance = false; // post remaining interest final Money remainigInterestToBePosted = interestOnMaturity.minus(interestPostedToDate); if (!remainigInterestToBePosted.isZero()) { final boolean postInterestAsOn = false; final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(), accountCloseDate, remainigInterestToBePosted, postInterestAsOn); addTransaction(newPostingTransaction); recalucateDailyBalance = true;/*from www. ja v a 2s . c o m*/ } applyWithholdTaxForDepositAccounts(accountCloseDate, recalucateDailyBalance); if (recalucateDailyBalance) { // update existing transactions so derived balance fields are // correct. recalculateDailyBalances(Money.zero(this.currency), accountCloseDate); } this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); this.accountTermAndPreClosure.updateMaturityDetails(this.getAccountBalance(), accountCloseDate); }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
public void updateToPreviousDueDate() { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { LocalDate nextDueLocalDate = new LocalDate(dueDate); if (isAnnualFee()) { nextDueLocalDate = nextDueLocalDate.withMonthOfYear(this.feeOnMonth).minusYears(1); nextDueLocalDate = setDayOfMonth(nextDueLocalDate); } else if (isMonthlyFee()) { nextDueLocalDate = nextDueLocalDate.minusMonths(this.feeInterval); nextDueLocalDate = setDayOfMonth(nextDueLocalDate); } else if (isWeeklyFee()) { nextDueLocalDate = nextDueLocalDate.minusDays(7 * this.feeInterval); nextDueLocalDate = setDayOfWeek(nextDueLocalDate); }/*from w ww .j a v a2 s . co m*/ this.dueDate = nextDueLocalDate.toDate(); } }