Example usage for java.sql Date compareTo

List of usage examples for java.sql Date compareTo

Introduction

In this page you can find the example usage for java.sql Date compareTo.

Prototype

public int compareTo(Date anotherDate) 

Source Link

Document

Compares two Dates for ordering.

Usage

From source file:org.kuali.ole.vnd.document.service.impl.VendorServiceImpl.java

/**
 * @see org.kuali.kfs.vnd.document.service.VendorService#isVendorContractExpired(org.kuali.kfs.vnd.businessobject.VendorDetail)
 *//*  w w w  .ja va 2s . co  m*/
@Override
public boolean isVendorContractExpired(Document document, VendorDetail vendorDetail) {
    boolean isExpired = false;

    Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();

    List<VendorContract> vendorContracts = vendorDetail.getVendorContracts();
    List<Note> notes = document.getNotes();

    for (VendorContract vendorContract : vendorContracts) {
        if (currentDate.compareTo(vendorContract.getVendorContractEndDate()) > 0
                || !vendorContract.isActive()) {
            Note newNote = new Note();
            newNote.setNoteText("Vendor Contract: " + vendorContract.getVendorContractName()
                    + " contract has expired contract end date.");
            newNote.setNotePostedTimestampToCurrent();
            newNote.setNoteTypeCode(OLEConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
            Note note = noteService.createNote(newNote, vendorDetail,
                    GlobalVariables.getUserSession().getPrincipalId());
            notes.add(note);
            return true;
        }
    }

    return isExpired;
}

From source file:org.mifos.accounting.struts.actionform.GeneralLedgerActionForm.java

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 {/* w  w  w  .  j  av  a  2  s. c om*/
        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 (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;
}

From source file:org.mifos.accounting.struts.actionform.JournalVoucherActionForm.java

private ActionErrors mandatoryCheck(UserContext userContext) {
    Locale locale = userContext.getPreferredLocale();
    ResourceBundle resources = ResourceBundle.getBundle(FilePaths.SIMPLE_ACCOUNTING_RESOURCE, locale);

    String voucher_date = resources.getString(SimpleAccountingConstants.VOUCHERDATE);
    String office_Hierarchy = resources.getString(SimpleAccountingConstants.OFFICE_HIERARCHY);
    String officeId = resources.getString(SimpleAccountingConstants.OFFICE);
    String main_Account = resources.getString(SimpleAccountingConstants.DEBIT_ACCOUNT);
    String subAccount = resources.getString(SimpleAccountingConstants.CREDIT_ACCOUNT);
    String Amount = resources.getString(SimpleAccountingConstants.AMOUNT);
    String Notes = resources.getString(SimpleAccountingConstants.VOUCHER_NOTES);

    ActionErrors errors = new ActionErrors();
    java.sql.Date currentDate = null;
    try {/*from   www  .  jav  a  2s .  com*/
        currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(),
                DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    } catch (InvalidDateException ide) {
        errors.add(SimpleAccountingConstants.INVALIDDATE,
                new ActionMessage(SimpleAccountingConstants.INVALIDDATE));
    }

    java.sql.Date voucherDate = null;

    if (getVoucherDate() == null || "".equals(getVoucherDate())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER,
                new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, voucher_date));
    } else if (getVoucherDate() != null && !getVoucherDate().equals("")
            && !DateUtils.isValidDate(getVoucherDate())) {
        errors = voucherDateValidate(errors, locale);
    } else if (DateUtils.isValidDate(getVoucherDate())) {
        try {
            voucherDate = DateUtils.getDateAsSentFromBrowser(getVoucherDate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
                    new ActionMessage(SimpleAccountingConstants.INVALIDDATE, voucher_date));
        }
        if (voucherDate.compareTo(currentDate) > 0) {
            errors.add(SimpleAccountingConstants.INVALID_FUTURE,
                    new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, voucher_date));
        }

    }

    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 (debitAccountHead == null || "".equals(debitAccountHead.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
                new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, main_Account));
    }

    if (creditAccountHead == null || "".equals(creditAccountHead.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 (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 (voucherNotes == null || "".equals(voucherNotes.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
                new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Notes));
    }

    return errors;
}

From source file:org.mifos.accounting.struts.actionform.MultipleGeneralLedgerActionForm.java

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 {// w  ww  .j a v  a  2 s.c  om
        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));
    }*/
    String[] amounts123 = getAmount1();
    String[] accountHead123 = getAccountHead1();
    String[] notes123 = getNotes1();
    for (int i = 0; i < amounts123.length; i++) {
        double amoun = Double.parseDouble(amounts123[i]);
        //String accounthead=accountHead123[i];
        if (amoun == 0) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
                    new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Amount));
        }

        if (accountHead123[i].isEmpty()) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
                    new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, subAccount));
        }

    }

    /*if (amount == null || "".equals(amount.trim())) {
       errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
       new ActionMessage(
             SimpleAccountingConstants.MANDATORYFIELDS, Amount));
    }*/
    //memberId == null || "".equals(memberId.trim())||
    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;
}

