Search in sources :

Example 1 with GroupLoanMemberAdjustmentDto

use of org.mifos.dto.screen.GroupLoanMemberAdjustmentDto in project head by mifos.

the class ApplyAdjustment method divide.

@TransactionDemarcate(joinToken = true)
public ActionForward divide(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm applyAdjustmentActionForm = (ApplyAdjustmentActionForm) form;
    Integer parentAccountId = getBizService().findBySystemId(applyAdjustmentActionForm.getGlobalAccountNum()).getAccountId();
    Integer parentPaymentId = applyAdjustmentActionForm.getPaymentId();
    BigDecimal newAmount = new BigDecimal(applyAdjustmentActionForm.getAmount());
    if (applyAdjustmentActionForm.getAdjustcheckbox()) {
        newAmount = BigDecimal.ZERO;
    }
    List<GroupLoanMemberAdjustmentDto> memberAdjustmentDtoList = this.groupLoanService.retrieveMemberAdjustmentDtos(parentAccountId, parentPaymentId, newAmount);
    applyAdjustmentActionForm.setMemberAdjustmentDtoList(memberAdjustmentDtoList);
    return mapping.findForward("divideadjustment_success");
}
Also used : ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) BigDecimal(java.math.BigDecimal) GroupLoanMemberAdjustmentDto(org.mifos.dto.screen.GroupLoanMemberAdjustmentDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with GroupLoanMemberAdjustmentDto

use of org.mifos.dto.screen.GroupLoanMemberAdjustmentDto in project head by mifos.

the class GroupLoanAccountServiceFacadeWebTier method retrieveMemberAdjustmentDtos.

@Override
public List<GroupLoanMemberAdjustmentDto> retrieveMemberAdjustmentDtos(Integer parentAccountId, Integer parentPaymentId, BigDecimal newAmount) {
    LoanBO parentLoanAccount = loanDao.findById(parentAccountId);
    List<GroupLoanMemberAdjustmentDto> memberAdjustmentDtoList = new ArrayList<GroupLoanMemberAdjustmentDto>();
    LoanBO memberAccount = null;
    AccountPaymentEntity memberPayment = null;
    BigDecimal currentAmount = null;
    BigDecimal amountSpent = BigDecimal.ZERO;
    List<LoanBO> members = new ArrayList<LoanBO>(parentLoanAccount.getMemberAccounts());
    Iterator<LoanBO> itr = members.iterator();
    while (itr.hasNext()) {
        memberAccount = itr.next();
        if (itr.hasNext()) {
            currentAmount = newAmount.divide(memberAccount.calcFactorOfEntireLoan(), RoundingMode.HALF_UP);
            memberPayment = memberAccount.findPaymentByParentPaymentId(parentPaymentId);
            if (memberPayment == null) {
                continue;
            }
            memberAdjustmentDtoList.add(new GroupLoanMemberAdjustmentDto(memberPayment.getPaymentId(), memberAccount.getAccountId(), memberPayment.getAmount().getAmount(), currentAmount, new LocalDate(memberPayment.getPaymentDate()), memberAccount.getGlobalAccountNum(), memberAccount.getCustomer().getGlobalCustNum(), memberAccount.getCustomer().getDisplayName()));
            amountSpent = amountSpent.add(currentAmount);
        } else {
            //last element
            memberPayment = memberAccount.findPaymentByParentPaymentId(parentPaymentId);
            memberAdjustmentDtoList.add(new GroupLoanMemberAdjustmentDto(memberPayment.getPaymentId(), memberAccount.getAccountId(), memberPayment.getAmount().getAmount(), newAmount.subtract(amountSpent), new LocalDate(memberPayment.getPaymentDate()), memberAccount.getGlobalAccountNum(), memberAccount.getCustomer().getGlobalCustNum(), memberAccount.getCustomer().getDisplayName()));
        }
    }
    Collections.sort(memberAdjustmentDtoList);
    return memberAdjustmentDtoList;
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LocalDate(org.joda.time.LocalDate) GroupLoanMemberAdjustmentDto(org.mifos.dto.screen.GroupLoanMemberAdjustmentDto) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)2 GroupLoanMemberAdjustmentDto (org.mifos.dto.screen.GroupLoanMemberAdjustmentDto)2 ArrayList (java.util.ArrayList)1 LocalDate (org.joda.time.LocalDate)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 ApplyAdjustmentActionForm (org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1