Search in sources :

Example 76 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class SavingsBO method makePayment.

/**
     * @deprecated for deposits use {@link SavingsBO#deposit(AccountPaymentEntity, Integer)} and withdrawals use
     *             {@link SavingsBO#withdraw(AccountPaymentEntity)}
     */
@Deprecated
@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
    Money totalAmount = paymentData.getTotalAmount();
    Money enteredAmount = totalAmount;
    Date transactionDate = paymentData.getTransactionDate();
    List<AccountPaymentData> accountPayments = paymentData.getAccountPayments();
    if (paymentData.getCustomer() == null) {
        throw new NullPointerException("Customer in payment data during payment should not be null");
    }
    CustomerBO customer = paymentData.getCustomer();
    AccountPaymentEntity accountPayment = new AccountPaymentEntity(this, totalAmount, paymentData.getReceiptNum(), paymentData.getReceiptDate(), getPaymentTypeEntity(paymentData.getPaymentTypeId()), transactionDate);
    accountPayment.setCreatedByUser(paymentData.getPersonnel());
    accountPayment.setComment(paymentData.getComment());
    // make savings account active if inactive
    if (this.getState().getValue().equals(AccountState.SAVINGS_INACTIVE.getValue())) {
        this.changeStatus(AccountState.SAVINGS_ACTIVE, null, "Account Made Active Due to Payment", paymentData.getPersonnel());
    }
    if (totalAmount.isGreaterThanZero() && paymentData.getAccountPayments().size() <= 0) {
        SavingsTrxnDetailEntity accountTrxn = buildUnscheduledDeposit(accountPayment, totalAmount, paymentData.getPersonnel(), customer, transactionDate);
        accountPayment.addAccountTrxn(accountTrxn);
        addSavingsActivityDetails(buildSavingsActivity(totalAmount, getSavingsBalance(), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), transactionDate, paymentData.getPersonnel()));
        return accountPayment;
    }
    for (AccountPaymentData accountPaymentData : accountPayments) {
        SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(accountPaymentData.getInstallmentId(), customer.getCustomerId());
        if (accountAction != null && depositAmountIsInExcess(enteredAmount)) {
            if (accountAction.isPaid()) {
                throw new AccountException("errors.update", new String[] { getGlobalAccountNum() });
            }
            Money depositAmount = new Money(getCurrency());
            PaymentStatus paymentStatus = PaymentStatus.UNPAID;
            if (enteredAmount.isGreaterThanOrEqual(accountAction.getTotalDepositDue())) {
                depositAmount = accountAction.getTotalDepositDue();
                enteredAmount = enteredAmount.subtract(accountAction.getTotalDepositDue());
                paymentStatus = PaymentStatus.PAID;
            } else {
                depositAmount = enteredAmount;
                enteredAmount = new Money(getCurrency());
            }
            if (this.isVoluntary() && depositAmountIsInExcess(depositAmount)) {
                paymentStatus = PaymentStatus.PAID;
            }
            savingsBalance = savingsBalance.add(depositAmount);
            savingsPerformance.setPaymentDetails(depositAmount);
            accountAction.setPaymentDetails(depositAmount, paymentStatus, new java.sql.Date(transactionDate.getTime()));
            Short installmentId = accountAction.getInstallmentId();
            SavingsTrxnDetailEntity accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(accountPayment, customer, this.savingsBalance, depositAmount, paymentData.getPersonnel(), accountAction.getActionDate(), paymentData.getTransactionDate(), paymentData.getTransactionDate(), installmentId);
            accountPayment.addAccountTrxn(accountTrxn);
        }
    }
    if (depositAmountIsInExcess(enteredAmount)) {
        SavingsTrxnDetailEntity accountTrxn = buildUnscheduledDeposit(accountPayment, enteredAmount, paymentData.getPersonnel(), customer, transactionDate);
        accountPayment.addAccountTrxn(accountTrxn);
    }
    addSavingsActivityDetails(buildSavingsActivity(totalAmount, getSavingsBalance(), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), transactionDate, paymentData.getPersonnel()));
    return accountPayment;
}
Also used : AccountPaymentData(org.mifos.accounts.util.helpers.AccountPaymentData) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerBO(org.mifos.customers.business.CustomerBO) PaymentStatus(org.mifos.accounts.util.helpers.PaymentStatus)

Example 77 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class SavingsBO method withdraw.

