Java Code Examples for java.sql.Date#after()

The following examples show how to use java.sql.Date#after() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomerRule.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * This method checks if customer end date is valid: 1. if a new address is being added, customer end date must be a future date
 * 2. if inactivating an address, customer end date must be current or future date
 *
 * @param endDate
 * @param canBeTodaysDateFlag
 * @return True if endDate is valid.
 */
public boolean checkEndDateIsValid(Date endDate, boolean canBeTodaysDateFlag) {
    boolean isValid = true;

    if (ObjectUtils.isNull(endDate)) {
        return isValid;
    }

    Timestamp today = dateTimeService.getCurrentTimestamp();
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());

    // end date must be todays date or future date
    if (canBeTodaysDateFlag) {
        if (endDate.before(today)) {
            isValid = false;
        }
    } // end date must be a future date
    else {
        if (!endDate.after(today)) {
            isValid = false;
        }
    }

    return isValid;
}
 
Example 2
Source File: AccountRule.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * This method checks to see if the account expiration date is today's date or earlier
 *
 * @param newAccount
 * @return fails if the expiration date is null or after today's date
 */
protected boolean checkAccountExpirationDateValidTodayOrEarlier(Account newAccount) {

    // get today's date, with no time component
    Date todaysDate = new Date(getDateTimeService().getCurrentDate().getTime());
    todaysDate.setTime(DateUtils.truncate(todaysDate, Calendar.DAY_OF_MONTH).getTime());
    // TODO: convert this to using Wes' Kuali KfsDateUtils once we're using Date's instead of Timestamp

    // get the expiration date, if any
    Date expirationDate = newAccount.getAccountExpirationDate();
    if (ObjectUtils.isNull(expirationDate)) {
        putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        return false;
    }

    // when closing an account, the account expiration date must be the current date or earlier
    expirationDate.setTime(DateUtils.truncate(expirationDate, Calendar.DAY_OF_MONTH).getTime());
    if (expirationDate.after(todaysDate)) {
        putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        return false;
    }

    return true;
}
 
Example 3
Source File: PerDiemExpense.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Determines if the mileage date for this per diem expense matches the range for the given mileage rate
 * @param mileageRate the mileage rate to check the mileage date against
 * @return true if the mileage date matches, false otherwise
 */
protected boolean isMileageDateWithinMileageRateRange(MileageRate mileageRate) {
    final Date fromDate = mileageRate.getActiveFromDate();
    final Date toDate = mileageRate.getActiveToDate();

    return (KfsDateUtils.isSameDay(fromDate, getMileageDate()) || fromDate.before(getMileageDate())) && (KfsDateUtils.isSameDay(toDate, getMileageDate()) || toDate.after(getMileageDate()));
}
 
Example 4
Source File: MileageRateServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public MileageRate findMileageRateByExpenseTypeCodeAndDate(String expenseTypeCode, Date effectiveDate) {
    for (MileageRate mileageRate : cachingMileageRateService.findAllMileageRates()) {
        if ((KfsDateUtils.isSameDay(effectiveDate, mileageRate.getActiveFromDate()) || effectiveDate.after(mileageRate.getActiveFromDate())) && (KfsDateUtils.isSameDay(effectiveDate, mileageRate.getActiveToDate()) || effectiveDate.before(mileageRate.getActiveToDate())) && mileageRate.getExpenseTypeCode().equals(expenseTypeCode)) {
            return mileageRate;
        }
    }

    return null;
}
 
Example 5
Source File: CGMaintenanceDocumentRuleBase.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Checks to see if the end date is after the begin date
 *
 * @param begin
 * @param end
 * @param propertyName
 * @return true if end is after begin, false otherwise
 */
protected boolean checkEndAfterBegin(Date begin, Date end, String propertyName) {
    boolean success = true;
    if (ObjectUtils.isNotNull(begin) && ObjectUtils.isNotNull(end) && !end.after(begin)) {
        putFieldError(propertyName, KFSKeyConstants.ERROR_ENDING_DATE_NOT_AFTER_BEGIN);
        success = false;
    }
    return success;
}
 
