use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method waivePenaltyAmountOverDue.
private void waivePenaltyAmountOverDue() throws AccountException {
Money chargeWaived = new Money(getCurrency());
Money principal = new Money(getCurrency());
Money interest = new Money(getCurrency());
Money fee = new Money(getCurrency());
List<AccountActionDateEntity> accountActionDateList = getApplicableIdsForNextInstallmentAndArrears();
// Fix for http://mifosforge.jira.com/browse/MIFOS-2826
if (getDetailsOfNextInstallment() != null) {
accountActionDateList.remove(accountActionDateList.size() - 1);
}
for (AccountActionDateEntity accountActionDateEntity : accountActionDateList) {
chargeWaived = chargeWaived.add(((LoanScheduleEntity) accountActionDateEntity).waivePenaltyCharges());
}
if (chargeWaived != null && chargeWaived.isGreaterThanZero()) {
updateTotalPenaltyAmount(chargeWaived);
updateAccountActivity(principal, interest, fee, chargeWaived, userContext.getId(), AccountConstants.AMOUNT + chargeWaived + AccountConstants.WAIVED);
waiveOverdueChargesFromMemberAccounts(LoanConstants.PENALTY_WAIVED);
}
try {
getlegacyLoanDao().createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method updateAccountActivity.
@Override
protected void updateAccountActivity(final Money principal, final Money interest, final Money fee, final Money penalty, final Short personnelId, final String description) throws AccountException {
try {
PersonnelBO personnel = legacyPersonnelDao.getPersonnel(personnelId);
LoanActivityEntity loanActivity = new LoanActivityEntity(this, personnel, description, principal, loanSummary.getOriginalPrincipal().subtract(loanSummary.getPrincipalPaid()), interest, loanSummary.getOriginalInterest().subtract(loanSummary.getInterestPaid()), fee, loanSummary.getOriginalFees().subtract(loanSummary.getFeesPaid()), penalty, loanSummary.getOriginalPenalty().subtract(loanSummary.getPenaltyPaid()), DateUtils.getCurrentDateWithoutTimeStamp());
this.addLoanActivity(loanActivity);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class SavingsServiceFacadeWebTier method withdraw.
@Override
public PaymentDto withdraw(SavingsWithdrawalDto savingsWithdrawal, boolean inTransaction) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsWithdrawal.getSavingsId());
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
savingsAccount.updateDetails(userContext);
PersonnelBO createdBy = this.personnelDao.findPersonnelById(Short.valueOf((short) user.getUserId()));
CustomerBO customer = this.customerDao.findCustomerById(savingsWithdrawal.getCustomerId().intValue());
Money totalAmount = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsWithdrawal.getAmount()));
PaymentData payment = PaymentData.createPaymentData(totalAmount, createdBy, savingsWithdrawal.getModeOfPayment().shortValue(), savingsWithdrawal.getDateOfWithdrawal().toDateMidnight().toDate());
if (savingsWithdrawal.getDateOfReceipt() != null) {
payment.setReceiptDate(savingsWithdrawal.getDateOfReceipt().toDateMidnight().toDate());
}
payment.setReceiptNum(savingsWithdrawal.getReceiptId());
payment.setCustomer(customer);
LocalDate dateOfWithdrawal = new LocalDate(payment.getTransactionDate());
if (withdrawalMakesBalanceNegativeOnDate(savingsAccount, payment.getTotalAmount(), dateOfWithdrawal)) {
throw new BusinessRuleException("errors.insufficentbalance", new String[] { savingsAccount.getGlobalAccountNum() });
}
try {
if (!inTransaction) {
this.transactionHelper.startTransaction();
}
this.transactionHelper.beginAuditLoggingFor(savingsAccount);
AccountPaymentEntity paymentEntity = savingsAccount.withdraw(payment, false);
this.savingsDao.save(savingsAccount);
Date lastIntPostDate = savingsAccount.getLastIntPostDate();
if (lastIntPostDate != null && DateUtils.dateFallsOnOrBeforeDate(payment.getTransactionDate(), lastIntPostDate)) {
this.recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(payment.getTransactionDate()));
}
// commit
if (inTransaction) {
this.transactionHelper.flushSession();
} else {
this.transactionHelper.commitTransaction();
}
return paymentEntity.toDto();
} catch (AccountException e) {
if (!inTransaction) {
this.transactionHelper.rollbackTransaction();
}
throw new BusinessRuleException(e.getKey(), e);
} finally {
if (!inTransaction) {
this.transactionHelper.closeSession();
}
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class SaveCollectionSheetAssembler method buildModelForSavingsAccounts.
private void buildModelForSavingsAccounts(final List<SaveCollectionSheetCustomerSavingDto> saveCollectionSheetCustomerSavings, final AccountPaymentEntity payment, final List<String> failedSavingsDepositAccountNums, final List<String> failedSavingsWithdrawalNums, final Integer customerId, final List<SavingsBO> savingsList) {
if (null != saveCollectionSheetCustomerSavings && saveCollectionSheetCustomerSavings.size() > 0) {
final String receiptNumber = payment.getReceiptNumber();
final Date receiptDate = payment.getReceiptDate();
final PaymentTypeEntity paymentType = payment.getPaymentType();
final Date paymentDate = payment.getPaymentDate();
final PersonnelBO user = payment.getCreatedByUser();
for (SaveCollectionSheetCustomerSavingDto saveCollectionSheetCustomerSaving : saveCollectionSheetCustomerSavings) {
final BigDecimal amountToDeposit = saveCollectionSheetCustomerSaving.getTotalDeposit();
final BigDecimal amountToWithdraw = saveCollectionSheetCustomerSaving.getTotalWithdrawal();
Boolean isDeposit = isPositiveAmountEntered(amountToDeposit);
Boolean isWithdrawal = isPositiveAmountEntered(amountToWithdraw);
if (isDeposit || isWithdrawal) {
boolean storeAccountForSavingLater = false;
final CustomerBO payingCustomer = customerDao.findCustomerById(customerId);
SavingsBO account = savingsDao.findById(saveCollectionSheetCustomerSaving.getAccountId());
if (isDeposit) {
final AccountPaymentEntity accountDeposit = new AccountPaymentEntity(account, new Money(Money.getDefaultCurrency(), amountToDeposit.toString()), receiptNumber, receiptDate, paymentType, paymentDate);
accountDeposit.setCreatedByUser(user);
try {
account.deposit(accountDeposit, payingCustomer);
storeAccountForSavingLater = true;
} catch (AccountException e) {
logger.warn("Savings deposit on account [" + account.getAccountId() + "] failed. Account changes will not be persisted due to: " + e.getMessage());
failedSavingsDepositAccountNums.add(account.getAccountId().toString());
}
}
if (isWithdrawal) {
final AccountPaymentEntity accountWithdrawal = new AccountPaymentEntity(account, new Money(Money.getDefaultCurrency(), amountToWithdraw.toString()), receiptNumber, receiptDate, paymentType, paymentDate);
accountWithdrawal.setCreatedByUser(user);
try {
account.withdraw(accountWithdrawal, payingCustomer);
storeAccountForSavingLater = true;
} catch (AccountException e) {
logger.warn("Savings withdrawal on account [" + account.getAccountId() + "] failed. Account changes will not be persisted due to: " + e.getMessage());
failedSavingsWithdrawalNums.add(account.getAccountId().toString());
}
}
if (storeAccountForSavingLater) {
if (!savingsList.contains(account)) {
savingsList.add(account);
}
} else {
StaticHibernateUtil.getSessionTL().evict(account);
}
}
}
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class SaveCollectionSheetAssembler method loanAccountAssemblerFromDto.
public List<LoanBO> loanAccountAssemblerFromDto(final List<SaveCollectionSheetCustomerDto> saveCollectionSheetCustomers, final AccountPaymentEntity payment, final List<String> failedLoanDisbursementAccountNumbers, final List<String> failedLoanRepaymentAccountNumbers, Short paymentTypeIdForFees) {
final List<LoanBO> loans = new ArrayList<LoanBO>();
Map<Integer, AccountPaymentEntity> groupLoanAccountParentsPayments = new HashMap<Integer, AccountPaymentEntity>();
for (SaveCollectionSheetCustomerDto saveCollectionSheetCustomer : saveCollectionSheetCustomers) {
if (saveCollectionSheetCustomer.getSaveCollectionSheetCustomerLoans() != null && saveCollectionSheetCustomer.getSaveCollectionSheetCustomerLoans().size() > 0) {
for (SaveCollectionSheetCustomerLoanDto saveCollectionSheetCustomerLoan : saveCollectionSheetCustomer.getSaveCollectionSheetCustomerLoans()) {
final Integer accountId = saveCollectionSheetCustomerLoan.getAccountId();
LoanBO account = findLoanAccountById(accountId);
final String globalAccountNum = account.getGlobalAccountNum();
final BigDecimal disbursalAmount = saveCollectionSheetCustomerLoan.getTotalDisbursement();
if (null != disbursalAmount && disbursalAmount.compareTo(BigDecimal.ZERO) > 0) {
try {
final AccountPaymentEntity accountDisbursalPayment = new AccountPaymentEntity(account, new Money(account.getCurrency(), disbursalAmount.toString()), payment.getReceiptNumber(), payment.getReceiptDate(), payment.getPaymentType(), payment.getPaymentDate());
accountDisbursalPayment.setCreatedByUser(payment.getCreatedByUser());
Integer transferAccountId = (payment.getOtherTransferPayment() == null || payment.getOtherTransferPayment().getAccount() == null || payment.getOtherTransferPayment().getAccount().getAccountId() == null) ? null : payment.getOtherTransferPayment().getAccount().getAccountId();
account.disburseLoan(accountDisbursalPayment, paymentTypeIdForFees, transferAccountId);
loans.add(account);
} catch (AccountException ae) {
logger.warn("Disbursal of loan on account [" + globalAccountNum + "] failed. Account changes will not be persisted due to: " + ae.getMessage());
failedLoanDisbursementAccountNumbers.add(globalAccountNum);
StaticHibernateUtil.getSessionTL().evict(account);
} catch (PersistenceException e) {
logger.warn("Disbursal of loan on account [" + globalAccountNum + "] failed. Account changes will not be persisted due to: " + e.getMessage());
failedLoanDisbursementAccountNumbers.add(globalAccountNum);
StaticHibernateUtil.getSessionTL().evict(account);
}
} else {
final BigDecimal loanPaymentAmount = saveCollectionSheetCustomerLoan.getTotalLoanPayment();
if (loanPaymentAmount != null && loanPaymentAmount.compareTo(BigDecimal.ZERO) > 0) {
try {
final PaymentData paymentData = getCustomerAccountPaymentDataView(new Money(account.getCurrency(), loanPaymentAmount.toString()), payment);
AccountPaymentEntity paymentEntity = account.applyPayment(paymentData);
if (account.isGroupLoanAccountParent()) {
groupLoanAccountParentsPayments.put(account.getAccountId(), paymentEntity);
} else if (account.isGroupLoanAccountMember()) {
paymentEntity.setParentPaymentId(groupLoanAccountParentsPayments.get(account.getParentAccount().getAccountId()));
}
loans.add(account);
} catch (AccountException ae) {
logger.warn("Loan repayment on account [" + globalAccountNum + "] failed. Account changes will not be persisted due to: " + ae.getMessage());
failedLoanRepaymentAccountNumbers.add(globalAccountNum);
StaticHibernateUtil.getSessionTL().evict(account);
}
}
}
}
}
}
return loans;
}
Aggregations