use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.
the class SavingsAdjustmentTest method accountBalanceIsUpdatedWhenLastDepositIsAdjusted.
@Test
public void accountBalanceIsUpdatedWhenLastDepositIsAdjusted() {
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(TestUtils.createMoney("0")).withDepositOf("15").build();
Money amountAdjustedTo = TestUtils.createMoney("25");
String adjustmentNote = "testAdjustment";
PersonnelBO updatedBy = new PersonnelBuilder().build();
// pre verification
assertThat(savingsAccount.getSavingsBalance(), is(TestUtils.createMoney(15)));
// exercise test
savingsAccount.adjustLastUserAction(amountAdjustedTo, adjustmentNote, updatedBy);
// verification
assertThat(savingsAccount.getSavingsBalance(), is(TestUtils.createMoney(25)));
}
use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.
the class SavingsAdjustmentTest method accountBalanceIsUpdatedWhenLastWithdrawalIsAdjusted.
@Test
public void accountBalanceIsUpdatedWhenLastWithdrawalIsAdjusted() {
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(TestUtils.createMoney("100")).withWithdrawalOf("15").build();
Money amountAdjustedTo = TestUtils.createMoney("25");
String adjustmentNote = "testAdjustment";
PersonnelBO updatedBy = new PersonnelBuilder().build();
// pre verification
assertThat(savingsAccount.getSavingsBalance(), is(TestUtils.createMoney(85)));
// exercise test
savingsAccount.adjustLastUserAction(amountAdjustedTo, adjustmentNote, updatedBy);
// verification
assertThat(savingsAccount.getSavingsBalance(), is(TestUtils.createMoney(75)));
}
use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.
the class SavingsAdjustmentTest method savingsPerformanceDetailsAreUpdatedWhenLastDepositIsAdjusted.
@Test
public void savingsPerformanceDetailsAreUpdatedWhenLastDepositIsAdjusted() {
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(TestUtils.createMoney("0")).withDepositOf("15").build();
Money amountAdjustedTo = TestUtils.createMoney("25");
String adjustmentNote = "testAdjustment";
PersonnelBO updatedBy = new PersonnelBuilder().build();
// pre verification
assertThat(savingsAccount.getSavingsPerformance().getTotalDeposits(), is(TestUtils.createMoney(15)));
// exercise test
savingsAccount.adjustLastUserAction(amountAdjustedTo, adjustmentNote, updatedBy);
// verification
assertThat(savingsAccount.getSavingsPerformance().getTotalDeposits(), is(TestUtils.createMoney(25)));
}
use of org.mifos.customers.personnel.business.PersonnelBO 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.customers.personnel.business.PersonnelBO 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();
}
Aggregations