Example 6
Source File: EquipmentLoanOrReturnDocumentRule.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Implementation of the rule that if a document has a valid expect loan date and loan return date, the both dates should come
 * before the 2 years limit.
 *
 * @param equipmentLoanOrReturnDocument the equipmentLoanOrReturn document to be validated
 * @return boolean false if the expect loan date or loan return date is not before the 2 years limit.
 */
protected boolean validateLoanDate(EquipmentLoanOrReturnDocument equipmentLoanOrReturnDocument) {
    boolean valid = true;
    Date loanDate = KfsDateUtils.clearTimeFields(equipmentLoanOrReturnDocument.getLoanDate());
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTime(loanDate);
    cal.add(Calendar.YEAR, 2);
    Date maxDate = new Date(cal.getTime().getTime());

    // Loan can not be before today
    Date loanReturnDate = equipmentLoanOrReturnDocument.getLoanReturnDate();
    if (equipmentLoanOrReturnDocument.isNewLoan() && loanDate.before(KfsDateUtils.clearTimeFields(new java.util.Date()))) {
        GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.LOAN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_LOAN_DATE);
    }

    // expect return date must be >= loan date and within 2 years limit
    Date expectReturnDate = equipmentLoanOrReturnDocument.getExpectedReturnDate();
    if (expectReturnDate != null) {
        KfsDateUtils.clearTimeFields(expectReturnDate);
        if (expectReturnDate.before(loanDate)) {
            valid &= false;
            GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.EXPECTED_RETURN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_EXPECTED_RETURN_DATE);
        }
        if (maxDate.before(expectReturnDate)) {
            valid &= false;
            GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.EXPECTED_RETURN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_EXPECTED_MAX_DATE);
        }
    }

    // loan return date must be >= loan date and within 2 years limit
    if (loanReturnDate != null) {
        KfsDateUtils.clearTimeFields(loanReturnDate);
        if (loanDate.after(loanReturnDate) || maxDate.before(loanReturnDate)) {
            valid &= false;
            GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.LOAN_RETURN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_LOAN_RETURN_DATE);
        }
    }

    return valid;
}
 
Example 7
Source File: CustomValidatorTest.java    From javalite with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRegisterCustomValidator() {

    class FutureBirthValidator extends ValidatorAdapter {
        FutureBirthValidator(){
            setMessage("invalid.dob.message");
        }
        @Override
        public void validate(Model m) {
            Date dob = m.getDate("dob");
            Date now = new java.sql.Date(System.currentTimeMillis());
            if(dob.after(now)){
                m.addValidator(this, "invalid.dob");//add validator to errors with a key
            }
        }
    }

    FutureBirthValidator validator = new FutureBirthValidator();

    Person.addValidator(validator);

    Person p = new Person();

    GregorianCalendar future = new GregorianCalendar();
    future.set(Calendar.YEAR, 3000);//will people still be using Java then... or computers? :)

    p.set("dob", new Date(future.getTimeInMillis()));
    p.validate();
    a(p.errors().size()).shouldBeEqual(3);

    a(p.errors().get("invalid.dob")).shouldBeEqual("date of birth cannot be in future");

    //this is so that other tests succeed
    Person.removeValidator(validator);
}
 
