Search in sources :

Example 1 with PaymentTypeDto

use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.

the class LoanAccountServiceFacadeWebTier method disburseLoan.

@Override
public void disburseLoan(AccountPaymentParametersDto loanDisbursement, Short paymentTypeId, Short paymentTypeIdForFees, Integer accountForTransferId) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    LoanBO loan = this.loanDao.findById(loanDisbursement.getAccountId());
    try {
        personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    PaymentTypeDto paymentType = null;
    try {
        for (org.mifos.dto.domain.PaymentTypeDto paymentTypeDto : accountService.getLoanDisbursementTypes()) {
            if (paymentTypeDto.getValue() == paymentTypeId) {
                paymentType = paymentTypeDto;
            }
        }
    } catch (Exception e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    if (paymentType == null) {
        throw new MifosRuntimeException("Expected loan PaymentTypeDto not found for id: " + paymentTypeId);
    }
    loanDisbursement.setPaymentType(paymentType);
    Date trxnDate = DateUtils.getDateWithoutTimeStamp(loanDisbursement.getPaymentDate().toDateMidnight().toDate());
    monthClosingServiceFacade.validateTransactionDate(trxnDate);
    if (!isTrxnDateValid(Integer.valueOf(loanDisbursement.getAccountId()), trxnDate)) {
        throw new BusinessRuleException("errors.invalidTxndate");
    }
    DateTime loanDisbursementDate = new DateTime(trxnDate);
    holidayServiceFacade.validateDisbursementDateForNewLoan(loan.getOfficeId(), loanDisbursementDate);
    if (loan.isFixedRepaymentSchedule()) {
        for (AccountActionDateEntity installment : loan.getAccountActionDates()) {
            if (installment.compareDate(trxnDate) <= 0) {
                throw new BusinessRuleException("errors.invalidTxndateWhenDisbursalAfterFirstRepayment");
            }
        }
    }
    List<AccountPaymentParametersDto> loanDisbursements = new ArrayList<AccountPaymentParametersDto>();
    loanDisbursements.add(loanDisbursement);
    try {
        accountService.disburseLoans(loanDisbursements, userContext.getPreferredLocale(), paymentTypeIdForFees, accountForTransferId);
    } catch (Exception e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) PropertyNotFoundException(org.mifos.framework.exceptions.PropertyNotFoundException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with PaymentTypeDto

use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.

the class LoanAccountServiceFacadeWebTier method retrieveLoanDetailsForLoanAccountCreation.

@Override
public LoanCreationLoanDetailsDto retrieveLoanDetailsForLoanAccountCreation(Integer customerId, Short productId, boolean isLoanWithBackdatedPayments) {
    try {
        List<org.mifos.dto.domain.FeeDto> additionalFees = new ArrayList<org.mifos.dto.domain.FeeDto>();
        List<org.mifos.dto.domain.FeeDto> defaultFees = new ArrayList<org.mifos.dto.domain.FeeDto>();
        List<PenaltyDto> defaultPenalties = new ArrayList<PenaltyDto>();
        LoanOfferingBO loanProduct = this.loanProductDao.findById(productId.intValue());
        MeetingBO loanProductMeeting = loanProduct.getLoanOfferingMeetingValue();
        MeetingDto loanOfferingMeetingDto = loanProductMeeting.toDto();
        List<FeeBO> fees = this.feeDao.getAllAppllicableFeeForLoanCreation();
        for (FeeBO fee : fees) {
            if (!fee.isPeriodic() || (MeetingBO.isMeetingMatched(fee.getFeeFrequency().getFeeMeetingFrequency(), loanProductMeeting))) {
                org.mifos.dto.domain.FeeDto feeDto = fee.toDto();
                FeeFrequencyType feeFrequencyType = FeeFrequencyType.getFeeFrequencyType(fee.getFeeFrequency().getFeeFrequencyType().getId());
                FeeFrequencyTypeEntity feeFrequencyEntity = this.loanProductDao.retrieveFeeFrequencyType(feeFrequencyType);
                String feeFrequencyTypeName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(feeFrequencyEntity.getLookUpValue());
                feeDto.setFeeFrequencyType(feeFrequencyTypeName);
                if (feeDto.getFeeFrequency().isOneTime()) {
                    FeePayment feePayment = FeePayment.getFeePayment(fee.getFeeFrequency().getFeePayment().getId());
                    FeePaymentEntity feePaymentEntity = this.loanProductDao.retrieveFeePaymentType(feePayment);
                    String feePaymentName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(feePaymentEntity.getLookUpValue());
                    feeDto.getFeeFrequency().setPayment(feePaymentName);
                }
                if (loanProduct.isFeePresent(fee)) {
                    defaultFees.add(feeDto);
                } else {
                    additionalFees.add(feeDto);
                }
            }
        }
        List<PenaltyBO> penalties = this.penaltyDao.getAllAppllicablePenaltyForLoanCreation();
        for (PenaltyBO penalty : penalties) {
            if (loanProduct.isPenaltyPresent(penalty)) {
                defaultPenalties.add(penalty.toDto());
            }
        }
        if (AccountingRules.isMultiCurrencyEnabled()) {
            defaultFees = getFilteredFeesByCurrency(defaultFees, loanProduct.getCurrency().getCurrencyId());
            additionalFees = getFilteredFeesByCurrency(additionalFees, loanProduct.getCurrency().getCurrencyId());
        }
        Map<String, String> defaultFeeOptions = new LinkedHashMap<String, String>();
        for (org.mifos.dto.domain.FeeDto feeDto : defaultFees) {
            defaultFeeOptions.put(feeDto.getId(), feeDto.getName());
        }
        Map<String, String> additionalFeeOptions = new LinkedHashMap<String, String>();
        for (org.mifos.dto.domain.FeeDto feeDto : additionalFees) {
            additionalFeeOptions.put(feeDto.getId(), feeDto.getName());
        }
        CustomerBO customer = this.customerDao.findCustomerById(customerId);
        boolean isRepaymentIndependentOfMeetingEnabled = new ConfigurationBusinessService().isRepaymentIndepOfMeetingEnabled();
        LoanDisbursementDateFactory loanDisbursementDateFactory = new LoanDisbursmentDateFactoryImpl();
        LoanDisbursementDateFinder loanDisbursementDateFinder = null;
        LocalDate nextPossibleDisbursementDate = null;
        MeetingBO customerMeeting = customer.getCustomerMeetingValue();
        LocalDate dateToStart = new LocalDate();
        if (customerMeeting.isWeekly()) {
            LocalDate meetingStartDate = new LocalDate(customerMeeting.getMeetingStartDate());
            if (dateToStart.isBefore(meetingStartDate)) {
                dateToStart = meetingStartDate;
                loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer, loanProduct, false, isLoanWithBackdatedPayments);
            } else {
                loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer, loanProduct, isRepaymentIndependentOfMeetingEnabled, isLoanWithBackdatedPayments);
            }
            nextPossibleDisbursementDate = loanDisbursementDateFinder.findClosestMatchingDateFromAndInclusiveOf(dateToStart);
        } else {
            loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer, loanProduct, isRepaymentIndependentOfMeetingEnabled, isLoanWithBackdatedPayments);
            nextPossibleDisbursementDate = loanDisbursementDateFinder.findClosestMatchingDateFromAndInclusiveOf(dateToStart);
        }
        LoanAmountOption eligibleLoanAmount = loanProduct.eligibleLoanAmount(customer.getMaxLoanAmount(loanProduct), customer.getMaxLoanCycleForProduct(loanProduct));
        LoanOfferingInstallmentRange eligibleNoOfInstall = loanProduct.eligibleNoOfInstall(customer.getMaxLoanAmount(loanProduct), customer.getMaxLoanCycleForProduct(loanProduct));
        Double defaultInterestRate = loanProduct.getDefInterestRate();
        Double maxInterestRate = loanProduct.getMaxInterestRate();
        Double minInterestRate = loanProduct.getMinInterestRate();
        LinkedHashMap<String, String> collateralOptions = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> purposeOfLoanOptions = new LinkedHashMap<String, String>();
        CustomValueDto customValueDto = legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES);
        List<CustomValueListElementDto> collateralTypes = customValueDto.getCustomValueListElements();
        for (CustomValueListElementDto element : collateralTypes) {
            collateralOptions.put(element.getId().toString(), element.getName());
        }
        // Business activities got in getPrdOfferings also but only for glim.
        List<ValueListElement> loanPurposes = legacyMasterDao.findValueListElements(MasterConstants.LOAN_PURPOSES);
        for (ValueListElement element : loanPurposes) {
            purposeOfLoanOptions.put(element.getId().toString(), element.getName());
        }
        List<FundDto> fundDtos = new ArrayList<FundDto>();
        List<FundBO> funds = getFunds(loanProduct);
        for (FundBO fund : funds) {
            FundDto fundDto = new FundDto();
            fundDto.setId(Short.toString(fund.getFundId()));
            fundDto.setCode(translateFundCodeToDto(fund.getFundCode()));
            fundDto.setName(fund.getFundName());
            fundDtos.add(fundDto);
        }
        ProductDetailsDto productDto = loanProduct.toDetailsDto();
        CustomerDetailDto customerDetailDto = customer.toCustomerDetailDto();
        Integer gracePeriodInInstallments = loanProduct.getGracePeriodDuration().intValue();
        final List<PrdOfferingDto> loanProductDtos = retrieveActiveLoanProductsApplicableForCustomer(customer, isRepaymentIndependentOfMeetingEnabled);
        InterestType interestType = InterestType.fromInt(loanProduct.getInterestTypes().getId().intValue());
        InterestTypesEntity productInterestType = this.loanProductDao.findInterestType(interestType);
        String interestTypeName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(productInterestType.getLookUpValue());
        LinkedHashMap<String, String> daysOfTheWeekOptions = new LinkedHashMap<String, String>();
        List<WeekDay> workingDays = new FiscalCalendarRules().getWorkingDays();
        for (WeekDay workDay : workingDays) {
            String weekdayName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(workDay.getPropertiesKey());
            workDay.setWeekdayName(weekdayName);
            daysOfTheWeekOptions.put(workDay.getValue().toString(), weekdayName);
        }
        LinkedHashMap<String, String> weeksOfTheMonthOptions = new LinkedHashMap<String, String>();
        for (RankOfDay weekOfMonth : RankOfDay.values()) {
            String weekOfMonthName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(weekOfMonth.getPropertiesKey());
            weeksOfTheMonthOptions.put(weekOfMonth.getValue().toString(), weekOfMonthName);
        }
        boolean variableInstallmentsAllowed = loanProduct.isVariableInstallmentsAllowed();
        boolean fixedRepaymentSchedule = loanProduct.isFixedRepaymentSchedule();
        Integer minGapInDays = Integer.valueOf(0);
        Integer maxGapInDays = Integer.valueOf(0);
        BigDecimal minInstallmentAmount = BigDecimal.ZERO;
        if (variableInstallmentsAllowed) {
            VariableInstallmentDetailsBO variableInstallmentsDetails = loanProduct.getVariableInstallmentDetails();
            minGapInDays = variableInstallmentsDetails.getMinGapInDays();
            maxGapInDays = variableInstallmentsDetails.getMaxGapInDays();
            minInstallmentAmount = variableInstallmentsDetails.getMinInstallmentAmount().getAmount();
        }
        boolean compareCashflowEnabled = loanProduct.isCashFlowCheckEnabled();
        // GLIM specific
        final boolean isGroup = customer.isGroup();
        final boolean isGlimEnabled = configurationPersistence.isGlimEnabled();
        //Group Loan Account with members specific
        final boolean isGroupLoanWithMembersEnabled = AccountingRules.isGroupLoanWithMembers();
        List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
        if (isGroup && (isGlimEnabled || isGroupLoanWithMembersEnabled)) {
            final List<ClientBO> activeClientsOfGroup = customerDao.findActiveClientsUnderGroup(customer);
            if (activeClientsOfGroup == null || activeClientsOfGroup.isEmpty()) {
                throw new BusinessRuleException(GroupConstants.IMPOSSIBLE_TO_CREATE_GROUP_LOAN);
            }
            for (ClientBO client : activeClientsOfGroup) {
                LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto();
                clientDetail.setClientId(client.getGlobalCustNum());
                clientDetail.setClientName(client.getDisplayName());
                clientDetails.add(clientDetail);
            }
        }
        // end of GLIM specific
        int digitsAfterDecimalForInterest = AccountingRules.getDigitsAfterDecimalForInterest().intValue();
        int digitsBeforeDecimalForInterest = AccountingRules.getDigitsBeforeDecimalForInterest().intValue();
        int digitsAfterDecimalForMonetaryAmounts = AccountingRules.getDigitsAfterDecimal().intValue();
        int digitsBeforeDecimalForMonetaryAmounts = AccountingRules.getDigitsBeforeDecimal().intValue();
        ApplicationConfigurationDto appConfig = new ApplicationConfigurationDto(digitsAfterDecimalForInterest, digitsBeforeDecimalForInterest, digitsAfterDecimalForMonetaryAmounts, digitsBeforeDecimalForMonetaryAmounts);
        Map<String, String> disbursalPaymentTypes = new LinkedHashMap<String, String>();
        try {
            for (PaymentTypeDto paymentTypeDto : accountService.getLoanDisbursementTypes()) {
                disbursalPaymentTypes.put(paymentTypeDto.getValue().toString(), paymentTypeDto.getName());
            }
        } catch (Exception e) {
            throw new SystemException(e);
        }
        Map<String, String> repaymentpaymentTypes = new LinkedHashMap<String, String>();
        try {
            for (PaymentTypeDto paymentTypeDto : accountService.getLoanPaymentTypes()) {
                repaymentpaymentTypes.put(paymentTypeDto.getValue().toString(), paymentTypeDto.getName());
            }
        } catch (Exception e) {
            throw new SystemException(e);
        }
        String currency = loanProduct.getCurrency().getCurrencyCode();
        return new LoanCreationLoanDetailsDto(currency, isRepaymentIndependentOfMeetingEnabled, loanOfferingMeetingDto, customer.getCustomerMeetingValue().toDto(), loanPurposes, productDto, gracePeriodInInstallments, customerDetailDto, loanProductDtos, interestTypeName, fundDtos, collateralOptions, purposeOfLoanOptions, defaultFeeOptions, additionalFeeOptions, defaultFees, additionalFees, BigDecimal.valueOf(eligibleLoanAmount.getDefaultLoanAmount()), BigDecimal.valueOf(eligibleLoanAmount.getMaxLoanAmount()), BigDecimal.valueOf(eligibleLoanAmount.getMinLoanAmount()), defaultInterestRate, maxInterestRate, minInterestRate, eligibleNoOfInstall.getDefaultNoOfInstall().intValue(), eligibleNoOfInstall.getMaxNoOfInstall().intValue(), eligibleNoOfInstall.getMinNoOfInstall().intValue(), nextPossibleDisbursementDate, daysOfTheWeekOptions, weeksOfTheMonthOptions, variableInstallmentsAllowed, fixedRepaymentSchedule, minGapInDays, maxGapInDays, minInstallmentAmount, compareCashflowEnabled, isGlimEnabled, isGroup, clientDetails, appConfig, defaultPenalties, disbursalPaymentTypes, repaymentpaymentTypes, isGroupLoanWithMembersEnabled);
    } catch (SystemException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : FeePayment(org.mifos.accounts.fees.util.helpers.FeePayment) LoanDisbursementDateFactory(org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateFactory) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomValueListElementDto(org.mifos.application.master.business.CustomValueListElementDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) LinkedHashMap(java.util.LinkedHashMap) RankOfDay(org.mifos.application.meeting.util.helpers.RankOfDay) ApplicationConfigurationDto(org.mifos.dto.domain.ApplicationConfigurationDto) FeeFrequencyTypeEntity(org.mifos.accounts.fees.business.FeeFrequencyTypeEntity) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) LoanDisbursmentDateFactoryImpl(org.mifos.clientportfolio.newloan.domain.LoanDisbursmentDateFactoryImpl) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) FeeFrequencyType(org.mifos.accounts.fees.util.helpers.FeeFrequencyType) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) FeeDto(org.mifos.dto.domain.FeeDto) WeekDay(org.mifos.application.meeting.util.helpers.WeekDay) InterestType(org.mifos.accounts.productdefinition.util.helpers.InterestType) VariableInstallmentDetailsBO(org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) LoanAmountOption(org.mifos.accounts.productdefinition.business.LoanAmountOption) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) LoanCreationLoanDetailsDto(org.mifos.dto.screen.LoanCreationLoanDetailsDto) LoanOfferingInstallmentRange(org.mifos.accounts.productdefinition.business.LoanOfferingInstallmentRange) InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) LoanCreationProductDetailsDto(org.mifos.dto.screen.LoanCreationProductDetailsDto) ProductDetailsDto(org.mifos.dto.domain.ProductDetailsDto) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) MultipleLoanAccountDetailsDto(org.mifos.dto.screen.MultipleLoanAccountDetailsDto) BusinessRuleException(org.mifos.service.BusinessRuleException) SystemException(org.mifos.framework.exceptions.SystemException) MessageLookup(org.mifos.application.master.MessageLookup) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) CustomerBO(org.mifos.customers.business.CustomerBO) FeeDto(org.mifos.dto.domain.FeeDto) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) PenaltyDto(org.mifos.dto.domain.PenaltyDto) LoanDisbursementDateFinder(org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateFinder) FundBO(org.mifos.accounts.fund.business.FundBO) FeePaymentEntity(org.mifos.accounts.fees.business.FeePaymentEntity) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) FundDto(org.mifos.accounts.fund.servicefacade.FundDto) BigDecimal(java.math.BigDecimal) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) PropertyNotFoundException(org.mifos.framework.exceptions.PropertyNotFoundException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MeetingDto(org.mifos.dto.domain.MeetingDto) PrdOfferingDto(org.mifos.dto.domain.PrdOfferingDto) CustomValueDto(org.mifos.application.master.business.CustomValueDto) ValueListElement(org.mifos.dto.domain.ValueListElement) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with PaymentTypeDto

use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.

the class StandardAccountServiceTest method testDisbursalAmountScaleDifferenceDoesNotMatter.

@Test
public void testDisbursalAmountScaleDifferenceDoesNotMatter() throws Exception {
    when(mockLoanAccount.getLoanAmount()).thenReturn(new Money(TestUtils.EURO, "300"));
    AccountPaymentParametersDto disbursal = new AccountPaymentParametersDto(new UserReferenceDto((short) 1), new AccountReferenceDto(1), new BigDecimal("300.0000000000000"), new LocalDate(), new PaymentTypeDto((short) 1, "CASH"), "");
    List<InvalidPaymentReason> errors = new ArrayList<InvalidPaymentReason>();
    standardAccountService.disbursalAmountMatchesFullLoanAmount(disbursal.getPaymentAmount(), errors, mockLoanAccount);
    assertThat(errors.isEmpty(), is(true));
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) Money(org.mifos.framework.util.helpers.Money) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) ArrayList(java.util.ArrayList) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with PaymentTypeDto

