use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method createSavingsAccount.
@Override
public String createSavingsAccount(OpeningBalanceSavingsAccount openingBalanceSavingsAccount) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
LocalDate createdDate = new LocalDate();
Integer createdById = user.getUserId();
PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
CustomerBO customer = this.customerDao.findCustomerBySystemId(openingBalanceSavingsAccount.getCustomerGlobalId());
SavingsOfferingBO savingsProduct = this.savingsProductDao.findBySystemId(openingBalanceSavingsAccount.getProductGlobalId());
AccountState savingsAccountState = AccountState.fromShort(openingBalanceSavingsAccount.getAccountState());
Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), openingBalanceSavingsAccount.getRecommendedOrMandatoryAmount());
Money openingBalance = new Money(savingsProduct.getCurrency(), new BigDecimal(0));
LocalDate activationDate = openingBalanceSavingsAccount.getActivationDate();
CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
SavingsAccountActivationDetail activationDetails = SavingsBO.generateAccountActivationDetails(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, calendarEvents, activationDate);
SavingsBO savingsAccount = SavingsBO.createOpeningBalanceIndividualSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, activationDetails, createdBy, openingBalance);
savingsAccount.setGlobalAccountNum(openingBalanceSavingsAccount.getAccountNumber());
savingsAccount.setSavingsBalance(openingBalance);
DateTimeService dateTimeService = new DateTimeService();
savingsAccount.setDateTimeService(dateTimeService);
openingBalance = new Money(savingsProduct.getCurrency(), openingBalanceSavingsAccount.getOpeningBalance());
if (savingsAccountState.isActiveLoanAccountState()) {
savingsAccount.resetRecommendedAmountOnFutureInstallments();
}
try {
if (openingBalance.isGreaterThanZero()) {
PaymentData paymentData = new PaymentData(openingBalance, createdBy, Short.valueOf("1"), activationDate.toDateMidnight().toDate());
paymentData.setCustomer(customer);
savingsAccount.applyPayment(paymentData);
}
this.transactionHelper.startTransaction();
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
// savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
this.savingsDao.save(savingsAccount);
this.transactionHelper.commitTransaction();
return savingsAccount.getGlobalAccountNum();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.savings.business.SavingsBO 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);
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method closeSavingsAccount.
@Override
public void closeSavingsAccount(Long savingsId, String notes, SavingsWithdrawalDto closeAccountDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
savingsAccount.updateDetails(userContext);
PersonnelBO createdBy = this.personnelDao.findPersonnelById(userContext.getId());
LocalDate closureDate = closeAccountDto.getDateOfWithdrawal();
// Assumption that all previous interest postings occurred correctly
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);
savingsAccount.postInterest(postingSchedule, postingPeriodAtClosureResult, createdBy);
AccountNotesEntity notesEntity = new AccountNotesEntity(new DateTimeService().getCurrentJavaSqlDate(), notes, createdBy, savingsAccount);
try {
CustomerBO customer = savingsAccount.getCustomer();
if (closeAccountDto.getCustomerId() != null) {
List<CustomerBO> clientList = new CustomerPersistence().getActiveAndOnHoldChildren(savingsAccount.getCustomer().getSearchId(), savingsAccount.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
for (CustomerBO client : clientList) {
if (closeAccountDto.getCustomerId().intValue() == client.getCustomerId().intValue()) {
customer = client;
break;
}
}
}
Money amount = new Money(savingsAccount.getCurrency(), closeAccountDto.getAmount().toString());
PaymentTypeEntity paymentType = new PaymentTypeEntity(closeAccountDto.getModeOfPayment().shortValue());
Date receiptDate = null;
if (closeAccountDto.getDateOfReceipt() != null) {
receiptDate = closeAccountDto.getDateOfReceipt().toDateMidnight().toDate();
}
AccountPaymentEntity closeAccount = new AccountPaymentEntity(savingsAccount, amount, closeAccountDto.getReceiptId(), receiptDate, paymentType, closeAccountDto.getDateOfWithdrawal().toDateMidnight().toDate());
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(savingsAccount);
savingsAccount.closeAccount(closeAccount, notesEntity, customer, createdBy);
this.savingsDao.save(savingsAccount);
this.transactionHelper.commitTransaction();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (PersistenceException e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method updateSavingsAccountStatus.
@Override
public void updateSavingsAccountStatus(AccountUpdateStatus updateStatus) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
SavingsBO savingsAccount = this.savingsDao.findById(updateStatus.getSavingsId());
savingsAccount.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(savingsAccount);
AccountState newStatus = AccountState.fromShort(updateStatus.getNewStatusId());
// FIXME - keithw - refactor savings specific logic out of changeStatus and create savings statue machine
// wrapper.
savingsAccount.changeStatus(newStatus, updateStatus.getFlagId(), updateStatus.getComment(), loggedInUser);
this.savingsDao.save(savingsAccount);
this.transactionHelper.commitTransaction();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveDepositDueDetails.
@Override
public SavingsAccountDepositDueDto retrieveDepositDueDetails(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
List<DueOnDateDto> previousDueDates = new ArrayList<DueOnDateDto>();
SavingsScheduleEntity nextInstallment = (SavingsScheduleEntity) savingsAccount.getDetailsOfNextInstallment();
Money totalDepositDue = Money.zero(savingsAccount.getCurrency());
LocalDate nextDueDate = new LocalDate();
if (nextInstallment != null) {
nextDueDate = new LocalDate(nextInstallment.getActionDate());
totalDepositDue = nextInstallment.getTotalDepositDue();
}
List<AccountActionDateEntity> scheduledDeposits = savingsAccount.getAccountActionDatesSortedByInstallmentId();
for (AccountActionDateEntity scheduledDeposit : scheduledDeposits) {
if (!scheduledDeposit.isPaid() && scheduledDeposit.isBefore(nextDueDate)) {
SavingsScheduleEntity savingsScheduledDeposit = (SavingsScheduleEntity) scheduledDeposit;
previousDueDates.add(new DueOnDateDto(scheduledDeposit.getActionDate(), MoneyUtils.currencyRound(savingsScheduledDeposit.getTotalDepositDue()).toString()));
}
}
DueOnDateDto nextDueDetail = new DueOnDateDto(new java.sql.Date(nextDueDate.toDateMidnight().toDate().getTime()), MoneyUtils.currencyRound(totalDepositDue).toString());
AccountStateEntity accountStateEntity = savingsAccount.getAccountState();
return new SavingsAccountDepositDueDto(nextDueDetail, previousDueDates, accountStateEntity.getId(), accountStateEntity.getName());
}
Aggregations