Example usage for java.sql Date before

List of usage examples for java.sql Date before

Introduction

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

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:org.kuali.kfs.module.ar.document.service.impl.ContractsGrantsBillingAwardVerificationServiceImpl.java

/**
 * @see org.kuali.kfs.module.ar.document.service.ContractsGrantsInvoiceDocumentService#hasNoBillsToInvoice(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)
 *//*  w  w w. j ava 2s  .c o m*/
@Override
public boolean hasBillsToInvoice(ContractsAndGrantsBillingAward award) {
    boolean hasBillsToInvoice = true;
    if (award.getBillingFrequencyCode().equalsIgnoreCase(ArConstants.PREDETERMINED_BILLING_SCHEDULE_CODE)) {

        List<Bill> bills = new ArrayList<Bill>();
        List<Bill> validBills = new ArrayList<Bill>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(KFSPropertyConstants.PROPOSAL_NUMBER, award.getProposalNumber());
        map.put(KFSPropertyConstants.ACTIVE, true);

        bills = (List<Bill>) businessObjectService.findMatching(Bill.class, map);
        // To retrieve the previous period end Date to check for milestones and billing schedule.

        Timestamp ts = new Timestamp(new java.util.Date().getTime());
        java.sql.Date today = new java.sql.Date(ts.getTime());
        AccountingPeriod currPeriod = accountingPeriodService.getByDate(today);
        java.sql.Date[] pair = verifyBillingFrequencyService
                .getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod);
        java.sql.Date invoiceDate = pair[1];

        for (Bill awdBill : bills) {
            if (awdBill.getBillDate() != null && !invoiceDate.before(awdBill.getBillDate())
                    && !awdBill.isBilled() && awdBill.getEstimatedAmount().isGreaterThan(KualiDecimal.ZERO)) {
                validBills.add(awdBill);
            }
        }
        if (CollectionUtils.isEmpty(validBills)) {
            hasBillsToInvoice = false;
        }
    }
    return hasBillsToInvoice;
}

From source file:org.kuali.kfs.module.ar.document.service.impl.InvoiceRecurrenceDocumentServiceImpl.java

/**
 * @see org.kuali.kfs.module.ar.document.service.InvoiceRecurrenceService#isValidEndDateAndTotalRecurrenceNumber(Date,Date,int,String)
 *//*from   www  .  j  a v a2  s .c om*/
@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;
}

From source file:org.kuali.kfs.module.ar.document.validation.impl.CustomerRule.java

/**
 * 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//  www . j  a  va2 s . c  om
 * @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;
}

From source file:org.kuali.kfs.module.ar.document.validation.impl.InvoiceRecurrenceRule.java

/**
 * This method checks that End Date and Total Recurrence Number are valid when both are entered.
 *
 * @param document the maintenance document
 * @return//w w w .  j a  v a2 s .  co  m
 */
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;
}

From source file:org.kuali.kfs.module.ar.service.impl.ContractsGrantsInvoiceCreateDocumentServiceImpl.java

/**
 * Generates InvoiceBills for each of the given Bills
 * @param bills the bulls to associate with a contracts & grants billing invoice
 * @param invoiceDate the date of the invoice we're building
 * @return the List of generated InvoiceBill objects
 *//* w  ww. ja  va  2 s .  c  o  m*/
protected List<InvoiceBill> buildInvoiceBills(List<Bill> bills, java.sql.Date invoiceDate) {
    List<InvoiceBill> invoiceBills = new ArrayList<>();
    for (Bill awdBill : bills) {
        // To check for null - Bill Completion date.
        // To consider the completed milestones only.
        if (awdBill.getBillDate() != null && !invoiceDate.before(awdBill.getBillDate()) && !awdBill.isBilled()
                && awdBill.getEstimatedAmount().isGreaterThan(KualiDecimal.ZERO)) {
            InvoiceBill invBill = new InvoiceBill();
            invBill.setBillNumber(awdBill.getBillNumber());
            invBill.setBillIdentifier(awdBill.getBillIdentifier());
            invBill.setBillDescription(awdBill.getBillDescription());
            invBill.setBillDate(awdBill.getBillDate());
            invBill.setEstimatedAmount(awdBill.getEstimatedAmount());
            invoiceBills.add(invBill);
        }
    }
    return invoiceBills;
}

From source file:org.kuali.kfs.module.ar.service.impl.ContractsGrantsInvoiceCreateDocumentServiceImpl.java

