Search in sources :

Example 1 with LoanAccountsProductDto

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

the class CollectionSheetEntryDto method addLoanAccountDetails.

public void addLoanAccountDetails(final LoanAccountDto loanAccount) {
    for (LoanAccountsProductDto loanAccountProductView : loanAccountDetails) {
        if (isProductExists(loanAccount, loanAccountProductView)) {
            loanAccountProductView.addLoanAccountView(loanAccount);
            return;
        }
    }
    LoanAccountsProductDto loanAccountProductView = new LoanAccountsProductDto(loanAccount.getPrdOfferingId(), loanAccount.getPrdOfferingShortName());
    loanAccountProductView.addLoanAccountView(loanAccount);
    this.loanAccountDetails.add(loanAccountProductView);
}
Also used : LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto)

Example 2 with LoanAccountsProductDto

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

the class CollectionSheetEntryAction method getAmountTotalLogs.

private String getAmountTotalLogs(CollectionSheetEntryDecomposedDto decomposedViews) {
    String logMsg = "";
    Double totalCustomerAccountAmountDue = 0.0;
    Double totalCustomerAccountAmountEntered = 0.0;
    Double totalLoanDisBursementAmountEntered = 0.0;
    Double totalLoanEnteredAmount = 0.0;
    Double totalLoanAmountDue = 0.0;
    Double totalLoanDisbursalAmountDue = 0.0;
    Double totalLoanDisbursalAmount = 0.0;
    for (CustomerAccountDto customerAccountDto : decomposedViews.getCustomerAccountViews()) {
        if (customerAccountDto.getCustomerAccountAmountEntered() != null) {
            totalCustomerAccountAmountEntered += Double.parseDouble(customerAccountDto.getCustomerAccountAmountEntered());
        }
        totalCustomerAccountAmountDue += customerAccountDto.getTotalAmountDue().getAmount().doubleValue();
    }
    for (LoanAccountsProductDto loanAccountsProductDto : decomposedViews.getLoanAccountViews()) {
        if (loanAccountsProductDto.getDisBursementAmountEntered() != null) {
            totalLoanDisBursementAmountEntered += Double.parseDouble(loanAccountsProductDto.getDisBursementAmountEntered());
        }
        if (loanAccountsProductDto.getEnteredAmount() != null) {
            totalLoanEnteredAmount += Double.parseDouble(loanAccountsProductDto.getEnteredAmount());
        }
        totalLoanAmountDue += loanAccountsProductDto.getTotalAmountDue();
        totalLoanDisbursalAmountDue += loanAccountsProductDto.getTotalDisbursalAmountDue();
        totalLoanDisbursalAmount += loanAccountsProductDto.getTotalDisburseAmount();
    }
    logMsg += ", totalDisBursementAmountEntered:" + totalLoanDisBursementAmountEntered;
    logMsg += ", totalDisbursalAmount:" + totalLoanDisbursalAmount;
    logMsg += ", totalEnteredAmount:" + totalLoanEnteredAmount;
    logMsg += ", totalAmountDue:" + totalLoanAmountDue;
    logMsg += ", totalDisbursalAmountDue:" + totalLoanDisbursalAmountDue;
    logMsg += ", totalCustomerAccountAmountEntered:" + totalCustomerAccountAmountEntered;
    logMsg += ", totalCustomerAccountAmountDue:" + totalCustomerAccountAmountDue;
    return logMsg;
}
Also used : CustomerAccountDto(org.mifos.customers.util.helpers.CustomerAccountDto) LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto)

Example 3 with LoanAccountsProductDto

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

the class CollectionSheetEntryDtoPostPreviewValidator method validatePopulatedData.

