Search in sources :

Example 1 with GroupIndividualLoanDto

use of org.mifos.dto.domain.GroupIndividualLoanDto in project head by mifos.

the class ApplyChargeAction method divide.

@TransactionDemarcate(joinToken = true)
public ActionForward divide(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyChargeActionForm chargeForm = (ApplyChargeActionForm) form;
    chargeForm.getIndividualValues().clear();
    Short feeId = Short.valueOf(chargeForm.getFeeId());
    FeeBO fee = feeDao.findById(feeId);
    String amount;
    List<GroupIndividualLoanDto> memberAccounts = groupLoanService.getMemberLoansAndDefaultPayments(Integer.valueOf(chargeForm.getAccountId()), new BigDecimal(chargeForm.getCharge()));
    if (null == fee || fee.getFeeType().equals(RateAmountFlag.AMOUNT)) {
        for (int i = 0; i < memberAccounts.size(); i++) {
            amount = String.valueOf(memberAccounts.get(i).getDefaultAmount().doubleValue());
            chargeForm.getIndividualValues().put(memberAccounts.get(i).getAccountId(), amount);
        }
    } else {
        for (int i = 0; i < memberAccounts.size(); i++) {
            amount = chargeForm.getCharge();
            chargeForm.getIndividualValues().put(memberAccounts.get(i).getAccountId(), amount);
        }
    }
    List<LoanBO> memberInfos = getMemberAccountsInformation(chargeForm.getAccountId());
    SessionUtils.setCollectionAttribute("memberInfos", memberInfos, request);
    return mapping.findForward("divide");
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) GroupIndividualLoanDto(org.mifos.dto.domain.GroupIndividualLoanDto) FeeBO(org.mifos.accounts.fees.business.FeeBO) ApplyChargeActionForm(org.mifos.accounts.struts.actionforms.ApplyChargeActionForm) BigDecimal(java.math.BigDecimal) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with GroupIndividualLoanDto

use of org.mifos.dto.domain.GroupIndividualLoanDto in project head by mifos.

the class AccountApplyGroupPaymentAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = getUserContext(request);
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
    actionForm.setReceiptDate(null);
    actionForm.setReceiptId(null);
    actionForm.setPaymentTypeId(null);
    actionForm.setTransactionDate(DateUtils.makeDateAsSentFromBrowser());
    actionForm.setPrintReceipt(false);
    actionForm.setTruePrintReceipt(false);
    final AccountReferenceDto accountReferenceDto = new AccountReferenceDto(Integer.valueOf(actionForm.getAccountId()));
    AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountReferenceDto.getAccountId(), request.getParameter(Constants.INPUT), userContext.getLocaleId(), new UserReferenceDto(userContext.getId()), DateUtils.getCurrentJavaDateTime());
    setValuesInSession(request, actionForm, accountPaymentDto);
    actionForm.setLastPaymentDate(accountPaymentDto.getLastPaymentDate());
    actionForm.setAmount(accountPaymentDto.getTotalPaymentDue());
    actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
    LoanBO loan = loanDao.findById(accountReferenceDto.getAccountId());
    if (loan.isGroupLoanAccountParent()) {
        SessionUtils.setAttribute(LOAN_TYPE, PARENT, request);
    } else if (loan.isGroupLoanAccountMember()) {
        SessionUtils.setAttribute(LOAN_TYPE, MEMBER, request);
    }
    List<LoanBO> memberInfos = getMemberAccountsInformation(actionForm.getAccountId());
    SessionUtils.setCollectionAttribute("memberInfos", memberInfos, request);
    if (memberInfos.size() > 0) {
        actionForm.getIndividualValues().clear();
        List<GroupIndividualLoanDto> memberAccounts = groupLoanService.getMemberLoansAndDefaultPayments(Integer.valueOf(actionForm.getAccountId()), new BigDecimal(actionForm.getAmount()));
        for (int i = 0; i < memberAccounts.size(); i++) {
            actionForm.getIndividualValues().put(memberAccounts.get(i).getAccountId(), String.valueOf(memberAccounts.get(i).getDefaultAmount().doubleValue()));
        }
    }
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) GroupIndividualLoanDto(org.mifos.dto.domain.GroupIndividualLoanDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) BigDecimal(java.math.BigDecimal) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 3 with GroupIndividualLoanDto

use of org.mifos.dto.domain.GroupIndividualLoanDto in project head by mifos.

the class GroupLoanAccountServiceFacadeWebTier method getMemberLoansAndDefaultPayments.

