Search in sources :

Example 16 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class ProcessAccountingTransactionsActionForm method mandatoryCheck.

private ActionErrors mandatoryCheck(UserContext userContext) {
    Locale locale = userContext.getPreferredLocale();
    ResourceBundle resources = ResourceBundle.getBundle(FilePaths.SIMPLE_ACCOUNTING_RESOURCE, locale);
    String last_process_date = resources.getString(SimpleAccountingConstants.LASTPROCESSDATE);
    String process_till_date = resources.getString(SimpleAccountingConstants.PROCESSTILLDATE);
    String groupBy = resources.getString(SimpleAccountingConstants.GROUPBY);
    ActionErrors errors = new ActionErrors();
    java.sql.Date currentDate = null;
    try {
        currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    } catch (InvalidDateException ide) {
        errors.add(SimpleAccountingConstants.INVALIDDATE, new ActionMessage(SimpleAccountingConstants.INVALIDDATE));
    }
    java.sql.Date trxnDate = null;
    if (getProcessTillDate() == null || "".equals(getProcessTillDate())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, process_till_date));
    } else if (getProcessTillDate() != null && !getProcessTillDate().equals("") && !DateUtils.isValidDate(getProcessTillDate())) {
        errors = processTillDateValidate(errors, locale);
    } else if (DateUtils.isValidDate(getProcessTillDate())) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getProcessTillDate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, process_till_date));
        }
        if (trxnDate.compareTo(currentDate) > 0) {
            errors.add(SimpleAccountingConstants.INVALID_FUTURE, new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, process_till_date));
        }
    } else if (DateUtils.isValidDate(getProcessTillDate())) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getProcessTillDate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, process_till_date));
        }
        if (trxnDate.compareTo(currentDate) < 0 && trxnDate.compareTo(DateUtils.getDate(getLastProcessDate())) < 0) {
            errors.add(SimpleAccountingConstants.INVALID_PAST, new ActionMessage(SimpleAccountingConstants.INVALID_PAST, process_till_date, last_process_date));
        }
    }
    if (groupBy == null || "".equals(groupBy.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, groupBy));
    }
    if (getLastProcessDate() == null) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, last_process_date));
    }
    if (getLastProcessDate() != null && !getLastProcessDate().equals("") && !DateUtils.isValidDate(getLastProcessDate()))
        errors = lastProcessDateValidate(errors, locale);
    return errors;
}
Also used : Locale(java.util.Locale) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) ResourceBundle(java.util.ResourceBundle) ActionErrors(org.apache.struts.action.ActionErrors)

Example 17 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class SingleGeneralLedgerActionForm method mandatoryCheck.

private ActionErrors mandatoryCheck(UserContext userContext) {
    Locale locale = userContext.getPreferredLocale();
    ResourceBundle resources = ResourceBundle.getBundle(FilePaths.SIMPLE_ACCOUNTING_RESOURCE, locale);
    String trxn_Date = resources.getString(SimpleAccountingConstants.TRXNDATE);
    String trxn_Type = resources.getString(SimpleAccountingConstants.TRXNTYPE);
    String office_Hierarchy = resources.getString(SimpleAccountingConstants.OFFICE_HIERARCHY);
    String officeId = resources.getString(SimpleAccountingConstants.OFFICE);
    String main_Account = resources.getString(SimpleAccountingConstants.MAIN_ACCOUNT);
    String subAccount = resources.getString(SimpleAccountingConstants.ACCOUNT_HEAD);
    String Amount = resources.getString(SimpleAccountingConstants.AMOUNT);
    String Notes = resources.getString(SimpleAccountingConstants.TRXN_NOTES);
    ActionErrors errors = new ActionErrors();
    java.sql.Date currentDate = null;
    try {
        currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    } catch (InvalidDateException ide) {
        errors.add(SimpleAccountingConstants.INVALIDDATE, new ActionMessage(SimpleAccountingConstants.INVALIDDATE));
    }
    java.sql.Date trxnDate = null;
    if (getTrxnDate() == null || "".equals(getTrxnDate())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, trxn_Date));
    } else if (getTrxnDate() != null && !getTrxnDate().equals("") && !DateUtils.isValidDate(getTrxnDate())) {
        errors = trxnDateValidate(errors, locale);
    } else if (DateUtils.isValidDate(getTrxnDate())) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getTrxnDate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, trxn_Date));
        }
        if (trxnDate.compareTo(currentDate) > 0) {
            errors.add(SimpleAccountingConstants.INVALID_FUTURE, new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, trxn_Date));
        }
    }
    if (trxnType == null || "".equals(trxnType.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, trxn_Type));
    }
    if (officeHierarchy == null || "".equals(officeHierarchy.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, office_Hierarchy));
    }
    if (office == null || "".equals(office.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, officeId));
    }
    if (mainAccount == null || "".equals(mainAccount.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, main_Account));
    }
    if (accountHead == null || "".equals(accountHead.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, subAccount));
    }
    if (amount == null || "".equals(amount.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Amount));
    }
    if (memberId.length() != 10 && memberId.length() > 0) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.ENTER_GRETERTHAN, memberId));
    }
    if (StringUtils.isNotBlank(getAmount())) {
        DoubleConversionResult conversionResult = validateAmount(getAmount(), Amount, errors);
        if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
            addError(errors, SimpleAccountingConstants.AMOUNT, SimpleAccountingConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, Amount);
        }
    }
    if (notes == null || "".equals(notes.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Notes));
    }
    if (getChequeDate() != null && !getChequeDate().equals("") && !DateUtils.isValidDate(getChequeDate()))
        errors = chequeDateValidate(errors, locale);
    return errors;
}
Also used : Locale(java.util.Locale) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) ResourceBundle(java.util.ResourceBundle) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) ActionErrors(org.apache.struts.action.ActionErrors)

