Search in sources :

Example 21 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class SavingsApplyAdjustmentAction method list.

@TransactionDemarcate(joinToken = true)
public ActionForward list(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    List<AdjustableSavingsPaymentDto> adjustablePayments = this.savingsServiceFacade.retrievePaymentsForAdjustment(savings.getAccountId());
    SessionUtils.setCollectionAttribute(SavingsConstants.ADJUSTABLE_PAYMENTS, adjustablePayments, request);
    return mapping.findForward("list_savings_adjustments");
}
Also used : SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 22 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class GenerateMeetingsForCustomerAndSavingsHelper method execute.

@Override
public void execute(@SuppressWarnings("unused") final long timeInMillis) throws BatchJobException {
    workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    officeCurrentAndFutureHolidays = new HashMap<Short, List<Holiday>>();
    long taskStartTime = new DateTimeService().getCurrentDateTime().getMillis();
    List<Integer> customerAndSavingsAccountIds = findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated();
    int accountCount = customerAndSavingsAccountIds.size();
    if (accountCount == 0) {
        return;
    }
    List<String> errorList = new ArrayList<String>();
    int currentRecordNumber = 0;
    int outputIntervalForBatchJobs = GeneralConfig.getOutputIntervalForBatchJobs();
    int batchSize = GeneralConfig.getBatchSizeForBatchJobs();
    // jpw - hardcoded recordCommittingSize to 500 because now only accounts that need more schedules are returned
    int recordCommittingSize = 500;
    infoLogBatchParameters(accountCount, outputIntervalForBatchJobs, batchSize, recordCommittingSize);
    long startTime = new DateTimeService().getCurrentDateTime().getMillis();
    Integer currentAccountId = null;
    int updatedRecordCount = 0;
    try {
        StaticHibernateUtil.getSessionTL();
        StaticHibernateUtil.startTransaction();
        for (Integer accountId : customerAndSavingsAccountIds) {
            currentRecordNumber++;
            currentAccountId = accountId;
            AccountBO accountBO = legacyAccountDao.getAccount(accountId);
            List<Holiday> currentAndFutureHolidays = getOfficeCurrentAndFutureHolidays(accountBO.getOffice().getOfficeId());
            ScheduledDateGeneration scheduleGenerationStrategy = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, currentAndFutureHolidays);
            if (accountBO instanceof CustomerAccountBO) {
                ((CustomerAccountBO) accountBO).generateNextSetOfMeetingDates(scheduleGenerationStrategy);
                updatedRecordCount++;
            } else if (accountBO instanceof SavingsBO) {
                ((SavingsBO) accountBO).generateNextSetOfMeetingDates(workingDays, currentAndFutureHolidays);
                updatedRecordCount++;
            }
            if (currentRecordNumber % batchSize == 0) {
                StaticHibernateUtil.flushAndClearSession();
                getLogger().debug("completed HibernateUtil.flushAndClearSession()");
            }
            if (updatedRecordCount > 0) {
                if (updatedRecordCount % recordCommittingSize == 0) {
                    StaticHibernateUtil.commitTransaction();
                    StaticHibernateUtil.getSessionTL();
                    StaticHibernateUtil.startTransaction();
                }
            }
            if (currentRecordNumber % outputIntervalForBatchJobs == 0) {
                long time = System.currentTimeMillis();
                String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
                logMessage(message);
                startTime = time;
            }
        }
        StaticHibernateUtil.commitTransaction();
        long time = System.currentTimeMillis();
        String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
        logMessage(message);
    } catch (Exception e) {
        logMessage("account " + currentAccountId.intValue() + " exception " + e.getMessage());
        StaticHibernateUtil.rollbackTransaction();
        errorList.add(currentAccountId.toString());
        getLogger().error("Unable to generate schedules for account with ID " + currentAccountId, e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
    logMessage("GenerateMeetingsForCustomerAndSavings ran in " + (new DateTimeService().getCurrentDateTime().getMillis() - taskStartTime));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Holiday(org.mifos.application.holiday.business.Holiday) ArrayList(java.util.ArrayList) List(java.util.List) DateTimeService(org.mifos.framework.util.DateTimeService) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 23 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class SavingsPersistenceIntegrationTest method testRetrieveLastTransaction.

@Test
public void testRetrieveLastTransaction() throws Exception {
    try {
        SavingsTestHelper helper = new SavingsTestHelper();
        createInitialObjects();
        PersonnelBO createdBy = legacyPersonnelDao.getPersonnel(userContext.getId());
        savingsOffering = helper.createSavingsOffering("effwe", "231");
        savings = new SavingsBO(userContext, savingsOffering, group, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), null);
        AccountPaymentEntity payment = helper.createAccountPaymentToPersist(savings, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "700.0"), new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "1700.0"), helper.getDate("15/01/2006"), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), savings, createdBy, group);
        AccountTestUtils.addAccountPayment(payment, savings);
        savings.save();
        StaticHibernateUtil.flushSession();
        payment = helper.createAccountPaymentToPersist(savings, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "1000.0"), new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "2700.0"), helper.getDate("20/02/2006"), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), savings, createdBy, group);
        AccountTestUtils.addAccountPayment(payment, savings);
        savings.update();
        StaticHibernateUtil.flushSession();
        savings = savingsDao.findById(savings.getAccountId());
        savings.setUserContext(userContext);
        payment = helper.createAccountPaymentToPersist(savings, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500.0"), new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "2200.0"), helper.getDate("10/03/2006"), AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), savings, createdBy, group);
        AccountTestUtils.addAccountPayment(payment, savings);
        savings.update();
        StaticHibernateUtil.flushSession();
        savings = savingsDao.findById(savings.getAccountId());
        savings.setUserContext(userContext);
        payment = helper.createAccountPaymentToPersist(savings, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "1200.0"), new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "3400.0"), helper.getDate("15/03/2006"), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), savings, createdBy, group);
        AccountTestUtils.addAccountPayment(payment, savings);
        savings.update();
        StaticHibernateUtil.flushSession();
        savings = savingsDao.findById(savings.getAccountId());
        savings.setUserContext(userContext);
        payment = helper.createAccountPaymentToPersist(savings, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "2500.0"), new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "900.0"), helper.getDate("25/03/2006"), AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), savings, createdBy, group);
        AccountTestUtils.addAccountPayment(payment, savings);
        savings.update();
        StaticHibernateUtil.flushSession();
        savings = savingsDao.findById(savings.getAccountId());
        savings.setUserContext(userContext);
        SavingsTrxnDetailEntity trxn = savingsPersistence.retrieveLastTransaction(savings.getAccountId(), helper.getDate("12/03/2006"));
        Assert.assertEquals(TestUtils.createMoney("500"), trxn.getAmount());
        group = savings.getCustomer();
        center = group.getParentCustomer();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) SavingsTestHelper(org.mifos.accounts.savings.util.helpers.SavingsTestHelper) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Test(org.junit.Test)

