Search in sources :

Example 26 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class CustomerPersistence method getLoanDetailDto.

@SuppressWarnings("unchecked")
public List<LoanDetailDto> getLoanDetailDto(Integer customerId, UserContext userContext) throws PersistenceException {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("CUSTOMER_ID", customerId);
    List<Object[]> queryResult = executeNamedQuery("Customer.getLoanDetailDto", queryParameters);
    if (queryResult.size() == 0) {
        return null;
    }
    List<LoanDetailDto> loanDetails = new ArrayList<LoanDetailDto>();
    String globalAccountNum;
    String prdOfferingName;
    Short accountStateId;
    String accountStateName;
    Money outstandingBalance;
    Money totalAmountDue;
    String lookupName;
    Short currency;
    MifosCurrency mifosCurrency = Money.getDefaultCurrency();
    for (Object[] loanDetail : queryResult) {
        globalAccountNum = (String) loanDetail[0];
        prdOfferingName = (String) loanDetail[1];
        accountStateId = (Short) loanDetail[2];
        lookupName = (String) loanDetail[3];
        accountStateName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupName);
        // TODO - use default currency or retrieved currency?
        currency = (Short) loanDetail[4];
        outstandingBalance = new Money(mifosCurrency, (BigDecimal) loanDetail[5]);
        // TODO
        totalAmountDue = new Money(mifosCurrency, "7.7");
        loanDetails.add(new LoanDetailDto(globalAccountNum, prdOfferingName, accountStateId, accountStateName, outstandingBalance.toString(), totalAmountDue.toString(), "0"));
    }
    return loanDetails;
}
Also used : HashMap(java.util.HashMap) LoanDetailDto(org.mifos.dto.domain.LoanDetailDto) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Money(org.mifos.framework.util.helpers.Money) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 27 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class CustomerPersistence method getTotalAmountForGroup.

public Money getTotalAmountForGroup(final Integer groupId, final AccountState accountState) throws PersistenceException {
    MifosCurrency currency = getCurrencyForTotalAmountForGroup(groupId, accountState);
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("customerId", groupId);
    params.put("accountState", accountState.getValue());
    BigDecimal amount = getCalculateValueFromQueryResult(executeNamedQuery(NamedQueryConstants.GET_TOTAL_AMOUNT_FOR_GROUP, params));
    Money totalAmount = new Money(currency, amount);
    return totalAmount;
}
Also used : Money(org.mifos.framework.util.helpers.Money) HashMap(java.util.HashMap) MifosCurrency(org.mifos.application.master.business.MifosCurrency) BigDecimal(java.math.BigDecimal)

Example 28 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class LoanAccountServiceFacadeWebTier method validateInputInstallments.

@Override
public Errors validateInputInstallments(Date disbursementDate, Integer minGapInDays, Integer maxGapInDays, BigDecimal minInstallmentAmount, List<LoanCreationInstallmentDto> dtoInstallments, Integer customerId) {
    Short officeId = customerDao.findCustomerById(customerId).getOfficeId();
    VariableInstallmentDetailsBO variableInstallmentDetails = new VariableInstallmentDetailsBO();
    variableInstallmentDetails.setMinGapInDays(minGapInDays);
    variableInstallmentDetails.setMaxGapInDays(maxGapInDays);
    InstallmentValidationContext context = new InstallmentValidationContext(disbursementDate, variableInstallmentDetails, minInstallmentAmount, holidayServiceFacade, officeId);
    MifosCurrency currency = Money.getDefaultCurrency();
    List<RepaymentScheduleInstallment> installments = new ArrayList<RepaymentScheduleInstallment>();
    for (LoanCreationInstallmentDto dto : dtoInstallments) {
        Money principal = new Money(currency, dto.getPrincipal());
        Money interest = new Money(currency, dto.getInterest());
        Money fees = new Money(currency, dto.getFees());
        Money miscFees = new Money(currency);
        Money miscPenalty = new Money(currency);
        RepaymentScheduleInstallment installment = new RepaymentScheduleInstallment(dto.getInstallmentNumber(), dto.getDueDate(), principal, interest, fees, miscFees, miscPenalty);
        installment.setTotalAndTotalValue(new Money(currency, dto.getTotal()));
        installments.add(installment);
    }
    return installmentsValidator.validateInputInstallments(installments, context);
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) VariableInstallmentDetailsBO(org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO) ArrayList(java.util.ArrayList) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) InstallmentValidationContext(org.mifos.accounts.loan.business.service.validators.InstallmentValidationContext) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 29 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class BulkEntryDisplayHelper method buildForCenter.