Example 8
Source File: CustomerInvoiceBothEndDateAndTotalRecurrenceNumberValidation.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean validate(AttributedDocumentEvent event) {
    
    // short circuit if no recurrence object at all
    if (ObjectUtils.isNull(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails())) {
        return true;
    }
    
    if (ObjectUtils.isNull(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceBeginDate()) || 
        ObjectUtils.isNull(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceIntervalCode()) ||
        ObjectUtils.isNull(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceEndDate()) ||
        ObjectUtils.isNull(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentTotalRecurrenceNumber())) {
        return true;
    }

    Calendar beginCalendar = Calendar.getInstance();
    beginCalendar.setTime(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceBeginDate());
    Date beginDate = customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceBeginDate();
    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceEndDate());
    Date endDate = customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceEndDate();
    Calendar nextCalendar = Calendar.getInstance();
    Date nextDate = beginDate;
             
    int totalRecurrences = 0;
    int addCounter = 0;
    String intervalCode = customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentRecurrenceIntervalCode();
    if (intervalCode.equals("M")) {
        addCounter = 1;
    }
    if (intervalCode.equals("Q")) {
        addCounter = 3;
    }
    /* perform this loop while begin_date is less than or equal to end_date */
    while (!(beginDate.after(endDate))){
        beginCalendar.setTime(beginDate);
        beginCalendar.add(Calendar.MONTH, addCounter);
        beginDate = KfsDateUtils.convertToSqlDate(beginCalendar.getTime());
        totalRecurrences++;
        nextDate = beginDate;
        nextCalendar.setTime(nextDate);
        nextCalendar.add(Calendar.MONTH, addCounter);
        nextDate = KfsDateUtils.convertToSqlDate(nextCalendar.getTime());
        if (endDate.after(beginDate) && endDate.before(nextDate)) {
            totalRecurrences++;
            break;
        }
    }
    if (totalRecurrences != customerInvoiceDocument.getCustomerInvoiceRecurrenceDetails().getDocumentTotalRecurrenceNumber().intValue()) {
        GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.INVOICE_DOCUMENT_RECURRENCE_END_DATE, ArKeyConstants.ERROR_END_DATE_AND_TOTAL_NUMBER_OF_RECURRENCES_NOT_VALID);
        return false;
    }
    return true;
}
 
Example 9
Source File: InvoiceRecurrencePreRules.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
     * This method calculates the total number of recurrences when a begin date and end date is entered.
     * 
     * @param document the maintenance document
     * @return
     */
    protected boolean setTotalRecurrenceNumberIfEndDateIsEntered(Document document) {

        MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
        InvoiceRecurrence newInvoiceRecurrence = (InvoiceRecurrence) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
        
        if (ObjectUtils.isNull(newInvoiceRecurrence.getDocumentRecurrenceEndDate())) {
            return true;            
        }
        if (ObjectUtils.isNotNull(newInvoiceRecurrence.getDocumentRecurrenceEndDate()) && ObjectUtils.isNotNull(newInvoiceRecurrence.getDocumentTotalRecurrenceNumber())) {
            return true;
        }
        
        Calendar beginCalendar = Calendar.getInstance();
/*
 *      beginCalendar.setTime(new Timestamp(newInvoiceRecurrence.getDocumentRecurrenceBeginDate().getTime()));
 */
        beginCalendar.setTime(newInvoiceRecurrence.getDocumentRecurrenceBeginDate());
        Date beginDate = newInvoiceRecurrence.getDocumentRecurrenceBeginDate();
        Calendar endCalendar = Calendar.getInstance();
/*
 *      endCalendar.setTime(new Timestamp(newInvoiceRecurrence.getDocumentRecurrenceEndDate().getTime()));
 */
        endCalendar.setTime(newInvoiceRecurrence.getDocumentRecurrenceEndDate());
        Date endDate = newInvoiceRecurrence.getDocumentRecurrenceEndDate();
        Calendar nextCalendar = Calendar.getInstance();
        Date nextDate = beginDate;
        
        int totalRecurrences = 0;
        int addCounter = 0;
        String intervalCode = newInvoiceRecurrence.getDocumentRecurrenceIntervalCode();
        if (intervalCode.equals("M")) {
            addCounter = 1;
        }
        if (intervalCode.equals("Q")) {
            addCounter = 3;
        }
        /* perform this loop while begin_date is less than or equal to end_date */
        while (!(beginDate.after(endDate))){
            beginCalendar.setTime(beginDate);
            beginCalendar.add(Calendar.MONTH, addCounter);
            beginDate = KfsDateUtils.convertToSqlDate(beginCalendar.getTime());
            totalRecurrences++;

            nextDate = beginDate;
            nextCalendar.setTime(nextDate);
            nextCalendar.add(Calendar.MONTH, addCounter);
            nextDate = KfsDateUtils.convertToSqlDate(nextCalendar.getTime());
            if (endDate.after(beginDate) && endDate.before(nextDate)) {
                totalRecurrences++;
                break;
            }
        }
        if (totalRecurrences > 0) {
            newInvoiceRecurrence.setDocumentTotalRecurrenceNumber(totalRecurrences);
        }
        return true;
    }
 
