List of usage examples for org.joda.time LocalDate toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. From source file:org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetReadPlatformServiceImpl.java
License:Apache License
@Override public JLGCollectionSheetData generateGroupCollectionSheet(final Long groupId, final JsonQuery query) { this.collectionSheetGenerateCommandFromApiJsonDeserializer.validateForGenerateCollectionSheet(query.json()); final Long calendarId = query.longValueOfParameterNamed(calendarIdParamName); final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); final String transactionDateStr = df.format(transactionDate.toDate()); final Calendar calendar = this.calendarRepositoryWrapper.findOneWithNotFoundDetection(calendarId); // check if transaction against calendar effective from date if (!calendar.isValidRecurringDate(transactionDate)) { throw new NotValidRecurringDateException("collectionsheet", "The date '" + transactionDate + "' is not a valid meeting date.", transactionDate); }// w w w . ja va 2s . c o m final AppUser currentUser = this.context.authenticatedUser(); final String hierarchy = currentUser.getOffice().getHierarchy(); final String officeHierarchy = hierarchy + "%"; final GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId); final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper(); // entityType should be center if it's within a center final CalendarEntityType entityType = (group.isChildGroup()) ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS; final SqlParameterSource namedParameters = new MapSqlParameterSource() .addValue("dueDate", transactionDateStr).addValue("groupId", group.getId()) .addValue("officeHierarchy", officeHierarchy).addValue("entityTypeId", entityType.getValue()); final Collection<JLGCollectionSheetFlatData> collectionSheetFlatDatas = this.namedParameterjdbcTemplate .query(mapper.collectionSheetSchema(false), namedParameters, mapper); // loan data for collection sheet JLGCollectionSheetData collectionSheetData = buildJLGCollectionSheet(transactionDate, collectionSheetFlatDatas); // mandatory savings data for collection sheet Collection<JLGGroupData> groupsWithSavingsData = this.namedParameterjdbcTemplate.query( mandatorySavingsExtractor.collectionSheetSchema(false), namedParameters, mandatorySavingsExtractor); // merge savings data into loan data mergeSavingsGroupDataIntoCollectionsheetData(groupsWithSavingsData, collectionSheetData); collectionSheetData = JLGCollectionSheetData.withSavingsProducts(collectionSheetData, retrieveSavingsProducts(groupsWithSavingsData)); return collectionSheetData; }
From source file:org.apache.fineract.portfolio.floatingrates.domain.FloatingRate.java
License:Apache License
public static FloatingRate createNew(AppUser currentUser, JsonCommand command) { final String name = command.stringValueOfParameterNamed("name"); final boolean isBaseLendingRate = command.parameterExists("isBaseLendingRate") ? command.booleanPrimitiveValueOfParameterNamed("isBaseLendingRate") : false;/*ww w . ja v a2 s .c om*/ final boolean isActive = command.parameterExists("isActive") ? command.booleanPrimitiveValueOfParameterNamed("isActive") : true; final Set<FloatingRatePeriod> floatingRatePeriods = getRatePeriods(currentUser, command); final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); return new FloatingRate(name, isBaseLendingRate, isActive, floatingRatePeriods, currentUser, currentUser, currentDate.toDate(), currentDate.toDate()); }
From source file:org.apache.fineract.portfolio.floatingrates.domain.FloatingRate.java
License:Apache License
private void updateRatePeriods(final Set<FloatingRatePeriod> newRatePeriods, final AppUser appUser) { final LocalDate today = DateUtils.getLocalDateOfTenant(); if (this.floatingRatePeriods != null) { for (FloatingRatePeriod ratePeriod : this.floatingRatePeriods) { LocalDate fromDate = LocalDate.fromDateFields(ratePeriod.getFromDate()); if (fromDate.isAfter(today)) { ratePeriod.setActive(false); ratePeriod.setModifiedBy(appUser); ratePeriod.setModifiedOn(today.toDate()); }/* w w w . java 2 s .co m*/ } } for (FloatingRatePeriod newRatePeriod : newRatePeriods) { newRatePeriod.updateFloatingRate(this); this.floatingRatePeriods.add(newRatePeriod); } }
From source file:org.apache.fineract.portfolio.group.service.GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private void validateLoansAndSavingsForGroupOrCenterClose(final Group groupOrCenter, final LocalDate closureDate) { final Collection<Loan> groupLoans = this.loanRepository.findByGroupId(groupOrCenter.getId()); for (final Loan loan : groupLoans) { final LoanStatusMapper loanStatus = new LoanStatusMapper(loan.status().getValue()); if (loanStatus.isOpen()) { final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() + " cannot be closed because of non-closed loans."; throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "loan.not.closed", errorMessage); } else if (loanStatus.isClosed() && loan.getClosedOnDate().after(closureDate.toDate())) { final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() + "closureDate cannot be before the loan closedOnDate."; throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "date.cannot.before.loan.closed.date", errorMessage, closureDate, loan.getClosedOnDate()); } else if (loanStatus.isPendingApproval()) { final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() + " cannot be closed because of non-closed loans."; throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "loan.not.closed", errorMessage); } else if (loanStatus.isAwaitingDisbursal()) { final String errorMessage = "Group cannot be closed because of non-closed loans."; throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "loan.not.closed", errorMessage); }//from w w w . j a v a 2s. c om } final List<SavingsAccount> groupSavingAccounts = this.savingsRepository .findByGroupId(groupOrCenter.getId()); for (final SavingsAccount saving : groupSavingAccounts) { if (saving.isActive() || saving.isSubmittedAndPendingApproval() || saving.isApproved()) { final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() + " cannot be closed with active savings accounts associated."; throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "savings.account.not.closed", errorMessage); } else if (saving.isClosed() && saving.getClosedOnDate().isAfter(closureDate)) { final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() + " closureDate cannot be before the loan closedOnDate."; throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "date.cannot.before.loan.closed.date", errorMessage, closureDate, saving.getClosedOnDate()); } } }
From source file:org.apache.fineract.portfolio.interestratechart.domain.InterestRateChartFields.java
License:Apache License
private InterestRateChartFields(String name, String description, LocalDate fromDate, LocalDate toDate) { this.name = name; this.description = description; this.fromDate = fromDate.toDate(); this.endDate = (toDate == null) ? null : toDate.toDate(); }
From source file:org.apache.fineract.portfolio.loanaccount.domain.Loan.java
License:Apache License
/** * Update interest recalculation settings if product configuration changes *///from w w w . ja v a 2 s .c om public void updateLoanInterestRecalculationSettings(final LocalDate recalculationRestFrequencyDate, final LocalDate recalculationCompoundingFrequencyDate, final JsonCommand command, final Map<String, Object> actualChanges) { if (isInterestRecalculationEnabledForProduct()) { Date restFrequencyDate = null; if (recalculationRestFrequencyDate != null) { restFrequencyDate = recalculationRestFrequencyDate.toDate(); } Date compoundingFrequencyDate = null; if (recalculationCompoundingFrequencyDate != null) { compoundingFrequencyDate = recalculationCompoundingFrequencyDate.toDate(); } if (this.loanInterestRecalculationDetails == null) { actualChanges.put(LoanProductConstants.isInterestRecalculationEnabledParameterName, true); this.loanInterestRecalculationDetails = LoanInterestRecalculationDetails.createFrom( this.loanProduct.getProductInterestRecalculationDetails() .getInterestRecalculationCompoundingMethod(), this.loanProduct.getProductInterestRecalculationDetails().getRescheduleStrategyMethod(), this.loanProduct.getProductInterestRecalculationDetails().getRestFrequencyType().getValue(), this.loanProduct.getProductInterestRecalculationDetails().getRestInterval(), restFrequencyDate, this.loanProduct.getProductInterestRecalculationDetails().getCompoundingFrequencyType() .getValue(), this.loanProduct.getProductInterestRecalculationDetails().getCompoundingInterval(), compoundingFrequencyDate); this.loanInterestRecalculationDetails.updateLoan(this); } else { this.loanInterestRecalculationDetails.update(command, actualChanges); } } else { this.loanInterestRecalculationDetails = null; } }
From source file:org.apache.fineract.portfolio.loanaccount.domain.Loan.java
License:Apache License
public void loanApplicationSubmittal(final AppUser currentUser, final LoanScheduleModel loanSchedule, final LoanApplicationTerms loanApplicationTerms, final LoanLifecycleStateMachine lifecycleStateMachine, final LocalDate submittedOn, final String externalId, final boolean allowTransactionsOnHoliday, final List<Holiday> holidays, final WorkingDays workingDays, final boolean allowTransactionsOnNonWorkingDay, final LocalDate recalculationRestFrequencyDate, final LocalDate recalculationCompoundingFrequencyDate) { updateLoanSchedule(loanSchedule, currentUser); LoanStatus from = null;//from w w w. j av a2 s . c o m if (this.loanStatus != null) { from = LoanStatus.fromInt(this.loanStatus); } final LoanStatus statusEnum = lifecycleStateMachine.transition(LoanEvent.LOAN_CREATED, from); this.loanStatus = statusEnum.getValue(); this.externalId = externalId; this.termFrequency = loanApplicationTerms.getLoanTermFrequency(); this.termPeriodFrequencyType = loanApplicationTerms.getLoanTermPeriodFrequencyType().getValue(); this.submittedOnDate = submittedOn.toDate(); this.submittedBy = currentUser; this.expectedDisbursementDate = loanApplicationTerms.getExpectedDisbursementDate().toDate(); this.expectedFirstRepaymentOnDate = loanApplicationTerms.getRepaymentStartFromDate(); this.interestChargedFromDate = loanApplicationTerms.getInterestChargedFromDate(); if (loanApplicationTerms.getRepaymentPeriodFrequencyType() == PeriodFrequencyType.MONTHS) { this.repaymentFrequencyNthDayType = loanApplicationTerms.getNthDay(); this.repaymentFrequencyDayOfWeekType = loanApplicationTerms.getWeekDayType().getValue(); } else { this.repaymentFrequencyNthDayType = NthDayType.INVALID.getValue(); this.repaymentFrequencyDayOfWeekType = DayOfWeekType.INVALID.getValue(); } updateLoanScheduleDependentDerivedFields(); if (submittedOn.isAfter(DateUtils.getLocalDateOfTenant())) { final String errorMessage = "The date on which a loan is submitted cannot be in the future."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.a.future.date", errorMessage, submittedOn); } if (this.client != null && this.client.isActivatedAfter(submittedOn)) { final String errorMessage = "The date on which a loan is submitted cannot be earlier than client's activation date."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.client.activation.date", errorMessage, submittedOn); } validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_CREATED, submittedOn); if (this.group != null && this.group.isActivatedAfter(submittedOn)) { final String errorMessage = "The date on which a loan is submitted cannot be earlier than groups's activation date."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.group.activation.date", errorMessage, submittedOn); } if (submittedOn.isAfter(getExpectedDisbursedOnLocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: " + getExpectedDisbursedOnLocalDate().toString(); throw new InvalidLoanStateTransitionException("submittal", "cannot.be.after.expected.disbursement.date", errorMessage, submittedOn, getExpectedDisbursedOnLocalDate()); } // charges are optional int penaltyWaitPeriod = 0; for (final LoanCharge loanCharge : charges()) { recalculateLoanCharge(loanCharge, penaltyWaitPeriod); } updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement()); // validate if disbursement date is a holiday or a non-working day validateDisbursementDateIsOnNonWorkingDay(workingDays, allowTransactionsOnNonWorkingDay); validateDisbursementDateIsOnHoliday(allowTransactionsOnHoliday, holidays); /** * Copy interest recalculation settings if interest recalculation is * enabled */ if (this.loanRepaymentScheduleDetail.isInterestRecalculationEnabled()) { Date restFrequencyDate = null; if (recalculationRestFrequencyDate != null) { restFrequencyDate = recalculationRestFrequencyDate.toDate(); } Date compoundingFrequencyDate = null; if (recalculationCompoundingFrequencyDate != null) { compoundingFrequencyDate = recalculationCompoundingFrequencyDate.toDate(); } this.loanInterestRecalculationDetails = LoanInterestRecalculationDetails.createFrom( this.loanProduct.getProductInterestRecalculationDetails() .getInterestRecalculationCompoundingMethod(), this.loanProduct.getProductInterestRecalculationDetails().getRescheduleStrategyMethod(), this.loanProduct.getProductInterestRecalculationDetails().getRestFrequencyType().getValue(), this.loanProduct.getProductInterestRecalculationDetails().getRestInterval(), restFrequencyDate, this.loanProduct.getProductInterestRecalculationDetails().getCompoundingFrequencyType() .getValue(), this.loanProduct.getProductInterestRecalculationDetails().getCompoundingInterval(), compoundingFrequencyDate); this.loanInterestRecalculationDetails.updateLoan(this); } }
From source file:org.apache.fineract.portfolio.loanaccount.domain.Loan.java
License:Apache License
public void regenerateScheduleOnDisbursement(final ScheduleGeneratorDTO scheduleGeneratorDTO, final boolean recalculateSchedule, final LocalDate actualDisbursementDate, BigDecimal emiAmount, final AppUser currentUser, LocalDate nextPossibleRepaymentDate, Date rescheduledRepaymentDate) { boolean isEmiAmountChanged = false; if ((this.loanProduct.isMultiDisburseLoan() || this.loanProduct.canDefineInstallmentAmount()) && emiAmount != null && emiAmount.compareTo(retriveLastEmiAmount()) != 0) { if (this.loanProduct.isMultiDisburseLoan()) { final Date dateValue = null; final boolean isSpecificToInstallment = false; LoanTermVariations loanVariationTerms = new LoanTermVariations( LoanTermVariationType.EMI_AMOUNT.getValue(), actualDisbursementDate.toDate(), emiAmount, dateValue, isSpecificToInstallment, this, LoanStatus.ACTIVE.getValue()); this.loanTermVariations.add(loanVariationTerms); } else {/* w ww. j a va 2s. c o m*/ this.fixedEmiAmount = emiAmount; } isEmiAmountChanged = true; } if (rescheduledRepaymentDate != null && this.loanProduct.isMultiDisburseLoan()) { final boolean isSpecificToInstallment = false; LoanTermVariations loanVariationTerms = new LoanTermVariations( LoanTermVariationType.DUE_DATE.getValue(), nextPossibleRepaymentDate.toDate(), emiAmount, rescheduledRepaymentDate, isSpecificToInstallment, this, LoanStatus.ACTIVE.getValue()); this.loanTermVariations.add(loanVariationTerms); } if (isRepaymentScheduleRegenerationRequiredForDisbursement(actualDisbursementDate) || recalculateSchedule || isEmiAmountChanged) { regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser); } }
From source file:org.apache.fineract.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void handleDisbursementTransaction(final LocalDate disbursedOn, final LocalDateTime createdDate, final AppUser currentUser) { // add repayment transaction to track incoming money from client to mfi // for (charges due at time of disbursement) /***//w ww .ja v a 2 s. c om * TODO Vishwas: do we need to be able to pass in payment type details * for repayments at disbursements too? ***/ final Money totalFeeChargesDueAtDisbursement = this.summary .getTotalFeeChargesDueAtDisbursement(loanCurrency()); /** * all Charges repaid at disbursal is marked as repaid and * "APPLY Charge" transactions are created for all other fees ( which * are created during disbursal but not repaid) **/ Money disbursentMoney = Money.zero(getCurrency()); final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(getOffice(), disbursentMoney, null, disbursedOn, null, createdDate, currentUser); final Integer installmentNumber = null; for (final LoanCharge charge : charges()) { Date actualDisbursementDate = getActualDisbursementDate(charge); if (charge.getCharge().getChargeTimeType() == ChargeTimeType.DISBURSEMENT.getValue() || (charge.getCharge().getChargeTimeType() == ChargeTimeType.TRANCHE_DISBURSEMENT.getValue() && disbursedOn.equals(new LocalDate(actualDisbursementDate)) && actualDisbursementDate != null && !charge.isWaived() && !charge.isFullyPaid())) { if (totalFeeChargesDueAtDisbursement.isGreaterThanZero() && !charge.getChargePaymentMode().isPaymentModeAccountTransfer()) { charge.markAsFullyPaid(); // Add "Loan Charge Paid By" details to this transaction final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(chargesPayment, charge, charge.amount(), installmentNumber); chargesPayment.getLoanChargesPaid().add(loanChargePaidBy); disbursentMoney = disbursentMoney.plus(charge.amount()); } } else if (disbursedOn.equals(new LocalDate(this.actualDisbursementDate))) { /** * create a Charge applied transaction if Up front Accrual, None * or Cash based accounting is enabled **/ if (isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct()) { handleChargeAppliedTransaction(charge, disbursedOn, currentUser); } } } if (disbursentMoney.isGreaterThanZero()) { final Money zero = Money.zero(getCurrency()); chargesPayment.updateComponentsAndTotal(zero, zero, disbursentMoney, zero); chargesPayment.updateLoan(this); this.loanTransactions.add(chargesPayment); updateLoanOutstandingBalaces(); } if (getApprovedOnDate() != null && disbursedOn.isBefore(getApprovedOnDate())) { final String errorMessage = "The date on which a loan is disbursed cannot be before its approval date: " + getApprovedOnDate().toString(); throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.before.approval.date", errorMessage, disbursedOn, getApprovedOnDate()); } if (getExpectedFirstRepaymentOnDate() != null && (disbursedOn.isAfter(this.fetchRepaymentScheduleInstallment(1).getDueDate()) || disbursedOn.isAfter(getExpectedFirstRepaymentOnDate())) && disbursedOn.toDate().equals(this.actualDisbursementDate)) { final String errorMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate: " + getExpectedFirstRepaymentOnDate().toString(); throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.after.expected.first.repayment.date", errorMessage, disbursedOn, getExpectedFirstRepaymentOnDate()); } validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_DISBURSED, disbursedOn); if (disbursedOn.isAfter(new LocalDate())) { final String errorMessage = "The date on which a loan with identifier : " + this.accountNumber + " is disbursed cannot be in the future."; throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.a.future.date", errorMessage, disbursedOn); } }
From source file:org.apache.fineract.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void handleLoanRepaymentInFull(final LocalDate transactionDate, final LoanLifecycleStateMachine loanLifecycleStateMachine) { boolean isAllChargesPaid = true; for (final LoanCharge loanCharge : this.charges) { if (loanCharge.isActive() && !(loanCharge.isPaid() || loanCharge.isWaived())) { isAllChargesPaid = false;// ww w .j a va2s . co m break; } } if (isAllChargesPaid) { final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.REPAID_IN_FULL, LoanStatus.fromInt(this.loanStatus)); this.loanStatus = statusEnum.getValue(); this.closedOnDate = transactionDate.toDate(); this.actualMaturityDate = transactionDate.toDate(); } else if (LoanStatus.fromInt(this.loanStatus).isOverpaid()) { final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_REPAYMENT_OR_WAIVER, LoanStatus.fromInt(this.loanStatus)); this.loanStatus = statusEnum.getValue(); } }