Search in sources :

Example 31 with LoanScheduleEntity

use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.

the class LegacyLoanDaoIntegrationTest method testSaveAndGetOriginalLoanScheduleEntity.

@Test
public void testSaveAndGetOriginalLoanScheduleEntity() throws PersistenceException, IOException {
    ArrayList<OriginalLoanScheduleEntity> originalLoanScheduleEntities = new ArrayList<OriginalLoanScheduleEntity>();
    Short installmentId = new Short("1");
    Date date = new Date(new java.util.Date().getTime());
    LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(goodAccount, group, installmentId, date, PaymentStatus.UNPAID, Money.zero(), Money.zero());
    originalLoanScheduleEntities.add(new OriginalLoanScheduleEntity(loanScheduleEntity));
    legacyLoanDao.saveOriginalSchedule(originalLoanScheduleEntities);
    List<OriginalLoanScheduleEntity> actual = legacyLoanDao.getOriginalLoanScheduleEntity(goodAccount.getAccountId());
    Assert.assertEquals(1, actual.size());
    Assert.assertNotNull(actual.get(0));
    assertThat(actual, is(new OriginalLoanScheduleEntitiesMatcher(originalLoanScheduleEntities)));
}
Also used : 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.sql.Date) OriginalLoanScheduleEntitiesMatcher(org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher) Test(org.junit.Test)

Example 32 with LoanScheduleEntity

use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.

