Search in sources :

Example 71 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class AccountStatusAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse httpservletresponse) throws Exception {
    AccountStatusActionForm accountStatusActionForm = (AccountStatusActionForm) form;
    List<AccountUpdateStatus> accountsForUpdate = new ArrayList<AccountUpdateStatus>();
    List<AccountUpdateStatus> individualAccountsForUpdate = new ArrayList<AccountUpdateStatus>();
    for (String accountId : accountStatusActionForm.getAccountRecords()) {
        if (StringUtils.isNotBlank(accountId)) {
            Long accountIdValue = Long.parseLong(accountId);
            //GLIM
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(Integer.valueOf(accountId));
            for (LoanBO indivdual : individualLoans) {
                Short newStatusId = getShortValue(accountStatusActionForm.getNewStatus());
                individualAccountsForUpdate.add(new AccountUpdateStatus(indivdual.getAccountId().longValue(), newStatusId, null, accountStatusActionForm.getComments()));
            }
            this.loanAccountServiceFacade.updateSeveralLoanAccountStatuses(individualAccountsForUpdate, null);
            Short newStatusId = getShortValue(accountStatusActionForm.getNewStatus());
            Short flagId = null;
            String comment = accountStatusActionForm.getComments();
            accountsForUpdate.add(new AccountUpdateStatus(accountIdValue, newStatusId, flagId, comment));
        }
    }
    List<String> accountNumbers = this.loanAccountServiceFacade.updateSeveralLoanAccountStatuses(accountsForUpdate, null);
    request.setAttribute(LoanConstants.ACCOUNTS_LIST, accountNumbers);
    return mapping.findForward(ActionForwards.changeAccountStatusConfirmation_success.toString());
}
Also used : AccountUpdateStatus(org.mifos.dto.domain.AccountUpdateStatus) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountStatusActionForm(org.mifos.accounts.loan.struts.actionforms.AccountStatusActionForm) ArrayList(java.util.ArrayList) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 72 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class ApplicationInitializer method applyMifos4948Fix.

@SuppressWarnings("unchecked")
private void applyMifos4948Fix() throws AccountException {
    Session session = StaticHibernateUtil.getSessionTL();
    List<LoanBO> fixLoans;
    Query query = session.getNamedQuery("fetchMissingInstalmentsForWriteOffsAndReschedules");
    fixLoans = query.list();
    if (fixLoans != null && fixLoans.size() > 0) {
        for (LoanBO fixLoan : fixLoans) {
            Set<AccountActionDateEntity> fixLoanSchedules = fixLoan.getAccountActionDates();
            Money totalMissedPayment = new Money(fixLoan.getCurrency());
            if (fixLoanSchedules != null && fixLoanSchedules.size() > 0) {
                for (AccountActionDateEntity fixLoanSchedule : fixLoanSchedules) {
                    LoanScheduleEntity loanInstallment = (LoanScheduleEntity) fixLoanSchedule;
                    totalMissedPayment = totalMissedPayment.add(loanInstallment.getPrincipalDue());
                }
            }
            logger.info("MIFOS-4948 - Loan: " + fixLoan.getGlobalAccountNum() + " - Adding payment: " + totalMissedPayment + " to fix instalments that should have been written-off or rescheduled.");
            fixLoan.applyMifos4948FixPayment(totalMissedPayment);
        }
        logger.info(fixLoans.size() + " Account Payments created to fix data related to MIFOS-4948");
    }
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) Query(org.hibernate.Query) LoanBO(org.mifos.accounts.loan.business.LoanBO) Session(org.hibernate.Session)

Example 73 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class AccountBOIntegrationTest method testAdjustmentForClosedAccnt.

@Test
public void testAdjustmentForClosedAccnt() throws Exception {
    Date currentDate = new Date(System.currentTimeMillis());
    LoanBO loan = groupLoan;
    loan.setUserContext(TestUtils.makeUser());
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.addAll(loan.getAccountActionDates());
    PaymentData accountPaymentDataView = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney(712), null, loan.getPersonnel(), "receiptNum", Short.valueOf("1"), currentDate, currentDate);
    IntegrationTestObjectMother.applyAccountPayment(loan, accountPaymentDataView);
    loan.setAccountState(new AccountStateEntity(AccountState.LOAN_CLOSED_OBLIGATIONS_MET));
    TestObjectFactory.updateObject(loan);
    try {
        PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
        loan.adjustPmnt("loan account has been adjusted by test code", loggedInUser);
    } catch (AccountException e) {
        Assert.assertEquals("exception.accounts.ApplicationException.CannotAdjust", e.getKey());
    }
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) Date(java.sql.Date) Test(org.junit.Test)

