Search in sources :

Example 1 with AccountPaymentData

use of org.mifos.accounts.util.helpers.AccountPaymentData 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 2 with AccountPaymentData

use of org.mifos.accounts.util.helpers.AccountPaymentData in project head by mifos.

the class SavingsServiceFacadeWebTier method deposit.

@Override
public PaymentDto deposit(SavingsDepositDto savingsDeposit, boolean inTransaction) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsDeposit.getSavingsId());
    try {
        personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    savingsAccount.updateDetails(userContext);
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(Short.valueOf((short) user.getUserId()));
    CustomerBO customer = this.customerDao.findCustomerById(savingsDeposit.getCustomerId().intValue());
    Money totalAmount = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsDeposit.getAmount()));
    PaymentData payment = PaymentData.createPaymentData(totalAmount, createdBy, savingsDeposit.getModeOfPayment().shortValue(), savingsDeposit.getDateOfDeposit().toDateMidnight().toDate());
    if (savingsDeposit.getDateOfReceipt() != null) {
        payment.setReceiptDate(savingsDeposit.getDateOfReceipt().toDateMidnight().toDate());
    }
    payment.setReceiptNum(savingsDeposit.getReceiptId());
    payment.setCustomer(customer);
    for (AccountActionDateEntity installment : savingsAccount.getTotalInstallmentsDue(savingsDeposit.getCustomerId().intValue())) {
        AccountPaymentData accountPaymentData = new SavingsPaymentData(installment);
        payment.addAccountPaymentData(accountPaymentData);
    }
    try {
        if (!inTransaction) {
            this.transactionHelper.startTransaction();
            this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        }
        AccountPaymentEntity newPaymentEntity = savingsAccount.applyPayment(payment);
        this.savingsDao.save(savingsAccount);
        Date lastIntPostDate = savingsAccount.getLastIntPostDate();
        if (lastIntPostDate != null && DateUtils.dateFallsOnOrBeforeDate(payment.getTransactionDate(), lastIntPostDate)) {
            this.recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(payment.getTransactionDate()));
        }
        // commit
        if (inTransaction) {
            this.transactionHelper.flushSession();
        } else {
            this.transactionHelper.commitTransaction();
        }
        return newPaymentEntity.toDto();
    } catch (AccountException e) {
        if (!inTransaction) {
            this.transactionHelper.rollbackTransaction();
        }
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        if (!inTransaction) {
            this.transactionHelper.closeSession();
        }
    }
}
Also used : AccountPaymentData(org.mifos.accounts.util.helpers.AccountPaymentData) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) AccountPaymentData(org.mifos.accounts.util.helpers.AccountPaymentData) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

Date (java.util.Date)2 LocalDate (org.joda.time.LocalDate)2 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 AccountException (org.mifos.accounts.exceptions.AccountException)2 AccountPaymentData (org.mifos.accounts.util.helpers.AccountPaymentData)2 CustomerBO (org.mifos.customers.business.CustomerBO)2 Money (org.mifos.framework.util.helpers.Money)2 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)1 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)1 PaymentData (org.mifos.accounts.util.helpers.PaymentData)1 PaymentStatus (org.mifos.accounts.util.helpers.PaymentStatus)1 SavingsPaymentData (org.mifos.accounts.util.helpers.SavingsPaymentData)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 MifosUser (org.mifos.security.MifosUser)1 UserContext (org.mifos.security.util.UserContext)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1