Search in sources :

Example 31 with MifosCurrency

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

the class CollectionSheetEntryAction method get.

/**
     * This method is called once the search criteria have been entered by the user to generate the bulk entry details
     * for a particular customer It retrieves the loan officer office, and parent customer that was selected and sets
     * them into the bulk entry business object. The list of attendance types and product list associated with the
     * center, and its children are also retrieved
     */
@TransactionDemarcate(joinToken = true)
public ActionForward get(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    logTrackingInfo("get", request, form);
    final BulkEntryActionForm collectionSheetEntryActionForm = (BulkEntryActionForm) form;
    final CollectionSheetEntryFormDto previousCollectionSheetEntryFormDto = retrieveFromRequestCollectionSheetEntryFormDto(request);
    final CollectionSheetEntryFormDtoDecorator dtoDecorator = new CollectionSheetEntryFormDtoDecorator(previousCollectionSheetEntryFormDto);
    final CollectionSheetFormEnteredDataDto formEnteredDataDto = new FormEnteredDataAssembler(collectionSheetEntryActionForm, dtoDecorator).toDto();
    final MifosCurrency currency = Configuration.getInstance().getSystemConfig().getCurrency();
    final CollectionSheetEntryGridDto collectionSheetEntry = collectionSheetServiceFacade.generateCollectionSheetEntryGridView(formEnteredDataDto, currency);
    storeOnRequestCollectionSheetEntryDto(request, collectionSheetEntry);
    return mapping.findForward(CollectionSheetEntryConstants.GETSUCCESS);
}
Also used : BulkEntryActionForm(org.mifos.application.collectionsheet.struts.actionforms.BulkEntryActionForm) FormEnteredDataAssembler(org.mifos.application.servicefacade.FormEnteredDataAssembler) CollectionSheetFormEnteredDataDto(org.mifos.application.servicefacade.CollectionSheetFormEnteredDataDto) CollectionSheetEntryFormDtoDecorator(org.mifos.application.servicefacade.CollectionSheetEntryFormDtoDecorator) MifosCurrency(org.mifos.application.master.business.MifosCurrency) CollectionSheetEntryFormDto(org.mifos.application.servicefacade.CollectionSheetEntryFormDto) CollectionSheetEntryGridDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 32 with MifosCurrency

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

the class LoanBOTestUtils method createLoanAccount.

/**
     * Like
     * <b>createLoanAccountWithDisbursement(String, CustomerBO, AccountState, Date, LoanOfferingBO, int, Short)</b>
     * but differs in various ways.
     * <p/>
     * This test code needs to be refactored! By creating the loan with a
     * set of terms, then directly manipulating instance variables to completely
     * change the repayment schedule, it leaves the loan in an inconsistent
     * state, which leads one to suspect the validity of any of the 67 unit
     * tests that use it.
     *
     * It has been verified that setActionDate method calls in the loop below
     * will set the dates of the installments incorrectly for some if not all
     * cases. For certain classes of tests this doesn't matter, but for others
     * (involving verifying dates) it does. So BEWARE if you call down through
     * this method.
     *
     * @param globalNum
     */
public static LoanBO createLoanAccount(final String globalNum, final CustomerBO customer, final AccountState state, final Date startDate, final LoanOfferingBO loanOffering) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(startDate);
    MeetingBO meeting = TestObjectFactory.createLoanMeeting(customer.getCustomerMeeting().getMeeting());
    List<Date> meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), meeting, 6);
    MifosCurrency currency = loanOffering.getCurrency();
    AmountFeeBO maintanenceFee = (AmountFeeBO) TestObjectFactory.createPeriodicAmountFee("Mainatnence Fee", FeeCategory.LOAN, "100", RecurrenceType.WEEKLY, Short.valueOf("1"));
    IntegrationTestObjectMother.saveFee(maintanenceFee);
    BigDecimal loanAmount = BigDecimal.valueOf(DEFAULT_LOAN_AMOUNT);
    BigDecimal minAllowedLoanAmount = loanAmount;
    BigDecimal maxAllowedLoanAmount = loanAmount;
    Double interestRate = loanOffering.getDefInterestRate();
    LocalDate disbursementDate = new LocalDate(meetingDates.get(0));
    int numberOfInstallments = 6;
    int minAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int maxAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int graceDuration = 0;
    Integer sourceOfFundId = null;
    Integer loanPurposeId = null;
    Integer collateralTypeId = null;
    String collateralNotes = null;
    String externalId = null;
    boolean repaymentScheduleIndependentOfCustomerMeeting = false;
    RecurringSchedule recurringSchedule = null;
    List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
    accountFees.add(new CreateAccountFeeDto(maintanenceFee.getFeeId().intValue(), maintanenceFee.getFeeAmount().toString()));
    CreateLoanAccount createLoanAccount = new CreateLoanAccount(customer.getCustomerId(), loanOffering.getPrdOfferingId().intValue(), state.getValue().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, repaymentScheduleIndependentOfCustomerMeeting, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    LoanBO loan = IntegrationTestObjectMother.createClientLoan(createLoanAccount);
    loan.updateDetails(TestUtils.makeUser());
    AccountFeesEntity accountPeriodicFee = new AccountFeesEntity(loan, maintanenceFee, (maintanenceFee).getFeeAmount().getAmountDoubleValue());
    AccountTestUtils.addAccountFees(accountPeriodicFee, loan);
    loan.setLoanMeeting(meeting);
    short i = 0;
    for (Date date : meetingDates) {
        LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(++i);
        actionDate.setPrincipal(new Money(currency, "100.0"));
        actionDate.setInterest(new Money(currency, "12.0"));
        // the following line overwrites the correct loan schedule dates
        // with dates that are not correct!
        actionDate.setActionDate(new java.sql.Date(date.getTime()));
        actionDate.setPaymentStatus(PaymentStatus.UNPAID);
        AccountTestUtils.addAccountActionDate(actionDate, loan);
        AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
        setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
        actionDate.addAccountFeesAction(accountFeesaction);
    }
    loan.setCreatedBy(Short.valueOf("1"));
    loan.setCreatedDate(new Date(System.currentTimeMillis()));
    setLoanSummary(loan, currency);
    return loan;
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosCurrency(org.mifos.application.master.business.MifosCurrency) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) BigDecimal(java.math.BigDecimal) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext)

