List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(Object instant)
From source file:com.gst.portfolio.group.service.CenterReadPlatformServiceImpl.java
License:Apache License
@Override public Collection<StaffCenterData> retriveAllCentersByMeetingDate(final Long officeId, final Date meetingDate, final Long staffId) { validateForGenerateCollectionSheet(staffId); LocalDate localDate = new LocalDate(meetingDate); final CenterCalendarDataMapper centerCalendarMapper = new CenterCalendarDataMapper(); String sql = centerCalendarMapper.schema(); Collection<CenterData> centerDataArray = null; String passeddate = formatter.print(localDate); if (staffId != null) { sql += " and g.staff_id=? "; sql += "and lrs.duedate<='" + passeddate + "' and l.loan_type_enum=3"; sql += " group by c.id,ci.id"; centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, new Object[] { passeddate, passeddate, passeddate, passeddate, passeddate, passeddate, officeId, staffId }); } else {//from w w w .j a v a 2s .c o m centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, new Object[] { passeddate, passeddate, passeddate, passeddate, passeddate, passeddate, officeId }); } Collection<StaffCenterData> staffCenterDataArray = new ArrayList<>(); Boolean flag = false; Integer numberOfDays = 0; boolean isSkipRepaymentOnFirstMonthEnabled = this.configurationDomainService .isSkippingMeetingOnFirstDayOfMonthEnabled(); if (isSkipRepaymentOnFirstMonthEnabled) { numberOfDays = this.configurationDomainService.retreivePeroidInNumberOfDaysForSkipMeetingDate() .intValue(); } for (CenterData centerData : centerDataArray) { if (centerData.getCollectionMeetingCalendar().isValidRecurringDate(new LocalDate(meetingDate), isSkipRepaymentOnFirstMonthEnabled, numberOfDays)) { if (staffCenterDataArray.size() <= 0) { Collection<CenterData> meetingFallCenter = new ArrayList<>(); meetingFallCenter.add(centerData); staffCenterDataArray.add(StaffCenterData.instance(centerData.staffId(), centerData.getStaffName(), meetingFallCenter)); } else { for (StaffCenterData staffCenterData : staffCenterDataArray) { flag = false; if (staffCenterData.getStaffId().equals(centerData.staffId())) { staffCenterData.getMeetingFallCenters().add(centerData); flag = true; break; } } if (!flag) { Collection<CenterData> meetingFallCenter = new ArrayList<>(); meetingFallCenter.add(centerData); staffCenterDataArray.add(StaffCenterData.instance(centerData.staffId(), centerData.getStaffName(), meetingFallCenter)); } } } } return staffCenterDataArray; }
From source file:com.gst.portfolio.interestratechart.domain.InterestRateChartFields.java
License:Apache License
public LocalDate getFromDateAsLocalDate() { LocalDate fromDate = null;//from w w w . j a v a 2 s . com if (this.fromDate != null) { fromDate = new LocalDate(this.fromDate); } return fromDate; }
From source file:com.gst.portfolio.interestratechart.domain.InterestRateChartFields.java
License:Apache License
public LocalDate getEndDateAsLocalDate() { LocalDate endDate = null;/* w w w . j a v a 2 s . c o m*/ if (this.endDate != null) { endDate = new LocalDate(this.endDate); } return endDate; }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void createOrUpdateDisbursementDetails(Long disbursementID, final Map<String, Object> actualChanges, Date expectedDisbursementDate, BigDecimal principal, List<Long> existingDisbursementList) { if (disbursementID != null) { LoanDisbursementDetails loanDisbursementDetail = fetchLoanDisbursementsById(disbursementID); existingDisbursementList.remove(disbursementID); if (loanDisbursementDetail.actualDisbursementDate() == null) { Date actualDisbursementDate = null; LoanDisbursementDetails disbursementDetails = new LoanDisbursementDetails(expectedDisbursementDate, actualDisbursementDate, principal); disbursementDetails.updateLoan(this); if (!loanDisbursementDetail.equals(disbursementDetails)) { loanDisbursementDetail.copy(disbursementDetails); actualChanges.put("disbursementDetailId", disbursementID); actualChanges.put("recalculateLoanSchedule", true); }//from www .j a va 2s . co m } } else { Date actualDisbursementDate = null; LoanDisbursementDetails disbursementDetails = new LoanDisbursementDetails(expectedDisbursementDate, actualDisbursementDate, principal); disbursementDetails.updateLoan(this); this.disbursementDetails.add(disbursementDetails); for (LoanTrancheCharge trancheCharge : trancheCharges) { Charge chargeDefinition = trancheCharge.getCharge(); final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(chargeDefinition, principal, null, null, null, new LocalDate(expectedDisbursementDate), null, null); loanCharge.update(this); LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge( loanCharge, disbursementDetails); loanCharge.updateLoanTrancheDisbursementCharge(loanTrancheDisbursementCharge); addLoanCharge(loanCharge); } actualChanges.put(LoanApiConstants.disbursementDataParameterName, expectedDisbursementDate + "-" + principal); actualChanges.put("recalculateLoanSchedule", true); } }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache 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 a v a2s. 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()) { recalculateAllCharges(); 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:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void handleDisbursementTransaction(final LocalDate disbursedOn, final LocalDateTime createdDate, final AppUser currentUser, final PaymentDetail paymentDetail) { // add repayment transaction to track incoming money from client to mfi // for (charges due at time of disbursement) /***// w w w .j a va 2 s .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) **/ Money disbursentMoney = Money.zero(getCurrency()); final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(getOffice(), disbursentMoney, paymentDetail, disbursedOn, null, createdDate, currentUser); final Integer installmentNumber = null; for (final LoanCharge charge : charges()) { Date actualDisbursementDate = getActualDisbursementDate(charge); if ((charge.getCharge().getChargeTimeType() == ChargeTimeType.DISBURSEMENT.getValue() && disbursedOn.equals(new LocalDate(actualDisbursementDate)) && actualDisbursementDate != null && !charge.isWaived() && !charge.isFullyPaid()) || (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); addLoanTransaction(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:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void processIncomeAccrualTransactionOnLoanClosure() { if (this.loanInterestRecalculationDetails != null && this.loanInterestRecalculationDetails.isCompoundingToBePostedAsTransaction() && this.status().isClosedObligationsMet()) { Date closedDate = this.getClosedOnDate(); LocalDate closedLocalDate = new LocalDate(closedDate); reverseTransactionsOnOrAfter(retreiveListOfIncomePostingTransactions(), closedDate); reverseTransactionsOnOrAfter(retreiveListOfAccrualTransactions(), closedDate); HashMap<String, BigDecimal> cumulativeIncomeFromInstallments = new HashMap<>(); determineCumulativeIncomeFromInstallments(cumulativeIncomeFromInstallments); HashMap<String, BigDecimal> cumulativeIncomeFromIncomePosting = new HashMap<>(); determineCumulativeIncomeDetails(retreiveListOfIncomePostingTransactions(), cumulativeIncomeFromIncomePosting); BigDecimal interestToPost = cumulativeIncomeFromInstallments.get("interest") .subtract(cumulativeIncomeFromIncomePosting.get("interest")); BigDecimal feeToPost = cumulativeIncomeFromInstallments.get("fee") .subtract(cumulativeIncomeFromIncomePosting.get("fee")); BigDecimal penaltyToPost = cumulativeIncomeFromInstallments.get("penalty") .subtract(cumulativeIncomeFromIncomePosting.get("penalty")); BigDecimal amountToPost = interestToPost.add(feeToPost).add(penaltyToPost); LoanTransaction finalIncomeTransaction = LoanTransaction.incomePosting(this, this.getOffice(), closedDate, amountToPost, interestToPost, feeToPost, penaltyToPost, null); addLoanTransaction(finalIncomeTransaction); if (isPeriodicAccrualAccountingEnabledOnLoanProduct()) { List<LoanTransaction> updatedAccrualTransactions = retreiveListOfAccrualTransactions(); LocalDate lastAccruedDate = this.getDisbursementDate(); if (updatedAccrualTransactions != null && updatedAccrualTransactions.size() > 0) { lastAccruedDate = updatedAccrualTransactions.get(updatedAccrualTransactions.size() - 1) .getTransactionDate(); }/*from w ww. j a v a 2 s.c o m*/ HashMap<String, Object> feeDetails = new HashMap<>(); determineFeeDetails(lastAccruedDate, closedLocalDate, feeDetails); LoanTransaction finalAccrual = LoanTransaction.accrueTransaction(this, this.getOffice(), closedLocalDate, amountToPost, interestToPost, feeToPost, penaltyToPost, null); updateLoanChargesPaidBy(finalAccrual, feeDetails, null); addLoanTransaction(finalAccrual); } } updateLoanOutstandingBalaces(); }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
/** * Behaviour added to comply with capability of previous mifos product to * support easier transition to fineract platform. *//*from w w w . ja va 2s .co m*/ public void closeAsMarkedForReschedule(final JsonCommand command, final LoanLifecycleStateMachine loanLifecycleStateMachine, final Map<String, Object> changes) { final LocalDate rescheduledOn = command.localDateValueOfParameterNamed("transactionDate"); final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_RESCHEDULE, LoanStatus.fromInt(this.loanStatus)); if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) { this.loanStatus = statusEnum.getValue(); changes.put("status", LoanEnumerations.status(this.loanStatus)); } this.closedOnDate = rescheduledOn.toDate(); this.rescheduledOnDate = rescheduledOn.toDate(); changes.put("closedOnDate", command.stringValueOfParameterNamed("transactionDate")); changes.put("rescheduledOnDate", command.stringValueOfParameterNamed("transactionDate")); final LocalDate rescheduledOnLocalDate = new LocalDate(this.rescheduledOnDate); if (rescheduledOnLocalDate.isBefore(getDisbursementDate())) { final String errorMessage = "The date on which a loan is rescheduled cannot be before the loan disbursement date: " + getDisbursementDate().toString(); throw new InvalidLoanStateTransitionException("close.reschedule", "cannot.be.before.submittal.date", errorMessage, rescheduledOnLocalDate, getDisbursementDate()); } if (rescheduledOnLocalDate.isAfter(new LocalDate())) { final String errorMessage = "The date on which a loan is rescheduled cannot be in the future."; throw new InvalidLoanStateTransitionException("close.reschedule", "cannot.be.a.future.date", errorMessage, rescheduledOnLocalDate); } }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public boolean isSubmittedOnDateAfter(final LocalDate compareDate) { return this.submittedOnDate == null ? false : new LocalDate(this.submittedOnDate).isAfter(compareDate); }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public LocalDate getApprovedOnDate() { LocalDate date = null;//from w ww . j a va 2 s .c om if (this.approvedOnDate != null) { date = new LocalDate(this.approvedOnDate); } return date; }