use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.
the class LoanAccountServiceFacadeWebTier method assembleLoanAccountDetail.
private LoanAccountDetail assembleLoanAccountDetail(CreateLoanAccount loanAccountInfo) {
CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getCustomerId());
LoanOfferingBO loanProduct = this.loanProductDao.findById(loanAccountInfo.getProductId());
Money loanAmount = new Money(loanProduct.getCurrency(), loanAccountInfo.getLoanAmount());
AccountState accountStateType = AccountState.fromShort(loanAccountInfo.getAccountState().shortValue());
FundBO fund = null;
if (loanAccountInfo.getSourceOfFundId() != null) {
fund = this.fundDao.findById(loanAccountInfo.getSourceOfFundId().shortValue());
}
return new LoanAccountDetail(customer, loanProduct, loanAmount, accountStateType, fund);
}
use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.
the class AccountBusinessService method filterDisbursementFee.
private void filterDisbursementFee(List<FeeBO> feeList, AccountBO account) {
for (Iterator<FeeBO> iter = feeList.iterator(); iter.hasNext(); ) {
FeeBO fee = iter.next();
FeePaymentEntity feePaymentEntity = fee.getFeeFrequency().getFeePayment();
if (feePaymentEntity != null) {
Short paymentType = feePaymentEntity.getId();
if (paymentType.equals(FeePayment.TIME_OF_DISBURSEMENT.getValue())) {
AccountState accountState = account.getState();
if (accountState == AccountState.LOAN_PARTIAL_APPLICATION || accountState == AccountState.LOAN_PENDING_APPROVAL || accountState == AccountState.LOAN_APPROVED || accountState == AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER) {
continue;
} else {
iter.remove();
}
}
}
}
}
use of org.mifos.accounts.util.helpers.AccountState 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.util.helpers.AccountState 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.util.helpers.AccountState 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();
}
}
Aggregations