Search in sources :

Example 36 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class TestObjectFactory method getDueActionDatesForAccount.

public static List<AccountActionDateEntity> getDueActionDatesForAccount(final Integer accountId, final java.sql.Date transactionDate) throws Exception {
    List<AccountActionDateEntity> dueActionDates = new CustomerPersistence().retrieveCustomerAccountActionDetails(accountId, transactionDate);
    for (AccountActionDateEntity accountActionDate : dueActionDates) {
        Hibernate.initialize(accountActionDate);
        if (accountActionDate instanceof LoanScheduleEntity) {
            LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDate;
            for (AccountFeesActionDetailEntity accountFeesActionDetail : loanScheduleEntity.getAccountFeesActionDetails()) {
                Hibernate.initialize(accountFeesActionDetail);
            }
        }
        if (accountActionDate instanceof CustomerScheduleEntity) {
            CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDate;
            for (AccountFeesActionDetailEntity accountFeesActionDetail : customerScheduleEntity.getAccountFeesActionDetails()) {
                Hibernate.initialize(accountFeesActionDetail);
            }
        }
    }
    StaticHibernateUtil.flushSession();
    return dueActionDates;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Example 37 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class LoanBO method writeOff.

@Override
protected void writeOff(Date transactionDate) throws AccountException {
    try {
        if (!isTrxnDateValid(transactionDate, new CustomerPersistence().getLastMeetingDateForCustomer(getCustomer().getCustomerId()), new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled())) {
            throw new BusinessRuleException("errors.invalidTxndate");
        }
        Short personnelId = this.getUserContext().getId();
        PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
        this.setUpdatedBy(personnelId);
        this.setUpdatedDate(transactionDate);
        AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, getEarlyClosureAmount(), null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
        this.addAccountPayment(accountPaymentEntity);
        makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.LOAN_WRITTEN_OFF, AccountActionTypes.WRITEOFF, currentUser);
        //for past arrears installments writeOff and reschedule are the same as 'make early repayment'
        //but differ in processing for future installments
        makeWriteOffOrReschedulePaymentForFutureInstallments(accountPaymentEntity, AccountConstants.LOAN_WRITTEN_OFF, AccountActionTypes.WRITEOFF, currentUser);
        addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_WRITTEN_OFF, transactionDate));
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
        // Client performance entry
        updateCustomerHistoryOnWriteOff();
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Example 38 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class LoanBO method reschedule.

@Override
protected void reschedule(Date transactionDate) throws AccountException {
    try {
        if (!isTrxnDateValid(transactionDate, new CustomerPersistence().getLastMeetingDateForCustomer(getCustomer().getCustomerId()), new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled())) {
            throw new BusinessRuleException("errors.invalidTxndate");
        }
        Short personnelId = this.getUserContext().getId();
        PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
        this.setUpdatedBy(personnelId);
        this.setUpdatedDate(transactionDate);
        AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, getEarlyClosureAmount(), null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
        this.addAccountPayment(accountPaymentEntity);
        makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.LOAN_RESCHEDULED, AccountActionTypes.LOAN_RESCHEDULED, currentUser);
        //for past arrears installments writeOff and reschedule are the same as 'make early repayment'
        //but differ in processing for future installments
        makeWriteOffOrReschedulePaymentForFutureInstallments(accountPaymentEntity, AccountConstants.LOAN_RESCHEDULED, AccountActionTypes.LOAN_RESCHEDULED, currentUser);
        addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_RESCHEDULED, transactionDate));
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
        // Client performance entry using the same as write off.
        updateCustomerHistoryOnWriteOff();
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Example 39 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class PortfolioAtRiskHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    long time1 = new DateTimeService().getCurrentDateTime().getMillis();
    List<BasicGroupInfo> groupInfos = null;
    List<String> errorList = new ArrayList<String>();
    try {
        groupInfos = new CustomerPersistence().getAllBasicGroupInfo();
    } catch (Exception e) {
        throw new BatchJobException(e);
    }
    if (groupInfos != null && !groupInfos.isEmpty()) {
        int groupCount = groupInfos.size();
        getLogger().info("PortfolioAtRisk: got " + groupCount + " groups to process.");
        long startTime = new DateTimeService().getCurrentDateTime().getMillis();
        int i = 1;
        Integer groupId = null;
        GroupPersistence groupPersistence = new GroupPersistence();
        try {
            for (BasicGroupInfo groupInfo : groupInfos) {
                groupId = groupInfo.getGroupId();
                String searchStr = groupInfo.getSearchId() + ".%";
                double portfolioAtRisk = PortfolioAtRiskCalculation.generatePortfolioAtRiskForTask(groupId, groupInfo.getBranchId(), searchStr);
                // updated_by and updated_date
                if (portfolioAtRisk > -1) {
                    groupPersistence.updateGroupInfoAndGroupPerformanceHistoryForPortfolioAtRisk(portfolioAtRisk, groupId);
                }
                if (i % 500 == 0) {
                    long time = new DateTimeService().getCurrentDateTime().getMillis();
                    getLogger().info("500 groups updated in " + (time - startTime) + " milliseconds. There are " + (groupCount - i) + " more groups to be updated.");
                    startTime = time;
                }
                i++;
            }
        } catch (Exception e) {
            getLogger().error("PortfolioAtRiskHelper execute failed with exception " + e.getClass().getName() + ": " + e.getMessage() + " at group " + groupId.toString(), e);
            StaticHibernateUtil.rollbackTransaction();
            errorList.add(groupId.toString());
        } finally {
            StaticHibernateUtil.closeSession();
        }
    }
    long time2 = new DateTimeService().getCurrentDateTime().getMillis();
    getLogger().info("PortfolioAtRiskTask ran in " + (time2 - time1) + " milliseconds");
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : BasicGroupInfo(org.mifos.customers.group.BasicGroupInfo) ArrayList(java.util.ArrayList) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DateTimeService(org.mifos.framework.util.DateTimeService) GroupPersistence(org.mifos.customers.group.persistence.GroupPersistence)

Example 40 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class CustomerTagGenerator method build.

@Override
protected StringBuilder build(AbstractBusinessObject obj, boolean selfLinkRequired, Object randomNum) {
    CustomerBO customer = (CustomerBO) obj;
    try {
        CustomerBO customerReloaded = new CustomerPersistence().getCustomer(customer.getCustomerId());
        StringBuilder strBuilder = getAssociatedGenerator().build(customerReloaded.getOffice(), randomNum);
        if (strBuilder == null) {
            strBuilder = new StringBuilder();
        }
        buildLink(strBuilder, customerReloaded, customerReloaded, selfLinkRequired, randomNum);
        return strBuilder;
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
}
Also used : PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Aggregations

CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)40 PersistenceException (org.mifos.framework.exceptions.PersistenceException)15 UserContext (org.mifos.security.util.UserContext)14 ArrayList (java.util.ArrayList)13 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)11 Date (java.util.Date)10 Test (org.junit.Test)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)9 ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)8 CustomerBO (org.mifos.customers.business.CustomerBO)8 LocalDate (org.joda.time.LocalDate)7 AccountException (org.mifos.accounts.exceptions.AccountException)7 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)7 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)7 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)6 CustomerException (org.mifos.customers.exceptions.CustomerException)6 BusinessRuleException (org.mifos.service.BusinessRuleException)6 AccountBO (org.mifos.accounts.business.AccountBO)5 CenterPersistence (org.mifos.customers.center.persistence.CenterPersistence)5 DateTime (org.joda.time.DateTime)4