Search in sources :

Example 1 with PaymentDto

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

the class LoanAccountServiceFacadeWebTier method makeEarlyRepaymentFromSavings.

public void makeEarlyRepaymentFromSavings(RepayLoanInfoDto repayLoanInfoDto, String savingsAccGlobalNum) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    SavingsAccountDetailDto savingsAcc = savingsServiceFacade.retrieveSavingsAccountDetails(savingsAccGlobalNum);
    Long savingsId = savingsAcc.getAccountId().longValue();
    Long customerId = savingsAcc.getCustomerId().longValue();
    LocalDate trxnDate = new LocalDate(repayLoanInfoDto.getDateOfPayment());
    Double amount = Double.parseDouble(repayLoanInfoDto.getEarlyRepayAmount());
    Integer paymentTypeId = Integer.parseInt(repayLoanInfoDto.getPaymentTypeId());
    String receiptId = repayLoanInfoDto.getReceiptNumber();
    LocalDate receiptDate = new LocalDate(repayLoanInfoDto.getReceiptDate());
    Locale preferredLocale = userContext.getPreferredLocale();
    SavingsWithdrawalDto savingsWithdrawalDto = new SavingsWithdrawalDto(savingsId, customerId, trxnDate, amount, paymentTypeId, receiptId, receiptDate, preferredLocale);
    try {
        transactionHelper.startTransaction();
        PaymentDto withdrawal = savingsServiceFacade.withdraw(savingsWithdrawalDto, true);
        repayLoanInfoDto.setSavingsPaymentId(withdrawal.getPaymentId());
        makeEarlyRepayment(repayLoanInfoDto);
        transactionHelper.commitTransaction();
    } catch (BusinessRuleException e) {
        transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    }
}
Also used : Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) PaymentDto(org.mifos.dto.domain.PaymentDto) AccountPaymentDto(org.mifos.dto.screen.AccountPaymentDto) LoanPaymentDto(org.mifos.dto.domain.LoanPaymentDto) ExpectedPaymentDto(org.mifos.dto.screen.ExpectedPaymentDto) 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) BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsAccountDetailDto(org.mifos.dto.domain.SavingsAccountDetailDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with PaymentDto

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

the class SavingsServiceFacadeWebTier method adjustTransaction.

@Override
public PaymentDto adjustTransaction(SavingsAdjustmentDto savingsAdjustment, boolean inTransaction) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsAdjustment.getSavingsId());
    try {
        personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    PersonnelBO updatedBy = this.personnelDao.findPersonnelById(userContext.getId());
    savingsAccount.updateDetails(userContext);
    Money amountAdjustedTo = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsAdjustment.getAdjustedAmount()));
    AccountPaymentEntity adjustedPayment = savingsAccount.findPaymentById(savingsAdjustment.getPaymentId());
    PaymentDto otherTransferPayment = adjustedPayment.getOtherTransferPaymentDto();
    Money originalAmount = adjustedPayment.getAmount();
    LocalDate dateOfWithdrawal = savingsAdjustment.getTrxnDate();
    if (adjustedPayment.isSavingsWithdrawal() && originalAmount.isLessThan(amountAdjustedTo)) {
        Money addedWithdrawalAmount = amountAdjustedTo.subtract(originalAmount);
        if (withdrawalMakesBalanceNegative(savingsAccount, addedWithdrawalAmount, dateOfWithdrawal)) {
            throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
        }
    } else if (adjustedPayment.isSavingsDeposit() && originalAmount.isGreaterThan(amountAdjustedTo)) {
        Money substractedAmount = originalAmount.subtract(amountAdjustedTo);
        if (withdrawalMakesBalanceNegative(savingsAccount, substractedAmount, dateOfWithdrawal)) {
            throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
        }
    }
    try {
        if (!inTransaction) {
            this.transactionHelper.startTransaction();
        }
        this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        AccountPaymentEntity newPayment = savingsAccount.adjustUserAction(amountAdjustedTo, savingsAdjustment.getNote(), savingsAdjustment.getTrxnDate(), updatedBy, savingsAdjustment.getPaymentId());
        recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(adjustedPayment.getPaymentDate()));
        if (hasAccountNegativeBalance(savingsAccount)) {
            throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
        }
        this.savingsDao.save(savingsAccount);
        // savings-savings transfer adjustment
        if (otherTransferPayment != null && otherTransferPayment.isSavingsPayment()) {
            this.transactionHelper.flushAndClearSession();
            SavingsBO otherSavingsAccount = this.savingsDao.findById(otherTransferPayment.getAccountId());
            otherSavingsAccount.updateDetails(userContext);
            AccountPaymentEntity newOtherTransferPayment = otherSavingsAccount.adjustUserAction(amountAdjustedTo, savingsAdjustment.getNote(), savingsAdjustment.getTrxnDate(), updatedBy, otherTransferPayment.getPaymentId());
            recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(adjustedPayment.getPaymentDate()));
            if (hasAccountNegativeBalance(otherSavingsAccount)) {
                throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
            }
            transactionHelper.flushAndClearSession();
            if (newPayment != null) {
                newPayment = savingsAccount.findPaymentById(newPayment.getPaymentId());
                newPayment.setOtherTransferPayment(newOtherTransferPayment);
                newOtherTransferPayment.setOtherTransferPayment(newPayment);
                legacyAcccountDao.updatePayment(newPayment);
            }
            this.savingsDao.save(otherSavingsAccount);
        }
        if (!inTransaction) {
            this.transactionHelper.commitTransaction();
        }
        return (newPayment == null) ? null : newPayment.toDto();
    } catch (BusinessRuleException e) {
        if (!inTransaction) {
            this.transactionHelper.rollbackTransaction();
        }
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        if (!inTransaction) {
            this.transactionHelper.rollbackTransaction();
        }
        throw new MifosRuntimeException(e.getMessage(), e);
    } finally {
        if (!inTransaction) {
            this.transactionHelper.closeSession();
        }
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) PaymentDto(org.mifos.dto.domain.PaymentDto) LocalDate(org.joda.time.LocalDate) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) 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) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with PaymentDto

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

