use of org.mifos.core.MifosRuntimeException 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());
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class SavingsServiceFacadeWebTier method waiveNextDepositAmountDue.
@Override
public void waiveNextDepositAmountDue(Long savingsId) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
savingsAccount.updateDetails(userContext);
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
try {
this.transactionHelper.startTransaction();
savingsAccount.waiveNextDepositAmountDue(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.core.MifosRuntimeException in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveCustomerThatQualifyForSavings.
@Override
public List<CustomerSearchResultDto> retrieveCustomerThatQualifyForSavings(CustomerSearchDto customerSearchDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>();
QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(customerSearchDto.getSearchTerm(), userContext.getId());
int position = this.resultsetOffset(customerSearchDto.getPage(), customerSearchDto.getPageSize());
List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize());
int i = 1;
for (AccountSearchResultsDto customerBO : pagedResults) {
CustomerSearchResultDto customer = new CustomerSearchResultDto();
customer.setCustomerId(customerBO.getClientId());
customer.setBranchName(customerBO.getOfficeName());
customer.setGlobalId(customerBO.getGlobelNo());
customer.setSearchIndex(i);
customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--"));
customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--"));
customer.setClientName(customerBO.getClientName());
pagedDetails.add(customer);
i++;
}
return pagedDetails;
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
} catch (HibernateSearchException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class SavingsServiceFacadeWebTier method createSavingsAccount.
@Override
public Long createSavingsAccount(SavingsAccountCreationDto savingsAccountCreation, List<QuestionGroupDetail> questionGroups) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
LocalDate createdDate = new LocalDate();
Integer createdById = user.getUserId();
PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
CustomerBO customer = this.customerDao.findCustomerById(savingsAccountCreation.getCustomerId());
SavingsOfferingBO savingsProduct = this.savingsProductDao.findById(savingsAccountCreation.getProductId());
Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), savingsAccountCreation.getRecommendedOrMandatoryAmount());
AccountState savingsAccountState = AccountState.fromShort(savingsAccountCreation.getAccountState());
CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
SavingsAccountTypeInspector savingsAccountWrapper = new SavingsAccountTypeInspector(customer, savingsProduct.getRecommendedAmntUnit());
try {
SavingsBO savingsAccount = null;
if (savingsAccountWrapper.isIndividualSavingsAccount()) {
savingsAccount = SavingsBO.createIndividalSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy);
} else if (savingsAccountWrapper.isJointSavingsAccountWithClientTracking()) {
List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(customer.getSearchId(), customer.getOfficeId(), CustomerLevel.CLIENT);
savingsAccount = SavingsBO.createJointSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy, activeAndOnHoldClients);
}
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.transactionHelper.startTransaction();
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
// save question groups
if (!questionGroups.isEmpty()) {
Integer eventSourceId = questionnaireServiceFacade.getEventSourceId("Create", "Savings");
QuestionGroupDetails questionGroupDetails = new QuestionGroupDetails(Integer.valueOf(user.getUserId()).shortValue(), savingsAccount.getAccountId(), eventSourceId, questionGroups);
questionnaireServiceFacade.saveResponses(questionGroupDetails);
}
this.transactionHelper.commitTransaction();
return savingsAccount.getAccountId().longValue();
} 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.core.MifosRuntimeException in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveAccountStatuses.
@Override
public AccountStatusDto retrieveAccountStatuses(Long savingsId) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
try {
List<ListElement> savingsStatesList = new ArrayList<ListElement>();
AccountStateMachines.getInstance().initializeSavingsStates();
List<AccountStateEntity> statusList = AccountStateMachines.getInstance().getSavingsStatusList(savingsAccount.getAccountState());
for (AccountStateEntity accountState : statusList) {
savingsStatesList.add(new ListElement(accountState.getId().intValue(), accountState.getName()));
}
return new AccountStatusDto(savingsStatesList);
} catch (StatesInitializationException e) {
throw new MifosRuntimeException(e);
}
}
Aggregations