Search in sources :

Example 11 with XmlBuilder

use of org.mifos.framework.struts.tags.XmlBuilder in project head by mifos.

the class LoanActivityTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    XmlBuilder xmlBuilder = new XmlBuilder();
    try {
        String currentFlowKey = (String) pageContext.getRequest().getAttribute(Constants.CURRENTFLOWKEY);
        HttpSession session = pageContext.getSession();
        FlowManager flowManager = (FlowManager) session.getAttribute(Constants.FLOWMANAGER);
        Object object = flowManager.getFromFlow(currentFlowKey, LoanConstants.LOAN_ALL_ACTIVITY_VIEW);
        if (object == null) {
            // for spring/ftl 
            object = pageContext.getRequest().getAttribute(LoanConstants.LOAN_ALL_ACTIVITY_VIEW);
        }
        if (null != object) {
            UserContext userContext = (UserContext) pageContext.getSession().getAttribute(Constants.USER_CONTEXT_KEY);
            locale = userContext.getPreferredLocale();
            xmlBuilder.startTag("table", "width", "100%", "border", "0", "cellspacing", "0", "cellpadding", "0", "id", "accountActivityTable");
            xmlBuilder.startTag("tr");
            xmlBuilder.startTag("td", "colspan", "8");
            //xmlBuilder.nonBreakingSpace();
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "colspan", "4", "class", "drawtablerowboldnoline");
            xmlBuilder.text(getLabel("loan.running_bal", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.endTag("tr");
            xmlBuilder.startTag("tr", "class", "drawtablerowbold");
            xmlBuilder.startTag("td", "width", "9%", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.date", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "19%", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.activity", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.principal", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.fees", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.penalty", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "6%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.total", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "4", "align", "right", "class", "fontnormalbold");
            //xmlBuilder.nonBreakingSpace();
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.principal", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.fees", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.startTag("td", "width", "6%", "align", "right", "class", "drawtablerowbold");
            xmlBuilder.text(getLabel("loan.total", locale));
            xmlBuilder.endTag("td");
            xmlBuilder.endTag("tr");
            List<LoanActivityDto> loanRecentActivityViewSet = (List<LoanActivityDto>) object;
            Iterator<LoanActivityDto> it = loanRecentActivityViewSet.iterator();
            while (it.hasNext()) {
                LoanActivityDto loanActivityDto = it.next();
                xmlBuilder.startTag("tr", "valign", "top");
                xmlBuilder.append(buildLeftHeaderRows(loanActivityDto));
                xmlBuilder.append(buildRightHeaderRows(loanActivityDto));
                xmlBuilder.endTag("tr");
            }
            xmlBuilder.endTag("table");
        }
        pageContext.getOut().write(xmlBuilder.toString());
    } catch (Exception e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}
Also used : FlowManager(org.mifos.framework.util.helpers.FlowManager) JspException(javax.servlet.jsp.JspException) LoanActivityDto(org.mifos.dto.domain.LoanActivityDto) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext) XmlBuilder(org.mifos.framework.struts.tags.XmlBuilder) List(java.util.List) JspException(javax.servlet.jsp.JspException)

Example 12 with XmlBuilder

use of org.mifos.framework.struts.tags.XmlBuilder in project head by mifos.

the class LoanActivityTag method buildLeftHeaderRows.

XmlBuilder buildLeftHeaderRows(LoanActivityDto loanRecentActivityView) {
    XmlBuilder xmlBuilder = new XmlBuilder();
    xmlBuilder.startTag("td", "class", "drawtablerow");
    xmlBuilder.text(DateUtils.getUserLocaleDate(locale, loanRecentActivityView.getActionDate().toString()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "class", "drawtablerow");
    xmlBuilder.text(loanRecentActivityView.getActivity());
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getPrincipal()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getInterest()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getFees()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getPenalty()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getTotal()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "fontnormalbold");
    xmlBuilder.singleTag("br");
    xmlBuilder.endTag("td");
    return xmlBuilder;
}
Also used : XmlBuilder(org.mifos.framework.struts.tags.XmlBuilder)

Example 13 with XmlBuilder

use of org.mifos.framework.struts.tags.XmlBuilder in project head by mifos.

the class LoanActivityTag method buildRightHeaderRows.

XmlBuilder buildRightHeaderRows(LoanActivityDto loanRecentActivityView) {
    XmlBuilder xmlBuilder = new XmlBuilder();
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getRunningBalancePrinciple()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getRunningBalanceInterest()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getRunningBalanceFees()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "drawtablerow");
    xmlBuilder.text(ConversionUtil.formatNumber(loanRecentActivityView.getRunningBalancePrincipleWithInterestAndFees()));
    xmlBuilder.endTag("td");
    xmlBuilder.startTag("td", "align", "right", "class", "fontnormalbold");
    xmlBuilder.singleTag("br");
    xmlBuilder.endTag("td");
    return xmlBuilder;
}
Also used : XmlBuilder(org.mifos.framework.struts.tags.XmlBuilder)

