List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:org.mifos.application.servicefacade.LoanAccountServiceFacadeWebTier.java
License:Open Source License
@Override public Errors validateLoanWithBackdatedPaymentsDisbursementDate(LocalDate loanDisbursementDate, Integer customerId, Integer productId) { Errors errors = new Errors(); if (!loanDisbursementDate.isBefore(new LocalDate())) { String[] args = { "" }; errors.addError("dibursementdate.before.todays.date", args); }/* w w w.ja va 2s . c o m*/ CustomerBO customer = this.customerDao.findCustomerById(customerId); LocalDate customerActivationDate = new LocalDate(customer.getCustomerActivationDate()); if (loanDisbursementDate.isBefore(customerActivationDate)) { String[] args = { customerActivationDate.toString("dd-MMM-yyyy") }; errors.addError("dibursementdate.before.customer.activation.date", args); } LoanOfferingBO loanProduct = this.loanProductDao.findById(productId); LocalDate productStartDate = new LocalDate(loanProduct.getStartDate()); if (loanDisbursementDate.isBefore(productStartDate)) { String[] args = { productStartDate.toString("dd-MMM-yyyy") }; errors.addError("dibursementdate.before.product.startDate", args); } try { this.holidayServiceFacade.validateDisbursementDateForNewLoan(customer.getOfficeId(), loanDisbursementDate.toDateMidnight().toDateTime()); } catch (BusinessRuleException e) { String[] args = { "" }; errors.addError("dibursementdate.falls.on.holiday", args); } return errors; }
From source file:org.mifos.application.servicefacade.SavingsServiceFacadeWebTier.java
License:Open Source License
@Override public List<AdjustableSavingsPaymentDto> retrievePaymentsForAdjustment(Integer accountId) { SavingsBO savingsAccount = this.savingsDao.findById(accountId); List<AdjustableSavingsPaymentDto> adjustablePayments = new ArrayList<AdjustableSavingsPaymentDto>(); for (AccountPaymentEntity payment : savingsAccount.getAccountPayments()) { if (payment.isSavingsDepositOrWithdrawal() && payment.getAmount().isGreaterThan(Money.zero())) { AdjustableSavingsPaymentDto adjustableSavingsPaymentDto = new AdjustableSavingsPaymentDto( payment.getPaymentId(), payment.getReceiptNumber(), payment.getAmount().getAmount(), new LocalDate(payment.getPaymentDate()), (payment.getReceiptDate() == null) ? null : new LocalDate(payment.getReceiptDate()), payment.getPaymentType().getName(), payment.isSavingsDeposit()); adjustablePayments.add(adjustableSavingsPaymentDto); }//from w w w . j a va 2s . com } Collections.sort(adjustablePayments, new Comparator<AdjustableSavingsPaymentDto>() { @Override public int compare(AdjustableSavingsPaymentDto o1, AdjustableSavingsPaymentDto o2) { int result; LocalDate firstDate = o1.getPaymentDate(); LocalDate secondDate = o2.getPaymentDate(); // sort by date if (firstDate.isAfter(secondDate)) { result = -1; } else if (firstDate.isBefore(secondDate)) { result = 1; } else { // withdrawal comes after deposit if (o1.isWithdrawal() && !o2.isWithdrawal()) { result = -1; } else if (!o1.isWithdrawal() && o2.isWithdrawal()) { result = 1; } else { result = 0; } } return result; } }); return adjustablePayments; }
From source file:org.mifos.clientportfolio.loan.ui.CashFlowSummaryFormBean.java
License:Open Source License
private void validatePaymentsAndAmounts(MessageContext messageContext, List<DateTime> actualPaymentDates, List<Number> actualPaymentAmounts) { int index = 0; LocalDate lastPaymentDate = null; BigDecimal totalPayment = BigDecimal.ZERO; for (Number actualPayment : actualPaymentAmounts) { String installment = Integer.valueOf(index + 1).toString(); LocalDate paymentDate = new LocalDate(actualPaymentDates.get(index)); if (paymentDate.isBefore(new LocalDate(this.disbursementDate))) { String defaultMessage = "The payment date cannot be before disbursement date"; ErrorEntry fieldError = new ErrorEntry("paymentDate.before.disbursementDate.invalid", "disbursementDate", defaultMessage); fieldError.setArgs(Arrays.asList(installment)); addErrorMessageToContext(messageContext, fieldError); }//from w ww . j a v a2s. com if (paymentDate.isAfter(new LocalDate()) && actualPayment.doubleValue() > 0) { String defaultMessage = "The payment date cannot be in the future."; ErrorEntry fieldError = new ErrorEntry("paymentDate.is.future.date.invalid", "disbursementDate", defaultMessage); fieldError.setArgs(Arrays.asList(installment)); addErrorMessageToContext(messageContext, fieldError); } if (lastPaymentDate != null) { if (!paymentDate.isEqual(lastPaymentDate) && !paymentDate.isAfter(lastPaymentDate)) { String defaultMessage = "The payment date cannot be before the previous payment date"; ErrorEntry fieldError = new ErrorEntry("paymentDate.before.lastPaymentDate.invalid", "disbursementDate", defaultMessage); fieldError.setArgs(Arrays.asList(installment)); addErrorMessageToContext(messageContext, fieldError); } } BigDecimal payment = BigDecimal.valueOf(actualPayment.doubleValue()); if (payment.doubleValue() > BigDecimal.ZERO.doubleValue()) { totalPayment = totalPayment.add(payment); } index++; lastPaymentDate = paymentDate; } BigDecimal totalAllowedPayments = this.loanPrincipal.add(this.totalLoanFees).add(this.totalLoanInterest); if (totalPayment.doubleValue() > totalAllowedPayments.doubleValue()) { String defaultMessage = "Exceeds total payments allowed for loan."; ErrorEntry fieldError = new ErrorEntry("totalPayments.exceeded.invalid", "disbursementDate", defaultMessage); addErrorMessageToContext(messageContext, fieldError); } }
From source file:org.mifos.clientportfolio.newloan.domain.LoanDisbursementCoupledToCustomerMeetingScheduleStrategyImpl.java
License:Open Source License
@Override public LocalDate findClosestMatchingDateFromAndInclusiveOf(LocalDate fromAndInclusiveOf) { LocalDate closestMatch = nextValidCustomerMeetingDate; if (closestMatch.isBefore(fromAndInclusiveOf)) { closestMatch = new LocalDate( scheduledEvent.nextEventDateAfter(closestMatch.toDateMidnight().toDateTime())); while (closestMatch.isBefore(fromAndInclusiveOf)) { closestMatch = new LocalDate( scheduledEvent.nextEventDateAfter(closestMatch.toDateMidnight().toDateTime())); }//w w w.j a v a2 s . com } return closestMatch; }
From source file:org.mifos.clientportfolio.newloan.domain.LoanDisbursementCoupledToCustomerMeetingScheduleStrategyImpl.java
License:Open Source License
@Override public boolean isDisbursementDateValidInRelationToSchedule(LocalDate disbursementDate) { boolean result = false; if (disbursementDate.isEqual(this.nextValidCustomerMeetingDate)) { result = true;// w ww . j a v a2s . c o m } else if (disbursementDate.isAfter(this.nextValidCustomerMeetingDate)) { LocalDate matchingDate = this.nextValidCustomerMeetingDate; matchingDate = new LocalDate( scheduledEvent.nextEventDateAfter(matchingDate.toDateMidnight().toDateTime())); while (matchingDate.isBefore(disbursementDate)) { matchingDate = new LocalDate( scheduledEvent.nextEventDateAfter(matchingDate.toDateMidnight().toDateTime())); } if (matchingDate.isEqual(disbursementDate)) { result = true; } } return result; }
From source file:org.mifos.clientportfolio.newloan.domain.VariableInstallmentsLoanDisbursementStrategyImpl.java
License:Open Source License
@Override public LocalDate findClosestMatchingDateFromAndInclusiveOf(LocalDate fromAndInclusiveOf) { LocalDate nearestMatchingDate = new LocalDate( scheduledEvent.nearestMatchNotTakingIntoAccountScheduleFrequency( fromAndInclusiveOf.minusDays(1).toDateMidnight().toDateTime())); if (nearestMatchingDate.isBefore(new LocalDate())) { nearestMatchingDate = new LocalDate(scheduledEvent.nearestMatchNotTakingIntoAccountScheduleFrequency( fromAndInclusiveOf.toDateMidnight().toDateTime())); }//w ww.j av a2 s. com return nearestMatchingDate; }
From source file:org.mifosplatform.infrastructure.reportmailingjob.service.ReportMailingJobWritePlatformServiceImpl.java
License:Mozilla Public License
/** * create the next recurring DateTime from recurrence pattern, start DateTime and current DateTime * /*ww w. j a v a 2 s . c o m*/ * @param recurrencePattern * @param startDateTime * @return DateTime object */ private DateTime createNextRecurringDateTime(final ReportMailingJob reportMailingJob) { DateTime nextRecurringDateTime = null; final String recurrencePattern = reportMailingJob.getRecurrence(); final DateTime nextRunDateTime = reportMailingJob.getNextRunDateTime(); // the recurrence pattern/rule cannot be empty if (StringUtils.isNotBlank(recurrencePattern) && nextRunDateTime != null) { final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); final LocalDate nextRunDate = nextRunDateTime.toLocalDate(); LocalDate nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, nextRunDate, nextRunDate); if (nextRecurringLocalDate.isBefore(currentDate)) { nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, nextRunDate, currentDate); } // get the date fields final int currentYearIntValue = nextRecurringLocalDate.get(DateTimeFieldType.year()); final int currentMonthIntValue = nextRecurringLocalDate.get(DateTimeFieldType.monthOfYear()); final int currentDayIntValue = nextRecurringLocalDate.get(DateTimeFieldType.dayOfMonth()); // append the time of the previous next run date time nextRecurringDateTime = nextRunDateTime.withDate(currentYearIntValue, currentMonthIntValue, currentDayIntValue); } return nextRecurringDateTime; }
From source file:org.mifosplatform.portfolio.loanaccount.domain.CreocoreLoanRepaymentScheduleTransactionProcessor.java
License:Mozilla Public License
/** * For creocore, early is defined as any date before the installment due * date/*www.ja v a 2s . c o m*/ */ @SuppressWarnings("unused") @Override protected boolean isTransactionInAdvanceOfInstallment(final int currentInstallmentIndex, final List<LoanRepaymentScheduleInstallment> installments, final LocalDate transactionDate, final Money transactionAmount) { LoanRepaymentScheduleInstallment currentInstallment = installments.get(currentInstallmentIndex); return transactionDate.isBefore(currentInstallment.getDueDate()); }
From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java
License:Mozilla Public License
public Map<String, Object> loanApplicationApproval(final AppUser currentUser, final JsonCommand command, final JsonArray disbursementDataArray, final LoanLifecycleStateMachine loanLifecycleStateMachine) { validateAccountStatus(LoanEvent.LOAN_APPROVED); final Map<String, Object> actualChanges = new LinkedHashMap<>(); /*/*from w w w .j av a 2 s .c o m*/ * statusEnum is holding the possible new status derived from * loanLifecycleStateMachine.transition. */ final LoanStatus newStatusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_APPROVED, LoanStatus.fromInt(this.loanStatus)); /* * FIXME: There is no need to check below condition, if * loanLifecycleStateMachine.transition is doing it's responsibility * properly. Better implementation approach is, if code passes invalid * combination of states (fromState and toState), state machine should * return invalidate state and below if condition should check for not * equal to invalidateState, instead of check new value is same as * present value. */ if (!newStatusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) { this.loanStatus = newStatusEnum.getValue(); actualChanges.put("status", LoanEnumerations.status(this.loanStatus)); // only do below if status has changed in the 'approval' case LocalDate approvedOn = command.localDateValueOfParameterNamed("approvedOnDate"); String approvedOnDateChange = command.stringValueOfParameterNamed("approvedOnDate"); if (approvedOn == null) { approvedOn = command.localDateValueOfParameterNamed("eventDate"); approvedOnDateChange = command.stringValueOfParameterNamed("eventDate"); } LocalDate expecteddisbursementDate = command.localDateValueOfParameterNamed("expectedDisbursementDate"); BigDecimal approvedLoanAmount = command .bigDecimalValueOfParameterNamed(LoanApiConstants.approvedLoanAmountParameterName); if (approvedLoanAmount != null) { // Approved amount has to be less than or equal to principal // amount demanded if (approvedLoanAmount.compareTo(this.proposedPrincipal) == -1) { this.approvedPrincipal = approvedLoanAmount; /* * All the calculations are done based on the principal * amount, so it is necessary to set principal amount to * approved amount */ this.loanRepaymentScheduleDetail.setPrincipal(approvedLoanAmount); actualChanges.put(LoanApiConstants.approvedLoanAmountParameterName, approvedLoanAmount); actualChanges.put(LoanApiConstants.disbursementPrincipalParameterName, approvedLoanAmount); } else if (approvedLoanAmount.compareTo(this.proposedPrincipal) == 1) { final String errorMessage = "Loan approved amount can't be greater than loan amount demanded."; throw new InvalidLoanStateTransitionException("approval", "amount.can't.be.greater.than.loan.amount.demanded", errorMessage, this.proposedPrincipal, approvedLoanAmount); } /* Update disbursement details */ if (disbursementDataArray != null) { updateDisbursementDetails(command, actualChanges); } } if (loanProduct.isMultiDisburseLoan()) { if (this.disbursementDetails.isEmpty()) { final String errorMessage = "For this loan product, disbursement details must be provided"; throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName, errorMessage); } if (this.disbursementDetails.size() > loanProduct.maxTrancheCount()) { final String errorMessage = "Number of tranche shouldn't be greter than " + loanProduct.maxTrancheCount(); throw new ExceedingTrancheCountException(LoanApiConstants.disbursementDataParameterName, errorMessage, loanProduct.maxTrancheCount(), disbursementDetails.size()); } } this.approvedOnDate = approvedOn.toDate(); this.approvedBy = currentUser; actualChanges.put("locale", command.locale()); actualChanges.put("dateFormat", command.dateFormat()); actualChanges.put("approvedOnDate", approvedOnDateChange); final LocalDate submittalDate = new LocalDate(this.submittedOnDate); if (approvedOn.isBefore(submittalDate)) { final String errorMessage = "The date on which a loan is approved cannot be before its submittal date: " + submittalDate.toString(); throw new InvalidLoanStateTransitionException("approval", "cannot.be.before.submittal.date", errorMessage, getApprovedOnDate(), submittalDate); } if (expecteddisbursementDate != null) { this.expectedDisbursementDate = expecteddisbursementDate.toDate(); actualChanges.put("expectedDisbursementDate", expectedDisbursementDate); if (expecteddisbursementDate.isBefore(approvedOn)) { final String errorMessage = "The expected disbursement date should be either on or after the approval date: " + approvedOn.toString(); throw new InvalidLoanStateTransitionException("expecteddisbursal", "should.be.on.or.after.approval.date", errorMessage, getApprovedOnDate(), expecteddisbursementDate); } } validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_APPROVED, approvedOn); if (approvedOn.isAfter(DateUtils.getLocalDateOfTenant())) { final String errorMessage = "The date on which a loan is approved cannot be in the future."; throw new InvalidLoanStateTransitionException("approval", "cannot.be.a.future.date", errorMessage, getApprovedOnDate()); } if (this.loanOfficer != null) { final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory = LoanOfficerAssignmentHistory .createNew(this, this.loanOfficer, approvedOn); this.loanOfficerHistory.add(loanOfficerAssignmentHistory); } } return actualChanges; }
From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java
License:Mozilla Public 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 2s .com * 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) **/ if (disbursedOn.toDate().equals(this.actualDisbursementDate)) { 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()) { if (charge.isDueAtDisbursement()) { 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 { /** * create a Charge applied transaction if Upfront 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(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); } }