use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class StandardAccountService method validatePayment.
@Override
public List<InvalidPaymentReason> validatePayment(AccountPaymentParametersDto payment) throws PersistenceException, AccountException {
List<InvalidPaymentReason> errors = new ArrayList<InvalidPaymentReason>();
AccountBO accountBo = this.legacyAccountDao.getAccount(payment.getAccountId());
Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(accountBo.getCustomer().getCustomerId());
boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (!accountBo.isTrxnDateValid(payment.getPaymentDate().toDateMidnight().toDate(), meetingDate, repaymentIndependentOfMeetingEnabled)) {
errors.add(InvalidPaymentReason.INVALID_DATE);
}
if (accountBo instanceof LoanBO) {
if (((LoanBO) accountBo).paymentsNotAllowed()) {
errors.add(InvalidPaymentReason.INVALID_LOAN_STATE);
}
}
if (accountBo instanceof SavingsBO) {
if (!accountBo.getState().equals(AccountState.SAVINGS_ACTIVE)) {
errors.add(InvalidPaymentReason.INVALID_LOAN_STATE);
}
}
if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.LOAN_ACCOUNT) {
if (!getLoanPaymentTypes().contains(payment.getPaymentType())) {
errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
}
} else if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.SAVINGS_ACCOUNT) {
if (!getSavingsPaymentTypes().contains(payment.getPaymentType())) {
errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
}
} else if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.CUSTOMER_ACCOUNT) {
if (!getFeePaymentTypes().contains(payment.getPaymentType())) {
errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
}
}
if (!accountBo.paymentAmountIsValid(new Money(accountBo.getCurrency(), payment.getPaymentAmount()), payment.getPaymentOptions())) {
errors.add(InvalidPaymentReason.INVALID_PAYMENT_AMOUNT);
}
return errors;
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CollectionSheetServiceImpl method saveCollectionSheet.
/**
* The method saves a collection sheet.
*
* @throws SaveCollectionSheetException
* */
@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) throws SaveCollectionSheetException {
Long totalTime;
Long totalTimeStart = System.currentTimeMillis();
Long readTime;
Long saveTime = null;
Long saveTimeStart;
Integer topCustomerId = saveCollectionSheet.getSaveCollectionSheetCustomers().get(0).getCustomerId();
CollectionSheetCustomerDto collectionSheetTopCustomer = new CustomerPersistence().findCustomerWithNoAssocationsLoaded(topCustomerId);
if (collectionSheetTopCustomer == null) {
List<InvalidSaveCollectionSheetReason> invalidSaveCollectionSheetReasons = new ArrayList<InvalidSaveCollectionSheetReason>();
List<String> invalidSaveCollectionSheetReasonsExtended = new ArrayList<String>();
invalidSaveCollectionSheetReasons.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER);
invalidSaveCollectionSheetReasonsExtended.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER.toString() + ": Customer Id: " + topCustomerId);
throw new SaveCollectionSheetException(invalidSaveCollectionSheetReasons, invalidSaveCollectionSheetReasonsExtended);
}
Short branchId = collectionSheetTopCustomer.getBranchId();
String searchId = collectionSheetTopCustomer.getSearchId();
// session caching: prefetch collection sheet data
// done prior to structure validation because it loads
// the customers and accounts to be validated into the session
SaveCollectionSheetSessionCache saveCollectionSheetSessionCache = new SaveCollectionSheetSessionCache();
saveCollectionSheetSessionCache.loadSessionCacheWithCollectionSheetData(saveCollectionSheet, branchId, searchId);
try {
new SaveCollectionSheetStructureValidator().execute(saveCollectionSheet);
} catch (SaveCollectionSheetException e) {
System.out.println(e.printInvalidSaveCollectionSheetReasons());
throw e;
}
/*
* With preprocessing complete...
*
* only errors and warnings from the business model remain
*/
final List<String> failedSavingsDepositAccountNums = new ArrayList<String>();
final List<String> failedSavingsWithdrawalNums = new ArrayList<String>();
final List<String> failedLoanDisbursementAccountNumbers = new ArrayList<String>();
final List<String> failedLoanRepaymentAccountNumbers = new ArrayList<String>();
final List<String> failedCustomerAccountPaymentNums = new ArrayList<String>();
final List<ClientAttendanceBO> clientAttendances = saveCollectionSheetAssembler.clientAttendanceAssemblerfromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), saveCollectionSheet.getTransactionDate(), branchId, searchId);
final AccountPaymentEntity payment = saveCollectionSheetAssembler.accountPaymentAssemblerFromDto(saveCollectionSheet.getTransactionDate(), saveCollectionSheet.getPaymentType(), saveCollectionSheet.getReceiptId(), saveCollectionSheet.getReceiptDate(), saveCollectionSheet.getUserId());
final List<SavingsBO> savingsAccounts = saveCollectionSheetAssembler.savingsAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedSavingsDepositAccountNums, failedSavingsWithdrawalNums);
Short paymentTypeId = (payment.getPaymentType() == null || payment.getPaymentType().getId() == null) ? null : payment.getPaymentType().getId();
final List<LoanBO> loanAccounts = saveCollectionSheetAssembler.loanAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, paymentTypeId);
final List<AccountBO> customerAccounts = saveCollectionSheetAssembler.customerAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedCustomerAccountPaymentNums);
boolean databaseErrorOccurred = false;
Throwable databaseError = null;
readTime = System.currentTimeMillis() - totalTimeStart;
try {
saveTimeStart = System.currentTimeMillis();
persistCollectionSheet(clientAttendances, loanAccounts, customerAccounts, savingsAccounts);
saveTime = System.currentTimeMillis() - saveTimeStart;
} catch (HibernateException e) {
logger.error("database error saving collection sheet", e);
databaseErrorOccurred = true;
databaseError = e;
}
totalTime = System.currentTimeMillis() - totalTimeStart;
printTiming(saveCollectionSheet.printSummary(), totalTime, saveTime, readTime, saveCollectionSheetSessionCache);
return new CollectionSheetErrorsDto(failedSavingsDepositAccountNums, failedSavingsWithdrawalNums, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, failedCustomerAccountPaymentNums, databaseErrorOccurred, databaseError);
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class SavingsDaoHibernate method findBySystemId.
@Override
public SavingsBO findBySystemId(String globalAccountNumber) {
logger.debug("In SavingsPersistence::findBySystemId(), globalAccountNumber: " + globalAccountNumber);
Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put(AccountConstants.GLOBAL_ACCOUNT_NUMBER, globalAccountNumber);
Object queryResult = baseDao.executeUniqueResultNamedQuery(NamedQueryConstants.FIND_ACCOUNT_BY_SYSTEM_ID, queryParameters);
SavingsBO savings = queryResult == null ? null : (SavingsBO) queryResult;
if (savings != null && savings.getRecommendedAmount() == null) {
savings.setRecommendedAmount(new Money(savings.getCurrency()));
Hibernate.initialize(savings.getAccountActionDates());
Hibernate.initialize(savings.getAccountNotes());
Hibernate.initialize(savings.getAccountFlags());
}
return savings;
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CustomerDaoHibernate method getSavingsDetailDto.
@SuppressWarnings("unchecked")
@Override
public List<SavingsDetailDto> getSavingsDetailDto(Integer customerId, UserContext userContext) {
Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put("CUSTOMER_ID", customerId);
List<Object[]> queryResult = (List<Object[]>) this.genericDao.executeNamedQuery("Customer.getSavingsDetailDto", queryParameters);
if (queryResult.size() == 0) {
return null;
}
List<SavingsDetailDto> savingsDetails = new ArrayList<SavingsDetailDto>();
String globalAccountNum;
String prdOfferingName;
Short accountStateId;
String accountStateName;
Money savingsBalance;
String lookupName;
Short currency;
BigDecimal maxWithdrawalAmount;
String savingsType = "";
MifosCurrency mifosCurrency = Money.getDefaultCurrency();
for (Object[] savingsDetail : queryResult) {
globalAccountNum = (String) savingsDetail[0];
prdOfferingName = (String) savingsDetail[1];
accountStateId = (Short) savingsDetail[2];
lookupName = (String) savingsDetail[3];
accountStateName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupName);
// TODO - use default currency or retrieved currency?
currency = (Short) savingsDetail[4];
savingsBalance = new Money(mifosCurrency, (BigDecimal) savingsDetail[5]);
try {
SavingsBO savingsBO = (SavingsBO) new AccountBusinessService().findBySystemId(globalAccountNum);
maxWithdrawalAmount = savingsBO.getSavingsOffering().getMaxAmntWithdrawl().getAmount();
if (savingsBO.getSavingsOffering().getSavingsType().getLookUpValue() != null) {
savingsType = savingsBO.getSavingsOffering().getSavingsType().getName();
}
savingsDetails.add(new SavingsDetailDto(globalAccountNum, prdOfferingName, accountStateId, accountStateName, savingsBalance.toString(), maxWithdrawalAmount, savingsType));
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
}
return savingsDetails;
}
use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.
the class CustomerServiceImpl method createSavingsAccountsForActiveSavingProducts.
private void createSavingsAccountsForActiveSavingProducts(ClientBO client, List<SavingsOfferingBO> savingProducts) {
UserContext userContext = client.getUserContext();
List<SavingsBO> savingsAccounts = new ArrayList<SavingsBO>();
for (SavingsOfferingBO clientSavingsProduct : savingProducts) {
try {
if (clientSavingsProduct.isActive()) {
List<CustomFieldDto> savingCustomFieldViews = new ArrayList<CustomFieldDto>();
SavingsBO savingsAccount = new SavingsBO(userContext, clientSavingsProduct, client, AccountState.SAVINGS_ACTIVE, clientSavingsProduct.getRecommendedAmount(), savingCustomFieldViews);
savingsAccounts.add(savingsAccount);
}
} catch (AccountException pe) {
throw new MifosRuntimeException(pe);
}
}
client.addSavingsAccounts(savingsAccounts);
}
Aggregations