the class LoanRepaymentTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    boolean twoTables = false;
    XmlBuilder html = new XmlBuilder();
    LoanBO loanBO = null;
    try {
        String currentFlowKey = (String) pageContext.getRequest().getAttribute(Constants.CURRENTFLOWKEY);
        HttpSession session = pageContext.getSession();
        FlowManager flowManager = (FlowManager) session.getAttribute(Constants.FLOWMANAGER);
        loanBO = (LoanBO) flowManager.getFromFlow(currentFlowKey, Constants.BUSINESS_KEY);
        if (StringUtils.isNotBlank(memberGlobalNum)) {
            loanBO = loanBO.findMemberByGlobalNum(memberGlobalNum);
        }
        Date viewDate = getViewDate(currentFlowKey, flowManager);
        Money totalPrincipal = new Money(loanBO.getCurrency(), "0");
        Money totalInterest = new Money(loanBO.getCurrency(), "0");
        Money totalFees = new Money(loanBO.getCurrency(), "0");
        Money totalPenalties = new Money(loanBO.getCurrency(), "0");
        /*
             * LoanBO loanBO = (LoanBO) pageContext.getRequest().getAttribute( Constants.BUSINESS_KEY);
             */
        List<AccountActionDateEntity> list = new ArrayList<AccountActionDateEntity>();
        if (isNewGropLoan) {
            List<LoanBO> memberAccounts = getMemberScheduleDetails(loanBO.getAccountId());
            list.addAll(generateGroupSchedule(memberAccounts, loanBO));
        } else {
            list.addAll(loanBO.getAccountActionDates());
        }
        UserContext userContext = (UserContext) pageContext.getSession().getAttribute(Constants.USER_CONTEXT_KEY);
        locale = userContext.getPreferredLocale();
        if (list.size() != 0) {
            // topmost table
            html.startTag("table", "width", "100%", "border", "0", "cellspacing", "0", "cellpadding", "0");
            // Left side header
            XmlBuilder htmlHeader1 = new XmlBuilder();
            htmlHeader1.startTag("tr");
            htmlHeader1.startTag("td", "width", "6%", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.no", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "15%", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.due_date", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "15%", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.date_paid", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "12%", "align", "right", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.principal", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "10%", "align", "right", "class", "drawtablerowbold");
            htmlHeader1.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "10%", "align", "right", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.fees", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "11%", "align", "right", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.penalty", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "11%", "align", "right", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.daysLate", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.startTag("td", "width", "10%", "align", "right", "class", "drawtablerowbold");
            htmlHeader1.text(getLabel("loan.total", locale));
            htmlHeader1.endTag("td");
            htmlHeader1.endTag("tr");
            for (AccountActionDateEntity acctDate : list) {
                LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) acctDate;
                totalPrincipal = totalPrincipal.add(loanScheduleEntity.getPrincipal());
                totalInterest = totalInterest.add(loanScheduleEntity.getEffectiveInterest());
                totalFees = totalFees.add(loanScheduleEntity.getTotalScheduledFeeAmountWithMiscFee());
                totalPenalties = totalPenalties.add(loanScheduleEntity.getTotalPenalty());
            }
            // check if at least the first installment is paid
            LoanScheduleEntity firstInstallment = (LoanScheduleEntity) list.get(0);
            XmlBuilder html1 = new XmlBuilder();
            XmlBuilder html2 = new XmlBuilder();
            XmlBuilder htmlHeader2 = new XmlBuilder();
            if (!firstInstallment.getTotalDueWithFees().equals(firstInstallment.getTotalScheduleAmountWithFees())) {
                twoTables = true;
                // installments paid and running balance table is
                // required
                htmlHeader2.startTag("tr");
                htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
                htmlHeader2.text(getLabel("loan.principal", locale));
                htmlHeader2.endTag("td");
                htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
                htmlHeader2.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
                htmlHeader2.endTag("td");
                htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
                htmlHeader2.text(getLabel("loan.fees", locale));
                htmlHeader2.endTag("td");
                htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
                htmlHeader2.text(getLabel("loan.penalty", locale));
                htmlHeader2.endTag("td");
                htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
                htmlHeader2.text(getLabel("loan.total", locale));
                htmlHeader2.endTag("td");
                htmlHeader2.endTag("tr");
            }
            html1.startTag("tr");
            html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
            html1.nonBreakingSpace();
            html1.endTag("td");
            html1.endTag("tr");
            html2.startTag("tr");
            html2.startTag("td", "colspan", "5", "class", "drawtablerowbold");
            html2.text(getLabel("loan.running_bal", locale));
            html2.endTag("td");
            html2.endTag("tr");
            html1.append(htmlHeader1);
            html2.append(htmlHeader2);
            if (twoTables) {
                html1.startTag("tr");
                html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
                html1.text(getLabel("loan.instt_paid", locale));
                html1.endTag("td");
                html1.endTag("tr");
                html2.startTag("tr");
                html2.startTag("td", "colspan", "5", "class", "drawtablerowbold");
                html2.nonBreakingSpace();
                html2.endTag("td");
                html2.endTag("tr");
            }
            int index = 0;
            boolean toContinue = true;
            LoanScheduleEntity installment = (LoanScheduleEntity) list.get(index);
            while (index <= list.size() - 1 && toContinue && !installment.getTotalDueWithFees().equals(installment.getTotalScheduleAmountWithFees())) {
                html1.append(createInstallmentRow(installment, true, isNewGropLoan));
                html2.append(createRunningBalanceRow(installment, totalPrincipal, totalInterest, totalFees, totalPenalties));
                totalPrincipal = totalPrincipal.subtract(installment.getPrincipalPaid());
                totalInterest = totalInterest.subtract(installment.getEffectiveInterestPaid());
                totalFees = totalFees.subtract(installment.getTotalFeeAmountPaidWithMiscFee());
                totalPenalties = totalPenalties.subtract(installment.getPenaltyPaid());
                if (index != list.size() - 1 && installment.isPaid()) {
                    index++;
                    installment = (LoanScheduleEntity) list.get(index);
                } else {
                    toContinue = false;
                }
            }
            boolean dueInstallments = false;
            if (!installment.isPaid() && installment.getActionDate().getTime() <= viewDate.getTime()) {
                dueInstallments = true;
            }
            if (dueInstallments) {
                html1.startTag("tr");
                html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
                html1.text(getLabel("loan.instt_due", locale));
                html1.endTag("td");
                html1.endTag("tr");
                while (index < list.size() - 1 && !installment.isPaid() && installment.getActionDate().getTime() <= viewDate.getTime()) {
                    index++;
                    html1.append(createInstallmentRow(installment, false, isNewGropLoan));
                    installment = (LoanScheduleEntity) list.get(index);
                }
            }
            boolean futureInstallments = false;
            if (!installment.isPaid() && installment.getActionDate().getTime() > viewDate.getTime()) {
                futureInstallments = true;
            }
            if (futureInstallments) {
                html1.startTag("tr");
                html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
                html1.text(getLabel("loan.future_install", locale));
                html1.endTag("td");
                html1.endTag("tr");
                while (index < list.size() - 1) {
                    index++;
                    html1.append(createInstallmentRow(installment, false, isNewGropLoan));
                    installment = (LoanScheduleEntity) list.get(index);
                }
            }
            // append the last transaction
            if (!installment.isPaid()) {
                html1.append(createInstallmentRow(installment, false, isNewGropLoan));
            }
            long totalDaysLate = 0;
            for (AccountActionDateEntity accountActionDateEntity : list) {
                totalDaysLate += accountActionDateEntity.getDaysLate();
            }
            XmlBuilder totalDaysLateXmlBuilder = new XmlBuilder();
            totalDaysLateXmlBuilder.startTag("tr");
            totalDaysLateXmlBuilder.startTag("td", "class", "drawtablerow", "colspan", "8", "align", "right");
            totalDaysLateXmlBuilder.text(getLabel("loan.total", locale) + ": " + totalDaysLate);
            totalDaysLateXmlBuilder.endTag("td");
            totalDaysLateXmlBuilder.startTag("td", "class", "drawtablerow");
            totalDaysLateXmlBuilder.nonBreakingSpace();
            totalDaysLateXmlBuilder.endTag("td");
            totalDaysLateXmlBuilder.endTag("tr");
            html1.append(totalDaysLateXmlBuilder);
            if (twoTables) {
                // add a tr with 2 td for each of the 2 tables
                html.startTag("tr");
                html.startTag("td", "width", "70%");
                html.startTag("table", "width", "95%", "border", "0", "cellspacing", "0", "cellpadding", "5", "id", "repaymentScheduleTable");
                html.append(html1);
                html.endTag("table");
                html.endTag("td");
                html.startTag("td", "width", "25%", "valign", "top");
                html.startTag("table", "width", "95%", "border", "0", "cellspacing", "0", "cellpadding", "5", "id", "runningBalanceTable");
                html.append(html2);
                html.endTag("table");
                html.endTag("td");
                html.endTag("tr");
                html.endTag("table");
            } else {
                html.startTag("tr");
                html.startTag("td", "width", "100%");
                html.startTag("table", "id", "installments", "width", "95%", "border", "0", "cellspacing", "0", "cellpadding", "5");
                html.append(html1);
                html.endTag("table");
                html.endTag("td");
                html.endTag("tr");
                html.endTag("table");
            }
        }
        pageContext.getOut().write(html.toString());
    } catch (Exception e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) FlowManager(org.mifos.framework.util.helpers.FlowManager) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) Date(java.util.Date) JspException(javax.servlet.jsp.JspException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) JspException(javax.servlet.jsp.JspException) XmlBuilder(org.mifos.framework.struts.tags.XmlBuilder)

