Search in sources :

Example 16 with AccountFeesActionDetailEntity

use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.

the class GroupLoanAccountServiceFacadeWebTier method fixMemberAndParentInstallmentDetails.

// fix installment details in order to match sum of interest of member accounts to interest of parent account
// update member fee amounts in order to match parent fee amount
private void fixMemberAndParentInstallmentDetails(LoanBO loan, List<LoanBO> memberLoans) {
    Map<Integer, LoanScheduleEntity> parentScheduleEntities = loan.getLoanScheduleEntityMap();
    List<RepaymentScheduleInstallment> correctedInstallments = new ArrayList<RepaymentScheduleInstallment>();
    for (Integer installmentId : parentScheduleEntities.keySet()) {
        LoanScheduleEntity parentEntity = parentScheduleEntities.get(installmentId);
        Map<Short, BigDecimal> feeAmountsForInstallment = new HashMap<Short, BigDecimal>();
        for (AccountFeesActionDetailEntity feesActionDetailEntity : parentEntity.getAccountFeesActionDetails()) {
            feeAmountsForInstallment.put(feesActionDetailEntity.getFee().getFeeId(), feesActionDetailEntity.getFeeAmount().getAmount());
        }
        RepaymentScheduleInstallment correctedInstallment = new RepaymentScheduleInstallment();
        correctedInstallment.setInstallment(installmentId);
        correctedInstallment.setDueDateValue(parentEntity.getActionDate());
        BigDecimal principal = BigDecimal.ZERO;
        BigDecimal interest = BigDecimal.ZERO;
        for (LoanBO memberLoan : memberLoans) {
            LoanScheduleEntity memberEntity = memberLoan.getLoanScheduleEntityMap().get(installmentId);
            principal = principal.add(memberEntity.getPrincipal().getAmount());
            interest = interest.add(memberEntity.getInterest().getAmount());
            for (AccountFeesActionDetailEntity feesActionDetailEntity : memberEntity.getAccountFeesActionDetails()) {
                if (feesActionDetailEntity.getFee().getFeeType().equals(RateAmountFlag.RATE)) {
                    continue;
                }
                BigDecimal currentAmount = feeAmountsForInstallment.get(feesActionDetailEntity.getFee().getFeeId());
                currentAmount = currentAmount.subtract(feesActionDetailEntity.getFeeAmount().getAmount());
                if (currentAmount.compareTo(BigDecimal.ZERO) == -1) {
                    BigDecimal toUpdate = feesActionDetailEntity.getFeeAmount().getAmount().add(currentAmount);
                    feesActionDetailEntity.updateFeeAmount(toUpdate);
                    currentAmount = BigDecimal.ZERO;
                }
                feeAmountsForInstallment.put(feesActionDetailEntity.getFee().getFeeId(), currentAmount);
            }
        }
        correctedInstallment.setPrincipal(new Money(parentEntity.getPrincipal().getCurrency(), principal));
        correctedInstallment.setInterest(new Money(parentEntity.getInterest().getCurrency(), interest));
        correctedInstallments.add(correctedInstallment);
    }
    loan.updateInstallmentSchedule(correctedInstallments);
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) HashMap(java.util.HashMap) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)

Example 17 with AccountFeesActionDetailEntity

use of org.mifos.accounts.business.AccountFeesActionDetailEntity 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 18 with AccountFeesActionDetailEntity

use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.

the class CustomerScheduleEntity method waiveCharges.

Money waiveCharges() {
    Money chargeWaived = new Money(getAccount().getCurrency());
    chargeWaived = chargeWaived.add((getMiscFee().subtract(getMiscFeePaid())).add(getMiscPenalty().subtract(getMiscPenaltyPaid())));
    setMiscFee(getMiscFeePaid());
    setMiscPenalty(getMiscPenaltyPaid());
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : getAccountFeesActionDetails()) {
        chargeWaived = chargeWaived.add(((CustomerFeeScheduleEntity) accountFeesActionDetailEntity).waiveCharges());
    }
    return chargeWaived;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity)

Example 19 with AccountFeesActionDetailEntity

use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.

the class CustomerScheduleEntity method waiveFeeCharges.

Money waiveFeeCharges() {
    Money chargeWaived = new Money(getAccount().getCurrency());
    chargeWaived = chargeWaived.add(getMiscFee());
    setMiscFee(new Money(getAccount().getCurrency()));
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : getAccountFeesActionDetails()) {
        chargeWaived = chargeWaived.add(((CustomerFeeScheduleEntity) accountFeesActionDetailEntity).waiveCharges());
    }
    return chargeWaived;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity)

Example 20 with AccountFeesActionDetailEntity

use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.

the class FinancialBusinessServiceIntegrationTest method getAccountTrxnObj.

private AccountTrxnEntity getAccountTrxnObj(AccountPaymentEntity accountPaymentEntity) throws Exception {
    Date currentDate = new Date(System.currentTimeMillis());
    LoanScheduleEntity accountAction = (LoanScheduleEntity) loan.getAccountActionDate(Short.valueOf("1"));
    LoanTrxnDetailEntity accountTrxnEntity = new LoanTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.LOAN_ADJUSTMENT, Short.valueOf("1"), accountAction.getActionDate(), TestObjectFactory.getPersonnel(PersonnelConstants.SYSTEM_USER), currentDate, TestUtils.createMoney(630), "test for loan adjustment", null, TestUtils.createMoney(200), TestUtils.createMoney(300), TestUtils.createMoney(), TestUtils.createMoney(10), TestUtils.createMoney(20), null, null);
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountAction.getAccountFeesActionDetails()) {
        LoanBOTestUtils.setFeeAmountPaid(accountFeesActionDetailEntity, TestUtils.createMoney(100));
        FeesTrxnDetailEntity feeTrxn = new FeesTrxnDetailEntity(accountTrxnEntity, accountFeesActionDetailEntity.getAccountFee(), accountFeesActionDetailEntity.getFeeAmount());
        accountTrxnEntity.addFeesTrxnDetail(feeTrxn);
    }
    return accountTrxnEntity;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity) Date(java.sql.Date) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Aggregations

AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)39 Money (org.mifos.framework.util.helpers.Money)21 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)9 ArrayList (java.util.ArrayList)8 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)8 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)7 BigDecimal (java.math.BigDecimal)6 FeesTrxnDetailEntity (org.mifos.accounts.business.FeesTrxnDetailEntity)6 Date (java.sql.Date)5 CustomerScheduleEntity (org.mifos.customers.business.CustomerScheduleEntity)5 Date (java.util.Date)4 LocalDate (org.joda.time.LocalDate)4 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 AccountException (org.mifos.accounts.exceptions.AccountException)4 FeeBO (org.mifos.accounts.fees.business.FeeBO)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)4 Test (org.junit.Test)3 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)3 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)3