Search in sources :

Example 1 with MifosCurrency

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

the class LoanAccountServiceFacadeWebTier method validateInstallmentSchedule.

@Override
public Errors validateInstallmentSchedule(List<LoanCreationInstallmentDto> dtoInstallments, BigDecimal minInstallmentAmount) {
    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.validateInstallmentSchedule(installments, minInstallmentAmount);
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) ArrayList(java.util.ArrayList) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 2 with MifosCurrency

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

the class SavingsProductAssembler method fromDto.

public SavingsOfferingBO fromDto(MifosUser user, SavingsProductDto savingsProductRequest) {
    try {
        // FIXME - keithw - this is general assembler common to both savings and loans i.e. all products. so
        // ProductDao and ProductAssembler
        ProductDetailsDto productDetails = savingsProductRequest.getProductDetails();
        String name = productDetails.getName();
        String shortName = productDetails.getShortName();
        String description = productDetails.getDescription();
        Integer category = productDetails.getCategory();
        ProductCategoryBO productCategory = this.loanProductDao.findActiveProductCategoryById(category);
        DateTime startDate = productDetails.getStartDate();
        DateTime endDate = productDetails.getEndDate();
        ApplicableTo applicableTo = ApplicableTo.fromInt(productDetails.getApplicableFor());
        PrdApplicableMasterEntity applicableToEntity = this.loanProductDao.findApplicableProductType(applicableTo);
        PrdStatusEntity activeStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.SAVINGS_ACTIVE);
        PrdStatusEntity inActiveStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.SAVINGS_INACTIVE);
        PrdStatusEntity selectedStatus = activeStatus;
        if (productDetails.getStatus() != null && inActiveStatus.getOfferingStatusId().equals(productDetails.getStatus().shortValue())) {
            selectedStatus = inActiveStatus;
        }
        String globalNum = generateProductGlobalNum(user);
        // savings specific
        SavingsType savingsType = SavingsType.fromInt(savingsProductRequest.getDepositType());
        SavingsTypeEntity savingsTypeEntity = this.loanProductDao.retrieveSavingsType(savingsType);
        RecommendedAmntUnitEntity recommendedAmntUnitEntity = null;
        if (savingsProductRequest.getGroupMandatorySavingsType() != null) {
            RecommendedAmountUnit recommendedAmountType = RecommendedAmountUnit.fromInt(savingsProductRequest.getGroupMandatorySavingsType());
            recommendedAmntUnitEntity = this.loanProductDao.retrieveRecommendedAmountType(recommendedAmountType);
        }
        Money amountForDeposit = new Money(Money.getDefaultCurrency(), BigDecimal.valueOf(savingsProductRequest.getAmountForDeposit()));
        Money maxWithdrawal = new Money(Money.getDefaultCurrency(), BigDecimal.valueOf(savingsProductRequest.getMaxWithdrawal()));
        // interest specific
        BigDecimal interestRate = savingsProductRequest.getInterestRate();
        InterestCalcType interestCalcType = InterestCalcType.fromInt(savingsProductRequest.getInterestCalculationType());
        InterestCalcTypeEntity interestCalcTypeEntity = this.savingsProductDao.retrieveInterestCalcType(interestCalcType);
        RecurrenceType recurrence = RecurrenceType.fromInt(savingsProductRequest.getInterestCalculationFrequencyPeriod().shortValue());
        Integer every = savingsProductRequest.getInterestCalculationFrequency();
        MeetingBO interestCalculationMeeting = new MeetingBO(recurrence, every.shortValue(), new Date(), MeetingType.SAVINGS_INTEREST_CALCULATION_TIME_PERIOD);
        Integer interestPostingEveryMonthFreq = savingsProductRequest.getInterestPostingFrequency();
        RecurrenceType interestPostingRecurrenceType = null;
        if (savingsProductRequest.isDailyPosting()) {
            interestPostingRecurrenceType = RecurrenceType.DAILY;
        } else {
            interestPostingRecurrenceType = RecurrenceType.MONTHLY;
        }
        MeetingBO interestPostingMeeting = new MeetingBO(interestPostingRecurrenceType, interestPostingEveryMonthFreq.shortValue(), new Date(), MeetingType.SAVINGS_INTEREST_POSTING);
        Money minAmountForCalculation = new Money(Money.getDefaultCurrency(), savingsProductRequest.getMinBalanceForInterestCalculation());
        GLCodeEntity depositGlEntity = this.generalLedgerDao.findGlCodeById(savingsProductRequest.getDepositGlCode().shortValue());
        GLCodeEntity interestGlEntity = this.generalLedgerDao.findGlCodeById(savingsProductRequest.getInterestGlCode().shortValue());
        MifosCurrency currency = Money.getDefaultCurrency();
        return SavingsOfferingBO.createNew(user.getUserId(), globalNum, name, shortName, description, productCategory, startDate, endDate, applicableToEntity, currency, selectedStatus, savingsTypeEntity, recommendedAmntUnitEntity, amountForDeposit, maxWithdrawal, interestRate, interestCalcTypeEntity, interestCalculationMeeting, interestPostingMeeting, minAmountForCalculation, depositGlEntity, interestGlEntity);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (MeetingException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ProductDetailsDto(org.mifos.dto.domain.ProductDetailsDto) DateTime(org.joda.time.DateTime) Money(org.mifos.framework.util.helpers.Money) MifosCurrency(org.mifos.application.master.business.MifosCurrency) RecommendedAmountUnit(org.mifos.accounts.productdefinition.util.helpers.RecommendedAmountUnit) InterestCalcType(org.mifos.accounts.productdefinition.util.helpers.InterestCalcType) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) InterestCalcTypeEntity(org.mifos.accounts.productdefinition.business.InterestCalcTypeEntity) RecurrenceType(org.mifos.application.meeting.util.helpers.RecurrenceType) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) RecommendedAmntUnitEntity(org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ApplicableTo(org.mifos.accounts.productdefinition.util.helpers.ApplicableTo) SavingsTypeEntity(org.mifos.accounts.productdefinition.business.SavingsTypeEntity) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity) SavingsType(org.mifos.accounts.productdefinition.util.helpers.SavingsType) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with MifosCurrency

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