@Override
public List<GroupIndividualLoanDto> getMemberLoansAndDefaultPayments(Integer parentAccountId, BigDecimal amount) {
    LoanBO loanAccount = loanDao.findById(parentAccountId);
    List<GroupIndividualLoanDto> memberAccountDtos = new ArrayList<GroupIndividualLoanDto>();
    BigDecimal amountSpent = BigDecimal.ZERO;
    List<LoanBO> members = new ArrayList<LoanBO>(loanAccount.getMemberAccounts());
    Iterator<LoanBO> itr = members.iterator();
    List<BigDecimal> factors = new ArrayList<BigDecimal>();
    BigDecimal total = BigDecimal.ZERO;
    BigDecimal totalFactor = BigDecimal.ZERO;
    amount = amount.setScale(AccountingRules.getDigitsAfterDecimal());
    while (itr.hasNext()) {
        LoanBO memberAccount = itr.next();
        BigDecimal factor = memberAccount.calcFactorOfEntireLoan();
        total = total.add(factor);
        if (memberAccount.isAccountActive() || memberAccount.isInState(AccountState.LOAN_PARTIAL_APPLICATION) || memberAccount.isInState(AccountState.LOAN_PENDING_APPROVAL) || memberAccount.isInState(AccountState.LOAN_APPROVED)) {
            factors.add(factor);
            totalFactor = totalFactor.add(factor);
        } else {
            itr.remove();
        }
    }
    BigDecimal scale = totalFactor.divide(total, RoundingMode.HALF_EVEN);
    for (int i = 0; i < factors.size(); ++i) {
        BigDecimal rescaled = factors.get(i).multiply(scale);
        factors.set(i, rescaled);
    }
    for (int i = 0; i < members.size(); ++i) {
        BigDecimal currentAmount;
        LoanBO memberAccount = members.get(i);
        BigDecimal totalAmountToPay = loanAccount.getTotalRepayableAmount().getAmount();
        totalAmountToPay = totalAmountToPay.setScale(AccountingRules.getDigitsAfterDecimal());
        if (totalAmountToPay.equals(amount) || (loanAccount.isInState(AccountState.LOAN_CLOSED_OBLIGATIONS_MET) && (loanAccount.getAccountOverpayments() == null || loanAccount.getAccountOverpayments().isEmpty()))) {
            currentAmount = memberAccount.getTotalRepayableAmount().getAmount();
            memberAccountDtos.add(new GroupIndividualLoanDto(memberAccount.getGlobalAccountNum(), currentAmount, memberAccount.getAccountId()));
            continue;
        }
        if (i < members.size() - 1) {
            currentAmount = amount.divide(factors.get(i), RoundingMode.HALF_UP);
            memberAccountDtos.add(new GroupIndividualLoanDto(memberAccount.getGlobalAccountNum(), currentAmount, memberAccount.getAccountId()));
            amountSpent = amountSpent.add(currentAmount);
        } else {
            //last element
            memberAccountDtos.add(new GroupIndividualLoanDto(memberAccount.getGlobalAccountNum(), amount.subtract(amountSpent), memberAccount.getAccountId()));
        }
    }
    Collections.sort(memberAccountDtos);
    return memberAccountDtos;
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) GroupIndividualLoanDto(org.mifos.dto.domain.GroupIndividualLoanDto) BigDecimal(java.math.BigDecimal)

Example 4 with GroupIndividualLoanDto

use of org.mifos.dto.domain.GroupIndividualLoanDto in project head by mifos.

the class StandardAccountService method createMembersLoanPaymentsData.

/**
     * Create default members payments data. 
     */
private void createMembersLoanPaymentsData(AccountPaymentParametersDto parentPaymentParametersDto) {
    List<GroupIndividualLoanDto> membersPayments = this.groupLoanAccountServiceFacade.getMemberLoansAndDefaultPayments(parentPaymentParametersDto.getAccountId(), parentPaymentParametersDto.getPaymentAmount());
    parentPaymentParametersDto.setMemberInfo(new HashMap<Integer, String>());
    for (GroupIndividualLoanDto memberPayment : membersPayments) {
        parentPaymentParametersDto.getMemberInfo().put(memberPayment.getAccountId(), memberPayment.getDefaultAmount().toString());
    }
}
Also used : GroupIndividualLoanDto(org.mifos.dto.domain.GroupIndividualLoanDto)

Example 5 with GroupIndividualLoanDto

use of org.mifos.dto.domain.GroupIndividualLoanDto in project head by mifos.

the class AccountApplyGroupPaymentAction method divide.

@TransactionDemarcate(joinToken = true)
public ActionForward divide(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
    actionForm.getIndividualValues().clear();
    List<GroupIndividualLoanDto> memberAccounts = groupLoanService.getMemberLoansAndDefaultPayments(Integer.valueOf(actionForm.getAccountId()), new BigDecimal(actionForm.getAmount()));
    for (int i = 0; i < memberAccounts.size(); i++) {
        actionForm.getIndividualValues().put(memberAccounts.get(i).getAccountId(), String.valueOf(memberAccounts.get(i).getDefaultAmount().doubleValue()));
    }
    List<LoanBO> memberInfos = getMemberAccountsInformation(actionForm.getAccountId());
    SessionUtils.setCollectionAttribute("memberInfos", memberInfos, request);
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) GroupIndividualLoanDto(org.mifos.dto.domain.GroupIndividualLoanDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) BigDecimal(java.math.BigDecimal) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

GroupIndividualLoanDto (org.mifos.dto.domain.GroupIndividualLoanDto)5 BigDecimal (java.math.BigDecimal)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)3 AccountApplyPaymentActionForm (org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm)2 ArrayList (java.util.ArrayList)1 FeeBO (org.mifos.accounts.fees.business.FeeBO)1 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)1 ApplyChargeActionForm (org.mifos.accounts.struts.actionforms.ApplyChargeActionForm)1 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)1 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)1 UserContext (org.mifos.security.util.UserContext)1