use of org.mifos.core.MifosRuntimeException 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.core.MifosRuntimeException in project head by mifos.
the class CollectionSheetServiceImplIntegrationTest method testAccountCollectionFeeUnderPaymentIsIdentified.
@Test
public void testAccountCollectionFeeUnderPaymentIsIdentified() throws Exception {
saveCollectionSheetUtils.setUnderpayFirstClientAccountCollectionFee();
SaveCollectionSheetDto saveCollectionSheet = saveCollectionSheetUtils.createSampleSaveCollectionSheet();
CollectionSheetErrorsDto errors = null;
try {
errors = collectionSheetService.saveCollectionSheet(saveCollectionSheet);
} catch (SaveCollectionSheetException e) {
throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
}
if (errors != null && errors.getCustomerAccountNumbers() != null) {
Assert.assertThat("There should have been one customer account error", errors.getCustomerAccountNumbers().size(), is(1));
} else {
Assert.assertTrue("There should have been one customer account error", false);
}
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class CollectionSheetServiceImplIntegrationTest method testAccountCollectionFeeOverPaymentIsIdentified.
@Test
public void testAccountCollectionFeeOverPaymentIsIdentified() throws Exception {
saveCollectionSheetUtils.setOverpayFirstClientAccountCollectionFee();
SaveCollectionSheetDto saveCollectionSheet = saveCollectionSheetUtils.createSampleSaveCollectionSheet();
CollectionSheetErrorsDto errors = null;
try {
errors = collectionSheetService.saveCollectionSheet(saveCollectionSheet);
} catch (SaveCollectionSheetException e) {
throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
}
if (errors != null && errors.getCustomerAccountNumbers() != null) {
Assert.assertThat("There should have been one customer account error", errors.getCustomerAccountNumbers().size(), is(1));
} else {
Assert.assertTrue("There should have been one customer account error", false);
}
}
use of org.mifos.core.MifosRuntimeException 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.core.MifosRuntimeException in project head by mifos.
the class CollectionSheetRESTController method saveCollectionSheet.
@RequestMapping(value = "/collectionsheet/save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> saveCollectionSheet(@RequestBody JSONSaveCollectionsheet request) throws Throwable {
Map<String, Object> map = new HashMap<String, Object>();
ObjectMapper om = createObjectMapper();
List<InvalidSaveCollectionSheetReason> reasons = new ArrayList<InvalidSaveCollectionSheetReason>();
CollectionSheetErrorsDto errors = null;
SaveCollectionSheetDto saveCollectionSheetDto = null;
try {
saveCollectionSheetDto = om.readValue(request.getJson(), SaveCollectionSheetDto.class);
} catch (JsonMappingException e) {
if (e.getCause() instanceof SaveCollectionSheetException) {
reasons.addAll(((SaveCollectionSheetException) e.getCause()).getInvalidSaveCollectionSheetReasons());
} else {
throw e.getCause();
}
}
if (saveCollectionSheetDto != null) {
try {
errors = collectionSheetServiceFacade.saveCollectionSheet(saveCollectionSheetDto);
map.put("errors", errors != null ? errors.getErrorText() : null);
} catch (MifosRuntimeException e) {
map.put("errors", e.getMessage());
}
}
map.put("invalidCollectionSheet", reasons);
return map;
}
Aggregations