private ActionErrors validatePopulatedData(final CollectionSheetEntryDto parent, final ActionErrors errors, final Locale locale) {
    List<CollectionSheetEntryDto> children = parent.getCollectionSheetEntryChildren();
    String acCollections = MessageLookup.getLocalizedMessage(CollectionSheetEntryConstants.AC_COLLECTION);
    if (null != children) {
        for (CollectionSheetEntryDto collectionSheetEntryDto : children) {
            validatePopulatedData(collectionSheetEntryDto, errors, locale);
        }
    }
    for (LoanAccountsProductDto accountView : parent.getLoanAccountDetails()) {
        if (accountView.isDisburseLoanAccountPresent() || accountView.getLoanAccountViews().size() > 1) {
            Money enteredAmount = new Money(Money.getDefaultCurrency(), 0.0);
            if (null != accountView.getEnteredAmount() && accountView.isValidAmountEntered()) {
                enteredAmount = new Money(Money.getDefaultCurrency(), getDoubleValue(accountView.getEnteredAmount()));
            }
            Money enteredDisbursalAmount = new Money(Money.getDefaultCurrency(), 0.0);
            if (null != accountView.getDisBursementAmountEntered() && accountView.isValidDisbursementAmount()) {
                enteredDisbursalAmount = new Money(Money.getDefaultCurrency(), getDoubleValue(accountView.getDisBursementAmountEntered()));
            }
            Money totalDueAmount = new Money(Money.getDefaultCurrency(), accountView.getTotalAmountDue());
            Money totalDisburtialAmount = new Money(Money.getDefaultCurrency(), accountView.getTotalDisburseAmount());
            if (totalDisburtialAmount.isGreaterThanZero()) {
                if ((!accountView.isValidDisbursementAmount() || accountView.getDisBursementAmountEntered() == null || !enteredDisbursalAmount.toString().equals(totalDisburtialAmount.toString())) && !enteredDisbursalAmount.isZero()) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                }
            }
            if (totalDueAmount.isGreaterThanZero()) {
                if ((!accountView.isValidAmountEntered() || accountView.getEnteredAmount() == null || !enteredAmount.toString().equals(totalDueAmount.toString())) && !enteredAmount.isZero()) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                }
            }
            boolean moreThanTwoLoanAccountsToPrepaid = isThereMoreThanTwoLoanAccountsToPrepaid(accountView.getLoanAccountViews());
            if (totalDisburtialAmount.isLessThanOrEqualZero() && totalDueAmount.isLessThanOrEqualZero()) {
                if (!accountView.isValidAmountEntered() || !accountView.isValidDisbursementAmount() || !enteredDisbursalAmount.isZero() || (!moreThanTwoLoanAccountsToPrepaid && !enteredAmount.isZero())) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                } else if (moreThanTwoLoanAccountsToPrepaid && !enteredAmount.isZero()) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDPREPAYAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDPREPAYAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                }
            }
        }
    }
    for (SavingsAccountDto savingsAccountDto : parent.getSavingsAccountDetails()) {
        if (!savingsAccountDto.isValidDepositAmountEntered() || !savingsAccountDto.isValidWithDrawalAmountEntered()) {
            errors.add(CollectionSheetEntryConstants.ERRORINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.ERRORINVALIDAMOUNT, savingsAccountDto.getSavingsOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
        }
    }
    CustomerAccountDto customerAccountDto = parent.getCustomerAccountDetails();
    Double customerAccountAmountEntered = 0.0;
    if (null != customerAccountDto.getCustomerAccountAmountEntered() && customerAccountDto.isValidCustomerAccountAmountEntered()) {
        customerAccountAmountEntered = getDoubleValue(customerAccountDto.getCustomerAccountAmountEntered());
    }
    if (!customerAccountDto.isValidCustomerAccountAmountEntered() || customerAccountAmountEntered < 0.0) {
        errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDACCOLLECTIONS, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDACCOLLECTIONS, acCollections, parent.getCustomerDetail().getDisplayName()));
    }
    return errors;
}
Also used : Money(org.mifos.framework.util.helpers.Money) CustomerAccountDto(org.mifos.customers.util.helpers.CustomerAccountDto) ActionMessage(org.apache.struts.action.ActionMessage) CollectionSheetEntryDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryDto) LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto) SavingsAccountDto(org.mifos.accounts.savings.util.helpers.SavingsAccountDto)

