use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveClosingDetails.
@Override
public SavingsAccountClosureDto retrieveClosingDetails(Long savingsId, LocalDate closureDate) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
InterestScheduledEvent postingSchedule = savingsInterestScheduledEventFactory.createScheduledEventFrom(savingsAccount.getInterestPostingMeeting());
LocalDate nextPostingDate = new LocalDate(savingsAccount.getNextIntPostDate());
LocalDate startOfPostingPeriod = postingSchedule.findFirstDateOfPeriodForMatchingDate(nextPostingDate);
CalendarPeriod postingPeriodAtClosure;
if (startOfPostingPeriod.isAfter(closureDate)) {
postingPeriodAtClosure = new CalendarPeriod(closureDate, closureDate);
} else {
postingPeriodAtClosure = new CalendarPeriod(startOfPostingPeriod, closureDate);
}
List<EndOfDayDetail> allEndOfDayDetailsForAccount = savingsDao.retrieveAllEndOfDayDetailsFor(savingsAccount.getCurrency(), Long.valueOf(savingsId));
InterestPostingPeriodResult postingPeriodAtClosureResult = determinePostingPeriodResult(postingPeriodAtClosure, savingsAccount, allEndOfDayDetailsForAccount);
Money endOfAccountBalance = postingPeriodAtClosureResult.getPeriodBalance();
Money interestAmountAtClosure = postingPeriodAtClosureResult.getPeriodInterest();
List<ListElement> depositPaymentTypes = retrieveDepositPaymentTypes(userContext);
return new SavingsAccountClosureDto(new LocalDate(), endOfAccountBalance.toString(), interestAmountAtClosure.toString(), depositPaymentTypes);
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveSavingsAccountNotes.
@Override
public SavingsAccountDetailDto retrieveSavingsAccountNotes(Long savingsId) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
savingsAccount.updateDetails(userContext);
return savingsAccount.toDto();
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method postInterestForAccount.
private void postInterestForAccount(Integer savingsId, UserContext userContext, PersonnelBO createdBy, boolean inTransaction) {
SavingsBO savingsAccount = this.savingsDao.findById(Long.valueOf(savingsId));
savingsAccount.updateDetails(userContext);
List<EndOfDayDetail> allEndOfDayDetailsForAccount = savingsDao.retrieveAllEndOfDayDetailsFor(savingsAccount.getCurrency(), Long.valueOf(savingsId));
LocalDate interestPostingDate = new LocalDate(savingsAccount.getNextIntPostDate());
InterestScheduledEvent postingSchedule = savingsInterestScheduledEventFactory.createScheduledEventFrom(savingsAccount.getInterestPostingMeeting());
LocalDate startOfPeriod = postingSchedule.findFirstDateOfPeriodForMatchingDate(interestPostingDate);
CalendarPeriod lastInterestPostingPeriod = new CalendarPeriod(startOfPeriod, interestPostingDate);
InterestPostingPeriodResult interestPostingPeriodResult = determinePostingPeriodResult(lastInterestPostingPeriod, savingsAccount, allEndOfDayDetailsForAccount);
savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
StringBuilder postingInfoMessage = new StringBuilder().append("account id: ").append(savingsAccount.getAccountId()).append("posting interest: ").append(interestPostingPeriodResult);
logger.info(postingInfoMessage.toString());
try {
if (!inTransaction) {
this.transactionHelper.startTransaction();
}
this.savingsDao.save(savingsAccount);
if (!inTransaction) {
this.transactionHelper.commitTransaction();
}
} catch (Exception e) {
if (!inTransaction) {
this.transactionHelper.rollbackTransaction();
}
throw new BusinessRuleException(savingsAccount.getAccountId().toString(), e);
} finally {
if (!inTransaction) {
this.transactionHelper.closeSession();
}
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveSavingsAccountDetails.
@Override
public SavingsAccountDetailDto retrieveSavingsAccountDetails(String globalAccountNum) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
savingsAccount.setUserContext(userContext);
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
return savingsAccount.toDto();
}
use of org.mifos.accounts.savings.business.SavingsBO 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();
}
}
}
Aggregations