public Money[] buildForCenter(final CollectionSheetEntryDto centerEntry, final List<ProductDto> loanProducts, final List<ProductDto> savingsProducts, final List<CustomValueListElementDto> custAttTypes, final StringBuilder builder, final String method, final UserContext userContext) {
    int rowIndex = 0;
    final int totalProductsSize = 2 * (loanProducts.size() + savingsProducts.size());
    final Money[] centerTotals = new Money[(totalProductsSize + 1)];
    Money[] groupTotals = new Money[(totalProductsSize + 1)];
    for (int i = 0; i < centerTotals.length; i++) {
        centerTotals[i] = new Money(centerEntry.getCurrency());
    }
    final MifosCurrency currency = centerEntry.getCurrency();
    final String accountLabel = getLocalizedMessage(CollectionSheetEntryConstants.ACCOUNTS_GROUP_CENTER);
    final List<CollectionSheetEntryDto> groupEntries = centerEntry.getCollectionSheetEntryChildren();
    for (CollectionSheetEntryDto groupEntry : groupEntries) {
        groupTotals = new Money[(totalProductsSize + 1)];
        int groupInitialAccNum = rowIndex;
        final List<CollectionSheetEntryDto> clientEntries = groupEntry.getCollectionSheetEntryChildren();
        final int clientCount = clientEntries.size();
        final String groupName = groupEntry.getCustomerDetail().getDisplayName();
        buildGroupName(builder, groupName, totalProductsSize + 1);
        for (CollectionSheetEntryDto clientEntry : clientEntries) {
            final int levelId = 1;
            buildClientRow(clientEntry, loanProducts, savingsProducts, clientCount, groupInitialAccNum, rowIndex, groupTotals, clientEntry.getCustomerDetail().getDisplayName(), builder, method, levelId, currency);
            generateAttendance(builder, custAttTypes, rowIndex, clientEntry, method);
            BulkEntryTagUIHelper.getInstance().generateEndTR(builder);
            rowIndex++;
        }
        final int levelId = 2;
        final String groupLabel = getLabel(ConfigurationConstants.GROUP, userContext);
        final String formattedGroupAccountStr = accountLabel.format(accountLabel, groupLabel);
        final String groupAccountStr = " " + formattedGroupAccountStr + " ";
        buildClientRow(groupEntry, loanProducts, savingsProducts, clientCount, groupInitialAccNum, rowIndex, groupTotals, groupAccountStr, builder, method, levelId, currency);
        BulkEntryTagUIHelper.getInstance().generateEmptyTD(builder, true);
        BulkEntryTagUIHelper.getInstance().generateEndTR(builder);
        rowIndex++;
        getTotalForRow(builder, groupEntry, groupTotals, rowIndex, method, userContext, loanProducts.size(), savingsProducts.size());
        for (int i = 0; i < groupTotals.length; i++) {
            if (groupTotals[i] != null) {
                centerTotals[i] = centerTotals[i].add(groupTotals[i]);
            }
        }
    }
    final int levelId = 3;
    final String center = getLabel(ConfigurationConstants.CENTER, userContext);
    final String formattedCenterAccountStr = accountLabel.format(accountLabel, center);
    final String centerAccountStr = " " + formattedCenterAccountStr + " ";
    buildClientRow(centerEntry, loanProducts, savingsProducts, 0, 0, rowIndex, groupTotals, centerAccountStr, builder, method, levelId, currency);
    BulkEntryTagUIHelper.getInstance().generateEmptyTD(builder, true);
    BulkEntryTagUIHelper.getInstance().generateEndTR(builder);
    getTotalForRow(builder, centerEntry, centerTotals, rowIndex, method, userContext, loanProducts.size(), savingsProducts.size());
    return centerTotals;
}
Also used : Money(org.mifos.framework.util.helpers.Money) MifosCurrency(org.mifos.application.master.business.MifosCurrency) CollectionSheetEntryDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryDto)

Example 30 with MifosCurrency

use of org.mifos.application.master.business.MifosCurrency in project head by mifos.

the class BulkEntryDisplayHelper method buildForGroup.

public Money[] buildForGroup(final CollectionSheetEntryDto parent, final List<ProductDto> loanProducts, final List<ProductDto> savingsProducts, final List<CustomValueListElementDto> custAttTypes, final StringBuilder builder, final String method, final UserContext userContext) {
    int rowIndex = 0;
    int totalProductsSize = 2 * (loanProducts.size() + savingsProducts.size());
    Money[] groupTotals = new Money[(totalProductsSize + 1)];
    MifosCurrency currency = parent.getCurrency();
    Locale locale = userContext.getPreferredLocale();
    String account = getLocalizedMessage(CollectionSheetEntryConstants.ACCOUNTS_GROUP_CENTER);
    String group = getLabel(ConfigurationConstants.GROUP, userContext);
    String groupAccountStr = account.format(account, group);
    groupAccountStr = " " + groupAccountStr + " ";
    for (CollectionSheetEntryDto child : parent.getCollectionSheetEntryChildren()) {
        buildClientRow(child, loanProducts, savingsProducts, parent.getCollectionSheetEntryChildren().size(), 0, rowIndex, groupTotals, child.getCustomerDetail().getDisplayName(), builder, method, 1, currency);
        generateAttendance(builder, custAttTypes, rowIndex, child, method);
        BulkEntryTagUIHelper.getInstance().generateEndTR(builder);
        rowIndex++;
    }
    buildClientRow(parent, loanProducts, savingsProducts, parent.getCollectionSheetEntryChildren().size(), 0, rowIndex, groupTotals, groupAccountStr, builder, method, 2, currency);
    BulkEntryTagUIHelper.getInstance().generateEmptyTD(builder, true);
    BulkEntryTagUIHelper.getInstance().generateEndTR(builder);
    rowIndex++;
    getTotalForRow(builder, parent, groupTotals, rowIndex, method, userContext, loanProducts.size(), savingsProducts.size());
    return groupTotals;
}
Also used : Locale(java.util.Locale) Money(org.mifos.framework.util.helpers.Money) MifosCurrency(org.mifos.application.master.business.MifosCurrency) CollectionSheetEntryDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryDto)

Aggregations

MifosCurrency (org.mifos.application.master.business.MifosCurrency)54 Money (org.mifos.framework.util.helpers.Money)26 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)12 BigDecimal (java.math.BigDecimal)10 Date (java.util.Date)10 HashMap (java.util.HashMap)10 Before (org.junit.Before)8 List (java.util.List)7 Locale (java.util.Locale)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)5 RepaymentScheduleInstallmentBuilder (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallmentBuilder)5 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 LocalDate (org.joda.time.LocalDate)3 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)3 BigInteger (java.math.BigInteger)2 Calendar (java.util.Calendar)2