Search in sources :

Example 56 with AccountPaymentEntity

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

the class GroupLoanAccountServiceFacadeWebTier method retrieveMemberAdjustmentDtos.

@Override
public List<GroupLoanMemberAdjustmentDto> retrieveMemberAdjustmentDtos(Integer parentAccountId, Integer parentPaymentId, BigDecimal newAmount) {
    LoanBO parentLoanAccount = loanDao.findById(parentAccountId);
    List<GroupLoanMemberAdjustmentDto> memberAdjustmentDtoList = new ArrayList<GroupLoanMemberAdjustmentDto>();
    LoanBO memberAccount = null;
    AccountPaymentEntity memberPayment = null;
    BigDecimal currentAmount = null;
    BigDecimal amountSpent = BigDecimal.ZERO;
    List<LoanBO> members = new ArrayList<LoanBO>(parentLoanAccount.getMemberAccounts());
    Iterator<LoanBO> itr = members.iterator();
    while (itr.hasNext()) {
        memberAccount = itr.next();
        if (itr.hasNext()) {
            currentAmount = newAmount.divide(memberAccount.calcFactorOfEntireLoan(), RoundingMode.HALF_UP);
            memberPayment = memberAccount.findPaymentByParentPaymentId(parentPaymentId);
            if (memberPayment == null) {
                continue;
            }
            memberAdjustmentDtoList.add(new GroupLoanMemberAdjustmentDto(memberPayment.getPaymentId(), memberAccount.getAccountId(), memberPayment.getAmount().getAmount(), currentAmount, new LocalDate(memberPayment.getPaymentDate()), memberAccount.getGlobalAccountNum(), memberAccount.getCustomer().getGlobalCustNum(), memberAccount.getCustomer().getDisplayName()));
            amountSpent = amountSpent.add(currentAmount);
        } else {
            //last element
            memberPayment = memberAccount.findPaymentByParentPaymentId(parentPaymentId);
            memberAdjustmentDtoList.add(new GroupLoanMemberAdjustmentDto(memberPayment.getPaymentId(), memberAccount.getAccountId(), memberPayment.getAmount().getAmount(), newAmount.subtract(amountSpent), new LocalDate(memberPayment.getPaymentDate()), memberAccount.getGlobalAccountNum(), memberAccount.getCustomer().getGlobalCustNum(), memberAccount.getCustomer().getDisplayName()));
        }
    }
    Collections.sort(memberAdjustmentDtoList);
    return memberAdjustmentDtoList;
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LocalDate(org.joda.time.LocalDate) GroupLoanMemberAdjustmentDto(org.mifos.dto.screen.GroupLoanMemberAdjustmentDto) BigDecimal(java.math.BigDecimal)

Example 57 with AccountPaymentEntity

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

the class CollectionSheetServiceImpl method saveCollectionSheet.

/**
     * The method saves a collection sheet.
     *
     * @throws SaveCollectionSheetException
     * */
@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) throws SaveCollectionSheetException {
    Long totalTime;
    Long totalTimeStart = System.currentTimeMillis();
    Long readTime;
    Long saveTime = null;
    Long saveTimeStart;
    Integer topCustomerId = saveCollectionSheet.getSaveCollectionSheetCustomers().get(0).getCustomerId();
    CollectionSheetCustomerDto collectionSheetTopCustomer = new CustomerPersistence().findCustomerWithNoAssocationsLoaded(topCustomerId);
    if (collectionSheetTopCustomer == null) {
        List<InvalidSaveCollectionSheetReason> invalidSaveCollectionSheetReasons = new ArrayList<InvalidSaveCollectionSheetReason>();
        List<String> invalidSaveCollectionSheetReasonsExtended = new ArrayList<String>();
        invalidSaveCollectionSheetReasons.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER);
        invalidSaveCollectionSheetReasonsExtended.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER.toString() + ": Customer Id: " + topCustomerId);
        throw new SaveCollectionSheetException(invalidSaveCollectionSheetReasons, invalidSaveCollectionSheetReasonsExtended);
    }
    Short branchId = collectionSheetTopCustomer.getBranchId();
    String searchId = collectionSheetTopCustomer.getSearchId();
    // session caching: prefetch collection sheet data
    // done prior to structure validation because it loads
    // the customers and accounts to be validated into the session
    SaveCollectionSheetSessionCache saveCollectionSheetSessionCache = new SaveCollectionSheetSessionCache();
    saveCollectionSheetSessionCache.loadSessionCacheWithCollectionSheetData(saveCollectionSheet, branchId, searchId);
    try {
        new SaveCollectionSheetStructureValidator().execute(saveCollectionSheet);
    } catch (SaveCollectionSheetException e) {
        System.out.println(e.printInvalidSaveCollectionSheetReasons());
        throw e;
    }
    /*
         * With preprocessing complete...
         *
         * only errors and warnings from the business model remain
         */
    final List<String> failedSavingsDepositAccountNums = new ArrayList<String>();
    final List<String> failedSavingsWithdrawalNums = new ArrayList<String>();
    final List<String> failedLoanDisbursementAccountNumbers = new ArrayList<String>();
    final List<String> failedLoanRepaymentAccountNumbers = new ArrayList<String>();
    final List<String> failedCustomerAccountPaymentNums = new ArrayList<String>();
    final List<ClientAttendanceBO> clientAttendances = saveCollectionSheetAssembler.clientAttendanceAssemblerfromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), saveCollectionSheet.getTransactionDate(), branchId, searchId);
    final AccountPaymentEntity payment = saveCollectionSheetAssembler.accountPaymentAssemblerFromDto(saveCollectionSheet.getTransactionDate(), saveCollectionSheet.getPaymentType(), saveCollectionSheet.getReceiptId(), saveCollectionSheet.getReceiptDate(), saveCollectionSheet.getUserId());
    final List<SavingsBO> savingsAccounts = saveCollectionSheetAssembler.savingsAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedSavingsDepositAccountNums, failedSavingsWithdrawalNums);
    Short paymentTypeId = (payment.getPaymentType() == null || payment.getPaymentType().getId() == null) ? null : payment.getPaymentType().getId();
    final List<LoanBO> loanAccounts = saveCollectionSheetAssembler.loanAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, paymentTypeId);
    final List<AccountBO> customerAccounts = saveCollectionSheetAssembler.customerAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedCustomerAccountPaymentNums);
    boolean databaseErrorOccurred = false;
    Throwable databaseError = null;
    readTime = System.currentTimeMillis() - totalTimeStart;
    try {
        saveTimeStart = System.currentTimeMillis();
        persistCollectionSheet(clientAttendances, loanAccounts, customerAccounts, savingsAccounts);
        saveTime = System.currentTimeMillis() - saveTimeStart;
    } catch (HibernateException e) {
        logger.error("database error saving collection sheet", e);
        databaseErrorOccurred = true;
        databaseError = e;
    }
    totalTime = System.currentTimeMillis() - totalTimeStart;
    printTiming(saveCollectionSheet.printSummary(), totalTime, saveTime, readTime, saveCollectionSheetSessionCache);
    return new CollectionSheetErrorsDto(failedSavingsDepositAccountNums, failedSavingsWithdrawalNums, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, failedCustomerAccountPaymentNums, databaseErrorOccurred, databaseError);
}
Also used : ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountBO(org.mifos.accounts.business.AccountBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) ClientAttendanceBO(org.mifos.customers.client.business.ClientAttendanceBO) HibernateException(org.hibernate.HibernateException) LoanBO(org.mifos.accounts.loan.business.LoanBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO)

