Search in sources :

Example 46 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class GroupServiceFacadeWebTier method updateCustomerHistoricalData.

@Override
public void updateCustomerHistoricalData(String globalCustNum, CustomerHistoricalDataUpdateRequest historicalData) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    customerBO.updateDetails(userContext);
    try {
        CustomerHistoricalDataEntity customerHistoricalDataEntity = customerBO.getHistoricalData();
        if (customerBO.getPersonnel() != null) {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), userContext.getId());
        }
        // Integer oldLoanCycleNo = 0;
        if (customerHistoricalDataEntity == null) {
            customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customerBO);
            customerHistoricalDataEntity.setCreatedBy(customerBO.getUserContext().getId());
            customerHistoricalDataEntity.setCreatedDate(new DateTimeService().getCurrentJavaDateTime());
        } else {
            // oldLoanCycleNo =
            // customerHistoricalDataEntity.getLoanCycleNumber();
            customerHistoricalDataEntity.setUpdatedDate(new DateTimeService().getCurrentJavaDateTime());
            customerHistoricalDataEntity.setUpdatedBy(customerBO.getUserContext().getId());
        }
        customerHistoricalDataEntity.setInterestPaid(StringUtils.isBlank(historicalData.getInterestPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getInterestPaid()));
        customerHistoricalDataEntity.setLoanAmount(StringUtils.isBlank(historicalData.getLoanAmount()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getLoanAmount()));
        customerHistoricalDataEntity.setLoanCycleNumber(historicalData.getLoanCycleNumber());
        customerHistoricalDataEntity.setMissedPaymentsCount(historicalData.getMissedPaymentsCount());
        customerHistoricalDataEntity.setNotes(historicalData.getNotes());
        customerHistoricalDataEntity.setProductName(historicalData.getProductName());
        customerHistoricalDataEntity.setTotalAmountPaid(StringUtils.isBlank(historicalData.getTotalAmountPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getTotalAmountPaid()));
        customerHistoricalDataEntity.setTotalPaymentsCount(historicalData.getTotalPaymentsCount());
        customerHistoricalDataEntity.setMfiJoiningDate(historicalData.getMfiJoiningDate());
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(customerBO);
        customerBO.updateHistoricalData(customerHistoricalDataEntity);
        this.customerDao.save(customerBO);
        this.transactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 47 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CenterServiceFacadeWebTier method createCustomerNote.