From source file:org.mifos.accounting.struts.actionform.ProcessAccountingTransactionsActionForm.java

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 {/*from  ww  w . j av  a2  s.c o  m*/
        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;
}

From source file:org.mifos.accounting.struts.actionform.SingleGeneralLedgerActionForm.java

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 {/*  w  w  w. j  a v a2 s.  com*/
        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));
    }
    //memberId == null || "".equals(memberId.trim())||

    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;
}

From source file:org.mifos.accounting.struts.actionform.ViewGlTransactionsActionForm.java

private ActionErrors mandatoryCheck(UserContext userContext) {
    Locale locale = userContext.getPreferredLocale();
    ResourceBundle resources = ResourceBundle.getBundle(FilePaths.SIMPLE_ACCOUNTING_RESOURCE, locale);

    String to_Trxn_Date = resources.getString(SimpleAccountingConstants.TO_TRXNDATE);
    String from_Trxn_Date = resources.getString(SimpleAccountingConstants.FROM_TRXNDATE);

    ActionErrors errors = new ActionErrors();
    java.sql.Date currentDate = null;
    try {//from   w  ww  .jav a 2  s.c om
        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 (getToTrxnDate() == null || "".equals(getToTrxnDate())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER,
                new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, to_Trxn_Date));
    } else if (getToTrxnDate() != null && !getToTrxnDate().equals("")
            && !DateUtils.isValidDate(getToTrxnDate())) {
        errors = toTrxnDateValidate(errors, locale);
    } else if (DateUtils.isValidDate(getToTrxnDate())) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getToTrxnDate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
                    new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, to_Trxn_Date));
        }
        if (trxnDate.compareTo(currentDate) > 0) {
            errors.add(SimpleAccountingConstants.INVALID_FUTURE,
                    new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, to_Trxn_Date));
        }
    }

    if (getFromTrxnDate() == null || "".equals(getFromTrxnDate())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER,
                new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, from_Trxn_Date));
    } else if (getFromTrxnDate() != null && !getFromTrxnDate().equals("")
            && !DateUtils.isValidDate(getFromTrxnDate())) {
        errors = fromTrxnDateValidate(errors, locale);
    } else if (DateUtils.isValidDate(getFromTrxnDate())) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getFromTrxnDate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS,
                    new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, from_Trxn_Date));
        }
        if (trxnDate.compareTo(currentDate) > 0) {
            errors.add(SimpleAccountingConstants.INVALID_FUTURE,
                    new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, from_Trxn_Date));
        }
    }

    return errors;
}

From source file:org.mifos.accounts.productdefinition.struts.actionforms.LoanPrdActionForm.java

private void validateEndDate(HttpServletRequest request, ActionErrors errors) {
    logger.debug(// w ww.ja  v  a 2 s  .c o  m
            "start validateEndDate method of Loan Product Action form method :" + startDate + "---" + endDate);
    Date startingDate = null;
    Date endingDate = null;
    try {
        startingDate = getStartDateValue(getUserContext(request).getPreferredLocale());
    } catch (InvalidDateException ide) {
        addError(errors, "startDate", ProductDefinitionConstants.INVALIDSTARTDATE);
    }
    try {
        endingDate = getEndDateValue(getUserContext(request).getPreferredLocale());
    } catch (InvalidDateException ide) {
        addError(errors, "endDate", ProductDefinitionConstants.INVALIDENDDATE);
    }
    if (startingDate != null && endingDate != null && startingDate.compareTo(endingDate) >= 0) {
        addError(errors, "endDate", ProductDefinitionConstants.INVALIDENDDATE);
    }
    logger.debug(
            "validateEndDate method of Loan Product Action form method called :" + startDate + "---" + endDate);
}