Example 74 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class AccountBOIntegrationTest method testGetTransactionHistoryViewByOtherUser.

@Test
public void testGetTransactionHistoryViewByOtherUser() throws Exception {
    Date currentDate = new Date(System.currentTimeMillis());
    LoanBO loan = groupLoan;
    loan.setUserContext(TestUtils.makeUser());
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.addAll(loan.getAccountActionDates());
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(Short.valueOf("2"));
    PaymentData accountPaymentDataView = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney(100), null, personnel, "receiptNum", Short.valueOf("1"), currentDate, currentDate);
    IntegrationTestObjectMother.applyAccountPayment(loan, accountPaymentDataView);
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    loan.setUserContext(TestUtils.makeUser());
    List<TransactionHistoryDto> trxnHistlist = loan.getTransactionHistoryView();
    Assert.assertNotNull("Account TrxnHistoryView list object should not be null", trxnHistlist);
    Assert.assertTrue("Account TrxnHistoryView list object Size should be greater than zero", trxnHistlist.size() > 0);
    for (TransactionHistoryDto transactionHistoryDto : trxnHistlist) {
        Assert.assertEquals(transactionHistoryDto.getPostedBy(), personnel.getDisplayName());
    }
    StaticHibernateUtil.flushSession();
    groupLoan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) TransactionHistoryDto(org.mifos.dto.screen.TransactionHistoryDto) Date(java.sql.Date) Test(org.junit.Test)

Example 75 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class AccountBOIntegrationTest method testUpdatePerformanceHistoryOnAdjustment.

@Test
public void testUpdatePerformanceHistoryOnAdjustment() throws Exception {
    Date currentDate = new Date(System.currentTimeMillis());
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    PaymentData paymentData1 = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney(212), null, groupLoan.getPersonnel(), "receiptNum", Short.valueOf("1"), currentDate, currentDate);
    IntegrationTestObjectMother.applyAccountPayment(groupLoan, paymentData1);
    IntegrationTestObjectMother.saveLoanAccount(groupLoan);
    LoanBO loan = IntegrationTestObjectMother.findLoanBySystemId(groupLoan.getGlobalAccountNum());
    PaymentData paymentData2 = TestObjectFactory.getLoanAccountPaymentData(null, TestUtils.createMoney(600), null, loan.getPersonnel(), "receiptNum", Short.valueOf("1"), currentDate, currentDate);
    IntegrationTestObjectMother.applyAccountPayment(loan, paymentData2);
    IntegrationTestObjectMother.saveLoanAccount(groupLoan);
    groupLoan = IntegrationTestObjectMother.findLoanBySystemId(groupLoan.getGlobalAccountNum());
    groupLoan.setUserContext(TestUtils.makeUser());
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    groupLoan.adjustPmnt("loan account has been adjusted by test code", loggedInUser);
    IntegrationTestObjectMother.saveLoanAccount(groupLoan);
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) Date(java.sql.Date) Test(org.junit.Test)

Aggregations

LoanBO (org.mifos.accounts.loan.business.LoanBO)215 ArrayList (java.util.ArrayList)76 Test (org.junit.Test)62 Money (org.mifos.framework.util.helpers.Money)60 UserContext (org.mifos.security.util.UserContext)45 MifosRuntimeException (org.mifos.core.MifosRuntimeException)42 Date (java.util.Date)37 AccountException (org.mifos.accounts.exceptions.AccountException)35 AccountBO (org.mifos.accounts.business.AccountBO)34 MifosUser (org.mifos.security.MifosUser)33 BigDecimal (java.math.BigDecimal)30 HashMap (java.util.HashMap)28 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)26 LocalDate (org.joda.time.LocalDate)23 PaymentData (org.mifos.accounts.util.helpers.PaymentData)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 ServiceException (org.mifos.framework.exceptions.ServiceException)19 BusinessRuleException (org.mifos.service.BusinessRuleException)19 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)18