the class SavingsServiceFacadeWebTier method fundTransfer.

@Override
public void fundTransfer(FundTransferDto fundTransferDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO targetAcc = this.savingsDao.findBySystemId(fundTransferDto.getTargetGlobalAccountNum());
    SavingsBO sourceAcc = this.savingsDao.findBySystemId(fundTransferDto.getSourceGlobalAccountNum());
    SavingsDepositDto depositDto;
    SavingsWithdrawalDto withdrawalDto;
    // prepare data
    try {
        depositDto = new SavingsDepositDto(targetAcc.getAccountId().longValue(), targetAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
        withdrawalDto = new SavingsWithdrawalDto(sourceAcc.getAccountId().longValue(), sourceAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
    } catch (PersistenceException ex) {
        throw new MifosRuntimeException(ex);
    }
    // transaction
    try {
        this.transactionHelper.startTransaction();
        PaymentDto deposit = deposit(depositDto, true);
        PaymentDto withdrawal = withdraw(withdrawalDto, true);
        // connect the two payments
        AccountPaymentEntity sourcePayment = sourceAcc.findPaymentById(withdrawal.getPaymentId());
        AccountPaymentEntity targetPayment = targetAcc.findPaymentById(deposit.getPaymentId());
        sourcePayment.setOtherTransferPayment(targetPayment);
        targetPayment.setOtherTransferPayment(sourcePayment);
        this.savingsDao.save(sourceAcc);
        this.savingsDao.save(targetAcc);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException ex) {
        this.transactionHelper.rollbackTransaction();
        throw ex;
    } catch (Exception ex) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(ex);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) UserContext(org.mifos.security.util.UserContext) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) PaymentDto(org.mifos.dto.domain.PaymentDto) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) 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) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 4 with PaymentDto

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

the class StandardAccountService method makePaymentFromSavings.

