List of usage examples for org.joda.time LocalDate now
public static LocalDate now()
ISOChronology
in the default time zone. From source file:org.libreplan.web.users.hierarchy.UserSuperiorModel.java
License:Open Source License
@Override public void initCreate(User user) { superior = UserSuperior.create(); superior.setUser(user); superior.setFromDate(LocalDate.now()); }
From source file:org.libreplan.web.users.hierarchy.UserSuperiorModel.java
License:Open Source License
@Override public UserSuperior findUserSuperior(User user) { return findUserSuperior(user, LocalDate.now()); }
From source file:org.mifosplatform.infrastructure.sms.domain.SmsMessage.java
License:Mozilla Public License
private SmsMessage(final Long externalId, final Group group, final Client client, final Staff staff, final SmsMessageStatusType statusType, final String message, final String sourceAddress, final String mobileNo, final String campaignName) { this.externalId = externalId; this.group = group; this.client = client; this.staff = staff; this.statusType = statusType.getValue(); this.mobileNo = mobileNo; this.sourceAddress = sourceAddress; this.message = message; this.campaignName = campaignName; this.submittedOnDate = LocalDate.now().toDate(); }
From source file:org.mifosplatform.portfolio.client.command.ClientIdentifierCommand.java
License:Mozilla Public License
public void validateForCreate() { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("clientIdentifier"); baseDataValidator.reset().parameter("documentTypeId").value(this.documentTypeId).notNull() .integerGreaterThanZero();/* w ww. jav a2 s.c om*/ baseDataValidator.reset().parameter("documentKey").value(this.documentKey).notBlank(); baseDataValidator.reset().parameter("validity").value(this.validity) .validateDateAfter(LocalDate.now().plusMonths(1)).ignoreIfNull(); baseDataValidator.reset().parameter("isLifeTime").value(this.isLifeTime).ignoreIfNull(); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } }
From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java
License:Mozilla Public License
public LoanTransaction waiveLoanCharge(final LoanCharge loanCharge, final LoanLifecycleStateMachine loanLifecycleStateMachine, final Map<String, Object> changes, final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds, final Integer loanInstallmentNumber, final ScheduleGeneratorDTO scheduleGeneratorDTO, final Money accruedCharge, final AppUser currentUser) { validateLoanIsNotClosed(loanCharge); final Money amountWaived = loanCharge.waive(loanCurrency(), loanInstallmentNumber); changes.put("amount", amountWaived.getAmount()); Money unrecognizedIncome = amountWaived.zero(); Money chargeComponent = amountWaived; if (isPeriodicAccrualAccountingEnabledOnLoanProduct()) { Money receivableCharge = accruedCharge.minus(loanCharge.getAmountPaid(getCurrency())); if (receivableCharge.isLessThanZero()) { receivableCharge = amountWaived.zero(); }/*from w ww. java 2 s .c o m*/ if (amountWaived.isGreaterThan(receivableCharge)) { chargeComponent = receivableCharge; unrecognizedIncome = amountWaived.minus(receivableCharge); } } Money feeChargesWaived = chargeComponent; Money penaltyChargesWaived = Money.zero(loanCurrency()); if (loanCharge.isPenaltyCharge()) { penaltyChargesWaived = chargeComponent; feeChargesWaived = Money.zero(loanCurrency()); } LocalDate transactionDate = getDisbursementDate(); if (loanCharge.isSpecifiedDueDate()) { transactionDate = loanCharge.getDueLocalDate(); } updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement()); existingTransactionIds.addAll(findExistingTransactionIds()); existingReversedTransactionIds.addAll(findExistingReversedTransactionIds()); final LoanTransaction waiveLoanChargeTransaction = LoanTransaction.waiveLoanCharge(this, getOffice(), amountWaived, transactionDate, feeChargesWaived, penaltyChargesWaived, unrecognizedIncome, DateUtils.getLocalDateTimeOfTenant(), currentUser); final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(waiveLoanChargeTransaction, loanCharge, waiveLoanChargeTransaction.getAmount(getCurrency()).getAmount(), loanInstallmentNumber); waiveLoanChargeTransaction.getLoanChargesPaid().add(loanChargePaidBy); this.loanTransactions.add(waiveLoanChargeTransaction); if (this.repaymentScheduleDetail().isInterestRecalculationEnabled() && (loanCharge.getDueLocalDate() == null || LocalDate.now().isAfter(loanCharge.getDueLocalDate()))) { regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser); } // Waive of charges whose due date falls after latest 'repayment' // transaction dont require entire loan schedule to be reprocessed. final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory .determineProcessor(this.transactionProcessingStrategy); if (!loanCharge.isDueAtDisbursement() && loanCharge.isPaidOrPartiallyPaid(loanCurrency())) { /**** * TODO Vishwas Currently we do not allow waiving fully paid loan * charge and waiving partially paid loan charges only waives the * remaining amount. * * Consider removing this block of code or logically completing it * for the future by getting the list of affected Transactions ***/ final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement(); loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(), allNonContraTransactionsPostDisbursement, getCurrency(), this.repaymentScheduleInstallments, charges()); } else { // reprocess loan schedule based on charge been waived. final LoanRepaymentScheduleProcessingWrapper wrapper = new LoanRepaymentScheduleProcessingWrapper(); wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, charges()); } updateLoanSummaryDerivedFields(); doPostLoanTransactionChecks(waiveLoanChargeTransaction.getTransactionDate(), loanLifecycleStateMachine); return waiveLoanChargeTransaction; }
From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java
License:Mozilla Public License
public ChangedTransactionDetail disburse(final AppUser currentUser, final JsonCommand command, final Map<String, Object> actualChanges, final ScheduleGeneratorDTO scheduleGeneratorDTO) { final LoanStatus statusEnum = this.loanLifecycleStateMachine.transition(LoanEvent.LOAN_DISBURSED, LoanStatus.fromInt(this.loanStatus)); final LocalDate actualDisbursementDate = command.localDateValueOfParameterNamed("actualDisbursementDate"); this.loanStatus = statusEnum.getValue(); actualChanges.put("status", LoanEnumerations.status(this.loanStatus)); this.disbursedBy = currentUser; updateLoanScheduleDependentDerivedFields(); actualChanges.put("locale", command.locale()); actualChanges.put("dateFormat", command.dateFormat()); actualChanges.put("actualDisbursementDate", command.stringValueOfParameterNamed("actualDisbursementDate")); HolidayDetailDTO holidayDetailDTO = scheduleGeneratorDTO.getHolidayDetailDTO(); // validate if disbursement date is a holiday or a non-working day validateDisbursementDateIsOnNonWorkingDay(holidayDetailDTO.getWorkingDays(), holidayDetailDTO.isAllowTransactionsOnNonWorkingDay()); validateDisbursementDateIsOnHoliday(holidayDetailDTO.isAllowTransactionsOnHoliday(), holidayDetailDTO.getHolidays()); if (this.repaymentScheduleDetail().isInterestRecalculationEnabled() && (fetchRepaymentScheduleInstallment(1).getDueDate().isBefore(LocalDate.now()) || isDisbursementMissed())) { regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser); }//from ww w. j ava 2 s. co m updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement()); updateLoanRepaymentPeriodsDerivedFields(actualDisbursementDate); updateLoanSummaryDerivedFields(); LocalDateTime createdDate = DateUtils.getLocalDateTimeOfTenant(); handleDisbursementTransaction(actualDisbursementDate, createdDate, currentUser); final Money interestApplied = Money.of(getCurrency(), this.summary.getTotalInterestCharged()); /** * Add an interest applied transaction of the interest is accrued * upfront (Up front accrual), no accounting or cash based accounting is * selected **/ if (isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct()) { final LoanTransaction interestAppliedTransaction = LoanTransaction.accrueInterest(getOffice(), this, interestApplied, actualDisbursementDate, createdDate, currentUser); this.loanTransactions.add(interestAppliedTransaction); } return reprocessTransactionForDisbursement(); }
From source file:org.mifosplatform.portfolio.loanaccount.guarantor.service.GuarantorDomainServiceImpl.java
License:Mozilla Public License
/** * Method is to recover funds from guarantor's in case loan is unpaid. * (Transfers guarantee amount from guarantor's account to loan account and * releases guarantor)// w ww .j a v a 2 s. c om */ @Override public void transaferFundsFromGuarantor(final Loan loan) { if (loan.getGuaranteeAmount().compareTo(BigDecimal.ZERO) != 1) { return; } final List<Guarantor> existGuarantorList = this.guarantorRepository.findByLoan(loan); final boolean isRegularTransaction = true; final boolean isExceptionForBalanceCheck = true; LocalDate transactionDate = LocalDate.now(); PortfolioAccountType fromAccountType = PortfolioAccountType.SAVINGS; PortfolioAccountType toAccountType = PortfolioAccountType.LOAN; final Long toAccountId = loan.getId(); final String description = "Payment from guarantor savings"; final Locale locale = null; final DateTimeFormatter fmt = null; final PaymentDetail paymentDetail = null; final Integer fromTransferType = null; final Integer toTransferType = null; final Long chargeId = null; final Integer loanInstallmentNumber = null; final Integer transferType = AccountTransferType.LOAN_REPAYMENT.getValue(); final AccountTransferDetails accountTransferDetails = null; final String noteText = null; final String txnExternalId = null; final SavingsAccount toSavingsAccount = null; Long loanId = loan.getId(); for (Guarantor guarantor : existGuarantorList) { final List<GuarantorFundingDetails> fundingDetails = guarantor.getGuarantorFundDetails(); for (GuarantorFundingDetails guarantorFundingDetails : fundingDetails) { if (guarantorFundingDetails.getStatus().isActive()) { final SavingsAccount fromSavingsAccount = guarantorFundingDetails.getLinkedSavingsAccount(); final Long fromAccountId = fromSavingsAccount.getId(); releaseLoanIds.put(loanId, guarantorFundingDetails.getId()); try { BigDecimal remainingAmount = guarantorFundingDetails.getAmountRemaining(); if (loan.getGuaranteeAmount().compareTo(loan.getPrincpal().getAmount()) == 1) { remainingAmount = remainingAmount.multiply(loan.getPrincpal().getAmount()) .divide(loan.getGuaranteeAmount(), roundingMode); } AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, remainingAmount, fromAccountType, toAccountType, fromAccountId, toAccountId, description, locale, fmt, paymentDetail, fromTransferType, toTransferType, chargeId, loanInstallmentNumber, transferType, accountTransferDetails, noteText, txnExternalId, loan, toSavingsAccount, fromSavingsAccount, isRegularTransaction, isExceptionForBalanceCheck); transferAmount(accountTransferDTO); } finally { releaseLoanIds.remove(loanId); } } } } }
From source file:org.mifosplatform.portfolio.loanaccount.guarantor.service.GuarantorWritePlatformServiceJpaRepositoryIImpl.java
License:Mozilla Public License
private CommandProcessingResult createGuarantor(final Loan loan, final JsonCommand command, final GuarantorCommand guarantorCommand, final Collection<Guarantor> existGuarantorList) { try {//from w w w .j a va 2 s . c o m guarantorCommand.validateForCreate(); validateLoanStatus(loan); final List<GuarantorFundingDetails> guarantorFundingDetails = new ArrayList<>(); AccountAssociations accountAssociations = null; if (guarantorCommand.getSavingsId() != null) { final SavingsAccount savingsAccount = this.savingsAccountAssembler .assembleFrom(guarantorCommand.getSavingsId()); accountAssociations = AccountAssociations.associateSavingsAccount(loan, savingsAccount, AccountAssociationType.GUARANTOR_ACCOUNT_ASSOCIATION.getValue(), true); GuarantorFundingDetails fundingDetails = new GuarantorFundingDetails(accountAssociations, GuarantorFundStatusType.ACTIVE.getValue(), guarantorCommand.getAmount()); guarantorFundingDetails.add(fundingDetails); if (loan.isDisbursed() || loan.isApproved() && (loan.getGuaranteeAmount() != null || loan.loanProduct().isHoldGuaranteeFundsEnabled())) { this.guarantorDomainService.assignGuarantor(fundingDetails, LocalDate.now()); loan.updateGuaranteeAmount(fundingDetails.getAmount()); } } final Long clientRelationshipId = guarantorCommand.getClientRelationshipTypeId(); CodeValue clientRelationshipType = null; if (clientRelationshipId != null) { clientRelationshipType = this.codeValueRepositoryWrapper .findOneByCodeNameAndIdWithNotFoundDetection( GuarantorConstants.GUARANTOR_RELATIONSHIP_CODE_NAME, clientRelationshipId); } final Long entityId = guarantorCommand.getEntityId(); final Integer guarantorTypeId = guarantorCommand.getGuarantorTypeId(); Guarantor guarantor = null; for (final Guarantor avilableGuarantor : existGuarantorList) { if (entityId != null && avilableGuarantor.getEntityId() != null && avilableGuarantor.getEntityId().equals(entityId) && avilableGuarantor.getGurantorType() == guarantorTypeId && avilableGuarantor.isActive()) { if (guarantorCommand.getSavingsId() == null || avilableGuarantor.hasGuarantor(guarantorCommand.getSavingsId())) { /** Get the right guarantor based on guarantorType **/ String defaultUserMessage = null; if (guarantorTypeId == GuarantorType.STAFF.getValue()) { defaultUserMessage = this.staffRepositoryWrapper.findOneWithNotFoundDetection(entityId) .displayName(); } else { defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId) .getDisplayName(); } defaultUserMessage = defaultUserMessage + " is already exist as a guarantor for this loan"; final String action = loan.client() != null ? "client.guarantor" : "group.guarantor"; throw new DuplicateGuarantorException(action, "is.already.exist.same.loan", defaultUserMessage, entityId, loan.getId()); } guarantor = avilableGuarantor; break; } } if (guarantor == null) { guarantor = Guarantor.fromJson(loan, clientRelationshipType, command, guarantorFundingDetails); } else { guarantor.addFundingDetails(guarantorFundingDetails); } validateGuarantorBusinessRules(guarantor); for (GuarantorFundingDetails fundingDetails : guarantorFundingDetails) { fundingDetails.updateGuarantor(guarantor); } if (accountAssociations != null) { this.accountAssociationsRepository.save(accountAssociations); } this.guarantorRepository.save(guarantor); return new CommandProcessingResultBuilder().withCommandId(command.commandId()) .withOfficeId(guarantor.getOfficeId()).withEntityId(guarantor.getId()).withLoanId(loan.getId()) .build(); } catch (final DataIntegrityViolationException dve) { handleGuarantorDataIntegrityIssues(dve); return CommandProcessingResult.empty(); } }
From source file:org.mifosplatform.portfolio.loanaccount.service.LoanReadPlatformServiceImpl.java
License:Mozilla Public License
@Override public LoanTransactionData retrieveLoanPrePaymentTemplate(final Long loanId, LocalDate onDate) { this.context.authenticatedUser(); final Loan loan = this.loanRepository.findOne(loanId); if (loan == null) { throw new LoanNotFoundException(loanId); }//from ww w . j a v a 2 s .co m loan.setHelpers(null, null, loanRepaymentScheduleTransactionProcessorFactory); final MonetaryCurrency currency = loan.getCurrency(); final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository .findOneWithNotFoundDetection(currency); final CurrencyData currencyData = applicationCurrency.toData(); final LocalDate earliestUnpaidInstallmentDate = LocalDate.now(); CalendarInstance restCalendarInstance = null; CalendarInstance compoundingCalendarInstance = null; HolidayDetailDTO holidayDetailDTO = null; if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) { restCalendarInstance = calendarInstanceRepository.findCalendarInstaneByEntityId( loan.loanInterestRecalculationDetailId(), CalendarEntityType.LOAN_RECALCULATION_REST_DETAIL.getValue()); compoundingCalendarInstance = calendarInstanceRepository.findCalendarInstaneByEntityId( loan.loanInterestRecalculationDetailId(), CalendarEntityType.LOAN_RECALCULATION_COMPOUNDING_DETAIL.getValue()); final boolean isHolidayEnabled = this.configurationDomainService .isRescheduleRepaymentsOnHolidaysEnabled(); final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate( loan.getOfficeId(), loan.getDisbursementDate().toDate(), HolidayStatusType.ACTIVE.getValue()); final WorkingDays workingDays = this.workingDaysRepository.findOne(); holidayDetailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays); } final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment = loan.fetchPrepaymentDetail( this.loanScheduleFactory, restCalendarInstance, compoundingCalendarInstance, holidayDetailDTO, onDate); final LoanTransactionEnumData transactionType = LoanEnumerations .transactionType(LoanTransactionType.REPAYMENT); final Collection<PaymentTypeData> paymentOptions = this.paymentTypeReadPlatformService .retrieveAllPaymentTypes(); final BigDecimal outstandingLoanBalance = loanRepaymentScheduleInstallment.getPrincipalOutstanding(currency) .getAmount(); final BigDecimal unrecognizedIncomePortion = null; return new LoanTransactionData(null, null, null, transactionType, null, currencyData, earliestUnpaidInstallmentDate, loanRepaymentScheduleInstallment.getTotalOutstanding(currency).getAmount(), loanRepaymentScheduleInstallment.getPrincipalOutstanding(currency).getAmount(), loanRepaymentScheduleInstallment.getInterestOutstanding(currency).getAmount(), loanRepaymentScheduleInstallment.getFeeChargesOutstanding(currency).getAmount(), loanRepaymentScheduleInstallment.getPenaltyChargesOutstanding(currency).getAmount(), null, unrecognizedIncomePortion, paymentOptions, null, null, null, outstandingLoanBalance, false); }
From source file:org.mifosplatform.portfolio.loanaccount.service.LoanReadPlatformServiceImpl.java
License:Mozilla Public License
@Override public Collection<Long> fetchArrearLoans() { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append("SELECT ml.id FROM m_loan ml "); sqlBuilder.append(" INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id "); sqlBuilder.append(/* w ww. ja va 2s . c om*/ " LEFT JOIN m_loan_disbursement_detail dd on dd.loan_id=ml.id and dd.disbursedon_date is null "); sqlBuilder.append(" WHERE ml.loan_status_id = ? "); sqlBuilder.append(" and ml.interest_recalculation_enabled = 1 "); sqlBuilder.append(" and ml.is_npa = 0 "); sqlBuilder.append(" and (("); sqlBuilder.append(" mr.completed_derived is false "); sqlBuilder.append(" and mr.duedate < ? )"); sqlBuilder.append(" or dd.expected_disburse_date < ? ) "); sqlBuilder.append(" group by ml.id"); try { return this.jdbcTemplate.queryForList(sqlBuilder.toString(), Long.class, new Object[] { LoanStatus.ACTIVE.getValue(), formatter.print(LocalDate.now()), formatter.print(LocalDate.now()) }); } catch (final EmptyResultDataAccessException e) { return null; } }