Example 10
Source File: InvoiceRecurrenceRule.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This method checks that End Date and Total Recurrence Number are valid when both are entered.
 *
 * @param document the maintenance document
 * @return
 */
protected boolean validateIfBothEndDateAndTotalRecurrenceNumberAreEntered(Date recurrenceBeginDate, Date recurrenceEndDate, Integer totalRecurrenceNumber, String recurrenceIntervalCode) {

    if (ObjectUtils.isNull(recurrenceBeginDate) ||
        ObjectUtils.isNull(recurrenceIntervalCode) ||
        ObjectUtils.isNull(recurrenceEndDate) ||
        ObjectUtils.isNull(totalRecurrenceNumber)) {
        return true;
    }

    Calendar beginCalendar = Calendar.getInstance();
    beginCalendar.setTime(recurrenceBeginDate);
    Date beginDate = recurrenceBeginDate;
    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(recurrenceEndDate);
    Date endDate = recurrenceEndDate;
    Calendar nextCalendar = Calendar.getInstance();
    Date nextDate = beginDate;

    int totalRecurrences = 0;
    int addCounter = 0;
    String intervalCode = recurrenceIntervalCode;
    if (intervalCode.equals("M")) {
        addCounter = 1;
    }
    if (intervalCode.equals("Q")) {
        addCounter = 3;
    }
    /* perform this loop while begin_date is less than or equal to end_date */
    while (!(beginDate.after(endDate))){
        beginCalendar.setTime(beginDate);
        beginCalendar.add(Calendar.MONTH, addCounter);
        beginDate = KfsDateUtils.convertToSqlDate(beginCalendar.getTime());
        totalRecurrences++;

        nextDate = beginDate;
        nextCalendar.setTime(nextDate);
        nextCalendar.add(Calendar.MONTH, addCounter);
        nextDate = KfsDateUtils.convertToSqlDate(nextCalendar.getTime());
        if (endDate.after(beginDate) && endDate.before(nextDate)) {
            totalRecurrences++;
            break;
        }
    }
    if (totalRecurrences != totalRecurrenceNumber.intValue()) {
        putFieldError(ArPropertyConstants.InvoiceRecurrenceFields.INVOICE_RECURRENCE_END_DATE, ArKeyConstants.ERROR_END_DATE_AND_TOTAL_NUMBER_OF_RECURRENCES_NOT_VALID);
        return false;
    }

    return true;
}
 
Example 11
Source File: InvoiceRecurrenceDocumentServiceImpl.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @see org.kuali.kfs.module.ar.document.service.InvoiceRecurrenceService#isValidEndDateAndTotalRecurrenceNumber(Date,Date,int,String)
 */
@Override
public boolean isValidEndDateAndTotalRecurrenceNumber( Date recurrenceBeginDate, Date recurrenceEndDate, Integer totalRecurrenceNumber, String recurrenceIntervalCode ) {

    if (ObjectUtils.isNull(recurrenceBeginDate) ||
        ObjectUtils.isNull(recurrenceIntervalCode) ||
        ObjectUtils.isNull(recurrenceEndDate) ||
        ObjectUtils.isNull(totalRecurrenceNumber)) {
        return true;
    }

    Calendar beginCalendar = Calendar.getInstance();
    beginCalendar.setTime(recurrenceBeginDate);
    Date beginDate = recurrenceBeginDate;
    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(recurrenceEndDate);
    Date endDate = recurrenceEndDate;
    Calendar nextCalendar = Calendar.getInstance();
    Date nextDate = beginDate;

    int totalRecurrences = 0;
    int addCounter = 0;
    String intervalCode = recurrenceIntervalCode;
    if (intervalCode.equals("M")) {
        addCounter = 1;
    }
    if (intervalCode.equals("Q")) {
        addCounter = 3;
    }
    /* perform this loop while begin_date is less than or equal to end_date */
    while (!(beginDate.after(endDate))){
        beginCalendar.setTime(beginDate);
        beginCalendar.add(Calendar.MONTH, addCounter);
        beginDate = KfsDateUtils.convertToSqlDate(beginCalendar.getTime());
        totalRecurrences++;

        nextDate = beginDate;
        nextCalendar.setTime(nextDate);
        nextCalendar.add(Calendar.MONTH, addCounter);
        nextDate = KfsDateUtils.convertToSqlDate(nextCalendar.getTime());
        if (endDate.after(beginDate) && endDate.before(nextDate)) {
            totalRecurrences++;
            break;
        }
    }
    if (totalRecurrences != totalRecurrenceNumber.intValue()) {
        return false;
    }

    return true;
}
 