@Override
public void makePaymentFromSavings(AccountPaymentParametersDto accountPaymentParametersDto, String savingsGlobalAccNum) {
    transactionHelper.flushAndClearSession();
    SavingsAccountDetailDto savingsAcc = savingsServiceFacade.retrieveSavingsAccountDetails(savingsGlobalAccNum);
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Long savingsId = savingsAcc.getAccountId().longValue();
    Long customerId = accountPaymentParametersDto.getCustomer().getCustomerId().longValue();
    LocalDate dateOfWithdrawal = accountPaymentParametersDto.getPaymentDate();
    Double amount = accountPaymentParametersDto.getPaymentAmount().doubleValue();
    Integer modeOfPayment = accountPaymentParametersDto.getPaymentType().getValue().intValue();
    String receiptId = accountPaymentParametersDto.getReceiptId();
    LocalDate dateOfReceipt = accountPaymentParametersDto.getReceiptDate();
    Locale preferredLocale = Localization.getInstance().getLocaleById(user.getPreferredLocaleId());
    SavingsWithdrawalDto savingsWithdrawalDto = new SavingsWithdrawalDto(savingsId, customerId, dateOfWithdrawal, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
    try {
        transactionHelper.startTransaction();
        PaymentDto withdrawal = this.savingsServiceFacade.withdraw(savingsWithdrawalDto, true);
        makePaymentNoCommit(accountPaymentParametersDto, withdrawal.getPaymentId(), null);
        transactionHelper.commitTransaction();
    } catch (AccountException e) {
        transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (BusinessRuleException e) {
        transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    }
}
Also used : Locale(java.util.Locale) MifosUser(org.mifos.security.MifosUser) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) PaymentDto(org.mifos.dto.domain.PaymentDto) NonUniqueResultException(org.hibernate.NonUniqueResultException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) SavingsAccountDetailDto(org.mifos.dto.domain.SavingsAccountDetailDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with PaymentDto

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

the class WebTierAccountServiceFacade method applyHistoricalAdjustment.

@Override
public void applyHistoricalAdjustment(String globalAccountNum, Integer paymentId, String adjustmentNote, Short personnelId, AdjustedPaymentDto adjustedPaymentDto) {
    try {
        AccountBO accountBO = accountBusinessService.findBySystemId(globalAccountNum);
        accountBO.setUserContext(getUserContext());
        checkPermissionForAdjustment(accountBO);
        PersonnelBO personnelBO = personnelPersistence.findPersonnelById(personnelId);
        AccountPaymentEntity accountPaymentEntity = accountBO.findPaymentById(paymentId);
        if (accountPaymentEntity == null) {
            throw new AccountException(AccountExceptionConstants.CANNOTADJUST);
        }
        monthClosingServiceFacade.validateTransactionDate(accountPaymentEntity.getPaymentDate());
        PaymentDto otherTransferPayment = accountPaymentEntity.getOtherTransferPaymentDto();
        //flush to avoid proxy casting problems
        transactionHelper.flushAndClearSession();
        transactionHelper.startTransaction();
        Integer newSavingsPaymentId = null;
        if (otherTransferPayment != null) {
            SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(otherTransferPayment.getAccountId().longValue(), (adjustedPaymentDto == null) ? 0 : Double.valueOf(adjustedPaymentDto.getAmount()), adjustmentNote, otherTransferPayment.getPaymentId(), (adjustedPaymentDto == null) ? otherTransferPayment.getPaymentDate() : new LocalDate(adjustedPaymentDto.getPaymentDate()));
            PaymentDto newSavingsPayment = this.savingsServiceFacade.adjustTransaction(savingsAdjustment, true);
            newSavingsPaymentId = (newSavingsPayment == null) ? null : newSavingsPayment.getPaymentId();
        }
        //reload after flush & clear
        accountBO = accountBusinessService.findBySystemId(globalAccountNum);
        accountBO.setUserContext(getUserContext());
        AccountPaymentEntity adjustedPayment = null;
        Integer adjustedId;
        Stack<PaymentData> paymentsToBeReapplied = new Stack<PaymentData>();
        Map<Integer, Stack<PaymentData>> memberPaymentsToBeReappliedMap = new HashMap<Integer, Stack<PaymentData>>();
        if (accountBO.isGroupLoanAccount()) {
            for (LoanBO memberAccount : ((LoanBO) accountBO).getMemberAccounts()) {
                Stack<PaymentData> memberPaymentsToBeReapplied = new Stack<PaymentData>();
                memberPaymentsToBeReappliedMap.put(memberAccount.getAccountId(), memberPaymentsToBeReapplied);
            }
        }
        do {
            adjustedPayment = accountBO.getLastPmntToBeAdjusted();
            if (adjustedPayment == null) {
                break;
            }
            adjustedId = adjustedPayment.getPaymentId();
            if (!accountPaymentEntity.getPaymentId().equals(adjustedId)) {
                PersonnelBO paymentCreator = (adjustedPayment.getCreatedByUser() == null) ? personnelBO : adjustedPayment.getCreatedByUser();
                PaymentData paymentData = accountBO.createPaymentData(adjustedPayment.getAmount(), adjustedPayment.getPaymentDate(), adjustedPayment.getReceiptNumber(), adjustedPayment.getReceiptDate(), adjustedPayment.getPaymentType().getId(), paymentCreator);
                paymentData.setOtherTransferPayment(adjustedPayment.getOtherTransferPayment());
                paymentsToBeReapplied.push(paymentData);
                // handling new Group Loan Members payments
                for (AccountPaymentEntity memberAdjustedPayment : adjustedPayment.getMemberPayments()) {
                    PaymentData memberPaymentData = memberAdjustedPayment.getAccount().createPaymentData(memberAdjustedPayment.getAmount(), adjustedPayment.getPaymentDate(), adjustedPayment.getReceiptNumber(), adjustedPayment.getReceiptDate(), adjustedPayment.getPaymentType().getId(), paymentCreator);
                    memberPaymentsToBeReappliedMap.get(memberAdjustedPayment.getAccount().getAccountId()).push(memberPaymentData);
                }
            }
            transactionHelper.flushAndClearSession();
            //reload after flush & clear
            accountBO = accountBusinessService.findBySystemId(globalAccountNum);
            accountBO.setUserContext(getUserContext());
            accountBO.adjustLastPayment(adjustmentNote, personnelBO);
            legacyAccountDao.createOrUpdate(accountBO);
            //adjust New Group Loan member payments
            if (accountBO.isGroupLoanAccount()) {
                for (LoanBO memberAccount : ((LoanBO) accountBO).getMemberAccounts()) {
                    AccountPaymentEntity memberPayment = memberAccount.getLastPmntToBeAdjusted();
                    if (memberPayment.getParentPaymentId() == null) {
                        continue;
                    }
                    memberAccount.setUserContext(getUserContext());
                    memberAccount.adjustLastPayment(adjustmentNote, personnelBO);
                    legacyAccountDao.createOrUpdate(memberAccount);
                }
            }
            transactionHelper.flushSession();
        } while (!accountPaymentEntity.getPaymentId().equals(adjustedId));
        if (adjustedPaymentDto != null) {
            //reapply adjusted payment
            PersonnelBO paymentCreator = (accountPaymentEntity.getCreatedByUser() == null) ? personnelBO : accountPaymentEntity.getCreatedByUser();
            Money amount = new Money(accountBO.getCurrency(), adjustedPaymentDto.getAmount());
            PaymentData paymentData = accountBO.createPaymentData(amount, adjustedPaymentDto.getPaymentDate(), accountPaymentEntity.getReceiptNumber(), accountPaymentEntity.getReceiptDate(), adjustedPaymentDto.getPaymentType(), paymentCreator);
            paymentData.setAdjustment(true);
            //new adjusted savings payment must be tied to this payment
            if (newSavingsPaymentId != null) {
                AccountPaymentEntity newSvngPayment = legacyAccountDao.findPaymentById(newSavingsPaymentId);
                paymentData.setOtherTransferPayment(newSvngPayment);
            }
            accountBO.applyPayment(paymentData);
            legacyAccountDao.createOrUpdate(accountBO);
            transactionHelper.flushSession();
            // handling new Group Loan Members payments
            if (accountBO.isGroupLoanAccount()) {
                for (AdjustedPaymentDto adjustedMemberPayment : adjustedPaymentDto.getMemberPayments()) {
                    AccountBO memberAccount = ((LoanBO) accountBO).findMemberById(adjustedMemberPayment.getAccountId());
                    BigDecimal adjustedMemberPaymentAmount = BigDecimal.ZERO;
                    if (!StringUtils.isBlank(adjustedMemberPayment.getAmount())) {
                        adjustedMemberPaymentAmount = new BigDecimal(adjustedMemberPayment.getAmount());
                    }
                    Money memberAmount = new Money(memberAccount.getCurrency(), adjustedMemberPaymentAmount.toString());
                    PaymentData memberPaymentData = memberAccount.createPaymentData(memberAmount, adjustedPaymentDto.getPaymentDate(), accountPaymentEntity.getReceiptNumber(), accountPaymentEntity.getReceiptDate(), adjustedPaymentDto.getPaymentType(), paymentCreator);
                    memberPaymentData.setParentPayment(accountBO.getLastPmnt());
                    memberAccount.applyPayment(memberPaymentData);
                    legacyAccountDao.createOrUpdate(memberAccount);
                }
            }
        }
        while (!paymentsToBeReapplied.isEmpty()) {
            PaymentData paymentData = paymentsToBeReapplied.pop();
            //avoid lazy loading exception
            if (paymentData.getOtherTransferPayment() != null) {
                legacyAccountDao.updatePayment(paymentData.getOtherTransferPayment());
            }
            accountBO.applyPayment(paymentData);
            legacyAccountDao.createOrUpdate(accountBO);
            transactionHelper.flushSession();
            if (accountBO.isGroupLoanAccount()) {
                for (LoanBO memberAccount : ((LoanBO) accountBO).getMemberAccounts()) {
                    PaymentData memberPaymentData = memberPaymentsToBeReappliedMap.get(memberAccount.getAccountId()).pop();
                    memberPaymentData.setParentPayment(accountBO.getLastPmnt());
                    memberAccount.applyPayment(memberPaymentData);
                    legacyAccountDao.createOrUpdate(memberAccount);
                }
            }
        }
        transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (AccountException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (PersistenceException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (RuntimeException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) HashMap(java.util.HashMap) SavingsAdjustmentDto(org.mifos.dto.domain.SavingsAdjustmentDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PaymentDto(org.mifos.dto.domain.PaymentDto) AdjustedPaymentDto(org.mifos.dto.domain.AdjustedPaymentDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Stack(java.util.Stack) AccountBO(org.mifos.accounts.business.AccountBO) Money(org.mifos.framework.util.helpers.Money) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) AdjustedPaymentDto(org.mifos.dto.domain.AdjustedPaymentDto) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

AccountException (org.mifos.accounts.exceptions.AccountException)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 PaymentDto (org.mifos.dto.domain.PaymentDto)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 LocalDate (org.joda.time.LocalDate)4 ServiceException (org.mifos.framework.exceptions.ServiceException)4 MifosUser (org.mifos.security.MifosUser)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)3 SavingsWithdrawalDto (org.mifos.dto.domain.SavingsWithdrawalDto)3 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)3 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)3 StatesInitializationException (org.mifos.framework.exceptions.StatesInitializationException)3 UserContext (org.mifos.security.util.UserContext)3 Locale (java.util.Locale)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 SavingsAccountDetailDto (org.mifos.dto.domain.SavingsAccountDetailDto)2 AdjustableSavingsPaymentDto (org.mifos.dto.screen.AdjustableSavingsPaymentDto)2