Search in sources :

Example 1 with PaymentStatus

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

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

the class SavingsPaymentStrategyImpl method makeScheduledPayments.

@Override
public Money makeScheduledPayments(final AccountPaymentEntity payment, final List<SavingsScheduleEntity> scheduledDeposits, final CustomerBO payingCustomer, final SavingsType savingsType, final Money savingsBalanceBeforeDeposit) {
    MifosCurrency currency = payment.getAccount().getCurrency();
    Money amountRemaining = new Money(currency, payment.getAmount().getAmount());
    Money runningBalance = new Money(currency, savingsBalanceBeforeDeposit.getAmount());
    final Date transactionDate = payment.getPaymentDate();
    Money depositAmount;
    PaymentStatus paymentStatus;
    if (savingsType.getValue().equals(SavingsType.VOLUNTARY.getValue())) {
        // For voluntary savings accounts - mark all outstanding
        // installments as paid and then put the deposit amount in the
        // latest installment
        paymentStatus = PaymentStatus.PAID;
        SavingsScheduleEntity lastExpectedPayment = null;
        for (SavingsScheduleEntity expectedPayment : scheduledDeposits) {
            lastExpectedPayment = expectedPayment;
            expectedPayment.setPaymentDetails(new Money(currency), paymentStatus, new java.sql.Date(transactionDate.getTime()));
        }
        if (lastExpectedPayment != null) {
            if (amountRemaining.isGreaterThanOrEqual(lastExpectedPayment.getTotalDepositDue())) {
                depositAmount = lastExpectedPayment.getTotalDepositDue();
                amountRemaining = amountRemaining.subtract(lastExpectedPayment.getTotalDepositDue());
            } else {
                depositAmount = new Money(currency, amountRemaining.getAmount());
                amountRemaining = new Money(currency);
            }
            lastExpectedPayment.setPaymentDetails(depositAmount, paymentStatus, new java.sql.Date(transactionDate.getTime()));
            runningBalance = runningBalance.add(depositAmount);
            final SavingsTrxnDetailEntity voluntaryPaymentTrxn = savingsTransactionActivityHelper.createSavingsTrxnForDeposit(payment, depositAmount, payingCustomer, lastExpectedPayment, runningBalance);
            payment.addAccountTrxn(voluntaryPaymentTrxn);
        }
    } else {
        // mandatory savings - pay off mandatory amounts as much as possible
        for (SavingsScheduleEntity accountAction : scheduledDeposits) {
            paymentStatus = PaymentStatus.UNPAID;
            if (amountRemaining.isGreaterThanOrEqual(accountAction.getTotalDepositDue())) {
                depositAmount = accountAction.getTotalDepositDue();
                amountRemaining = amountRemaining.subtract(accountAction.getTotalDepositDue());
                paymentStatus = PaymentStatus.PAID;
            } else {
                depositAmount = new Money(currency, amountRemaining.getAmount());
                amountRemaining = new Money(currency);
            }
            accountAction.setPaymentDetails(depositAmount, paymentStatus, new java.sql.Date(transactionDate.getTime()));
            runningBalance = runningBalance.add(depositAmount);
            final SavingsTrxnDetailEntity mandatoryScheduledPaymentTrxn = savingsTransactionActivityHelper.createSavingsTrxnForDeposit(payment, depositAmount, payingCustomer, accountAction, runningBalance);
            payment.addAccountTrxn(mandatoryScheduledPaymentTrxn);
            if (amountRemaining.isLessThanOrEqualZero()) {
                return amountRemaining;
            }
        }
    }
    return amountRemaining;
}
Also used : Money(org.mifos.framework.util.helpers.Money) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Date(java.util.Date) PaymentStatus(org.mifos.accounts.util.helpers.PaymentStatus)

Aggregations

Date (java.util.Date)2 PaymentStatus (org.mifos.accounts.util.helpers.PaymentStatus)2 Money (org.mifos.framework.util.helpers.Money)2 LocalDate (org.joda.time.LocalDate)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 AccountPaymentData (org.mifos.accounts.util.helpers.AccountPaymentData)1 MifosCurrency (org.mifos.application.master.business.MifosCurrency)1 CustomerBO (org.mifos.customers.business.CustomerBO)1