Example 33 with MifosCurrency

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

the class LoanBusinessServiceTest method setupAndInjectDependencies.

@Before
public void setupAndInjectDependencies() {
    loanBusinessService = new LoanBusinessService(legacyLoanDao, configService, null, holidayService, scheduleCalculatorAdaptor);
    locale = new Locale("en", "GB");
    installmentBuilder = new RepaymentScheduleInstallmentBuilder(locale);
    rupee = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
    officeId = Short.valueOf("1");
}
Also used : Locale(java.util.Locale) RepaymentScheduleInstallmentBuilder(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallmentBuilder) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Before(org.junit.Before)

Example 34 with MifosCurrency

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

the class LoanBusinessServiceTest method originalLoanScheduleShouldPersistMiscFee.

@Test
public void originalLoanScheduleShouldPersistMiscFee() throws PersistenceException {
    Set<LoanScheduleEntity> installments = new LinkedHashSet<LoanScheduleEntity>();
    MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
    Money money = new Money(mifosCurrency, "123");
    AccountBO accountBO = mock(AccountBO.class);
    CustomerBO customerBO = mock(CustomerBO.class);
    when(accountBO.getCurrency()).thenReturn(mifosCurrency);
    LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(accountBO, customerBO, new Short("1"), new java.sql.Date(new Date().getTime()), PaymentStatus.UNPAID, money, money);
    loanScheduleEntity.setMiscFee(money);
    installments.add(loanScheduleEntity);
    when(loanBO.getLoanScheduleEntities()).thenReturn(installments);
    loanBusinessService.persistOriginalSchedule(loanBO);
    ArrayList<OriginalLoanScheduleEntity> expected = new ArrayList<OriginalLoanScheduleEntity>();
    OriginalLoanScheduleEntity originalLoanScheduleEntity = new OriginalLoanScheduleEntity(loanScheduleEntity);
    assertEquals(originalLoanScheduleEntity.getMiscFee(), loanScheduleEntity.getMiscFee());
    expected.add(originalLoanScheduleEntity);
    verify(legacyLoanDao).saveOriginalSchedule(Mockito.argThat(new OriginalLoanScheduleEntitiesMatcher(expected)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) OriginalLoanScheduleEntitiesMatcher(org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Example 35 with MifosCurrency

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

the class LoanBusinessServiceTest method shouldNotModifyPrincipalEvenIfMiscChargeIsPresent.

//Test for the bug fix
@Test
public void shouldNotModifyPrincipalEvenIfMiscChargeIsPresent() {
    MifosCurrency rupee = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
    RepaymentScheduleInstallment installment1 = getRepaymentScheduleInstallment("25-Sep-2010", 1, "78.6", "20.4", "1", "200", "100", "0");
    RepaymentScheduleInstallment installment2 = getRepaymentScheduleInstallment("25-Oct-2010", 2, "182.8", "16.2", "1", "200", "0", "0");
    RepaymentScheduleInstallment installment3 = getRepaymentScheduleInstallment("25-Nov-2010", 3, "186.0", "13.0", "1", "200", "0", "0");
    RepaymentScheduleInstallment installment4 = getRepaymentScheduleInstallment("25-Dec-2010", 4, "452.6", "8.9", "1", "462.5", "0", "0");
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3, installment4);
    Date disbursementDate = TestUtils.getDate(25, 8, 2010);
    final Money loanAmount = new Money(rupee, "1000");
    loanBusinessService.applyDailyInterestRates(new LoanScheduleGenerationDto(disbursementDate, loanAmount, 24d, installments), false);
    assertInstallment(installment1, "78.6", "20.4");
    assertInstallment(installment2, "180.8", "18.2");
    assertInstallment(installment3, "183.9", "15.1");
    assertInstallment(installment4, "556.7", "11.0");
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Date(java.util.Date) Test(org.junit.Test)

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