Search in sources :

Example 31 with AccountFeesActionDetailEntity

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

the class LoanScheduleEntity method getTotalFeeAmountPaidWithMiscFee.

public Money getTotalFeeAmountPaidWithMiscFee() {
    Money totalFees = new Money(getCurrency());
    for (AccountFeesActionDetailEntity obj : accountFeesActionDetails) {
        totalFees = totalFees.add(obj.getFeeAmountPaid());
    }
    totalFees = totalFees.add(getMiscFeePaid());
    return totalFees;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity)

Example 32 with AccountFeesActionDetailEntity

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

the class LoanScheduleEntity method removeFees.

Money removeFees(Short feeId) {
    Money feeAmount = null;
    AccountFeesActionDetailEntity objectToRemove = null;
    Set<AccountFeesActionDetailEntity> accountFeesActionDetailSet = this.getAccountFeesActionDetails();
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountFeesActionDetailSet) {
        if (accountFeesActionDetailEntity.getFee().getFeeId().equals(feeId) && (accountFeesActionDetailEntity.getFeeAmountPaid() == null || accountFeesActionDetailEntity.getFeeAmountPaid().isZero())) {
            objectToRemove = accountFeesActionDetailEntity;
            feeAmount = objectToRemove.getFeeAmount();
            break;
        } else if (accountFeesActionDetailEntity.getFee().getFeeId().equals(feeId) && accountFeesActionDetailEntity.getFeeAmountPaid() != null && accountFeesActionDetailEntity.getFeeAmountPaid().isGreaterThanZero()) {
            feeAmount = accountFeesActionDetailEntity.getFeeAmount().subtract(accountFeesActionDetailEntity.getFeeAmountPaid());
            ((LoanFeeScheduleEntity) accountFeesActionDetailEntity).setFeeAmount(accountFeesActionDetailEntity.getFeeAmountPaid());
            break;
        }
    }
    if (objectToRemove != null) {
        this.removeAccountFeesActionDetailEntity(objectToRemove);
    }
    return feeAmount;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity)

Example 33 with AccountFeesActionDetailEntity

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

the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentSchedule.

