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");
}
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;
}
Aggregations