Example 4 with LoanAccountsProductDto

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

the class CollectionSheetDtoTranslatorImplTest method shouldTranslateLoanSavingsAndCustomerDetailsOnToCollectionSheetEntryGridDto.

@Test
public void shouldTranslateLoanSavingsAndCustomerDetailsOnToCollectionSheetEntryGridDto() throws Exception {
    // setup
    final Integer customerId = Integer.valueOf(7);
    final Integer customerAccountId = Integer.valueOf("55");
    final Integer savingsAccountId = Integer.valueOf("77");
    final String savingsProductShortName = "sav1";
    final Double savingsDepositDue = Double.valueOf("125.00");
    final Integer loanAccountId = Integer.valueOf("101");
    final String loanProductShortName = "lon1";
    final Double totalRepaymentDue = Double.valueOf("67.00");
    final Double totalCustomerAccountCollectionFee = Double.valueOf("29.87");
    final CollectionSheetCustomerAccountDto customerAccountDto = new CollectionSheetCustomerAccountDto(customerAccountId, defaultCurrencyId, totalCustomerAccountCollectionFee);
    final List<CollectionSheetCustomerDto> collectionSheetCustomer = Arrays.asList(centerCustomer);
    final List<CollectionSheetCustomerSavingDto> collectionSheetCustomerSavings = Arrays.asList(collectionSheetSaving);
    final List<CollectionSheetCustomerLoanDto> collectionSheetCustomerLoans = Arrays.asList(collectionSheetLoan);
    // stubbing
    when(collectionSheetData.getCollectionSheetCustomer()).thenReturn(collectionSheetCustomer);
    when(centerCustomer.getCustomerId()).thenReturn(customerId);
    when(centerCustomer.getCollectionSheetCustomerAccount()).thenReturn(customerAccountDto);
    when(centerCustomer.getCollectionSheetCustomerSaving()).thenReturn(collectionSheetCustomerSavings);
    when(centerCustomer.getCollectionSheetCustomerLoan()).thenReturn(collectionSheetCustomerLoans);
    // stub savings
    when(collectionSheetSaving.getCustomerId()).thenReturn(customerId);
    when(collectionSheetSaving.getAccountId()).thenReturn(savingsAccountId);
    when(collectionSheetSaving.getProductShortName()).thenReturn(savingsProductShortName);
    when(collectionSheetSaving.getTotalDepositAmount()).thenReturn(savingsDepositDue);
    // stub loans
    when(collectionSheetLoan.getCustomerId()).thenReturn(customerId);
    when(collectionSheetLoan.getAccountId()).thenReturn(loanAccountId);
    when(collectionSheetLoan.getProductShortName()).thenReturn(loanProductShortName);
    when(collectionSheetLoan.getPayInterestAtDisbursement()).thenReturn(Constants.NO);
    when(collectionSheetLoan.getTotalRepaymentDue()).thenReturn(totalRepaymentDue);
    when(collectionSheetLoan.getAccountStateId()).thenReturn(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue());
    // exercise test
    final CollectionSheetEntryGridDto formDto = collectionSheetDtoTranslator.toLegacyDto(collectionSheetData, formEnteredDataDto, null, defaultCurrency);
    // verification
    assertThat(formDto.getTotalCustomers(), is(collectionSheetCustomer.size()));
    // assert that the parent entry view exists with correctly populated
    final CollectionSheetEntryDto collectionSheetEntryParent = formDto.getBulkEntryParent();
    assertThat(collectionSheetEntryParent, is(notNullValue()));
    assertThat(collectionSheetEntryParent.getAttendence(), is(Short.valueOf("0")));
    assertThat(collectionSheetEntryParent.getCountOfCustomers(), is(1));
    assertThat(collectionSheetEntryParent.getCustomerDetail().getCustomerId(), is(customerId));
    // customer account details
    assertThat(collectionSheetEntryParent.getCustomerAccountDetails().getAccountId(), is(customerAccountId));
    assertThat(collectionSheetEntryParent.getCustomerAccountDetails().getTotalAmountDue().getAmountDoubleValue(), is(totalCustomerAccountCollectionFee));
    // savings account
    List<SavingsAccountDto> savingAccounts = collectionSheetEntryParent.getSavingsAccountDetails();
    assertThat(savingAccounts.size(), is(1));
    assertThat(savingAccounts.get(0).getAccountId(), is(savingsAccountId));
    assertThat(savingAccounts.get(0).getCustomerId(), is(customerId));
    assertThat(savingAccounts.get(0).getTotalDepositDue(), is(savingsDepositDue));
    // loan accounts
    List<LoanAccountsProductDto> loanAccountProductViews = collectionSheetEntryParent.getLoanAccountDetails();
    assertThat(loanAccountProductViews.size(), is(1));
    assertThat(loanAccountProductViews.get(0).getPrdOfferingShortName(), is(loanProductShortName));
    assertThat(loanAccountProductViews.get(0).getTotalAmountDue(), is(totalRepaymentDue));
    assertThat(loanAccountProductViews.get(0).getLoanAccountViews().size(), is(1));
    assertThat(loanAccountProductViews.get(0).getLoanAccountViews().get(0).getTotalAmountDue(), is(totalRepaymentDue));
}
Also used : LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto) SavingsAccountDto(org.mifos.accounts.savings.util.helpers.SavingsAccountDto) CollectionSheetEntryDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryDto) CollectionSheetEntryGridDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto) Test(org.junit.Test)

