Search in sources :

Example 21 with AccountBO

use of org.mifos.accounts.business.AccountBO 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)

Example 22 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class ApplyCustomerFeeChangesHelper method execute.

@Override
public void execute(@SuppressWarnings("unused") long timeInMillis) throws BatchJobException {
    List<String> errorList = new ArrayList<String>();
    List<Short> updatedFeeIds = new ArrayList<Short>();
    try {
        updatedFeeIds = getFeeDao().getUpdatedFeesForCustomer();
    } catch (Exception e) {
        errorList.add(e.getMessage());
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
    for (Short feeId : updatedFeeIds) {
        try {
            FeeBO hydratedFee = getFeeDao().findById(feeId);
            if (!hydratedFee.getFeeChangeType().equals(FeeChangeType.NOT_UPDATED)) {
                List<AccountBO> accounts = new CustomerPersistence().getCustomerAccountsForFee(hydratedFee.getFeeId());
                if (accounts != null && accounts.size() > 0) {
                    for (AccountBO account : accounts) {
                        updateAccountFee(account, hydratedFee);
                    }
                }
            }
            hydratedFee.updateFeeChangeType(FeeChangeType.NOT_UPDATED);
            UserContext userContext = new UserContext();
            userContext.setId(PersonnelConstants.SYSTEM_USER);
            hydratedFee.setUserContext(userContext);
            hydratedFee.save();
            StaticHibernateUtil.commitTransaction();
        } catch (Exception e) {
            StaticHibernateUtil.rollbackTransaction();
            errorList.add("feeId: " + feeId);
        }
    }
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) FeeBO(org.mifos.accounts.fees.business.FeeBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException)

Example 23 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class SavingsCloseTest method whenClosingAccountShouldCreateStatusChangeHistoryForClosure.

@Test
public void whenClosingAccountShouldCreateStatusChangeHistoryForClosure() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // pre verification
    assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(1));
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(2));
    AccountStatusChangeHistoryEntity closure = savingsAccount.getAccountStatusChangeHistory().get(1);
    assertThat(closure.getAccount(), is((AccountBO) savingsAccount));
    assertTrue(closure.getOldStatus().isInState(AccountState.SAVINGS_ACTIVE));
    assertTrue(closure.getNewStatus().isInState(AccountState.SAVINGS_CLOSED));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 24 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class StandardAccountService method handleParentGroupLoanPayment.

/**
     * Handles parent NOT-GLIM group loan payment.
     */
private void handleParentGroupLoanPayment(AccountBO account, AccountPaymentParametersDto parentPaymentParametersDto, Integer savingsPaymentId, AccountPaymentEntity paymentEntity) throws PersistenceException, AccountException {
    if (account instanceof LoanBO && account.isParentGroupLoanAccount()) {
        if (parentPaymentParametersDto.getMemberInfo() == null || parentPaymentParametersDto.getMemberInfo().isEmpty()) {
            createMembersLoanPaymentsData(parentPaymentParametersDto);
        }
        for (Map.Entry<Integer, String> member : parentPaymentParametersDto.getMemberInfo().entrySet()) {
            AccountBO memberAcc = this.legacyAccountDao.getAccount(member.getKey());
            if (null == parentPaymentParametersDto.getMemberAccountIdToRepay() || (null != parentPaymentParametersDto.getMemberAccountIdToRepay() && !parentPaymentParametersDto.getMemberAccountIdToRepay().equals(memberAcc.getAccountId()))) {
                AccountPaymentParametersDto memberAccountPaymentParametersDto = new AccountPaymentParametersDto(parentPaymentParametersDto.getUserMakingPayment(), new AccountReferenceDto(memberAcc.getAccountId()), new BigDecimal(member.getValue()), parentPaymentParametersDto.getPaymentDate(), parentPaymentParametersDto.getPaymentType(), parentPaymentParametersDto.getComment(), parentPaymentParametersDto.getReceiptDate(), parentPaymentParametersDto.getReceiptId(), memberAcc.getCustomer().toCustomerDto());
                if (parentPaymentParametersDto.getPaymentOptions().contains(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS)) {
                    memberAccountPaymentParametersDto.addPaymentOption(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS);
                }
                makePaymentNoCommit(memberAccountPaymentParametersDto, savingsPaymentId, paymentEntity);
            } else {
                AccountPaymentDto paymentDto = new AccountPaymentDto(Double.valueOf(member.getValue()), parentPaymentParametersDto.getPaymentDate().toDateMidnight().toDate(), parentPaymentParametersDto.getReceiptId(), reciptDateNullValidation(parentPaymentParametersDto.getReceiptDate()), parentPaymentParametersDto.getPaymentType().getValue());
                ((LoanBO) memberAcc).makeEarlyRepayment(paymentDto, parentPaymentParametersDto.getUserMakingPayment().getUserId(), parentPaymentParametersDto.getRepayLoanInfoDto().isWaiveInterest(), new Money(account.getCurrency(), parentPaymentParametersDto.getInterestDueForCurrentInstalmanet()));
            }
        }
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Map(java.util.Map) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Example 25 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class StandardAccountService method doesTransactionIntroduceOverpayment.

public boolean doesTransactionIntroduceOverpayment(AccountPaymentParametersDto payment) throws Exception {
    AccountBO account = this.legacyAccountDao.getAccount(payment.getAccountId());
    Money amount = new Money(account.getCurrency(), payment.getPaymentAmount());
    return amount.isGreaterThan(((LoanBO) account).getTotalRepayableAmount());
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money)

Aggregations

AccountBO (org.mifos.accounts.business.AccountBO)106 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)39 LoanBO (org.mifos.accounts.loan.business.LoanBO)35 ArrayList (java.util.ArrayList)30 Money (org.mifos.framework.util.helpers.Money)30 UserContext (org.mifos.security.util.UserContext)29 Test (org.junit.Test)27 MifosRuntimeException (org.mifos.core.MifosRuntimeException)26 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)20 ServiceException (org.mifos.framework.exceptions.ServiceException)19 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)18 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)16 AccountException (org.mifos.accounts.exceptions.AccountException)15 MifosUser (org.mifos.security.MifosUser)14 Date (java.util.Date)13 LocalDate (org.joda.time.LocalDate)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)11 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 FeeBO (org.mifos.accounts.fees.business.FeeBO)9