Example 18 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException 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 19 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class ClientBO method updatePersonalInfo.

public void updatePersonalInfo(ClientPersonalInfoUpdate personalInfo) throws CustomerException {
    this.governmentId = personalInfo.getGovernmentId();
    try {
        setDateOfBirth(DateUtils.getDateAsSentFromBrowser(personalInfo.getDateOfBirth()));
    } catch (InvalidDateException e) {
        throw new CustomerException(ClientConstants.INVALID_DOB_EXCEPTION);
    }
    ClientNameDetailDto clientName = personalInfo.getClientNameDetails();
    this.getClientName().updateNameDetails(clientName);
    this.firstName = clientName.getFirstName();
    this.lastName = clientName.getLastName();
    this.secondLastName = clientName.getSecondLastName();
    if (personalInfo.getSpouseFather() != null) {
        // can be null when family details configuration is turned on
        if (this.getSpouseName() != null) {
            this.getSpouseName().updateNameDetails(personalInfo.getSpouseFather());
        } else {
            ClientNameDetailEntity spouseFatherNameDetailEntity = new ClientNameDetailEntity(this, personalInfo.getSpouseFather().getSecondLastName(), personalInfo.getSpouseFather());
            addNameDetailSet(spouseFatherNameDetailEntity);
        }
    }
    this.updateClientDetails(personalInfo.getClientDetail());
    setDisplayName(personalInfo.getClientDisplayName());
    Address address = null;
    if (personalInfo.getAddress() != null) {
        ;
    }
    {
        address = new Address(personalInfo.getAddress().getLine1(), personalInfo.getAddress().getLine2(), personalInfo.getAddress().getLine3(), personalInfo.getAddress().getCity(), personalInfo.getAddress().getState(), personalInfo.getAddress().getCountry(), personalInfo.getAddress().getZip(), personalInfo.getAddress().getPhoneNumber());
        updateAddress(address);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) Address(org.mifos.framework.business.util.Address) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto)

Example 20 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class GroupServiceFacadeWebTier method retrieveCustomerHistoricalData.

@Override
public CustomerHistoricalDataDto retrieveCustomerHistoricalData(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customer = this.customerDao.findCustomerBySystemId(globalCustNum);
    boolean client = false;
    boolean group = false;
    if (customer.isClient()) {
        client = true;
    } else if (customer.isGroup()) {
        group = true;
    }
    CustomerHistoricalDataEntity customerHistoricalDataEntity = customer.getHistoricalData();
    if (customerHistoricalDataEntity == null) {
        customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customer);
    }
    try {
        String currentDate = DateUtils.getCurrentDate(userContext.getPreferredLocale());
        java.sql.Date mfiJoiningDate = null;
        if (customerHistoricalDataEntity.getMfiJoiningDate() == null) {
            mfiJoiningDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), currentDate);
        } else {
            mfiJoiningDate = new Date(customerHistoricalDataEntity.getMfiJoiningDate().getTime());
        }
        return new CustomerHistoricalDataDto(client, group, mfiJoiningDate);
    } catch (InvalidDateException e) {
        throw new BusinessRuleException(e.getMessage(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerHistoricalDataDto(org.mifos.dto.screen.CustomerHistoricalDataDto) UserContext(org.mifos.security.util.UserContext) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) Date(java.sql.Date) Date(java.sql.Date)

Aggregations

InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)46 ActionMessage (org.apache.struts.action.ActionMessage)22 ActionErrors (org.apache.struts.action.ActionErrors)20 Locale (java.util.Locale)12 Date (java.sql.Date)9 ResourceBundle (java.util.ResourceBundle)9 PersistenceException (org.mifos.framework.exceptions.PersistenceException)6 Date (java.util.Date)5 AccountException (org.mifos.accounts.exceptions.AccountException)5 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)5 SimpleDateFormat (java.text.SimpleDateFormat)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 CustomerException (org.mifos.customers.exceptions.CustomerException)4 ParseException (java.text.ParseException)3 LocalDate (org.joda.time.LocalDate)3 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)3 BusinessRuleException (org.mifos.service.BusinessRuleException)3 ArrayList (java.util.ArrayList)2 DateMidnight (org.joda.time.DateMidnight)2 DateTime (org.joda.time.DateTime)2