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");
}
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));
}
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();
}
}
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")));
}
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()));
}
}
Aggregations