use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class ClientBO method createDepositSchedule.
/**
* delete when usage in constructor is removed...
*/
@Deprecated
public void createDepositSchedule(final List<Days> workingDays, final List<Holiday> holidays) throws CustomerException {
try {
if (getParentCustomer() != null) {
List<SavingsBO> savingsList = getCustomerPersistence().retrieveSavingsAccountForCustomer(getParentCustomer().getCustomerId());
if (getParentCustomer().getParentCustomer() != null) {
savingsList.addAll(getCustomerPersistence().retrieveSavingsAccountForCustomer(getParentCustomer().getParentCustomer().getCustomerId()));
}
for (SavingsBO savings : savingsList) {
savings.setUserContext(getUserContext());
savings.generateAndUpdateDepositActionsForClient(this, workingDays, holidays);
}
}
} catch (PersistenceException pe) {
throw new CustomerException(pe);
} catch (AccountException ae) {
throw new CustomerException(ae);
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CustomerServiceImpl method createCustomer.
private void createCustomer(CustomerBO customer, MeetingBO meeting, List<AccountFeesEntity> accountFees) {
try {
this.hibernateTransactionHelper.startTransaction();
this.customerDao.save(customer);
this.hibernateTransactionHelper.flushSession();
// must first be saved via the customer save.
for (AccountBO account : customer.getAccounts()) {
if (account.isSavingsAccount()) {
SavingsBO savingsAccount = (SavingsBO) account;
savingsAccount.setUserContext(customer.getUserContext());
savingsAccount.generateSystemId(customer.getOffice().getGlobalOfficeNum());
}
}
this.customerDao.save(customer);
this.hibernateTransactionHelper.flushSession();
CalendarEvent applicableCalendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
CustomerAccountBO customerAccount = this.customerAccountFactory.create(customer, accountFees, meeting, applicableCalendarEvents);
customer.addAccount(customerAccount);
this.customerDao.save(customer);
this.hibernateTransactionHelper.flushSession();
if (customer.getParentCustomer() != null) {
this.customerDao.save(customer.getParentCustomer());
}
customer.generateGlobalCustomerNumber();
customer.generateSearchId();
this.customerDao.save(customer);
if (customer.getParentCustomer() != null) {
this.customerDao.save(customer.getParentCustomer());
}
this.hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CustomerServiceImpl method changeStatus.
private void changeStatus(CustomerBO customer, CustomerStatus oldStatus, CustomerStatus newStatus) throws CustomerException {
Short oldStatusId = oldStatus.getValue();
Short newStatusId = newStatus.getValue();
if (customer.isClient()) {
ClientBO client = (ClientBO) customer;
if (client.isActiveForFirstTime(oldStatusId, newStatusId)) {
if (client.getParentCustomer() != null) {
CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
client.addCustomerHierarchy(hierarchy);
}
CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customer.getCustomerAccount().getAccountFees());
client.getCustomerAccount().createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(customer, accountFees, customer.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
client.setCustomerActivationDate(new DateTimeService().getCurrentJavaDateTime());
if (client.getOfferingsAssociatedInCreate() != null) {
for (ClientInitialSavingsOfferingEntity clientOffering : client.getOfferingsAssociatedInCreate()) {
try {
SavingsOfferingBO savingsOffering = savingsProductDao.findById(clientOffering.getSavingsOffering().getPrdOfferingId().intValue());
if (savingsOffering.isActive()) {
List<CustomFieldDto> customerFieldsForSavings = new ArrayList<CustomFieldDto>();
client.addAccount(new SavingsBO(client.getUserContext(), savingsOffering, client, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), customerFieldsForSavings));
}
} catch (AccountException pe) {
throw new CustomerException(pe);
}
}
}
new SavingsPersistence().persistSavingAccounts(client);
try {
if (client.getParentCustomer() != null) {
List<SavingsBO> savingsList = new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getCustomerId());
if (client.getParentCustomer().getParentCustomer() != null) {
savingsList.addAll(new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getParentCustomer().getCustomerId()));
}
for (SavingsBO savings : savingsList) {
savings.setUserContext(client.getUserContext());
if (client.getCustomerMeeting().getMeeting() != null) {
if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
DateTime today = new DateTime().toDateMidnight().toDateTime();
savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), applicableCalendarEvents.getWorkingDays(), applicableCalendarEvents.getHolidays(), today);
savings.update();
}
}
}
}
} catch (PersistenceException pe) {
throw new CustomerException(pe);
} catch (AccountException ae) {
throw new CustomerException(ae);
}
}
}
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CustomerBO method getSavingsBalance.
public Money getSavingsBalance(MifosCurrency currency) {
Money amount = new Money(currency);
for (AccountBO account : getAccounts()) {
if (account.getType() == AccountTypes.SAVINGS_ACCOUNT) {
SavingsBO savingsBO = (SavingsBO) account;
amount = amount.add(savingsBO.getSavingsBalance());
}
}
return amount;
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class EditStatusAction method load.
@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
EditStatusActionForm actionForm = (EditStatusActionForm) form;
actionForm.setSelectedItems(null);
actionForm.setNotes(null);
actionForm.setNewStatusId(null);
actionForm.setFlagId(null);
actionForm.setQuestionGroups(null);
actionForm.setTransactionDate(DateUtils.makeDateAsSentFromBrowser());
actionForm.setAllowBackDatedApprovals(AccountingRules.isBackDatedApprovalAllowed());
request.getSession().removeAttribute(Constants.BUSINESS_KEY);
UserContext userContext = getUserContext(request);
Integer accountId = Integer.valueOf(actionForm.getAccountId());
AccountBO accountBO = new AccountBusinessService().getAccount(accountId);
java.util.Date lastPaymentDate = new java.util.Date(0);
AccountPaymentEntity lastPayment = accountBO.findMostRecentNonzeroPaymentByPaymentDate();
if (lastPayment != null) {
lastPaymentDate = lastPayment.getPaymentDate();
}
actionForm.setLastPaymentDate(lastPaymentDate);
if (accountBO.isLoanAccount() || accountBO.isGroupLoanAccount()) {
// NOTE - not using dto values at present but available when ui is refactored away from jsp
AccountStatusDto accountStatuses = this.loanAccountServiceFacade.retrieveAccountStatuses(accountId.longValue());
LoanBO loanAccount = this.loanDao.findById(accountId);
EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
editStatusActionForm.setAccountTypeId(AccountTypes.LOAN_ACCOUNT.getValue().toString());
editStatusActionForm.setCurrentStatusId(loanAccount.getAccountState().getId().toString());
editStatusActionForm.setGlobalAccountNum(loanAccount.getGlobalAccountNum());
editStatusActionForm.setAccountName(loanAccount.getLoanOffering().getPrdOfferingName());
if (loanAccount.isGroupLoanAccount() && loanAccount.getParentAccount() == null) {
editStatusActionForm.setInput("grouploan");
} else {
editStatusActionForm.setInput("loan");
}
if (loanAccount.getAccountState().getId().equals(Short.valueOf("2"))) {
List<AdminDocumentBO> allAdminDocuments = legacyAdminDocumentDao.getAllActiveAdminDocuments();
List<AdminDocumentBO> loanAdminDocuments = new ArrayList();
for (AdminDocumentBO adminDocumentBO : allAdminDocuments) {
List<AdminDocAccStateMixBO> admindoclist = legacyAdminDocAccStateMixDao.getMixByAdminDocuments(adminDocumentBO.getAdmindocId());
if (!loanAdminDocuments.contains(adminDocumentBO) && admindoclist.size() > 0 && admindoclist.get(0).getAccountStateID().getPrdType().getProductTypeID().equals(loanAccount.getType().getValue().shortValue())) {
for (AdminDocAccStateMixBO admindoc : admindoclist) {
if (admindoc.getAccountStateID().getId().shortValue() == loanAccount.getAccountState().getId().shortValue()) {
loanAdminDocuments.add(adminDocumentBO);
}
}
}
}
SessionUtils.setCollectionAttribute("editAccountStatusDocumentsList", loanAdminDocuments, request);
} else {
SessionUtils.setCollectionAttribute("editAccountStatusDocumentsList", null, request);
}
}
if (accountBO.isSavingsAccount()) {
// NOTE - not using dto values at present but available when ui is refactored away from jsp
AccountStatusDto accountStatuses = this.savingsServiceFacade.retrieveAccountStatuses(accountId.longValue());
SavingsBO savingsAccount = this.savingsDao.findById(accountId.longValue());
EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
editStatusActionForm.setAccountTypeId(AccountTypes.SAVINGS_ACCOUNT.getValue().toString());
editStatusActionForm.setCurrentStatusId(savingsAccount.getAccountState().getId().toString());
editStatusActionForm.setGlobalAccountNum(savingsAccount.getGlobalAccountNum());
editStatusActionForm.setAccountName(savingsAccount.getSavingsOffering().getPrdOfferingName());
editStatusActionForm.setInput("savings");
}
List<AccountStateEntity> accountStatuses = new AccountBusinessService().getStatusList(accountBO.getAccountState(), accountBO.getType(), userContext.getLocaleId());
for (AccountStateEntity customerStatusEntity : accountStatuses) {
for (AccountStateFlagEntity flag : customerStatusEntity.getFlagSet()) {
String statusMessageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(flag.getLookUpValue().getPropertiesKey());
flag.setStatusFlagMessageText(statusMessageText);
}
}
SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
SessionUtils.setCollectionAttribute(SavingsConstants.STATUS_LIST, accountStatuses, request);
return mapping.findForward(ActionForwards.load_success.toString());
}
Aggregations