use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LoanBO method getAccountPaymentEntity.
private AccountPaymentEntity getAccountPaymentEntity(PaymentData paymentData) {
final AccountPaymentEntity accountPayment = new AccountPaymentEntity(this, paymentData.getTotalAmount(), paymentData.getReceiptNum(), paymentData.getReceiptDate(), getPaymentTypeEntity(paymentData.getPaymentTypeId()), paymentData.getTransactionDate());
accountPayment.setCreatedByUser(paymentData.getPersonnel());
accountPayment.setComment(paymentData.getComment());
accountPayment.setParentPaymentId(paymentData.getParentPayment());
//for savings transfers
AccountPaymentEntity otherTransferPayment = paymentData.getOtherTransferPayment();
if (otherTransferPayment != null) {
accountPayment.setOtherTransferPayment(otherTransferPayment);
}
return accountPayment;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsAdjustmentAccountingEntry method isAdjustmentForWithdrawal.
protected boolean isAdjustmentForWithdrawal(SavingsBO savings) {
AccountPaymentEntity payment = savings.findMostRecentPaymentByPaymentDate();
boolean isWithdrawal = false;
if (payment != null) {
isWithdrawal = payment.isSavingsWithdrawal();
}
return isWithdrawal;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class WebTierAccountServiceFacade method applyMemberAccountHistoricalAdjustment.
/**
* adjustment for member account payment has to be handled along with parent account payments and other members payments.
* This method prepares data and run applyHistoricalAdjustment so adjustment will be made for parent payment context.
*/
@Override
@PreAuthorize("isFullyAuthenticated()")
public void applyMemberAccountHistoricalAdjustment(String memberGlobalAccountNum, Integer memberPaymentId, String adjustmentNote, Short personnelId, AdjustedPaymentDto adjustedPaymentDto) {
try {
LoanBO memberAccount = (LoanBO) accountBusinessService.findBySystemId(memberGlobalAccountNum);
LoanBO parentAccount = memberAccount.getParentAccount();
if (parentAccount == null) {
throw new AccountException(LoanExceptionConstants.NO_PARENT_ACCOUNT_EXCEPTION);
}
AccountPaymentEntity parentPaymentEntity = memberAccount.findParentPaymentByMemberPaymentId(memberPaymentId);
List<AdjustedPaymentDto> membersAdjustedPaymentDtoList = new ArrayList<AdjustedPaymentDto>();
for (AccountPaymentEntity memberPayment : parentPaymentEntity.getMemberPayments()) {
if (memberPayment.getAccount().getAccountId().equals(memberAccount.getAccountId())) {
membersAdjustedPaymentDtoList.add(new AdjustedPaymentDto(adjustedPaymentDto.getAmount(), adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), memberAccount.getAccountId()));
} else {
membersAdjustedPaymentDtoList.add(new AdjustedPaymentDto(memberPayment.getAmount().getAmount().toString(), adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), memberPayment.getAccount().getAccountId()));
}
}
BigDecimal parentAmountSubstraction = memberAccount.findPaymentById(memberPaymentId).getAmount().getAmount().subtract((new BigDecimal(adjustedPaymentDto.getAmount())));
String newParentAmount = parentPaymentEntity.getAmount().getAmount().subtract(parentAmountSubstraction).toString();
AdjustedPaymentDto parentAdjustedPaymentDto = new AdjustedPaymentDto(newParentAmount, adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), parentAccount.getAccountId(), membersAdjustedPaymentDtoList);
this.applyHistoricalAdjustment(parentAccount.getGlobalAccountNum(), parentPaymentEntity.getPaymentId(), adjustmentNote, personnelId, parentAdjustedPaymentDto);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
} catch (AccountException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsServiceFacadeWebTier method adjustTransaction.
@Override
public PaymentDto adjustTransaction(SavingsAdjustmentDto savingsAdjustment, boolean inTransaction) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsAdjustment.getSavingsId());
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
PersonnelBO updatedBy = this.personnelDao.findPersonnelById(userContext.getId());
savingsAccount.updateDetails(userContext);
Money amountAdjustedTo = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsAdjustment.getAdjustedAmount()));
AccountPaymentEntity adjustedPayment = savingsAccount.findPaymentById(savingsAdjustment.getPaymentId());
PaymentDto otherTransferPayment = adjustedPayment.getOtherTransferPaymentDto();
Money originalAmount = adjustedPayment.getAmount();
LocalDate dateOfWithdrawal = savingsAdjustment.getTrxnDate();
if (adjustedPayment.isSavingsWithdrawal() && originalAmount.isLessThan(amountAdjustedTo)) {
Money addedWithdrawalAmount = amountAdjustedTo.subtract(originalAmount);
if (withdrawalMakesBalanceNegative(savingsAccount, addedWithdrawalAmount, dateOfWithdrawal)) {
throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
}
} else if (adjustedPayment.isSavingsDeposit() && originalAmount.isGreaterThan(amountAdjustedTo)) {
Money substractedAmount = originalAmount.subtract(amountAdjustedTo);
if (withdrawalMakesBalanceNegative(savingsAccount, substractedAmount, dateOfWithdrawal)) {
throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
}
}
try {
if (!inTransaction) {
this.transactionHelper.startTransaction();
}
this.transactionHelper.beginAuditLoggingFor(savingsAccount);
AccountPaymentEntity newPayment = savingsAccount.adjustUserAction(amountAdjustedTo, savingsAdjustment.getNote(), savingsAdjustment.getTrxnDate(), updatedBy, savingsAdjustment.getPaymentId());
recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(adjustedPayment.getPaymentDate()));
if (hasAccountNegativeBalance(savingsAccount)) {
throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
}
this.savingsDao.save(savingsAccount);
// savings-savings transfer adjustment
if (otherTransferPayment != null && otherTransferPayment.isSavingsPayment()) {
this.transactionHelper.flushAndClearSession();
SavingsBO otherSavingsAccount = this.savingsDao.findById(otherTransferPayment.getAccountId());
otherSavingsAccount.updateDetails(userContext);
AccountPaymentEntity newOtherTransferPayment = otherSavingsAccount.adjustUserAction(amountAdjustedTo, savingsAdjustment.getNote(), savingsAdjustment.getTrxnDate(), updatedBy, otherTransferPayment.getPaymentId());
recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(adjustedPayment.getPaymentDate()));
if (hasAccountNegativeBalance(otherSavingsAccount)) {
throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
}
transactionHelper.flushAndClearSession();
if (newPayment != null) {
newPayment = savingsAccount.findPaymentById(newPayment.getPaymentId());
newPayment.setOtherTransferPayment(newOtherTransferPayment);
newOtherTransferPayment.setOtherTransferPayment(newPayment);
legacyAcccountDao.updatePayment(newPayment);
}
this.savingsDao.save(otherSavingsAccount);
}
if (!inTransaction) {
this.transactionHelper.commitTransaction();
}
return (newPayment == null) ? null : newPayment.toDto();
} catch (BusinessRuleException e) {
if (!inTransaction) {
this.transactionHelper.rollbackTransaction();
}
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
if (!inTransaction) {
this.transactionHelper.rollbackTransaction();
}
throw new MifosRuntimeException(e.getMessage(), e);
} finally {
if (!inTransaction) {
this.transactionHelper.closeSession();
}
}
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveAdjustmentReferenceData.
@Override
public SavingsAdjustmentReferenceDto retrieveAdjustmentReferenceData(Long savingsId, Integer paymentId) {
SavingsBO savings = savingsDao.findById(savingsId);
AccountPaymentEntity payment = (paymentId == null) ? null : savings.findPaymentById(paymentId);
String clientName = null;
String amount = null;
boolean depositOrWithdrawal = false;
if (payment != null) {
amount = payment.getAmount().toString();
depositOrWithdrawal = payment.isSavingsDepositOrWithdrawal();
}
if (!savings.getCustomer().isClient() && payment != null) {
CustomerBO customer = null;
for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
customer = accountTrxn.getCustomer();
break;
}
if (customer != null && customer.isClient()) {
clientName = customer.getDisplayName();
}
}
return new SavingsAdjustmentReferenceDto(clientName, amount, depositOrWithdrawal);
}
Aggregations