use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class GroupPersistence method updateGroupInfoAndGroupPerformanceHistoryForPortfolioAtRisk.
// this code is used in the PAR task to improve performance
public boolean updateGroupInfoAndGroupPerformanceHistoryForPortfolioAtRisk(double portfolioAtRisk, Integer groupId) throws Exception {
boolean result = false;
Session session = StaticHibernateUtil.getSessionTL();
try {
session.beginTransaction();
// this is bach job, so no user
short userId = 1;
Date currentDate = new DateTimeService().getCurrentJavaSqlDate();
Query query = session.createSQLQuery("update customer set updated_by = " + userId + ", updated_date='" + currentDate + "' where customer_id=" + groupId.toString());
int rows = query.executeUpdate();
if (rows != 1) {
throw new PersistenceException("Unable to update group table for group id " + groupId.toString());
}
query = session.createSQLQuery("update group_perf_history set portfolio_at_risk = " + portfolioAtRisk + " where customer_id=" + groupId.toString());
rows = query.executeUpdate();
if (rows != 1) {
throw new PersistenceException("Unable to update group performance history for group id " + groupId.toString());
}
result = true;
} catch (Exception ex) {
session.getTransaction().rollback();
throw new PersistenceException(ex);
} finally {
StaticHibernateUtil.closeSession();
}
return result;
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class SavingsClosureAction method preview.
@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
AccountPaymentEntity payment = (AccountPaymentEntity) SessionUtils.getAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
AccountPaymentEntity accountPaymentEntity = null;
Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
if (actionForm.getReceiptDate() != null && actionForm.getReceiptDate() != "") {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), new java.util.Date(DateUtils.getDateAsSentFromBrowser(actionForm.getReceiptDate()).getTime()), new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
} else {
if (actionForm.getPaymentTypeId() != null && !actionForm.getPaymentTypeId().equals("")) {
if (!(actionForm.getPaymentTypeId().equals(""))) {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
} else {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
}
} else {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
}
}
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, accountPaymentEntity, request);
return closeSavingsQuestionnaire.fetchAppliedQuestions(mapping, actionForm, request, ActionForwards.preview_success);
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class AccountIntegrationTestCase method tearDown.
@After
public void tearDown() throws Exception {
try {
this.getBranchOffice().setHolidays(null);
holiday = null;
groupLoan = null;
clientLoan = null;
savingsBO = null;
client = null;
group = null;
center = null;
legacyAccountDao = null;
} catch (Exception e) {
// TODO Whoops, cleanup didnt work, reset db
} finally {
new DateTimeService().resetToCurrentSystemDateTime();
StaticHibernateUtil.flushSession();
}
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class AccountRegenerateScheduleIntegrationTestCase method testChangeInMeetingScheduleForDates.
public void testChangeInMeetingScheduleForDates(MeetingBO customerMeeting, MeetingBO loanMeeting, MeetingBO newMeeting, LocalDate startDate, LocalDate dateWhenMeetingWillBeChanged, boolean useClosedAndCancelled) throws Exception {
log("Start: " + startDate + ", Test: " + dateWhenMeetingWillBeChanged);
accountBO = createLoanAccount(customerMeeting, loanMeeting);
savingsBO = createSavingsAccount(customerMeeting);
// center initially set up with meeting today
center = TestObjectFactory.getCenter(center.getCustomerId());
accountBO = TestObjectFactory.getObject(LoanBO.class, accountBO.getAccountId());
if (useClosedAndCancelled) {
PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
accountBO.changeStatus(AccountState.LOAN_CANCELLED, null, "", loggedInUser);
savingsBO.changeStatus(AccountState.SAVINGS_CANCELLED.getValue(), null, "", loggedInUser);
CustomerStatusEntity customerStatusEntity = new CustomerStatusEntity(CustomerStatus.GROUP_CLOSED);
CustomerBOTestUtils.setCustomerStatus(group, customerStatusEntity);
StaticHibernateUtil.flushSession();
}
new DateTimeService().setCurrentDateTime(dateWhenMeetingWillBeChanged.toDateTimeAtStartOfDay());
CustomerService customerService = ApplicationContextProvider.getBean(CustomerService.class);
newMeeting.updateDetails(TestUtils.makeUser());
customerService.updateCustomerMeetingSchedule(newMeeting, center);
TestObjectFactory.updateObject(center);
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> holidays = new ArrayList<Holiday>();
boolean isTopOfHierarchy = center.isTopOfHierarchy();
center.getCustomerAccount().handleChangeInMeetingSchedule(workingDays, holidays, isTopOfHierarchy);
accountBO.handleChangeInMeetingSchedule(workingDays, holidays, isTopOfHierarchy);
savingsBO.handleChangeInMeetingSchedule(workingDays, holidays, isTopOfHierarchy);
StaticHibernateUtil.flushSession();
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class ImportedFilesServiceImpl method saveImportedFileName.
@Override
public void saveImportedFileName(String fileName, PersonnelBO submittedBy, List<AccountTrxDto> idsToUndoImport, Boolean phaseOut, Boolean undoable) {
Timestamp submittedOn = new Timestamp(new DateTimeService().getCurrentDateTime().getMillis());
Set<AccountTrxnEntity> accTrxEnt = new HashSet<AccountTrxnEntity>();
ImportedFilesEntity importedFile = new ImportedFilesEntity(fileName, submittedOn, submittedBy, accTrxEnt, phaseOut, undoable);
if (null != idsToUndoImport) {
for (AccountTrxDto trx : idsToUndoImport) {
accTrxEnt.add(importedFileDao.getAccTrxById(trx.getId()));
}
importedFile.setImportedTrxn(accTrxEnt);
}
try {
hibernateTransactionHelper.startTransaction();
importedFileDao.saveImportedFile(importedFile);
hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
}
Aggregations