Example 58 with AccountPaymentEntity

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

the class ClientServiceFacadeWebTier method getClientAccountPayments.

@Override
public List<AccountPaymentDto> getClientAccountPayments(String globalAccountNum) {
    List<AccountPaymentDto> clientAccountPayments = new ArrayList<AccountPaymentDto>();
    try {
        AccountBO account = legacyAccountDao.findBySystemId(globalAccountNum);
        List<AccountPaymentEntity> clientAccountPaymentsEntities = account.getAccountPayments();
        for (AccountPaymentEntity accountPaymentEntity : clientAccountPaymentsEntities) {
            clientAccountPayments.add(accountPaymentEntity.toScreenDto());
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
    return clientAccountPayments;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountPaymentDto(org.mifos.dto.screen.AccountPaymentDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 59 with AccountPaymentEntity

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

the class LoanAccountServiceFacadeWebTier method getLoanAccountPayments.

@Override
public List<AccountPaymentDto> getLoanAccountPayments(String globalAccountNum) {
    List<AccountPaymentDto> loanAccountPayments = new ArrayList<AccountPaymentDto>();
    LoanBO loanAccount = loanDao.findByGlobalAccountNum(globalAccountNum);
    List<AccountPaymentEntity> loanAccountPaymentsEntities = loanAccount.getAccountPayments();
    for (AccountPaymentEntity accountPaymentEntity : loanAccountPaymentsEntities) {
        loanAccountPayments.add(accountPaymentEntity.toScreenDto());
    }
    //for new group loan accounts
    if (loanAccount.isGroupLoanAccount() && null == loanAccount.getParentAccount()) {
        for (LoanBO member : loanAccount.getMemberAccounts()) {
            for (AccountPaymentEntity accPayment : member.getAccountPayments()) {
                if (!accPayment.isLoanDisbursment()) {
                    loanAccountPayments.add(accPayment.toScreenDto());
                }
            }
        }
        Collections.sort(loanAccountPayments, new AccountPaymentDtoComperator());
        Collections.reverse(loanAccountPayments);
    }
    return loanAccountPayments;
}
Also used : AccountPaymentDtoComperator(org.mifos.application.util.helpers.AccountPaymentDtoComperator) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountPaymentDto(org.mifos.dto.screen.AccountPaymentDto)

Example 60 with AccountPaymentEntity

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

the class ApplyAdjustment method listPossibleAdjustments.

@TransactionDemarcate(joinToken = true)
public ActionForward listPossibleAdjustments(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    this.resetActionFormFields(appAdjustActionForm);
    AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
    boolean decliningRecalculation = false;
    if (accnt instanceof LoanBO) {
        LoanBO loan = (LoanBO) accnt;
        if (loan.getInterestType().getId().equals(InterestType.DECLINING_PB.getValue())) {
            decliningRecalculation = true;
        }
    }
    List<AccountPaymentEntity> payments = accnt.getAccountPayments();
    ArrayList<AdjustablePaymentDto> adjustablePayments = new ArrayList<AdjustablePaymentDto>();
    int i = 1;
    for (AccountPaymentEntity payment : payments) {
        //ommit disbursal payment
        if (!payment.getAmount().equals(Money.zero()) && i != payments.size()) {
            AdjustablePaymentDto adjustablePaymentDto = new AdjustablePaymentDto(payment.getPaymentId(), payment.getAmount(), payment.getPaymentType().getName(), payment.getPaymentDate(), payment.getReceiptDate(), payment.getReceiptNumber());
            adjustablePayments.add(adjustablePaymentDto);
            if (decliningRecalculation) {
                //only last payment
                break;
            }
        }
        i++;
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
    SessionUtils.setAttribute(Constants.POSSIBLE_ADJUSTMENTS, adjustablePayments, request);
    request.setAttribute("method", "loadAdjustment");
    return mapping.findForward("loadadjustments_success");
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) AdjustablePaymentDto(org.mifos.accounts.business.AdjustablePaymentDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ArrayList(java.util.ArrayList) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)113 Money (org.mifos.framework.util.helpers.Money)56 Date (java.util.Date)43 LocalDate (org.joda.time.LocalDate)41 Test (org.junit.Test)36 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)34 AccountException (org.mifos.accounts.exceptions.AccountException)30 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)24 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)23 UserContext (org.mifos.security.util.UserContext)23 ArrayList (java.util.ArrayList)22 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)22 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 PaymentData (org.mifos.accounts.util.helpers.PaymentData)18 CustomerBO (org.mifos.customers.business.CustomerBO)18 AccountBO (org.mifos.accounts.business.AccountBO)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 BigDecimal (java.math.BigDecimal)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 Date (java.sql.Date)13