Example 12
Source File: AccountGlobalRule.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This method checks to see if any expiration date field rules were violated Loops through each detail object and calls
 * {@link AccountGlobalRule#checkExpirationDate(MaintenanceDocument, AccountGlobalDetail)}
 *
 * @param maintenanceDocument
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument) {
    LOG.info("checkExpirationDate called");

    boolean success = true;
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();

    // If creating a new account if acct_expiration_dt is set then
    // the acct_expiration_dt must be changed to a date that is today or later
    // unless the date was valid upon submission, this is an approval action
    // and the approver hasn't changed the value
    if (maintenanceDocument.isNew() && ObjectUtils.isNotNull(newExpDate)) {
        Date oldExpDate = null;

        if (maintenanceDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested()) {
            try {
                MaintenanceDocument oldMaintDoc = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(maintenanceDocument.getDocumentNumber());
                AccountGlobal oldAccountGlobal = (AccountGlobal)oldMaintDoc.getDocumentBusinessObject();
                if (ObjectUtils.isNotNull(oldAccountGlobal)) {
                    oldExpDate = oldAccountGlobal.getAccountExpirationDate();
                }
            }
            catch (WorkflowException ex) {
                LOG.warn( "Error retrieving maintenance doc for doc #" + maintenanceDocument.getDocumentNumber()+ ". This shouldn't happen.", ex );
            }
        }

        if (ObjectUtils.isNull(oldExpDate) || !oldExpDate.equals(newExpDate)) {
            if (!newExpDate.after(today) && !newExpDate.equals(today)) {
                putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                success &= false;
            }
        }
    }


    // a continuation account is required if the expiration date is completed.
    success &= checkContinuationAccount(maintenanceDocument, newExpDate);

    for (AccountGlobalDetail detail : newAccountGlobal.getAccountGlobalDetails()) {
        success &= checkExpirationDate(maintenanceDocument, detail);
    }
    return success;
}
 
Example 13
Source File: AccountGlobalRule.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This method checks to see if any expiration date field rules were violated in relation to the given detail record
 *
 * @param maintenanceDocument
 * @param detail - the account detail we are investigating
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument, AccountGlobalDetail detail) {
    boolean success = true;
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();

    Date prevExpDate = null;

    // get previous expiration date for possible check later
    if (maintenanceDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested()) {
        try {
            MaintenanceDocument oldMaintDoc = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(maintenanceDocument.getDocumentNumber());
            AccountGlobal oldAccountGlobal = (AccountGlobal)oldMaintDoc.getDocumentBusinessObject();
            if (ObjectUtils.isNotNull(oldAccountGlobal)) {
                prevExpDate = oldAccountGlobal.getAccountExpirationDate();
            }
        }
        catch (WorkflowException ex) {
            LOG.warn( "Error retrieving maintenance doc for doc #" + maintenanceDocument.getDocumentNumber()+ ". This shouldn't happen.", ex );
        }
    }


    // load the object by keys
    Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, detail.getPrimaryKeys());
    if (ObjectUtils.isNotNull(account)) {
        Date oldExpDate = account.getAccountExpirationDate();

        // When updating an account expiration date, the date must be today or later
        // (except for C&G accounts). Only run this test if this maint doc
        // is an edit doc
        if (isUpdatedExpirationDateInvalid(account, newAccountGlobal)) {
            // if the date was valid upon submission, and this is an approval,
            // we're not interested unless the approver changed the value
            if (ObjectUtils.isNull(prevExpDate) || !prevExpDate.equals(newExpDate)) {
                putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                success &= false;
            }
        }

        // If creating a new account if acct_expiration_dt is set and the fund_group is not "CG" then
        // the acct_expiration_dt must be changed to a date that is today or later
        // unless the date was valid upon submission, this is an approval action
        // and the approver hasn't changed the value
        if (maintenanceDocument.isNew() && ObjectUtils.isNotNull(newExpDate)) {
            if (ObjectUtils.isNull(prevExpDate) || !prevExpDate.equals(newExpDate)) {
                if (ObjectUtils.isNotNull(newExpDate) && ObjectUtils.isNull(newAccountGlobal.getSubFundGroup())) {
                    if (ObjectUtils.isNotNull(account.getSubFundGroup())) {
                        if (!account.isForContractsAndGrants()) {
                            if (!newExpDate.after(today) && !newExpDate.equals(today)) {
                                putGlobalError(KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                                success &= false;
                            }
                        }
                    }
                }
            }
        }

        // acct_expiration_dt can not be before acct_effect_dt
        Date effectiveDate = account.getAccountEffectiveDate();
        if (ObjectUtils.isNotNull(effectiveDate) && ObjectUtils.isNotNull(newExpDate)) {
            if (newExpDate.before(effectiveDate)) {
                putGlobalError(KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_CANNOT_BE_BEFORE_EFFECTIVE_DATE);
                success &= false;
            }
        }
    }

    return success;
}
 
