use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.
the class StandardAccountService method makePaymentNoCommit.
public void makePaymentNoCommit(AccountPaymentParametersDto accountPaymentParametersDto, Integer savingsPaymentId, AccountPaymentEntity parentPayment) 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() && parentPayment == null) {
AccountPaymentParametersDto parentPaymentParametersDto = this.createParentLoanPaymentData(account, accountPaymentParametersDto);
makePaymentNoCommit(parentPaymentParametersDto, savingsPaymentId, null);
return;
}
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 (account instanceof LoanBO && account.isGroupLoanAccountMember() && parentPayment != null) {
paymentData.setParentPayment(parentPayment);
}
AccountPaymentEntity paymentEntity = account.applyPayment(paymentData);
handleParentGroupLoanPayment(account, accountPaymentParametersDto, savingsPaymentId, paymentEntity);
this.legacyAccountDao.createOrUpdate(account);
}
use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.
the class StandardAccountService method disburseLoans.
@Override
public void disburseLoans(List<AccountPaymentParametersDto> accountPaymentParametersDtoList, Locale locale, Short paymentTypeIdForFees, Integer accountForTransferId) throws Exception {
StaticHibernateUtil.startTransaction();
for (AccountPaymentParametersDto accountPaymentParametersDto : accountPaymentParametersDtoList) {
LoanBO loan = this.legacyLoanDao.getAccount(accountPaymentParametersDto.getAccountId());
PersonnelBO personnelBO = personnelDao.findPersonnelById(accountPaymentParametersDto.getUserMakingPayment().getUserId());
BigDecimal paymentAmount = accountPaymentParametersDto.getPaymentAmount();
handleLoanDisbursal(locale, loan, personnelBO, paymentAmount, accountPaymentParametersDto.getPaymentType(), accountPaymentParametersDto.getReceiptDate(), accountPaymentParametersDto.getPaymentDate(), accountPaymentParametersDto.getReceiptId(), paymentTypeIdForFees, accountForTransferId);
}
StaticHibernateUtil.commitTransaction();
}
use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.
the class StandardAccountService method makePaymentsForImport.
/**
* method created for undo transaction import ability MIFOS-5702
* changed return type
* */
@Override
public List<AccountTrxDto> makePaymentsForImport(List<AccountPaymentParametersDto> accountPaymentParametersDtoList) throws PersistenceException, AccountException {
/*
* We're counting on rollback on exception behavior in BaseAction. If we want to expose makePayments via a
* non-Mifos-Web-UI service, we'll need to handle the rollback here.
*/
List<AccountTrxDto> trxIds = new ArrayList<AccountTrxDto>();
List<AccountBO> accounts = new ArrayList<AccountBO>();
StaticHibernateUtil.startTransaction();
int i = 0;
for (AccountPaymentParametersDto accountPaymentParametersDTO : accountPaymentParametersDtoList) {
CollectionUtils.addIgnoreNull(accounts, makeImportedPayments(accountPaymentParametersDTO));
if (i % 30 == 0) {
StaticHibernateUtil.getSessionTL().flush();
StaticHibernateUtil.getSessionTL().clear();
}
i++;
}
StaticHibernateUtil.getSessionTL().flush();
StaticHibernateUtil.getSessionTL().clear();
StaticHibernateUtil.commitTransaction();
for (AccountBO account : accounts) {
trxIds.add(new AccountTrxDto(getAccTrxId(account)));
}
return trxIds;
}
use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.
the class LoanAccountServiceFacadeWebTier method disburseLoan.
@Override
public void disburseLoan(AccountPaymentParametersDto loanDisbursement, Short paymentTypeId, Short paymentTypeIdForFees, Integer accountForTransferId) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loan = this.loanDao.findById(loanDisbursement.getAccountId());
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
PaymentTypeDto paymentType = null;
try {
for (org.mifos.dto.domain.PaymentTypeDto paymentTypeDto : accountService.getLoanDisbursementTypes()) {
if (paymentTypeDto.getValue() == paymentTypeId) {
paymentType = paymentTypeDto;
}
}
} catch (Exception e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
if (paymentType == null) {
throw new MifosRuntimeException("Expected loan PaymentTypeDto not found for id: " + paymentTypeId);
}
loanDisbursement.setPaymentType(paymentType);
Date trxnDate = DateUtils.getDateWithoutTimeStamp(loanDisbursement.getPaymentDate().toDateMidnight().toDate());
monthClosingServiceFacade.validateTransactionDate(trxnDate);
if (!isTrxnDateValid(Integer.valueOf(loanDisbursement.getAccountId()), trxnDate)) {
throw new BusinessRuleException("errors.invalidTxndate");
}
DateTime loanDisbursementDate = new DateTime(trxnDate);
holidayServiceFacade.validateDisbursementDateForNewLoan(loan.getOfficeId(), loanDisbursementDate);
if (loan.isFixedRepaymentSchedule()) {
for (AccountActionDateEntity installment : loan.getAccountActionDates()) {
if (installment.compareDate(trxnDate) <= 0) {
throw new BusinessRuleException("errors.invalidTxndateWhenDisbursalAfterFirstRepayment");
}
}
}
List<AccountPaymentParametersDto> loanDisbursements = new ArrayList<AccountPaymentParametersDto>();
loanDisbursements.add(loanDisbursement);
try {
accountService.disburseLoans(loanDisbursements, userContext.getPreferredLocale(), paymentTypeIdForFees, accountForTransferId);
} catch (Exception e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
}
use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.
the class StandardAccountServiceIntegrationTest method testMakePaymentComment.
@Test
public void testMakePaymentComment() throws Exception {
String paymentAmount = "700";
String comment = "test comment";
AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(new UserReferenceDto(groupLoan.getPersonnel().getPersonnelId()), new AccountReferenceDto(groupLoan.getAccountId()), new BigDecimal(paymentAmount), new LocalDate(), defaultPaymentType, comment);
standardAccountService.makePayment(accountPaymentParametersDto);
TestObjectFactory.updateObject(groupLoan);
Assert.assertEquals("We should get the comment back", comment, groupLoan.findMostRecentPaymentByPaymentDate().getComment());
}
Aggregations