/**
 * Generates InvoiceMilestones for each of the given milestones
 * @param milestones the milestones to associate with a contracts & grants billing invoice
 * @param invoiceDate the date of the invoice we're building
 * @return the List of InvoiceMilestones
 *//*from w  ww  .j  a v a 2s .  com*/
protected List<InvoiceMilestone> buildInvoiceMilestones(List<Milestone> milestones, java.sql.Date invoiceDate) {
    List<InvoiceMilestone> invoiceMilestones = new ArrayList<>();
    for (Milestone awdMilestone : milestones) {
        // To consider the completed milestones only.
        // To check for null - Milestone Completion date.

        if (awdMilestone.getMilestoneActualCompletionDate() != null
                && !invoiceDate.before(awdMilestone.getMilestoneActualCompletionDate())
                && !awdMilestone.isBilled()
                && awdMilestone.getMilestoneAmount().isGreaterThan(KualiDecimal.ZERO)) {

            InvoiceMilestone invMilestone = new InvoiceMilestone();
            invMilestone.setMilestoneNumber(awdMilestone.getMilestoneNumber());
            invMilestone.setMilestoneIdentifier(awdMilestone.getMilestoneIdentifier());
            invMilestone.setMilestoneDescription(awdMilestone.getMilestoneDescription());
            invMilestone.setMilestoneActualCompletionDate(awdMilestone.getMilestoneActualCompletionDate());
            invMilestone.setMilestoneAmount(awdMilestone.getMilestoneAmount());
            invoiceMilestones.add(invMilestone);
        }
    }
    return invoiceMilestones;
}

From source file:org.kuali.kfs.module.cam.document.validation.impl.EquipmentLoanOrReturnDocumentRule.java

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

From source file:org.kuali.kfs.module.cg.document.validation.impl.AwardPreRules.java

/**
 * Checks if the entry date is before the begin date. if so asks the user if they want to continue validation. if no is selected
 * further validation is aborted and the user is returned to the award document.
 * //from   w w w. j a  va  2  s  .co m
 * @return true if the user selects yes, false otherwise
 */
protected boolean continueIfEntryDateBeforeBeginDate() {
    boolean proceed = true;
    Date entryDate = newAward.getAwardEntryDate();
    Date beginDate = newAward.getAwardBeginningDate();

    if (ObjectUtils.isNotNull(entryDate) && ObjectUtils.isNotNull(beginDate) && entryDate.before(beginDate)) {
        String entryDateLabel = dataDictionaryService.getAttributeErrorLabel(Award.class,
                KFSPropertyConstants.AWARD_ENTRY_DATE);
        String beginDateLabel = dataDictionaryService.getAttributeErrorLabel(Award.class,
                KFSPropertyConstants.AWARD_BEGINNING_DATE);
        proceed = askOrAnalyzeYesNoQuestion("entryDateBeforeStartDate", buildConfirmationQuestion(
                KFSKeyConstants.WARNING_AWARD_ENTRY_BEFORE_START_DATE, entryDateLabel, beginDateLabel));
    }
    return proceed;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.MileageRateServiceImpl.java

@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;
        }//from  w w  w  .j a  v  a  2 s  .  c  om
    }

    return null;
}

From source file:org.kuali.kra.award.timeandmoney.AwardDirectFandADistributionRuleImpl.java

/**
 * This is a helper method for doExistingFandADistributionDatesOverlap.
 *///  w w w  . ja  v  a  2 s .  co  m
boolean targetOverlapsWithExistingPeriods(AwardDirectFandADistribution thisAwardDirectFandADistribution,
        List<AwardDirectFandADistribution> thisAwardDirectFandADistributions, int currentIndex) {
    boolean invalid = false;
    Date testStartDate;
    Date testEndDate;
    Date startDate = thisAwardDirectFandADistribution.getStartDate();
    Date endDate = thisAwardDirectFandADistribution.getEndDate();
    int newCurrentIndex = 0;
    for (AwardDirectFandADistribution testAwardDirectFandADistribution : thisAwardDirectFandADistributions) {
        testStartDate = testAwardDirectFandADistribution.getStartDate();
        testEndDate = testAwardDirectFandADistribution.getEndDate();
        if (newCurrentIndex != currentIndex) {
            if (startDate.before(testEndDate) && startDate.after(testStartDate)
                    || endDate.after(testStartDate) && endDate.before(testEndDate)
                    || startDate.equals(testEndDate) || endDate.equals(testStartDate)) {
                invalid = true;
                break;
            }
        }
        newCurrentIndex++;
    }
    return invalid;
}