@Override
public void createCustomerNote(CustomerNoteFormDto customerNoteForm) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customer = this.customerDao.findCustomerBySystemId(customerNoteForm.getGlobalNum());
    customer.updateDetails(userContext);
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    CustomerNoteEntity customerNote = new CustomerNoteEntity(customerNoteForm.getComment(), new DateTimeService().getCurrentJavaSqlDate(), loggedInUser, customer);
    customer.addCustomerNotes(customerNote);
    try {
        this.transactionHelper.startTransaction();
        this.customerDao.save(customer);
        this.transactionHelper.commitTransaction();
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(customer.getCustomerAccount().getAccountId().toString(), e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) ServiceException(org.mifos.framework.exceptions.ServiceException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException)

Example 48 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class MeetingAction method createMeeting.

private MeetingBO createMeeting(MeetingActionForm form) throws MeetingException {
    MeetingBO meeting = null;
    Date startDate = null;
    if (form.getMeetingStartDate() == null || form.getMeetingStartDate().isEmpty()) {
        startDate = new DateTimeService().getCurrentJavaDateTime();
    } else {
        startDate = DateUtils.getDate(form.getMeetingStartDate());
    }
    if (form.getRecurrenceType().equals(RecurrenceType.WEEKLY)) {
        meeting = new MeetingBO(form.getWeekDayValue(), form.getRecurWeekValue(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
    } else if (form.getRecurrenceType().equals(RecurrenceType.DAILY)) {
        meeting = new MeetingBO(form.getRecurDayShort(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
    } else if (form.isMonthlyOnDate()) {
        meeting = new MeetingBO(form.getMonthDayValue(), form.getDayRecurMonthValue(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
    } else {
        meeting = new MeetingBO(form.getMonthWeekValue(), form.getMonthRankValue(), form.getRecurMonthValue(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
    }
    return meeting;
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date)

Example 49 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class EditStatusAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = getUserContext(request);
    EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
    Integer accountId = Integer.valueOf(editStatusActionForm.getAccountId());
    AccountBO accountBO = new AccountBusinessService().getAccount(accountId);
    Short flagId = null;
    Short newStatusId = null;
    String updateComment = editStatusActionForm.getNotes();
    if (StringUtils.isNotBlank(editStatusActionForm.getFlagId())) {
        flagId = getShortValue(editStatusActionForm.getFlagId());
    }
    if (StringUtils.isNotBlank(editStatusActionForm.getNewStatusId())) {
        newStatusId = getShortValue(editStatusActionForm.getNewStatusId());
    }
    Date trxnDate = editStatusActionForm.getTransactionDateValue(userContext.getPreferredLocale());
    if (editStatusActionForm.getNewStatusId().equals(AccountState.LOAN_APPROVED) && !AccountingRules.isBackDatedApprovalAllowed()) {
        trxnDate = new DateTimeService().getCurrentJavaDateTime();
    }
    checkPermission(accountBO, getUserContext(request), newStatusId, flagId);
    if (accountBO.isLoanAccount() || accountBO.isGroupLoanAccount()) {
        initializeLoanQuestionnaire(accountBO.getGlobalAccountNum(), newStatusId != null ? newStatusId.toString() : null);
        loanQuestionnaire.saveResponses(request, editStatusActionForm, accountId);
        //GLIM
        List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(accountId);
        List<AccountUpdateStatus> updateStatus = new ArrayList<AccountUpdateStatus>(individualLoans.size() + 1);
        updateStatus.add(new AccountUpdateStatus(accountId.longValue(), newStatusId, flagId, updateComment));
        for (LoanBO individual : individualLoans) {
            updateStatus.add(new AccountUpdateStatus(individual.getAccountId().longValue(), newStatusId, flagId, updateComment));
        }
        try {
            if (individualLoans.size() == 0) {
                this.loanAccountServiceFacade.updateSingleLoanAccountStatus(updateStatus.get(0), trxnDate);
            } else {
                this.loanAccountServiceFacade.updateSeveralLoanAccountStatuses(updateStatus, trxnDate);
            }
        } catch (AccessDeniedException e) {
            throw new ServiceException(SecurityConstants.KEY_ACTIVITY_APPROVE_LOAN_NOT_ALLOWED);
        }
        return mapping.findForward(ActionForwards.loan_detail_page.toString());
    }
    if (accountBO.isSavingsAccount()) {
        AccountUpdateStatus updateStatus = new AccountUpdateStatus(accountId.longValue(), newStatusId, flagId, updateComment);
        this.savingsServiceFacade.updateSavingsAccountStatus(updateStatus);
        return mapping.findForward(ActionForwards.savings_details_page.toString());
    }
    // nothing but loan of savings account should be detected. customer account status change goes through separate action.
    return null;
}
Also used : AccountUpdateStatus(org.mifos.dto.domain.AccountUpdateStatus) EditStatusActionForm(org.mifos.accounts.struts.actionforms.EditStatusActionForm) AccessDeniedException(org.springframework.security.access.AccessDeniedException) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) Date(java.util.Date) AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) DateTimeService(org.mifos.framework.util.DateTimeService) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 50 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanAdjustmentsIntegrationTest method testWhenACompletedLoanIsAdjustedThatAnAccountStatusChangeHistoryEntryisCreated.

@Test
public void testWhenACompletedLoanIsAdjustedThatAnAccountStatusChangeHistoryEntryisCreated() throws Exception {
    // relates to mifos-3479
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 10, 13));
    loan = createLoan();
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // pay 3 installments
    makePayment(loan, "333.0");
    loan.updateDetails(TestUtils.makeUserWithLocales());
    makeEarlyPayment(loan);
    loan.updateDetails(TestUtils.makeUserWithLocales());
    adjustLastLoanPayment(loan);
    loan.updateDetails(TestUtils.makeUserWithLocales());
    assertNotNull("Account Status Change History Should Not Be Null", loan.getAccountStatusChangeHistory());
    Integer listSize = loan.getAccountStatusChangeHistory().size();
    assertFalse(listSize == 0);
    // check if the last entry has an oldstatus LOAN_CLOSED_OBLIGATIONS_MET and a new status of
    // LOAN_ACTIVE_IN_GOOD_STANDING
    AccountStateEntity oldStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getOldStatus();
    AccountStateEntity newStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getNewStatus();
    assertTrue("Old Status Should Have Been LOAN_CLOSED_OBLIGATIONS_MET", oldStatus.isInState(AccountState.LOAN_CLOSED_OBLIGATIONS_MET));
    assertTrue("New Status Should Have Been LOAN_ACTIVE_IN_GOOD_STANDING", newStatus.isInState(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING));
}
Also used : AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Test(org.junit.Test)

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