Search in sources :

Example 1 with DateTimeService

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

the class LoanBO method applyMifos4948FixPayment.

/*
 * Mifos-4948 specific code
 */
public void applyMifos4948FixPayment(Money totalMissedPayment) throws AccountException {
    String comment = "MIFOS-4948 - Loan: " + this.getGlobalAccountNum() + " - Adding payment: " + totalMissedPayment;
    try {
        PersonnelBO currentUser = legacyPersonnelDao.getPersonnel((short) 1);
        Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
        AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, totalMissedPayment, null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
        addAccountPayment(accountPaymentEntity);
        accountPaymentEntity.setComment(comment);
        AccountActionTypes accountActionTypes;
        String accountConstants;
        if (this.getAccountState().getId().equals(AccountState.LOAN_CLOSED_WRITTEN_OFF.getValue())) {
            accountActionTypes = AccountActionTypes.WRITEOFF;
            accountConstants = AccountConstants.LOAN_WRITTEN_OFF;
        } else {
            accountActionTypes = AccountActionTypes.LOAN_RESCHEDULED;
            accountConstants = AccountConstants.LOAN_RESCHEDULED;
        }
        makeWriteOffOrReschedulePaymentForMifos4948(accountPaymentEntity, accountConstants, accountActionTypes, currentUser);
        addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, accountConstants, transactionDate));
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Example 2 with DateTimeService

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

the class ClientServiceFacadeWebTier method removeGroupMembership.

@Override
public void removeGroupMembership(String globalCustNum, Short loanOfficerId, String comment) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(mifosUser);
    ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
    client.updateDetails(userContext);
    PersonnelBO loanOfficer = null;
    if (loanOfficerId != null) {
        loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
    }
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    java.sql.Date commentDate = new DateTimeService().getCurrentJavaSqlDate();
    CustomerNoteEntity accountNotesEntity = new CustomerNoteEntity(comment, commentDate, loggedInUser, client);
    customerService.removeGroupMembership(client, loanOfficer, accountNotesEntity, userContext.getLocaleId());
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 3 with DateTimeService

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

the class CustomerServiceImpl method changeStatus.

private void changeStatus(CustomerBO customer, CustomerStatus oldStatus, CustomerStatus newStatus) throws CustomerException {
    Short oldStatusId = oldStatus.getValue();
    Short newStatusId = newStatus.getValue();
    if (customer.isClient()) {
        ClientBO client = (ClientBO) customer;
        if (client.isActiveForFirstTime(oldStatusId, newStatusId)) {
            if (client.getParentCustomer() != null) {
                CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
                client.addCustomerHierarchy(hierarchy);
            }
            CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
            List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customer.getCustomerAccount().getAccountFees());
            client.getCustomerAccount().createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(customer, accountFees, customer.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
            client.setCustomerActivationDate(new DateTimeService().getCurrentJavaDateTime());
            if (client.getOfferingsAssociatedInCreate() != null) {
                for (ClientInitialSavingsOfferingEntity clientOffering : client.getOfferingsAssociatedInCreate()) {
                    try {
                        SavingsOfferingBO savingsOffering = savingsProductDao.findById(clientOffering.getSavingsOffering().getPrdOfferingId().intValue());
                        if (savingsOffering.isActive()) {
                            List<CustomFieldDto> customerFieldsForSavings = new ArrayList<CustomFieldDto>();
                            client.addAccount(new SavingsBO(client.getUserContext(), savingsOffering, client, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), customerFieldsForSavings));
                        }
                    } catch (AccountException pe) {
                        throw new CustomerException(pe);
                    }
                }
            }
            new SavingsPersistence().persistSavingAccounts(client);
            try {
                if (client.getParentCustomer() != null) {
                    List<SavingsBO> savingsList = new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getCustomerId());
                    if (client.getParentCustomer().getParentCustomer() != null) {
                        savingsList.addAll(new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getParentCustomer().getCustomerId()));
                    }
                    for (SavingsBO savings : savingsList) {
                        savings.setUserContext(client.getUserContext());
                        if (client.getCustomerMeeting().getMeeting() != null) {
                            if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
                                DateTime today = new DateTime().toDateMidnight().toDateTime();
                                savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), applicableCalendarEvents.getWorkingDays(), applicableCalendarEvents.getHolidays(), today);
                                savings.update();
                            }
                        }
                    }
                }
            } catch (PersistenceException pe) {
                throw new CustomerException(pe);
            } catch (AccountException ae) {
                throw new CustomerException(ae);
            }
        }
    }
}
Also used : CustomerHierarchyEntity(org.mifos.customers.business.CustomerHierarchyEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CalendarEvent(org.mifos.calendar.CalendarEvent) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) DateTime(org.joda.time.DateTime) AccountException(org.mifos.accounts.exceptions.AccountException) DateMidnight(org.joda.time.DateMidnight) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 4 with DateTimeService

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

the class CustomerAccountBO method addFeeToAccountFee.

private void addFeeToAccountFee(final Short feeId, final Double charge) {
    FeeBO fee = getFeeDao().findById(feeId);
    AccountFeesEntity accountFee = null;
    if (fee.isPeriodic() && !isFeeAlreadyApplied(fee) || !fee.isPeriodic()) {
        accountFee = new AccountFeesEntity(this, fee, charge, FeeStatus.ACTIVE.getValue(), new DateTimeService().getCurrentJavaDateTime(), null);
        addAccountFees(accountFee);
    } else {
        accountFee = getAccountFees(fee.getFeeId());
        accountFee.setFeeAmount(charge);
        accountFee.setFeeStatus(FeeStatus.ACTIVE);
        accountFee.setStatusChangeDate(new DateTimeService().getCurrentJavaDateTime());
    }
}
Also used : FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 5 with DateTimeService

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

the class CustomerDaoHibernate method getLastMeetingDateForCustomer.

@Override
public Date getLastMeetingDateForCustomer(final Integer customerId) {
    Date meetingDate = null;
    Date actionDate = new DateTimeService().getCurrentJavaSqlDate();
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("CUSTOMER_ID", customerId);
    queryParameters.put("ACTION_DATE", actionDate);
    meetingDate = (Date) genericDao.executeUniqueResultNamedQuery(NamedQueryConstants.GET_LAST_MEETINGDATE_FOR_CUSTOMER, queryParameters);
    return meetingDate;
}
Also used : HashMap(java.util.HashMap) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date)

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