use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.

the class AccountApplyGroupPaymentAction method applyPayment.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward applyPayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
    String paymentType = request.getParameter(Constants.INPUT);
    Integer accountId;
    if (actionForm.getAccountId().isEmpty() || actionForm.getAccountId() == null) {
        accountId = loanDao.findByGlobalAccountNum(actionForm.getGlobalAccountNum()).getAccountId();
    } else {
        accountId = Integer.valueOf(actionForm.getAccountId());
    }
    UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
    AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountId, paymentType, userContext.getLocaleId(), userReferenceDto, actionForm.getTrxnDate());
    validateAccountPayment(accountPaymentDto, accountId, request);
    validateAmount(accountPaymentDto, actionForm.getAmount());
    PaymentTypeDto paymentTypeDto;
    String amount = actionForm.getAmount();
    if (accountPaymentDto.getAccountType().equals(AccountTypeDto.LOAN_ACCOUNT) || accountPaymentDto.getAccountType().equals(AccountTypeDto.GROUP_LOAN_ACCOUNT)) {
        paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    } else {
        paymentTypeDto = getFeePaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    }
    AccountPaymentParametersDto accountPaymentParametersDto;
    if (isGroupParentAccount(accountId)) {
        accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto(), actionForm.getIndividualValues());
    } else if (isGroupMemberAccount(accountId)) {
        accountPaymentParametersDto = preparePaymentParametersDto(accountId, userReferenceDto, amount, actionForm, paymentTypeDto, userContext, paymentType);
    } else {
        accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto());
    }
    if (paymentTypeDto.getValue().equals(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId())) {
        this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, actionForm.getAccountForTransfer());
    } else {
        this.accountServiceFacade.makePayment(accountPaymentParametersDto);
    }
    request.getSession().setAttribute("globalAccountNum", ((AccountApplyPaymentActionForm) form).getGlobalAccountNum());
    ActionForward findForward;
    if (actionForm.getPrintReceipt()) {
        findForward = mapping.findForward(getForward("PRINT"));
    } else {
        findForward = mapping.findForward(getForward(((AccountApplyPaymentActionForm) form).getInput()));
    }
    return findForward;
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) BigDecimal(java.math.BigDecimal) ActionForward(org.apache.struts.action.ActionForward) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with PaymentTypeDto

