Search in sources :

Example 31 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class DecliningBalanceWithEqualPrincipalInstallmentsLoanInterestCalculatorTest method shouldCalculateLoanInterestWithPrincipalOnlyGrace.

@Test
public void shouldCalculateLoanInterestWithPrincipalOnlyGrace() {
    // setup
    LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0").withInterestRate("10.0").withDurationInYears("1.0").withGraceType(GraceType.PRINCIPALONLYGRACE).withGraceDurationOf(0).withNumberOfInstallments(6).withInterestFractionalRatePerInstallmentOf("0.16").build();
    // exercise test
    Money calculatedInterest = decliningBalanceWithEqualPrincipalInstallmentsLoanInterestCalculator.calculate(loanInterestCalculationDetails);
    // verification
    assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("56.0"))));
}
Also used : Money(org.mifos.framework.util.helpers.Money) Test(org.junit.Test)

Example 32 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class FlatLoanInterestCalculatorTest method shouldCalculateFlatLoanInterest.

@Test
public void shouldCalculateFlatLoanInterest() {
    // setup
    LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0").withInterestRate("10.0").withDurationInYears("1.0").build();
    // exercise test
    Money calculatedInterest = flatLoanInterestCalculator.calculate(loanInterestCalculationDetails);
    // verification
    assertThat(calculatedInterest, is(TestMoneyUtil.createMoney("10.0")));
}
Also used : Money(org.mifos.framework.util.helpers.Money) Test(org.junit.Test)

Example 33 with Money

use of org.mifos.framework.util.helpers.Money 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 34 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class BulkEntryDisplayHelper method generateSavingsValues.

private void generateSavingsValues(final StringBuilder builder, final int rows, final int columns, final SavingsAccountDto accountView, final Money[] groupTotals, final int size, final int initialAccNo, final String method, final boolean isDeposit, final int totalsColumn, final int loanProductsSize, final int savingsProductSize, final int levelId, final MifosCurrency currency) {
    String name = isDeposit ? "depositAmountEntered" : "withDrawalAmountEntered";
    String amount = "";
    Money totalAmount = new Money(Money.getDefaultCurrency(), "0.0");
    int depWithFlag = isDeposit ? 1 : 2;
    if (isDeposit) {
        if (method.equals(CollectionSheetEntryConstants.GETMETHOD)) {
            totalAmount = new Money(Money.getDefaultCurrency(), accountView.getTotalDepositDue());
            amount = totalAmount.toString();
        } else if (method.equals(CollectionSheetEntryConstants.PREVIOUSMETHOD) || method.equals(CollectionSheetEntryConstants.VALIDATEMETHOD) || method.equals(CollectionSheetEntryConstants.PREVIEWMETHOD)) {
            if (accountView.getDepositAmountEntered() != null) {
                amount = accountView.getDepositAmountEntered();
                if (!"".equals(accountView.getDepositAmountEntered().trim()) && accountView.isValidDepositAmountEntered()) {
                    totalAmount = new Money(currency, accountView.getDepositAmountEntered());
                    amount = totalAmount.toString();
                    accountView.setDepositAmountEntered(amount);
                }
            }
        }
    } else {
        if (method.equals(CollectionSheetEntryConstants.PREVIOUSMETHOD) || method.equals(CollectionSheetEntryConstants.VALIDATEMETHOD) || method.equals(CollectionSheetEntryConstants.PREVIEWMETHOD)) {
            if (accountView.getWithDrawalAmountEntered() != null) {
                amount = accountView.getWithDrawalAmountEntered();
                if (!"".equals(accountView.getWithDrawalAmountEntered().trim()) && accountView.isValidWithDrawalAmountEntered()) {
                    totalAmount = new Money(currency, accountView.getWithDrawalAmountEntered());
                    amount = totalAmount.toString();
                    accountView.setWithDrawalAmountEntered(amount);
                }
            }
        }
    }
    if (method.equals(CollectionSheetEntryConstants.PREVIOUSMETHOD) || method.equals(CollectionSheetEntryConstants.VALIDATEMETHOD) || method.equals(CollectionSheetEntryConstants.GETMETHOD)) {
        if (ClientRules.getCenterHierarchyExists()) {
            BulkEntryTagUIHelper.getInstance().generateSavingsTextInput(builder, name + "[" + rows + "][" + columns + "]", amount, rows, columns, size, initialAccNo, loanProductsSize, savingsProductSize, depWithFlag, totalsColumn, levelId);
        } else {
            BulkEntryTagUIHelper.getInstance().generateSavingsTextInput(builder, name + "[" + rows + "][" + columns + "]", amount, columns, size, depWithFlag, loanProductsSize, savingsProductSize);
        }
    } else if (method.equals(CollectionSheetEntryConstants.PREVIEWMETHOD)) {
        Money depositDue = new Money(Money.getDefaultCurrency(), accountView.getTotalDepositDue());
        if (isDeposit && totalAmount.subtract(depositDue).isNonZero() && accountView.getSavingsTypeId().equals(SavingsType.MANDATORY.getValue())) {
            builder.append("<font color=\"#FF0000\">");
            builder.append(ConversionUtil.formatNumber(amount.toString()));
            builder.append("</font>");
        } else if ("".equals(amount)) {
            builder.append("&nbsp;");
        } else {
            builder.append(ConversionUtil.formatNumber(amount.toString()));
        }
    }
    groupTotals[totalsColumn] = groupTotals[totalsColumn] == null ? totalAmount : groupTotals[totalsColumn].add(totalAmount);
}
Also used : Money(org.mifos.framework.util.helpers.Money)