public void withdraw(final AccountPaymentEntity payment, final CustomerBO payingCustomer) throws AccountException {
    final Money amountToWithdraw = payment.getAmount();
    if (amountToWithdraw.isGreaterThan(savingsBalance)) {
        throw new AccountException("errors.insufficentbalance", new String[] { getGlobalAccountNum() });
    }
    final Money maxWithdrawAmount = getSavingsOffering().getMaxAmntWithdrawl();
    if (maxWithdrawAmount != null && maxWithdrawAmount.isNonZero() && amountToWithdraw.isGreaterThan(maxWithdrawAmount)) {
        throw new AccountException("errors.exceedmaxwithdrawal", new String[] { getGlobalAccountNum() });
    }
    // make savings account active if inactive
    if (this.getState().getValue().equals(AccountState.SAVINGS_INACTIVE.getValue())) {
        this.changeStatus(AccountState.SAVINGS_ACTIVE, null, "Account Made Active Due to Payment", payment.getCreatedByUser());
    }
    this.addAccountPayment(payment);
    savingsBalance = savingsBalance.subtract(amountToWithdraw);
    savingsPerformance.setWithdrawDetails(amountToWithdraw);
    final SavingsActivityEntity savingsActivity = this.savingsTransactionActivityHelper.createSavingsActivityForWithdrawal(payment, this.savingsBalance, this);
    addSavingsActivityDetails(savingsActivity);
    final SavingsTrxnDetailEntity accountTrxnBO = this.savingsTransactionActivityHelper.createSavingsTrxnForWithdrawal(payment, amountToWithdraw, payingCustomer, this.savingsBalance);
    payment.addAccountTrxn(accountTrxnBO);
    buildFinancialEntries(payment.getAccountTrxns());
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException)

Example 78 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class CustomerServiceImpl method createSavingsAccountsForActiveSavingProducts.

private void createSavingsAccountsForActiveSavingProducts(ClientBO client, List<SavingsOfferingBO> savingProducts) {
    UserContext userContext = client.getUserContext();
    List<SavingsBO> savingsAccounts = new ArrayList<SavingsBO>();
    for (SavingsOfferingBO clientSavingsProduct : savingProducts) {
        try {
            if (clientSavingsProduct.isActive()) {
                List<CustomFieldDto> savingCustomFieldViews = new ArrayList<CustomFieldDto>();
                SavingsBO savingsAccount = new SavingsBO(userContext, clientSavingsProduct, client, AccountState.SAVINGS_ACTIVE, clientSavingsProduct.getRecommendedAmount(), savingCustomFieldViews);
                savingsAccounts.add(savingsAccount);
            }
        } catch (AccountException pe) {
            throw new MifosRuntimeException(pe);
        }
    }
    client.addSavingsAccounts(savingsAccounts);
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 79 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class CustomerServiceImpl method updateCustomerMeetingSchedule.

@Override
public void updateCustomerMeetingSchedule(MeetingBO updatedMeeting, CustomerBO customer) {
    try {
        customer.validateIsTopOfHierarchy();
        customerDao.checkPermissionForEditMeetingSchedule(updatedMeeting.getUserContext(), customer);
        CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
        this.hibernateTransactionHelper.startTransaction();
        boolean scheduleUpdateRequired = false;
        CustomerMeetingEntity meetingEntity = customer.getCustomerMeeting();
        if (meetingEntity != null) {
            MeetingBO meeting = customer.getCustomerMeetingValue();
            scheduleUpdateRequired = updateMeeting(meeting, updatedMeeting);
        } else {
            CustomerMeetingEntity newMeetingEntity = customer.createCustomerMeeting(updatedMeeting);
            customer.setCustomerMeeting(newMeetingEntity);
        }
        customerDao.save(customer);
        if (scheduleUpdateRequired) {
            handleChangeInMeetingSchedule(customer, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
        }
        this.hibernateTransactionHelper.commitTransaction();
    } catch (CustomerException e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (AccountException e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.hibernateTransactionHelper.closeSession();
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerMeetingEntity(org.mifos.customers.business.CustomerMeetingEntity) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CalendarEvent(org.mifos.calendar.CalendarEvent)

Example 80 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class GroupBO method updatePerformanceHistoryOnReversal.

@Override
public void updatePerformanceHistoryOnReversal(final LoanBO loan, final Money lastLoanAmount) throws CustomerException {
    try {
        GroupPerformanceHistoryEntity groupPerformanceHistoryEntity = (GroupPerformanceHistoryEntity) getPerformanceHistory();
        groupPerformanceHistoryEntity.updateOnReversal(loan, lastLoanAmount);
    } catch (AccountException e) {
        throw new CustomerException(e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) AccountException(org.mifos.accounts.exceptions.AccountException)

Aggregations

AccountException (org.mifos.accounts.exceptions.AccountException)115 MifosRuntimeException (org.mifos.core.MifosRuntimeException)47 UserContext (org.mifos.security.util.UserContext)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)42 Money (org.mifos.framework.util.helpers.Money)42 MifosUser (org.mifos.security.MifosUser)38 LoanBO (org.mifos.accounts.loan.business.LoanBO)31 ArrayList (java.util.ArrayList)30 LocalDate (org.joda.time.LocalDate)30 BusinessRuleException (org.mifos.service.BusinessRuleException)29 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)26 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)25 Date (java.util.Date)22 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)21 CustomerBO (org.mifos.customers.business.CustomerBO)19 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)17 PaymentData (org.mifos.accounts.util.helpers.PaymentData)17 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)16 ServiceException (org.mifos.framework.exceptions.ServiceException)16 BigDecimal (java.math.BigDecimal)14