use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.

the class LoanDisbursementAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;
    UserContext uc = getUserContext(request);
    Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
    trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
    Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());
    Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
    Integer accountForTransferId = (StringUtils.isBlank(actionForm.getAccountForTransfer())) ? null : legacyAccountDao.getAccountIdByGlobalAccountNumber(actionForm.getAccountForTransfer());
    AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);
    Date originalDisbursementDate = DateUtils.getDateWithoutTimeStamp(((LoanBO) accountBO).getDisbursementDate());
    createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);
    try {
        String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
        String paymentTypeIdStringForFees = actionForm.getPaymentModeOfPayment();
        Short paymentTypeIdForDisbursement = StringUtils.isEmpty(paymentTypeIdStringForDisbursement) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForDisbursement);
        Short paymentTypeIdForFees = StringUtils.isEmpty(paymentTypeIdStringForFees) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForFees);
        Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
        final String comment = "";
        final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
        CustomerDto customerDto = null;
        PaymentTypeDto paymentType = null;
        AccountPaymentParametersDto loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(loanAccountId), disbursalAmount, new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
        monthClosingServiceFacade.validateTransactionDate(trxnDate);
        // GLIM
        List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
        for (LoanBO individual : individualLoans) {
            if (!loanAccountServiceFacade.isTrxnDateValid(Integer.valueOf(individual.getAccountId()), trxnDate)) {
                throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
            }
        }
        this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        for (LoanBO individual : individualLoans) {
            loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(individual.getAccountId()), individual.getLoanAmount().getAmount(), new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
            this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        }
        if (!((LoanBO) accountBO).isFixedRepaymentSchedule() && !originalDisbursementDate.equals(((LoanBO) accountBO).getDisbursementDate())) {
            this.loanAccountServiceFacade.updateMemberLoansFeeAmounts(loanAccountId);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessage());
    } catch (MifosRuntimeException e) {
        if (e.getCause() != null && e.getCause() instanceof AccountException) {
            throw new AccountException(e.getCause().getMessage());
        }
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    } catch (Exception e) {
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    }
    return mapping.findForward(Constants.UPDATE_SUCCESS);
}
Also used : UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerDto(org.mifos.dto.domain.CustomerDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) DateUtils.getUserLocaleDate(org.mifos.framework.util.helpers.DateUtils.getUserLocaleDate) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) LoanDisbursementActionForm(org.mifos.accounts.loan.struts.actionforms.LoanDisbursementActionForm) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) AccountException(org.mifos.accounts.exceptions.AccountException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)15 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)12 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)11 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)11 BigDecimal (java.math.BigDecimal)9 LocalDate (org.joda.time.LocalDate)9 UserContext (org.mifos.security.util.UserContext)6 ArrayList (java.util.ArrayList)5 LoanBO (org.mifos.accounts.loan.business.LoanBO)5 Money (org.mifos.framework.util.helpers.Money)5 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)4 CustomerDto (org.mifos.dto.domain.CustomerDto)4 CloseSession (org.mifos.framework.util.helpers.CloseSession)4 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)4 MifosUser (org.mifos.security.MifosUser)4 HashMap (java.util.HashMap)3 ActionForward (org.apache.struts.action.ActionForward)3 DateTime (org.joda.time.DateTime)3 Test (org.junit.Test)3 AccountException (org.mifos.accounts.exceptions.AccountException)3