Example 35 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class BulkEntryDisplayHelper method generateCustomerAccountVaues.

private void generateCustomerAccountVaues(final CustomerAccountDto customerAccountDto, final String method, final StringBuilder builder, final MifosCurrency currency, final int rows, final Money[] groupTotals, final int size, final int initialAccNo, final int loanProductSize, final int savingsProductSize, final int levelId) {
    String amount = "";
    Money totalAmount = new Money(Money.getDefaultCurrency(), "0.0");
    if (method.equals(CollectionSheetEntryConstants.GETMETHOD)) {
        totalAmount = customerAccountDto.getTotalAmountDue();
        amount = new Money(currency, totalAmount.toString()).toString();
    } else if (method.equals(CollectionSheetEntryConstants.PREVIOUSMETHOD) || method.equals(CollectionSheetEntryConstants.VALIDATEMETHOD) || method.equals(CollectionSheetEntryConstants.PREVIEWMETHOD)) {
        if (customerAccountDto.getCustomerAccountAmountEntered() != null) {
            amount = customerAccountDto.getCustomerAccountAmountEntered();
            if (!"".equals(amount.trim()) && customerAccountDto.isValidCustomerAccountAmountEntered()) {
                totalAmount = new Money(currency, amount);
                amount = totalAmount.toString();
                customerAccountDto.setCustomerAccountAmountEntered(amount);
            }
        }
    }
    if (method.equals(CollectionSheetEntryConstants.PREVIOUSMETHOD) || method.equals(CollectionSheetEntryConstants.VALIDATEMETHOD) || method.equals(CollectionSheetEntryConstants.GETMETHOD)) {
        if (ClientRules.getCenterHierarchyExists()) {
            BulkEntryTagUIHelper.getInstance().generateCustomerAccountTextInput(builder, "customerAccountAmountEntered" + "[" + rows + "][" + columnIndex + "]", amount, rows, columnIndex, size, initialAccNo, loanProductSize, savingsProductSize, levelId);
        } else {
            BulkEntryTagUIHelper.getInstance().generateCustomerAccountTextInput(builder, "customerAccountAmountEntered" + "[" + rows + "][" + columnIndex + "]", amount, columnIndex, size, loanProductSize, savingsProductSize);
        }
    } else if (method.equals(CollectionSheetEntryConstants.PREVIEWMETHOD)) {
        if (totalAmount.subtract(customerAccountDto.getTotalAmountDue()).isNonZero()) {
            builder.append("<font color=\"#FF0000\">");
            builder.append(ConversionUtil.formatNumber(amount.toString()));
            builder.append("</font>");
        } else {
            builder.append(ConversionUtil.formatNumber(amount));
        }
    }
    groupTotals[columnIndex] = groupTotals[columnIndex] == null ? totalAmount : groupTotals[columnIndex].add(totalAmount);
}
Also used : Money(org.mifos.framework.util.helpers.Money)

Aggregations

Money (org.mifos.framework.util.helpers.Money)688 Test (org.junit.Test)326 Date (java.util.Date)110 ArrayList (java.util.ArrayList)93 LocalDate (org.joda.time.LocalDate)90 Date (java.sql.Date)85 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)80 DateTime (org.joda.time.DateTime)67 LoanBO (org.mifos.accounts.loan.business.LoanBO)64 MeetingBO (org.mifos.application.meeting.business.MeetingBO)57 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)56 BigDecimal (java.math.BigDecimal)53 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)49 AccountException (org.mifos.accounts.exceptions.AccountException)48 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)46 UserContext (org.mifos.security.util.UserContext)46 CustomerBO (org.mifos.customers.business.CustomerBO)39 MifosUser (org.mifos.security.MifosUser)35 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)34 PaymentData (org.mifos.accounts.util.helpers.PaymentData)34