@Override
public List<LoanRepaymentScheduleItemDto> retrieveLoanRepaymentSchedule(String globalAccountNum, Date viewDate) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    LoanBO loanBO = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    try {
        personnelDao.checkAccessPermission(userContext, loanBO.getOfficeId(), loanBO.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    Errors errors = loanBusinessService.computeExtraInterest(loanBO, viewDate);
    if (errors.hasErrors()) {
        throw new MifosRuntimeException(errors.getErrorEntries().get(0).getDefaultMessage());
    }
    List<LoanRepaymentScheduleItemDto> loanSchedule = new ArrayList<LoanRepaymentScheduleItemDto>();
    for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) {
        LoanScheduleEntity loanAccountAction = (LoanScheduleEntity) accountAction;
        Set<AccountFeesActionDetailEntity> feeEntities = loanAccountAction.getAccountFeesActionDetails();
        List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
        for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
            feeDtos.add(convertToDto(feeEntity));
        }
        loanSchedule.add(new LoanRepaymentScheduleItemDto(loanAccountAction.getInstallmentId(), loanAccountAction.getActionDate(), loanAccountAction.getPaymentStatus(), loanAccountAction.getPaymentDate(), loanAccountAction.getPrincipal().toString(), loanAccountAction.getPrincipalPaid().toString(), loanAccountAction.getInterest().toString(), loanAccountAction.getInterestPaid().toString(), loanAccountAction.getPenalty().toString(), loanAccountAction.getPenaltyPaid().toString(), loanAccountAction.getExtraInterest().toString(), loanAccountAction.getExtraInterestPaid().toString(), loanAccountAction.getMiscFee().toString(), loanAccountAction.getMiscFeePaid().toString(), loanAccountAction.getMiscPenalty().toString(), loanAccountAction.getMiscPenaltyPaid().toString(), feeDtos));
    }
    return loanSchedule;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) UserContext(org.mifos.security.util.UserContext) LoanRepaymentScheduleItemDto(org.mifos.dto.domain.LoanRepaymentScheduleItemDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountFeeScheduleDto(org.mifos.dto.domain.AccountFeeScheduleDto) Errors(org.mifos.platform.validations.Errors) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 34 with AccountFeesActionDetailEntity

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

the class CustomerAccountBO method makePayment.

@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
    Money totalPaid = paymentData.getTotalAmount();
    if (totalPaid.isZero()) {
        throw new AccountException("errors.update", new String[] { "Attempting to pay a customer account balance of zero for customer: " + paymentData.getCustomer().getGlobalCustNum() });
    }
    final List<CustomerScheduleEntity> customerAccountPayments = findAllUnpaidInstallmentsUpToDatePlusNextMeeting(paymentData.getTransactionDate());
    if (customerAccountPayments.isEmpty()) {
        throw new AccountException(AccountConstants.NO_TRANSACTION_POSSIBLE, new String[] { "Trying to pay account charges before the due date." });
    }
    Money totalAllUnpaidInstallments = new Money(totalPaid.getCurrency(), "0.0");
    for (CustomerScheduleEntity customerSchedule : customerAccountPayments) {
        totalAllUnpaidInstallments = totalAllUnpaidInstallments.add(new Money(totalPaid.getCurrency(), dueAmountForCustomerSchedule(customerSchedule)));
    }
    if (totalAllUnpaidInstallments.compareTo(totalPaid) < 0) {
        throw new AccountException(AccountConstants.NO_TRANSACTION_POSSIBLE, new String[] { "Overpayments are not supported" });
    }
    final AccountPaymentEntity accountPayment = new AccountPaymentEntity(this, paymentData.getTotalAmount(), paymentData.getReceiptNum(), paymentData.getReceiptDate(), getPaymentTypeEntity(paymentData.getPaymentTypeId()), paymentData.getTransactionDate());
    BigDecimal leftFromPaidIn = totalPaid.getAmount();
    for (CustomerScheduleEntity customerSchedule : customerAccountPayments) {
        if (leftFromPaidIn.compareTo(BigDecimal.ZERO) == 0) {
            break;
        }
        final List<FeesTrxnDetailEntity> feeTrxns = new ArrayList<FeesTrxnDetailEntity>();
        for (AccountFeesActionDetailEntity accountFeesActionDetail : customerSchedule.getAccountFeesActionDetails()) {
            if (leftFromPaidIn.compareTo(BigDecimal.ZERO) > 0) {
                CustomerFeeScheduleEntity customerFeeSchedule = (CustomerFeeScheduleEntity) accountFeesActionDetail;
                BigDecimal feeFromScheduleToPay = leftFromPaidIn.min(customerFeeSchedule.getFeeDue().getAmount());
                customerFeeSchedule.makePayment(new Money(totalPaid.getCurrency(), feeFromScheduleToPay));
                final FeesTrxnDetailEntity feesTrxnDetailBO = new FeesTrxnDetailEntity(null, customerFeeSchedule.getAccountFee(), new Money(totalPaid.getCurrency(), feeFromScheduleToPay));
                feeTrxns.add(feesTrxnDetailBO);
                leftFromPaidIn = leftFromPaidIn.subtract(feeFromScheduleToPay);
            }
        }
        BigDecimal miscPenaltyToPay = leftFromPaidIn.min(customerSchedule.getMiscPenaltyDue().getAmount());
        if (miscPenaltyToPay.compareTo(BigDecimal.ZERO) > 0) {
            customerSchedule.payMiscPenalty(new Money(totalPaid.getCurrency(), miscPenaltyToPay));
            customerSchedule.setPaymentDate(new java.sql.Date(paymentData.getTransactionDate().getTime()));
            leftFromPaidIn = leftFromPaidIn.subtract(miscPenaltyToPay);
        }
        BigDecimal miscFeeToPay = BigDecimal.ZERO;
        if (leftFromPaidIn.compareTo(BigDecimal.ZERO) > 0) {
            miscFeeToPay = leftFromPaidIn.min(customerSchedule.getMiscFeeDue().getAmount());
            if (miscFeeToPay.compareTo(BigDecimal.ZERO) > 0) {
                customerSchedule.payMiscFee(new Money(totalPaid.getCurrency(), miscFeeToPay));
                customerSchedule.setPaymentDate(new java.sql.Date(paymentData.getTransactionDate().getTime()));
                leftFromPaidIn = leftFromPaidIn.subtract(miscFeeToPay);
            }
        }
        if (dueAmountForCustomerSchedule(customerSchedule).compareTo(BigDecimal.ZERO) == 0) {
            customerSchedule.setPaymentStatus(PaymentStatus.PAID);
        }
        Money customerScheduleAmountPaid = new Money(totalPaid.getCurrency(), miscFeeToPay.add(miscPenaltyToPay));
        final CustomerTrxnDetailEntity accountTrxn = new CustomerTrxnDetailEntity(accountPayment, AccountActionTypes.CUSTOMER_ACCOUNT_REPAYMENT, customerSchedule.getInstallmentId(), customerSchedule.getActionDate(), paymentData.getPersonnel(), paymentData.getTransactionDate(), customerScheduleAmountPaid, AccountConstants.PAYMENT_RCVD, null, new Money(totalPaid.getCurrency(), miscFeeToPay), new Money(totalPaid.getCurrency(), miscPenaltyToPay));
        for (FeesTrxnDetailEntity feesTrxnDetailEntity : feeTrxns) {
            accountTrxn.addFeesTrxnDetail(feesTrxnDetailEntity);
            feesTrxnDetailEntity.setAccountTrxn(accountTrxn);
        }
        accountPayment.addAccountTrxn(accountTrxn);
    }
    addCustomerActivity(new CustomerActivityEntity(this, paymentData.getPersonnel(), paymentData.getTotalAmount(), AccountConstants.PAYMENT_RCVD, paymentData.getTransactionDate()));
    return accountPayment;
}
Also used : AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Example 35 with AccountFeesActionDetailEntity

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