Example 33 with LoanScheduleEntity

use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.

the class LoanRepaymentTag method copyAndSetToZeroSchedule.

private List<AccountActionDateEntity> copyAndSetToZeroSchedule(Money principal, Money principalPaid, Money interest, Money interestPaid, Money penalty, Money extraInterest, Money extraInterestPaid, Money miscFee, Money miscFeePaid, Money miscPenalty, Money penaltyPaid, Money miscPenaltyPaid, List<AccountActionDateEntity> accActionList) {
    for (AccountActionDateEntity element : accActionList) {
        LoanScheduleEntity schedule = (LoanScheduleEntity) element;
        schedule.setPrincipal(principal);
        schedule.setPrincipalPaid(principalPaid);
        schedule.setInterest(interest);
        schedule.setInterestPaid(interestPaid);
        schedule.setPenalty(penalty);
        schedule.setPrincipalPaid(penaltyPaid);
        schedule.setExtraInterest(extraInterest);
        schedule.setExtraInterestPaid(extraInterestPaid);
        schedule.setMiscFee(miscFee);
        schedule.setMiscFeePaid(miscFeePaid);
        schedule.setMiscPenalty(miscPenalty);
        schedule.setMiscPenaltyPaid(miscPenaltyPaid);
    }
    return accActionList;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity)

Example 34 with LoanScheduleEntity

use of org.mifos.accounts.loan.business.LoanScheduleEntity 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)

Example 35 with LoanScheduleEntity

use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.

the class AccountFeesActionDetailEntityIntegrationTest method testMakeEarlyRepaymentEnteriesForNotPayingFee.

@Test
public void testMakeEarlyRepaymentEnteriesForNotPayingFee() {
    for (AccountActionDateEntity installment : accountBO.getAccountActionDates()) {
        LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) installment;
        for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountActionDateEntity.getAccountFeesActionDetails()) {
            Money preRepaymentFeeAmount = accountFeesActionDetailEntity.getFeeAmount();
            accountFeesActionDetailEntity.makeRepaymentEnteries(LoanConstants.DONOT_PAY_FEES_PENALTY_INTEREST);
            Assert.assertEquals(accountFeesActionDetailEntity.getFeeAmount(), preRepaymentFeeAmount);
        }
    }
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) Test(org.junit.Test)

Aggregations

LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)54 Money (org.mifos.framework.util.helpers.Money)32 ArrayList (java.util.ArrayList)19 OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)18 Test (org.junit.Test)16 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)14 BigDecimal (java.math.BigDecimal)11 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)8 LoanBO (org.mifos.accounts.loan.business.LoanBO)8 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)7 Date (java.util.Date)5 CustomerBO (org.mifos.customers.business.CustomerBO)5 UserContext (org.mifos.security.util.UserContext)5 LocalDate (org.joda.time.LocalDate)4 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)4 OriginalLoanScheduleEntitiesMatcher (org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher)4 InstallmentDetailsDto (org.mifos.dto.domain.InstallmentDetailsDto)4 LoanInstallmentDetailsDto (org.mifos.dto.domain.LoanInstallmentDetailsDto)4 MifosUser (org.mifos.security.MifosUser)4 Date (java.sql.Date)3