Example 5 with LoanAccountsProductDto

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

the class CollectionSheetEntryDto method setLoanAmountsEntered.

public void setLoanAmountsEntered(final Short prdOfferingId, final String enteredAmountValue, final String disbursementAmount) {
    for (LoanAccountsProductDto loanAccountView : loanAccountDetails) {
        if (prdOfferingId.equals(loanAccountView.getPrdOfferingId())) {
            loanAccountView.setEnteredAmount(enteredAmountValue);
            loanAccountView.setDisBursementAmountEntered(disbursementAmount);
            try {
                if (null != enteredAmountValue) {
                    new LocalizationConverter().getDoubleValueForCurrentLocale(enteredAmountValue);
                }
                loanAccountView.setValidAmountEntered(true);
            } catch (NumberFormatException ne) {
                loanAccountView.setValidAmountEntered(false);
            }
            try {
                if (null != disbursementAmount) {
                    new LocalizationConverter().getDoubleValueForCurrentLocale(disbursementAmount);
                }
                loanAccountView.setValidDisbursementAmount(true);
            } catch (NumberFormatException ne) {
                loanAccountView.setValidDisbursementAmount(false);
            }
        }
    }
}
Also used : LocalizationConverter(org.mifos.framework.util.LocalizationConverter) LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto)

Aggregations

LoanAccountsProductDto (org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto)8 SavingsAccountDto (org.mifos.accounts.savings.util.helpers.SavingsAccountDto)3 CollectionSheetEntryDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryDto)3 ArrayList (java.util.ArrayList)2 LoanAccountDto (org.mifos.accounts.loan.util.helpers.LoanAccountDto)2 CollectionSheetEntryGridDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto)2 ProductDto (org.mifos.application.servicefacade.ProductDto)2 CustomerAccountDto (org.mifos.customers.util.helpers.CustomerAccountDto)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 ActionMessage (org.apache.struts.action.ActionMessage)1 Test (org.junit.Test)1 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)1 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)1 CustomValueListElementDto (org.mifos.application.master.business.CustomValueListElementDto)1 MeetingBO (org.mifos.application.meeting.business.MeetingBO)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 OfficeDetailsDto (org.mifos.dto.domain.OfficeDetailsDto)1 PersonnelDto (org.mifos.dto.domain.PersonnelDto)1 LocalizationConverter (org.mifos.framework.util.LocalizationConverter)1