use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail 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.SavingsAccountActivationDetail in project head by mifos.
the class SavingsAccountBuilder method buildForUnitTests.
public SavingsBO buildForUnitTests() {
List<AccountActionDateEntity> listOfScheduledPayments = new ArrayList<AccountActionDateEntity>();
if (scheduledPayments != null) {
listOfScheduledPayments = new ArrayList<AccountActionDateEntity>(scheduledPayments);
}
activationDetails = new SavingsAccountActivationDetail(new LocalDate(activationDate), nextInterestPostingDate, listOfScheduledPayments);
return buildAccount(activationDetails);
}
use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail in project head by mifos.
the class SavingsAccountBuilder method build.
// build individual savings account
public SavingsBO build() {
CalendarEvent calendarEvents = new CalendarEvent(workingDays, holidays);
LocalDate activationDate = new LocalDate(createdDate);
SavingsAccountActivationDetail derivedActivationDetails = SavingsBO.determineAccountActivationDetails(customer, savingsProduct, recommendedAmount, accountState, calendarEvents, activationDate);
return buildAccount(derivedActivationDetails);
}
use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail in project head by mifos.
the class SavingsAccountBuilder method buildAccount.
private SavingsBO buildAccount(SavingsAccountActivationDetail derivedActivationDetails) {
List<AccountActionDateEntity> listOfScheduledPayments = new ArrayList<AccountActionDateEntity>();
if (scheduledPayments == null) {
listOfScheduledPayments = derivedActivationDetails.getScheduledPayments();
} else {
listOfScheduledPayments = new ArrayList<AccountActionDateEntity>(scheduledPayments);
}
activationDetails = new SavingsAccountActivationDetail(new LocalDate(activationDate), nextInterestPostingDate, listOfScheduledPayments);
CreationDetail creationDetail = new CreationDetail(new DateTime(createdDate), createdByUserId.intValue());
SavingsBO savingsAccount = new SavingsBO(accountState, customer, activationDetails, creationDetail, savingsProduct, recommendedAmountUnit, recommendedAmount, createdBy, savingsBalanceAmount);
savingsAccount.setCustomerPersistence(customerDao);
savingsAccount.setSavingsPaymentStrategy(savingsPaymentStrategy);
savingsAccount.setSavingsTransactionActivityHelper(savingsTransactionActivityHelper);
savingsAccount.updateDetails(TestUtils.makeUserWithLocales());
for (AccountPaymentEntity depositPayment : deposits) {
try {
depositPayment.setAccount(savingsAccount);
savingsAccount.deposit(depositPayment, customer);
} catch (AccountException e) {
throw new MifosRuntimeException("builder failed to apply deposits.", e);
}
}
for (AccountPaymentEntity withdrawal : withdrawals) {
try {
withdrawal.setAccount(savingsAccount);
savingsAccount.withdraw(withdrawal, customer);
} catch (AccountException e) {
throw new MifosRuntimeException("builder failed to apply withdrawals.", e);
}
}
return savingsAccount;
}
use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail in project head by mifos.
the class SavingsAccountBuilder method buildJointSavingsAccount.
public SavingsBO buildJointSavingsAccount() {
CalendarEvent calendarEvents = new CalendarEvent(workingDays, holidays);
SavingsAccountActivationDetail derivedActivationDetails = SavingsBO.determineAccountActivationDetails(customer, savingsProduct, recommendedAmount, accountState, calendarEvents, jointAccountMembers);
return buildAccount(derivedActivationDetails);
}
Aggregations