Example 24 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class SavingsAccountAdjustmentAndInterestCalculationServiceFacadeIntegrationTest method shouldHaveCorrectBalanceAfterDepositAndAdjustment.

@Test
public void shouldHaveCorrectBalanceAfterDepositAndAdjustment() throws Exception {
    createCenterGroupClientHierarchy(aWeeklyMeeting);
    SavingsOfferingBO savingsProduct = new SavingsProductBuilder().mandatory().withMandatoryAmount("33.0").appliesToClientsOnly().buildForIntegrationTests();
    SavingsBO savingsAccount = new SavingsAccountBuilder().active().withActivationDate(mondayTwoWeeksAgo()).withSavingsProduct(savingsProduct).withCustomer(client).withCreatedBy(IntegrationTestObjectMother.testUser()).withBalanceOf(TestUtils.createMoney("0")).withDepositOn("20", new DateTime()).build();
    IntegrationTestObjectMother.saveSavingsProductAndAssociatedSavingsAccounts(savingsProduct, savingsAccount);
    Long savingsId = Long.valueOf(savingsAccount.getAccountId());
    Double adjustedAmount = Double.valueOf("35");
    String note = "I entered 20 but it should of being 35 which is an overpayment of the mandatory sum.";
    SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(savingsId, adjustedAmount, note, savingsAccount.getLastPmnt().getPaymentId(), new LocalDate(savingsAccount.getLastPmnt().getPaymentDate()));
    // exercise test
    this.savingsServiceFacade.adjustTransaction(savingsAdjustment);
    // verification
    savingsAccount = IntegrationTestObjectMother.findSavingsAccountById(savingsId);
    assertThat(savingsAccount.getSavingsBalance(), is(TestUtils.createMoney("35")));
}
Also used : SavingsProductBuilder(org.mifos.domain.builders.SavingsProductBuilder) SavingsAdjustmentDto(org.mifos.dto.domain.SavingsAdjustmentDto) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 25 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class SavingsAccountSchedulesIntegrationTest method shouldGenerateSavingsAccountSchedulesForActiveClientsOfGroupWhenUsingPerIndividualSetting.

@Test
public void shouldGenerateSavingsAccountSchedulesForActiveClientsOfGroupWhenUsingPerIndividualSetting() throws Exception {
    createCenterGroupClientHierarchy(aWeeklyMeeting);
    SavingsOfferingBO savingsProduct = new SavingsProductBuilder().mandatory().withMandatoryAmount("33.0").appliesToGroupsOnly().trackedPerIndividual().buildForIntegrationTests();
    SavingsBO savingsAccount = new SavingsAccountBuilder().active().withActivationDate(mondayTwoWeeksAgo()).withSavingsProduct(savingsProduct).withCustomer(group).withMember(client).withCreatedBy(IntegrationTestObjectMother.testUser()).buildJointSavingsAccount();
    IntegrationTestObjectMother.saveSavingsProductAndAssociatedSavingsAccounts(savingsProduct, savingsAccount);
    List<AccountActionDateEntity> savingSchedules = savingsAccount.getAccountActionDatesSortedByInstallmentId();
    for (AccountActionDateEntity savingSchedule : savingSchedules) {
        assertThat("saving schedule should be generated for active client belong to group savings account", savingSchedule.getCustomer().getCustomerId(), is(client.getCustomerId()));
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) SavingsProductBuilder(org.mifos.domain.builders.SavingsProductBuilder) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) Test(org.junit.Test)

Aggregations

SavingsBO (org.mifos.accounts.savings.business.SavingsBO)111 UserContext (org.mifos.security.util.UserContext)43 MifosRuntimeException (org.mifos.core.MifosRuntimeException)30 AccountException (org.mifos.accounts.exceptions.AccountException)28 LocalDate (org.joda.time.LocalDate)27 MifosUser (org.mifos.security.MifosUser)26 Test (org.junit.Test)25 Money (org.mifos.framework.util.helpers.Money)24 ArrayList (java.util.ArrayList)22 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 Date (java.util.Date)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)19 BusinessRuleException (org.mifos.service.BusinessRuleException)18 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)17 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)17 CustomerBO (org.mifos.customers.business.CustomerBO)15 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)14 ServiceException (org.mifos.framework.exceptions.ServiceException)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12