Search in sources :

Example 56 with DateTimeService

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;
}
Also used : Query(org.hibernate.Query) PersistenceException(org.mifos.framework.exceptions.PersistenceException) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.sql.Date) CustomerException(org.mifos.customers.exceptions.CustomerException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Session(org.hibernate.Session)

Example 57 with DateTimeService

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);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 58 with DateTimeService

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();
    }
}
Also used : DateTimeService(org.mifos.framework.util.DateTimeService) After(org.junit.After)

Example 59 with DateTimeService

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();
}
Also used : CustomerService(org.mifos.customers.business.service.CustomerService) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Holiday(org.mifos.application.holiday.business.Holiday) LoanBO(org.mifos.accounts.loan.business.LoanBO) Days(org.joda.time.Days) ArrayList(java.util.ArrayList) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) DateTimeService(org.mifos.framework.util.DateTimeService) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules)

Example 60 with DateTimeService

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();
    }
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountTrxDto(org.mifos.dto.domain.AccountTrxDto) Timestamp(java.sql.Timestamp) DateTimeService(org.mifos.framework.util.DateTimeService) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) HashSet(java.util.HashSet) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8