the class CustomerAccountBO method applyFeeToInstallments.

private Money applyFeeToInstallments(final List<FeeInstallment> feeInstallmentList, final List<AccountActionDateEntity> accountActionDateList) {
    Date lastAppliedDate = null;
    Money totalFeeAmountApplied = new Money(getCurrency());
    AccountFeesEntity accountFeesEntity = null;
    for (AccountActionDateEntity accountActionDateEntity : accountActionDateList) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        for (FeeInstallment feeInstallment : feeInstallmentList) {
            if (feeInstallment.getInstallmentId().equals(customerScheduleEntity.getInstallmentId())) {
                lastAppliedDate = customerScheduleEntity.getActionDate();
                totalFeeAmountApplied = totalFeeAmountApplied.add(feeInstallment.getAccountFee());
                AccountFeesActionDetailEntity accountFeesActionDetailEntity = new CustomerFeeScheduleEntity(customerScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
                customerScheduleEntity.addAccountFeesAction(accountFeesActionDetailEntity);
                accountFeesEntity = feeInstallment.getAccountFeesEntity();
            }
        }
    }
    if (accountFeesEntity != null) {
        accountFeesEntity.setLastAppliedDate(lastAppliedDate);
        addAccountFees(accountFeesEntity);
    }
    return totalFeeAmountApplied;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Aggregations

AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)39 Money (org.mifos.framework.util.helpers.Money)21 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)9 ArrayList (java.util.ArrayList)8 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)8 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)7 BigDecimal (java.math.BigDecimal)6 FeesTrxnDetailEntity (org.mifos.accounts.business.FeesTrxnDetailEntity)6 Date (java.sql.Date)5 CustomerScheduleEntity (org.mifos.customers.business.CustomerScheduleEntity)5 Date (java.util.Date)4 LocalDate (org.joda.time.LocalDate)4 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 AccountException (org.mifos.accounts.exceptions.AccountException)4 FeeBO (org.mifos.accounts.fees.business.FeeBO)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)4 Test (org.junit.Test)3 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)3 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)3