the class LoanAccountActionFormTest method setUp.

@Before
public void setUp() throws Exception {
    form = new LoanAccountActionForm();
    paymentMock = createMock(PaymentDataHtmlBean.class);
    expect(paymentMock.hasTotalAmount()).andReturn(true);
    actionErrors = new ActionErrors();
    locale = new Locale("en", "GB");
    installmentBuilder = new RepaymentScheduleInstallmentBuilder(locale);
    rupee = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
}
Also used : Locale(java.util.Locale) PaymentDataHtmlBean(org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean) RepaymentScheduleInstallmentBuilder(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallmentBuilder) ActionErrors(org.apache.struts.action.ActionErrors) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Before(org.junit.Before)

Example 4 with MifosCurrency

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

the class AccountApplyPaymentActionForm method validateAmount.

protected void validateAmount(ActionErrors errors) {
    MifosCurrency currency = null;
    if (getCurrencyId() != null && AccountingRules.isMultiCurrencyEnabled()) {
        currency = AccountingRules.getCurrencyByCurrencyId(getCurrencyId());
    }
    DoubleConversionResult conversionResult = validateAmount(getAmount(), currency, AccountConstants.ACCOUNT_AMOUNT, errors, "");
    if (amountCannotBeZero() && conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
        addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
    }
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 5 with MifosCurrency

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

the class ApplyAdjustmentActionForm method validateAmount.

protected void validateAmount(ActionErrors errors) {
    MifosCurrency currency = null;
    if (getCurrencyId() != null && AccountingRules.isMultiCurrencyEnabled()) {
        currency = AccountingRules.getCurrencyByCurrencyId(getCurrencyId());
    }
    DoubleConversionResult conversionResult = validateAmount(getAmount(), currency, AccountConstants.ACCOUNT_AMOUNT, errors, "");
    if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
        addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
    }
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

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