Example 14
Source File: AccountGlobalRule.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This method checks to see if the updated expiration is not a valid one Only gets checked for specific {@link SubFundGroup}s
 *
 * @param oldAccount
 * @param newAccountGlobal
 * @return true if date has changed and is invalid
 */
protected boolean isUpdatedExpirationDateInvalid(Account oldAccount, AccountGlobal newAccountGlobal) {

    Date oldExpDate = oldAccount.getAccountExpirationDate();
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();

    // When updating an account expiration date, the date must be today or later
    // (except for C&G accounts). Only run this test if this maint doc
    // is an edit doc
    boolean expDateHasChanged = false;

    // if the old version of the account had no expiration date, and the new
    // one has a date
    if (ObjectUtils.isNull(oldExpDate) && ObjectUtils.isNotNull(newExpDate)) {
        expDateHasChanged = true;
    }

    // if there was an old and a new expDate, but they're different
    else if (ObjectUtils.isNotNull(oldExpDate) && ObjectUtils.isNotNull(newExpDate)) {
        if (!oldExpDate.equals(newExpDate)) {
            expDateHasChanged = true;
        }
    }

    // if the expiration date hasnt changed, we're not interested
    if (!expDateHasChanged) {
        return false;
    }

    // if a subFundGroup isnt present, we cannot continue the testing
    SubFundGroup subFundGroup = newAccountGlobal.getSubFundGroup();
    if (ObjectUtils.isNull(subFundGroup)) {
        return false;
    }

    // get the fundGroup code
    String fundGroupCode = newAccountGlobal.getSubFundGroup().getFundGroupCode().trim();

    // if the account is part of the CG fund group, then this rule does not
    // apply, so we're done
    if (SpringContext.getBean(SubFundGroupService.class).isForContractsAndGrants(newAccountGlobal.getSubFundGroup())) {
        return false;
    }

    // at this point, we know its not a CG fund group, so we must apply the rule

    // expirationDate must be today or later than today (cannot be before today)
    if (newExpDate.equals(today) || newExpDate.after(today)) {
        return false;
    }
    else {
        return true;
    }
}
 
Example 15
Source File: DisbursementVoucherDocument.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Convenience method to set dv payee detail fields based on a given vendor.
 *
 * @param vendor
 */
