use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class StandardAccountService method makeImportedPayments.
/**
* method created for undo transaction import ability MIFOS-5702
* returns Id of transaction
* */
public AccountBO makeImportedPayments(AccountPaymentParametersDto accountPaymentParametersDto, Integer savingsPaymentId) throws PersistenceException, AccountException {
final int accountId = accountPaymentParametersDto.getAccountId();
final AccountBO account = this.legacyAccountDao.getAccount(accountId);
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
try {
personnelDao.checkAccessPermission(userContext, account.getOfficeId(), account.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED, e);
}
monthClosingServiceFacade.validateTransactionDate(accountPaymentParametersDto.getPaymentDate().toDateMidnight().toDate());
/**
* Handle member payment if parent payment data not provided.
* Situation may occur when payment is executed directly on group member account (e.g. from transaction import).
* Loan Group Member payments should be posted after parent payment.
*/
if (account.isGroupLoanAccountMember()) {
AccountPaymentParametersDto parentPaymentParametersDto = this.createParentLoanPaymentData(account, accountPaymentParametersDto);
return makeImportedPayments(parentPaymentParametersDto, savingsPaymentId);
}
PersonnelBO loggedInUser = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).findPersonnelById(accountPaymentParametersDto.getUserMakingPayment().getUserId());
List<InvalidPaymentReason> validationErrors = validatePayment(accountPaymentParametersDto);
if (!(account instanceof CustomerAccountBO) && validationErrors.contains(InvalidPaymentReason.INVALID_DATE)) {
throw new AccountException("errors.invalidTxndate");
}
Money overpaymentAmount = null;
Money amount = new Money(account.getCurrency(), accountPaymentParametersDto.getPaymentAmount());
if (account instanceof LoanBO && accountPaymentParametersDto.getPaymentOptions().contains(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS) && amount.isGreaterThan(((LoanBO) account).getTotalRepayableAmount())) {
overpaymentAmount = amount.subtract(((LoanBO) account).getTotalRepayableAmount());
amount = ((LoanBO) account).getTotalRepayableAmount();
}
Date receiptDate = null;
if (accountPaymentParametersDto.getReceiptDate() != null) {
receiptDate = accountPaymentParametersDto.getReceiptDate().toDateMidnight().toDate();
}
PaymentData paymentData = account.createPaymentData(amount, accountPaymentParametersDto.getPaymentDate().toDateMidnight().toDate(), accountPaymentParametersDto.getReceiptId(), receiptDate, accountPaymentParametersDto.getPaymentType().getValue(), loggedInUser);
if (savingsPaymentId != null) {
AccountPaymentEntity withdrawal = legacyAccountDao.findPaymentById(savingsPaymentId);
paymentData.setOtherTransferPayment(withdrawal);
}
if (accountPaymentParametersDto.getCustomer() != null) {
paymentData.setCustomer(customerDao.findCustomerById(accountPaymentParametersDto.getCustomer().getCustomerId()));
}
paymentData.setComment(accountPaymentParametersDto.getComment());
paymentData.setOverpaymentAmount(overpaymentAmount);
if (accountPaymentParametersDto.getPaymentOptions().contains(PaymentOptions.ALLOW_OVERPAYMENTS)) {
paymentData.setAllowOverpayment(true);
}
AccountPaymentEntity paymentEntity = account.applyPayment(paymentData);
handleParentGroupLoanPayment(account, accountPaymentParametersDto, savingsPaymentId, paymentEntity);
this.legacyAccountDao.createOrUpdate(account);
/*
* Return null when only overpayment is being apply
*/
if (amount.isZero() && overpaymentAmount != null && overpaymentAmount.isGreaterThanZero()) {
return null;
}
return account;
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class BaseFinancialActivity method getMiscPenaltyAmount.
public Money getMiscPenaltyAmount() {
AccountBO account = getAccountTrxn().getAccount();
Money amount = new Money(account.getCurrency());
if (account.getType() == AccountTypes.LOAN_ACCOUNT) {
amount = ((LoanTrxnDetailEntity) getAccountTrxn()).getMiscPenaltyAmount();
} else if (account.getType() == AccountTypes.CUSTOMER_ACCOUNT) {
amount = ((CustomerTrxnDetailEntity) getAccountTrxn()).getMiscPenaltyAmount();
}
return amount;
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class GroupServiceFacadeWebTier method convertFeeViewsToAccountFeeEntities.
private List<AccountFeesEntity> convertFeeViewsToAccountFeeEntities(List<ApplicableAccountFeeDto> feesToApply) {
List<AccountFeesEntity> feesForCustomerAccount = new ArrayList<AccountFeesEntity>();
for (ApplicableAccountFeeDto feeDto : feesToApply) {
FeeBO fee = feeDao.findById(feeDto.getFeeId().shortValue());
Double feeAmount = new LocalizationConverter().getDoubleValueForCurrentLocale(feeDto.getAmount());
AccountBO nullReferenceForNow = null;
AccountFeesEntity accountFee = new AccountFeesEntity(nullReferenceForNow, fee, feeAmount);
feesForCustomerAccount.add(accountFee);
}
return feesForCustomerAccount;
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class GroupServiceFacadeWebTier method getGroupInformationDto.
// private void checkPermissionForCreate(Short newState, UserContext userContext, Short recordOfficeId,
// Short recordLoanOfficerId) throws ApplicationException {
// if (!isPermissionAllowed(newState, userContext, recordOfficeId, recordLoanOfficerId)) {
// logger.info("permission not allowed: " + userContext.toString() + " officeId: " + recordLoanOfficerId + " loanOfficerId: " + recordLoanOfficerId);
// throw new AccountException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
// }
// }
// private boolean isPermissionAllowed(Short newState, UserContext userContext, Short recordOfficeId,
// Short recordLoanOfficerId) {
// return ActivityMapper.getInstance().isSavePermittedForCustomer(newState.shortValue(), userContext,
// recordOfficeId, recordLoanOfficerId);
// }
@Override
public GroupInformationDto getGroupInformationDto(String globalCustNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
GroupBO group = this.customerDao.findGroupBySystemId(globalCustNum);
if (group == null) {
throw new MifosRuntimeException("Group not found for globalCustNum: " + globalCustNum);
}
try {
personnelDao.checkAccessPermission(userContext, group.getOfficeId(), group.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
GroupDisplayDto groupDisplay = this.customerDao.getGroupDisplayDto(group.getCustomerId(), userContext);
Integer groupId = group.getCustomerId();
String searchId = group.getSearchId();
Short branchId = groupDisplay.getBranchId();
CustomerAccountSummaryDto customerAccountSummary = this.customerDao.getCustomerAccountSummaryDto(groupId);
GroupPerformanceHistoryDto groupPerformanceHistory = assembleGroupPerformanceHistoryDto(group.getGroupPerformanceHistory(), searchId, branchId, groupId);
CustomerAddressDto groupAddress = this.customerDao.getCustomerAddressDto(group);
List<CustomerDetailDto> clients = this.customerDao.findClientsThatAreNotCancelledOrClosedReturningDetailDto(searchId, branchId);
List<CustomerNoteDto> recentCustomerNotes = this.customerDao.getRecentCustomerNoteDto(groupId);
List<CustomerPositionOtherDto> customerPositions = this.customerDao.getCustomerPositionDto(groupId, userContext);
List<CustomerFlagDto> customerFlags = this.customerDao.getCustomerFlagDto(group.getCustomerFlags());
List<LoanDetailDto> loanDetail = this.customerDao.getLoanDetailDto(group.getOpenLoanAccountsAndGroupLoans());
List<SavingsDetailDto> savingsDetail = this.customerDao.getSavingsDetailDto(groupId, userContext);
CustomerMeetingDto customerMeeting = this.customerDao.getCustomerMeetingDto(group.getCustomerMeeting(), userContext);
List<AccountBO> allClosedLoanAndSavingsAccounts = customerDao.retrieveAllClosedLoanAndSavingsAccounts(groupId);
List<LoanDetailDto> closedLoanAccounts = new ArrayList<LoanDetailDto>();
List<SavingsDetailDto> closedSavingsAccounts = new ArrayList<SavingsDetailDto>();
for (AccountBO closedAccount : allClosedLoanAndSavingsAccounts) {
if (closedAccount.getAccountType().getAccountTypeId() == AccountTypes.LOAN_ACCOUNT.getValue().intValue()) {
closedLoanAccounts.add(new LoanDetailDto(closedAccount.getGlobalAccountNum(), ((LoanBO) closedAccount).getLoanOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((LoanBO) closedAccount).getLoanSummary().getOutstandingBalance().toString(), closedAccount.getTotalAmountDue().toString(), closedAccount.getTotalAmountInArrears().toString()));
} else {
closedSavingsAccounts.add(new SavingsDetailDto(closedAccount.getGlobalAccountNum(), ((SavingsBO) closedAccount).getSavingsOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((SavingsBO) closedAccount).getSavingsBalance().toString()));
}
}
boolean activeSurveys = false;
// boolean activeSurveys = new SurveysPersistence().isActiveSurveysForSurveyType(SurveyType.GROUP);
List<SurveyDto> customerSurveys = new ArrayList<SurveyDto>();
List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
return new GroupInformationDto(groupDisplay, customerAccountSummary, groupPerformanceHistory, groupAddress, clients, recentCustomerNotes, customerPositions, customerFlags, loanDetail, savingsDetail, customerMeeting, activeSurveys, customerSurveys, customFields, closedLoanAccounts, closedSavingsAccounts);
}
use of org.mifos.accounts.business.AccountBO 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);
}
Aggregations