Search in sources :

Example 26 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class CollectionSheetServiceFacadeWebTier method loadAllActiveBranchesAndSubsequentDataIfApplicable.

@Override
public CollectionSheetEntryFormDto loadAllActiveBranchesAndSubsequentDataIfApplicable(final UserContext userContext) {
    final Short branchId = userContext.getBranchId();
    final Short centerHierarchyExists = ClientRules.getCenterHierarchyExists() ? Constants.YES : Constants.NO;
    List<OfficeDetailsDto> activeBranches = new ArrayList<OfficeDetailsDto>();
    List<ListItem<Short>> paymentTypesDtoList = new ArrayList<ListItem<Short>>();
    List<CustomerDto> customerList = new ArrayList<CustomerDto>();
    List<PersonnelDto> loanOfficerList = new ArrayList<PersonnelDto>();
    Short reloadFormAutomatically = Constants.YES;
    final Short backDatedTransactionAllowed = Constants.NO;
    try {
        final List<PaymentTypeEntity> paymentTypesList = legacyMasterDao.findMasterDataEntitiesWithLocale(PaymentTypeEntity.class);
        paymentTypesDtoList = convertToPaymentTypesListItemDto(paymentTypesList);
        activeBranches = officePersistence.getActiveOffices(branchId);
        if (activeBranches.size() == 1) {
            loanOfficerList = legacyPersonnelDao.getActiveLoanOfficersInBranch(PersonnelConstants.LOAN_OFFICER, branchId, userContext.getId(), userContext.getLevelId());
            if (loanOfficerList.size() == 1) {
                Short customerLevel;
                if (centerHierarchyExists.equals(Constants.YES)) {
                    customerLevel = Short.valueOf(CustomerLevel.CENTER.getValue());
                } else {
                    customerLevel = Short.valueOf(CustomerLevel.GROUP.getValue());
                }
                customerList = customerPersistence.getActiveParentList(loanOfficerList.get(0).getPersonnelId(), customerLevel, branchId);
                if (customerList.size() == 1) {
                    reloadFormAutomatically = Constants.YES;
                }
                reloadFormAutomatically = Constants.NO;
            }
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
    return new CollectionSheetEntryFormDto(activeBranches, paymentTypesDtoList, loanOfficerList, customerList, reloadFormAutomatically, centerHierarchyExists, backDatedTransactionAllowed);
}
Also used : ArrayList(java.util.ArrayList) CustomerDto(org.mifos.dto.domain.CustomerDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) OfficeDetailsDto(org.mifos.dto.domain.OfficeDetailsDto) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 27 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class AccountingServiceFacadeWebTier method updateFinancialYear.

@Override
public FinancialYearBO updateFinancialYear(FinancialYearBO oldFinancialYearBO, UserContext context) {
    FinancialYearBO newFinancialYearBO = null;
    //updating current financial year as Inactive
    accountingDao.savingFinancialYearBO(oldFinancialYearBO);
    this.hibernateTransactionHelper.flushSession();
    //creating new Finincial year
    Calendar calendar = new GregorianCalendar();
    newFinancialYearBO = new FinancialYearBO();
    newFinancialYearBO.setFinancialYearStartDate(nextYear(oldFinancialYearBO.getFinancialYearStartDate(), calendar));
    newFinancialYearBO.setFinancialYearEndDate(nextYear(oldFinancialYearBO.getFinancialYearEndDate(), calendar));
    try {
        newFinancialYearBO.setCreatedDate(DateUtils.getLocaleDate(context.getPreferredLocale(), DateUtils.getCurrentDate(context.getPreferredLocale())));
    } catch (InvalidDateException e) {
        throw new MifosRuntimeException(e);
    }
    newFinancialYearBO.setCreatedBy(context.getId());
    newFinancialYearBO.setStatus(SimpleAccountingConstants.ACTIVE);
    calendar.setTime(newFinancialYearBO.getFinancialYearStartDate());
    newFinancialYearBO.setFinancialYearId(Integer.parseInt(calendar.get(calendar.YEAR) + "" + calendar.get(calendar.YEAR)));
    newFinancialYearBO = accountingDao.savingFinancialYearBO(newFinancialYearBO);
    this.hibernateTransactionHelper.flushSession();
    return newFinancialYearBO;
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) FinancialYearBO(org.mifos.application.accounting.business.FinancialYearBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 28 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class AdminServiceFacadeWebTier method updateSavingsProduct.

@Override
public PrdOfferingDto updateSavingsProduct(SavingsProductDto savingsProductRequest) {
    SavingsOfferingBO savingsProductForUpdate = this.savingsProductDao.findById(savingsProductRequest.getProductDetails().getId());
    // enforced by integrity constraints on table also.
    if (savingsProductForUpdate.isDifferentName(savingsProductRequest.getProductDetails().getName())) {
        this.savingsProductDao.validateProductWithSameNameDoesNotExist(savingsProductRequest.getProductDetails().getName());
    }
    if (savingsProductForUpdate.isDifferentShortName(savingsProductRequest.getProductDetails().getShortName())) {
        this.savingsProductDao.validateProductWithSameShortNameDoesNotExist(savingsProductRequest.getProductDetails().getShortName());
    }
    // domain rule validation - put on domain entity
    if (savingsProductForUpdate.isDifferentStartDate(savingsProductRequest.getProductDetails().getStartDate())) {
        validateStartDateIsNotBeforeToday(savingsProductRequest.getProductDetails().getStartDate());
        validateStartDateIsNotOverOneYearFromToday(savingsProductRequest.getProductDetails().getStartDate());
        validateEndDateIsPastStartDate(savingsProductRequest.getProductDetails().getStartDate(), savingsProductRequest.getProductDetails().getEndDate());
    }
    boolean activeOrInactiveSavingsAccountExist = this.savingsProductDao.activeOrInactiveSavingsAccountsExistForProduct(savingsProductRequest.getProductDetails().getId());
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    SavingsOfferingBO newSavingsDetails = new SavingsProductAssembler(this.loanProductDao, this.savingsProductDao, this.generalLedgerDao).fromDto(user, savingsProductRequest);
    savingsProductForUpdate.updateDetails(userContext);
    HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
    try {
        transactionHelper.startTransaction();
        transactionHelper.beginAuditLoggingFor(savingsProductForUpdate);
        if (activeOrInactiveSavingsAccountExist) {
            LocalDate updateDate = new LocalDate();
            savingsProductForUpdate.updateProductDetails(newSavingsDetails.getPrdOfferingName(), newSavingsDetails.getPrdOfferingShortName(), newSavingsDetails.getDescription(), newSavingsDetails.getPrdCategory(), newSavingsDetails.getStartDate(), newSavingsDetails.getEndDate(), newSavingsDetails.getPrdStatus());
            savingsProductForUpdate.updateSavingsDetails(newSavingsDetails.getRecommendedAmount(), newSavingsDetails.getRecommendedAmntUnit(), newSavingsDetails.getMaxAmntWithdrawl(), newSavingsDetails.getInterestRate(), newSavingsDetails.getMinAmntForInt(), updateDate);
        } else {
            savingsProductForUpdate.updateDetailsOfProductNotInUse(newSavingsDetails.getPrdOfferingName(), newSavingsDetails.getPrdOfferingShortName(), newSavingsDetails.getDescription(), newSavingsDetails.getPrdCategory(), newSavingsDetails.getStartDate(), newSavingsDetails.getEndDate(), newSavingsDetails.getPrdApplicableMaster(), newSavingsDetails.getPrdStatus());
            savingsProductForUpdate.updateDetailsOfSavingsProductNotInUse(newSavingsDetails.getSavingsType(), newSavingsDetails.getRecommendedAmount(), newSavingsDetails.getRecommendedAmntUnit(), newSavingsDetails.getMaxAmntWithdrawl(), newSavingsDetails.getInterestRate(), newSavingsDetails.getInterestCalcType(), newSavingsDetails.getTimePerForInstcalc(), newSavingsDetails.getFreqOfPostIntcalc(), newSavingsDetails.getMinAmntForInt());
        }
        this.savingsProductDao.save(savingsProductForUpdate);
        transactionHelper.commitTransaction();
        return savingsProductForUpdate.toDto();
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : HibernateTransactionHelper(org.mifos.framework.hibernate.helper.HibernateTransactionHelper) HibernateTransactionHelperForStaticHibernateUtil(org.mifos.framework.hibernate.helper.HibernateTransactionHelperForStaticHibernateUtil) UserContext(org.mifos.security.util.UserContext) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) LocalDate(org.joda.time.LocalDate) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 29 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class AdminServiceFacadeWebTier method retrieveNotAllowedProductsForMix.

@Override
public List<PrdOfferingDto> retrieveNotAllowedProductsForMix(Integer productTypeId, Integer productId) {
    try {
        List<PrdOfferingDto> notAllowedProductDtos = new ArrayList<PrdOfferingDto>();
        List<PrdOfferingBO> allowedProducts = new PrdOfferingPersistence().getNotAllowedPrdOfferingsForMixProduct(productId.toString(), productTypeId.toString());
        for (PrdOfferingBO product : allowedProducts) {
            notAllowedProductDtos.add(product.toDto());
        }
        return notAllowedProductDtos;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) PrdOfferingBO(org.mifos.accounts.productdefinition.business.PrdOfferingBO) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) PrdOfferingDto(org.mifos.dto.domain.PrdOfferingDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 30 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class AdminServiceFacadeWebTier method updateAcceptedPaymentTypes.

@Override
public void updateAcceptedPaymentTypes(String[] chosenAcceptedFees, String[] chosenAcceptedLoanDisbursements, String[] chosenAcceptedLoanRepayments, String[] chosenAcceptedSavingDeposits, String[] chosenAcceptedSavingWithdrawals) {
    LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
    List<AcceptedPaymentType> deletedPaymentTypeList = new ArrayList<AcceptedPaymentType>();
    List<AcceptedPaymentType> addedPaymentTypeList = new ArrayList<AcceptedPaymentType>();
    List<PaymentTypeDto> allPayments = getAllPaymentTypes(null);
    AcceptedPaymentTypeDto oldAcceptedPaymentTypeDto = retrieveAcceptedPaymentTypes();
    for (int i = 0; i < TrxnTypes.values().length; i++) {
        TrxnTypes transactionType = TrxnTypes.values()[i];
        List<PaymentTypeDto> selectedPaymentTypes = new ArrayList<PaymentTypeDto>();
        List<PaymentTypeDto> outList = null;
        if (transactionType == TrxnTypes.fee) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedFees, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutFeeList();
        } else if (transactionType == TrxnTypes.loan_disbursement) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedLoanDisbursements, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutDisbursementList();
        } else if (transactionType == TrxnTypes.loan_repayment) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedLoanRepayments, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutRepaymentList();
        } else if (transactionType == TrxnTypes.savings_deposit) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedSavingDeposits, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutDepositList();
        } else if (transactionType == TrxnTypes.savings_withdrawal) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedSavingWithdrawals, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutWithdrawalList();
        } else {
            throw new MifosRuntimeException("Unknown account action for accepted payment type " + transactionType.toString());
        }
        process(selectedPaymentTypes, outList, deletedPaymentTypeList, addedPaymentTypeList, persistence, transactionType);
    }
    try {
        if (addedPaymentTypeList.size() > 0) {
            persistence.addAcceptedPaymentTypes(addedPaymentTypeList);
            StaticHibernateUtil.commitTransaction();
        }
        if (deletedPaymentTypeList.size() > 0) {
            persistence.deleteAcceptedPaymentTypes(deletedPaymentTypeList);
            StaticHibernateUtil.commitTransaction();
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AcceptedPaymentType(org.mifos.accounts.acceptedpaymenttype.business.AcceptedPaymentType) TrxnTypes(org.mifos.application.util.helpers.TrxnTypes) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AcceptedPaymentTypeDto(org.mifos.dto.domain.AcceptedPaymentTypeDto) PaymentTypeDto(org.mifos.dto.screen.PaymentTypeDto) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) AcceptedPaymentTypeDto(org.mifos.dto.domain.AcceptedPaymentTypeDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

MifosRuntimeException (org.mifos.core.MifosRuntimeException)305 PersistenceException (org.mifos.framework.exceptions.PersistenceException)136 ArrayList (java.util.ArrayList)102 BusinessRuleException (org.mifos.service.BusinessRuleException)95 UserContext (org.mifos.security.util.UserContext)94 MifosUser (org.mifos.security.MifosUser)87 AccountException (org.mifos.accounts.exceptions.AccountException)79 ServiceException (org.mifos.framework.exceptions.ServiceException)69 ApplicationException (org.mifos.framework.exceptions.ApplicationException)48 LoanBO (org.mifos.accounts.loan.business.LoanBO)41 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)39 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)37 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)36 LocalDate (org.joda.time.LocalDate)35 CustomerBO (org.mifos.customers.business.CustomerBO)29 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)28 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)27 CustomerException (org.mifos.customers.exceptions.CustomerException)27 Money (org.mifos.framework.util.helpers.Money)27 AccountBO (org.mifos.accounts.business.AccountBO)25