Example 14 with XmlBuilder

use of org.mifos.framework.struts.tags.XmlBuilder 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 15 with XmlBuilder

use of org.mifos.framework.struts.tags.XmlBuilder in project head by mifos.

the class LoanRepaymentTag method createRunningBalanceRow.

XmlBuilder createRunningBalanceRow(LoanScheduleEntity installment, Money totalPrincipal, Money totalInterest, Money totalFees, Money totalPenalties) {
    XmlBuilder html = new XmlBuilder();
    html.startTag("tr");
    html.startTag("td", "width", "20%", "align", "right", "class", "drawtablerow");
    html.text(ConversionUtil.formatNumber(totalPrincipal.subtract(installment.getPrincipalPaid()).toString()));
    html.endTag("td");
    html.startTag("td", "width", "20%", "align", "right", "class", "drawtablerow");
    html.text(ConversionUtil.formatNumber(totalInterest.subtract(installment.getEffectiveInterestPaid()).toString()));
    html.endTag("td");
    html.startTag("td", "width", "20%", "align", "right", "class", "drawtablerow");
    html.text(ConversionUtil.formatNumber(totalFees.subtract(installment.getTotalFeeAmountPaidWithMiscFee()).toString()));
    html.endTag("td");
    html.startTag("td", "width", "20%", "align", "right", "class", "drawtablerow");
    html.text(ConversionUtil.formatNumber(totalPenalties.subtract(installment.getTotalPenaltyPaid()).toString()));
    html.endTag("td");
    html.startTag("td", "width", "20%", "align", "right", "class", "drawtablerow");
    html.text((ConversionUtil.formatNumber(String.valueOf(totalPrincipal.add(totalInterest).add(totalFees).add(totalPenalties).subtract(installment.getPrincipalPaid()).subtract(installment.getEffectiveInterestPaid()).subtract(installment.getTotalFeeAmountPaidWithMiscFee()).subtract(installment.getTotalPenaltyPaid())))).toString());
    html.endTag("td");
    html.endTag("tr");
    return html;
}
Also used : XmlBuilder(org.mifos.framework.struts.tags.XmlBuilder)

Aggregations

XmlBuilder (org.mifos.framework.struts.tags.XmlBuilder)20 JspException (javax.servlet.jsp.JspException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HttpSession (javax.servlet.http.HttpSession)2 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)2 FlowManager (org.mifos.framework.util.helpers.FlowManager)2 UserContext (org.mifos.security.util.UserContext)2 IOException (java.io.IOException)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JspWriter (javax.servlet.jsp.JspWriter)1 Before (org.junit.Before)1 Test (org.junit.Test)1 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)1 OfficeBO (org.mifos.customers.office.business.OfficeBO)1 LoanActivityDto (org.mifos.dto.domain.LoanActivityDto)1 OfficeDetailsDto (org.mifos.dto.domain.OfficeDetailsDto)1