From source file:org.mifos.accounts.productdefinition.struts.actionforms.SavingsPrdActionForm.java

private void checkPreviewValidation(ActionErrors errors, HttpServletRequest request)
        throws ApplicationException {
    Date startingDate = getStartDateValue(getUserContext(request).getPreferredLocale());
    Date endingDate = getEndDateValue(getUserContext(request).getPreferredLocale());
    //validate start date
    if (startingDate != null && ((DateUtils.getDateWithoutTimeStamp(startingDate.getTime())
            .compareTo(DateUtils.getCurrentDateWithoutTimeStamp()) < 0)
            || (DateUtils.getDateWithoutTimeStamp(startingDate.getTime())
                    .compareTo(DateUtils.getCurrentDateOfNextYearWithOutTimeStamp()) > 0))) {
        addError(errors, "startDate", ProductDefinitionConstants.INVALIDSTARTDATE);
    }/*from  w  w w .  ja  va2s  .c  om*/
    //validate end date
    if (startingDate != null && endingDate != null && startingDate.compareTo(endingDate) >= 0) {
        addError(errors, "endDate", ProductDefinitionConstants.INVALIDENDDATE);
    }

    validateRecommendedAmount(errors, request);
    validateMaxAmntWithdrawl(errors, request);
    validateInterestRate(errors, request);
    validateMinAmntForInt(errors, request);
    validateInterestGLCode(request, errors);
}

From source file:org.mifos.application.collectionsheet.struts.actionforms.BulkEntryActionForm.java

private ActionErrors mandatoryCheck(Date meetingDate, UserContext userContext, short isCenterHierarchyExists) {
    Locale locale = userContext.getPreferredLocale();
    ResourceBundle resources = ResourceBundle.getBundle(FilePaths.BULKENTRY_RESOURCE, locale);
    String loanOfficer = resources.getString(CollectionSheetEntryConstants.LOANOFFICERS);
    String modeOfPayment = resources.getString(CollectionSheetEntryConstants.MODE_OF_PAYMENT);
    String dateOfTransaction = resources.getString(CollectionSheetEntryConstants.DATEOFTRXN);
    ActionErrors errors = receiptDateValidate(new ActionErrors(), locale);
    java.sql.Date currentDate = null;
    try {//from  w w w  .  ja  v a2 s .  co  m
        currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(),
                DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    } catch (InvalidDateException ide) {
        errors.add(CollectionSheetEntryConstants.INVALIDDATE,
                new ActionMessage(CollectionSheetEntryConstants.INVALIDDATE));
    }

    java.sql.Date trxnDate = null;
    String customerLabel = isCenterHierarchyExists == Constants.YES ? ConfigurationConstants.CENTER
            : ConfigurationConstants.GROUP;

    if (officeId == null || "".equals(officeId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS,
                        getMessageText(ConfigurationConstants.BRANCHOFFICE)));
    }

    if (loanOfficerId == null || "".equals(loanOfficerId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS, loanOfficer));
    }

    if (customerId == null || "".equals(customerId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS, getLabel(customerLabel)));
    }

    if (getTransactionDate() != null && !getTransactionDate().equals("")) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getTransactionDate());
        } catch (InvalidDateException ide) {
            errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                    new ActionMessage(AccountConstants.ERROR_INVALID_TRXN));
        }
    } else {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                new ActionMessage(CollectionSheetEntryConstants.MANDATORYENTER, dateOfTransaction));
    }

    if (currentDate != null && meetingDate != null && trxnDate != null
            && (meetingDate.compareTo(trxnDate) > 0 || trxnDate.compareTo(currentDate) > 0)) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                new ActionMessage(CollectionSheetEntryConstants.INVALIDENDDATE, dateOfTransaction));
    } else if (meetingDate == null && trxnDate != null && trxnDate.compareTo(currentDate) != 0) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                new ActionMessage(CollectionSheetEntryConstants.MEETINGDATEEXCEPTION, dateOfTransaction));
    }

    if (paymentId == null || "".equals(paymentId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS,
                new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS, modeOfPayment));
    }

    return errors;
}