use of org.mifos.accounts.business.AccountPaymentEntity 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;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class CollectionSheetServiceImpl method saveCollectionSheet.
/**
* The method saves a collection sheet.
*
* @throws SaveCollectionSheetException
* */
@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) throws SaveCollectionSheetException {
Long totalTime;
Long totalTimeStart = System.currentTimeMillis();
Long readTime;
Long saveTime = null;
Long saveTimeStart;
Integer topCustomerId = saveCollectionSheet.getSaveCollectionSheetCustomers().get(0).getCustomerId();
CollectionSheetCustomerDto collectionSheetTopCustomer = new CustomerPersistence().findCustomerWithNoAssocationsLoaded(topCustomerId);
if (collectionSheetTopCustomer == null) {
List<InvalidSaveCollectionSheetReason> invalidSaveCollectionSheetReasons = new ArrayList<InvalidSaveCollectionSheetReason>();
List<String> invalidSaveCollectionSheetReasonsExtended = new ArrayList<String>();
invalidSaveCollectionSheetReasons.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER);
invalidSaveCollectionSheetReasonsExtended.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER.toString() + ": Customer Id: " + topCustomerId);
throw new SaveCollectionSheetException(invalidSaveCollectionSheetReasons, invalidSaveCollectionSheetReasonsExtended);
}
Short branchId = collectionSheetTopCustomer.getBranchId();
String searchId = collectionSheetTopCustomer.getSearchId();
// session caching: prefetch collection sheet data
// done prior to structure validation because it loads
// the customers and accounts to be validated into the session
SaveCollectionSheetSessionCache saveCollectionSheetSessionCache = new SaveCollectionSheetSessionCache();
saveCollectionSheetSessionCache.loadSessionCacheWithCollectionSheetData(saveCollectionSheet, branchId, searchId);
try {
new SaveCollectionSheetStructureValidator().execute(saveCollectionSheet);
} catch (SaveCollectionSheetException e) {
System.out.println(e.printInvalidSaveCollectionSheetReasons());
throw e;
}
/*
* With preprocessing complete...
*
* only errors and warnings from the business model remain
*/
final List<String> failedSavingsDepositAccountNums = new ArrayList<String>();
final List<String> failedSavingsWithdrawalNums = new ArrayList<String>();
final List<String> failedLoanDisbursementAccountNumbers = new ArrayList<String>();
final List<String> failedLoanRepaymentAccountNumbers = new ArrayList<String>();
final List<String> failedCustomerAccountPaymentNums = new ArrayList<String>();
final List<ClientAttendanceBO> clientAttendances = saveCollectionSheetAssembler.clientAttendanceAssemblerfromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), saveCollectionSheet.getTransactionDate(), branchId, searchId);
final AccountPaymentEntity payment = saveCollectionSheetAssembler.accountPaymentAssemblerFromDto(saveCollectionSheet.getTransactionDate(), saveCollectionSheet.getPaymentType(), saveCollectionSheet.getReceiptId(), saveCollectionSheet.getReceiptDate(), saveCollectionSheet.getUserId());
final List<SavingsBO> savingsAccounts = saveCollectionSheetAssembler.savingsAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedSavingsDepositAccountNums, failedSavingsWithdrawalNums);
Short paymentTypeId = (payment.getPaymentType() == null || payment.getPaymentType().getId() == null) ? null : payment.getPaymentType().getId();
final List<LoanBO> loanAccounts = saveCollectionSheetAssembler.loanAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, paymentTypeId);
final List<AccountBO> customerAccounts = saveCollectionSheetAssembler.customerAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedCustomerAccountPaymentNums);
boolean databaseErrorOccurred = false;
Throwable databaseError = null;
readTime = System.currentTimeMillis() - totalTimeStart;
try {
saveTimeStart = System.currentTimeMillis();
persistCollectionSheet(clientAttendances, loanAccounts, customerAccounts, savingsAccounts);
saveTime = System.currentTimeMillis() - saveTimeStart;
} catch (HibernateException e) {
logger.error("database error saving collection sheet", e);
databaseErrorOccurred = true;
databaseError = e;
}
totalTime = System.currentTimeMillis() - totalTimeStart;
printTiming(saveCollectionSheet.printSummary(), totalTime, saveTime, readTime, saveCollectionSheetSessionCache);
return new CollectionSheetErrorsDto(failedSavingsDepositAccountNums, failedSavingsWithdrawalNums, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, failedCustomerAccountPaymentNums, databaseErrorOccurred, databaseError);
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class ClientServiceFacadeWebTier method getClientAccountPayments.
@Override
public List<AccountPaymentDto> getClientAccountPayments(String globalAccountNum) {
List<AccountPaymentDto> clientAccountPayments = new ArrayList<AccountPaymentDto>();
try {
AccountBO account = legacyAccountDao.findBySystemId(globalAccountNum);
List<AccountPaymentEntity> clientAccountPaymentsEntities = account.getAccountPayments();
for (AccountPaymentEntity accountPaymentEntity : clientAccountPaymentsEntities) {
clientAccountPayments.add(accountPaymentEntity.toScreenDto());
}
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
return clientAccountPayments;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method getLoanAccountPayments.
@Override
public List<AccountPaymentDto> getLoanAccountPayments(String globalAccountNum) {
List<AccountPaymentDto> loanAccountPayments = new ArrayList<AccountPaymentDto>();
LoanBO loanAccount = loanDao.findByGlobalAccountNum(globalAccountNum);
List<AccountPaymentEntity> loanAccountPaymentsEntities = loanAccount.getAccountPayments();
for (AccountPaymentEntity accountPaymentEntity : loanAccountPaymentsEntities) {
loanAccountPayments.add(accountPaymentEntity.toScreenDto());
}
//for new group loan accounts
if (loanAccount.isGroupLoanAccount() && null == loanAccount.getParentAccount()) {
for (LoanBO member : loanAccount.getMemberAccounts()) {
for (AccountPaymentEntity accPayment : member.getAccountPayments()) {
if (!accPayment.isLoanDisbursment()) {
loanAccountPayments.add(accPayment.toScreenDto());
}
}
}
Collections.sort(loanAccountPayments, new AccountPaymentDtoComperator());
Collections.reverse(loanAccountPayments);
}
return loanAccountPayments;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class ApplyAdjustment method listPossibleAdjustments.
@TransactionDemarcate(joinToken = true)
public ActionForward listPossibleAdjustments(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
this.resetActionFormFields(appAdjustActionForm);
AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
boolean decliningRecalculation = false;
if (accnt instanceof LoanBO) {
LoanBO loan = (LoanBO) accnt;
if (loan.getInterestType().getId().equals(InterestType.DECLINING_PB.getValue())) {
decliningRecalculation = true;
}
}
List<AccountPaymentEntity> payments = accnt.getAccountPayments();
ArrayList<AdjustablePaymentDto> adjustablePayments = new ArrayList<AdjustablePaymentDto>();
int i = 1;
for (AccountPaymentEntity payment : payments) {
//ommit disbursal payment
if (!payment.getAmount().equals(Money.zero()) && i != payments.size()) {
AdjustablePaymentDto adjustablePaymentDto = new AdjustablePaymentDto(payment.getPaymentId(), payment.getAmount(), payment.getPaymentType().getName(), payment.getPaymentDate(), payment.getReceiptDate(), payment.getReceiptNumber());
adjustablePayments.add(adjustablePaymentDto);
if (decliningRecalculation) {
//only last payment
break;
}
}
i++;
}
SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
SessionUtils.setAttribute(Constants.POSSIBLE_ADJUSTMENTS, adjustablePayments, request);
request.setAttribute("method", "loadAdjustment");
return mapping.findForward("loadadjustments_success");
}
Aggregations