use of org.mifos.accounts.business.AccountBO 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.accounts.business.AccountBO 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.accounts.business.AccountBO in project head by mifos.
the class ClientIntegrationTest method testGenerateScheduleForClient_OnClientCreate.
@Test
public void testGenerateScheduleForClient_OnClientCreate() throws Exception {
SavingsOfferingBO savingsOffering = TestObjectFactory.createSavingsProduct("Offering1", "s1", SavingsType.MANDATORY, ApplicableTo.GROUPS, new Date(System.currentTimeMillis()));
createParentObjects(CustomerStatus.GROUP_ACTIVE);
accountBO = TestObjectFactory.createSavingsAccount("globalNum", center, AccountState.SAVINGS_ACTIVE, new java.util.Date(), savingsOffering, TestObjectFactory.getContext());
Assert.assertEquals(0, accountBO.getAccountActionDates().size());
client = createClient(CustomerStatus.CLIENT_ACTIVE);
StaticHibernateUtil.flushSession();
accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
Assert.assertEquals(1, accountBO.getAccountCustomFields().size());
Assert.assertEquals(10, accountBO.getAccountActionDates().size());
for (AccountActionDateEntity actionDate : accountBO.getAccountActionDates()) {
Assert.assertEquals(client.getCustomerId(), actionDate.getCustomer().getCustomerId());
Assert.assertTrue(true);
}
client = TestObjectFactory.getClient(client.getCustomerId());
group = TestObjectFactory.getGroup(group.getCustomerId());
center = TestObjectFactory.getCenter(center.getCustomerId());
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class ClientIntegrationTest method testSuccessfulCreateInActiveState_WithAssociatedSavingsOffering.
@Test
public void testSuccessfulCreateInActiveState_WithAssociatedSavingsOffering() throws Exception {
savingsOffering1 = TestObjectFactory.createSavingsProduct("offering1", "s1", SavingsType.MANDATORY, ApplicableTo.CLIENTS, new Date(System.currentTimeMillis()));
StaticHibernateUtil.flushSession();
List<SavingsOfferingBO> selectedOfferings = new ArrayList<SavingsOfferingBO>();
selectedOfferings.add(savingsOffering1);
String name = "Client 1";
Short povertyStatus = Short.valueOf("41");
ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), TestObjectFactory.SAMPLE_SALUTATION, "Client", "", "1", "");
clientNameDetailDto.setNames(ClientRules.getNameSequence());
ClientNameDetailDto spouseNameDetailView = new ClientNameDetailDto(NameType.SPOUSE.getValue(), TestObjectFactory.SAMPLE_SALUTATION, "first", "middle", "last", "secondLast");
spouseNameDetailView.setNames(ClientRules.getNameSequence());
ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(1, 1, 1, 1, 1, 1, Short.valueOf("1"), Short.valueOf("1"), povertyStatus);
client = new ClientBO(TestUtils.makeUser(), clientNameDetailDto.getDisplayName(), CustomerStatus.CLIENT_ACTIVE, null, null, null, null, null, selectedOfferings, personnel, new OfficePersistence().getOffice(TestObjectFactory.SAMPLE_BRANCH_OFFICE), getMeeting(), personnel, null, null, null, null, YesNoFlag.NO.getValue(), clientNameDetailDto, spouseNameDetailView, clientPersonalDetailDto, null);
legacyClientDao.saveClient(client);
StaticHibernateUtil.flushSession();
client = TestObjectFactory.getClient(client.getCustomerId());
Assert.assertEquals(name, client.getDisplayName());
Assert.assertEquals(1, client.getOfferingsAssociatedInCreate().size());
Assert.assertEquals(2, client.getAccounts().size());
for (AccountBO account : client.getAccounts()) {
if (account instanceof SavingsBO) {
Assert.assertEquals(savingsOffering1.getPrdOfferingId(), ((SavingsBO) account).getSavingsOffering().getPrdOfferingId());
Assert.assertNotNull(account.getGlobalAccountNum());
Assert.assertTrue(true);
}
}
StaticHibernateUtil.flushSession();
client = TestObjectFactory.getClient(client.getCustomerId());
savingsOffering1 = null;
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class CustomerActionStrutsTest method ignore_testForwardWaiveChargeDue.
public void ignore_testForwardWaiveChargeDue() {
createInitialObjects();
setRequestPathInfo("/customerAction.do");
addRequestParameter("method", "waiveChargeDue");
addRequestParameter("type", "Client");
AccountBO accountBO = client.getCustomerAccount();
addRequestParameter("accountId", accountBO.getAccountId().toString());
getRequest().getSession().setAttribute("security_param", "Client");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
verifyForward("waiveChargesDue_Success");
verifyNoActionErrors();
verifyNoActionMessages();
Assert.assertNotNull(request.getAttribute(Constants.CURRENTFLOWKEY));
}
Aggregations