public void templateVendor(VendorDetail vendor, VendorAddress vendorAddress) {
    if (vendor == null) {
        return;
    }

    this.getDvPayeeDetail().setDisbursementVoucherPayeeTypeCode(KFSConstants.PaymentPayeeTypes.VENDOR);
    this.getDvPayeeDetail().setDisbVchrPayeeIdNumber(vendor.getVendorNumber());
    this.getDvPayeeDetail().setDisbVchrPayeePersonName(vendor.getVendorName());

    this.getDvPayeeDetail().setDisbVchrAlienPaymentCode(vendor.getVendorHeader().getVendorForeignIndicator());


    if (ObjectUtils.isNotNull(vendorAddress) && ObjectUtils.isNotNull(vendorAddress.getVendorAddressGeneratedIdentifier())) {
        this.getDvPayeeDetail().setDisbVchrVendorAddressIdNumber(vendorAddress.getVendorAddressGeneratedIdentifier().toString());
        this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr(vendorAddress.getVendorLine1Address());
        this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr(vendorAddress.getVendorLine2Address());
        this.getDvPayeeDetail().setDisbVchrPayeeCityName(vendorAddress.getVendorCityName());
        this.getDvPayeeDetail().setDisbVchrPayeeStateCode(vendorAddress.getVendorStateCode());
        this.getDvPayeeDetail().setDisbVchrPayeeZipCode(vendorAddress.getVendorZipCode());
        this.getDvPayeeDetail().setDisbVchrPayeeCountryCode(vendorAddress.getVendorCountryCode());
    }
    else {
        this.getDvPayeeDetail().setDisbVchrVendorAddressIdNumber(StringUtils.EMPTY);
        this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr(StringUtils.EMPTY);
        this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr(StringUtils.EMPTY);
        this.getDvPayeeDetail().setDisbVchrPayeeCityName(StringUtils.EMPTY);
        this.getDvPayeeDetail().setDisbVchrPayeeStateCode(StringUtils.EMPTY);
        this.getDvPayeeDetail().setDisbVchrPayeeZipCode(StringUtils.EMPTY);
        this.getDvPayeeDetail().setDisbVchrPayeeCountryCode(StringUtils.EMPTY);
    }

    this.getDvPayeeDetail().setDisbVchrAlienPaymentCode(vendor.getVendorHeader().getVendorForeignIndicator());
    this.getDvPayeeDetail().setDvPayeeSubjectPaymentCode(VendorConstants.VendorTypes.SUBJECT_PAYMENT.equals(vendor.getVendorHeader().getVendorTypeCode()));
    this.getDvPayeeDetail().setDisbVchrEmployeePaidOutsidePayrollCode(getVendorService().isVendorInstitutionEmployee(vendor.getVendorHeaderGeneratedIdentifier()));

    this.getDvPayeeDetail().setHasMultipleVendorAddresses(1 < vendor.getVendorAddresses().size());

    boolean w9AndW8Checked = false;
    if ( (ObjectUtils.isNotNull(vendor.getVendorHeader().getVendorW9ReceivedIndicator()) && vendor.getVendorHeader().getVendorW9ReceivedIndicator() == true) ||
         (ObjectUtils.isNotNull(vendor.getVendorHeader().getVendorW8BenReceivedIndicator()) && vendor.getVendorHeader().getVendorW8BenReceivedIndicator() == true) ) {

        w9AndW8Checked = true;
    }

//    this.disbVchrPayeeW9CompleteCode = vendor.getVendorHeader().getVendorW8BenReceivedIndicator()  == null ? false : vendor.getVendorHeader().getVendorW8BenReceivedIndicator();
    this.disbVchrPayeeW9CompleteCode = w9AndW8Checked;

    Date vendorFederalWithholdingTaxBeginDate = vendor.getVendorHeader().getVendorFederalWithholdingTaxBeginningDate();
    Date vendorFederalWithholdingTaxEndDate = vendor.getVendorHeader().getVendorFederalWithholdingTaxEndDate();
    java.util.Date today = getDateTimeService().getCurrentDate();
    if ((vendorFederalWithholdingTaxBeginDate != null && vendorFederalWithholdingTaxBeginDate.before(today)) && (vendorFederalWithholdingTaxEndDate == null || vendorFederalWithholdingTaxEndDate.after(today))) {
        this.disbVchrPayeeTaxControlCode = DisbursementVoucherConstants.TAX_CONTROL_CODE_BEGIN_WITHHOLDING;
    }

    // if vendor is foreign, default alien payment code to true
    if (getVendorService().isVendorForeign(vendor.getVendorHeaderGeneratedIdentifier())) {
        getDvPayeeDetail().setDisbVchrAlienPaymentCode(true);
    }
}