Example usage for java.sql Date after

List of usage examples for java.sql Date after

Introduction

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

Prototype

public boolean after(Date when) 

Source Link

Document

Tests if this date is after the specified date.

Usage

From source file:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java

/**
 * Apply tax for block charging.// ww  w . j  ava  2  s. c om
 *
 * @param CatEntry the cat entry
 * @param rate the rate
 * @param year the year
 * @param month the month
 * @throws Exception 
 */
private static void applyTaxForBlockCharging(Map.Entry<CategoryCharge, BilledCharge> CatEntry, ChargeRate rate,
        String year, String month) throws Exception {

    TaxDAO taxDAO = new TaxDAO();
    List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList());
    CategoryCharge categorycharge = CatEntry.getKey();
    BilledCharge billed = CatEntry.getValue();

    BigDecimal totalTax = BigDecimal.ZERO;
    Date billingDate = Date.valueOf(year + "-" + month + "-01"); // start of
    // the
    // month

    for (Tax tax : taxList) {
        // select the taxes applicable at the billing date
        if (!billingDate.before(tax.getEffective_from()) && !billingDate.after(tax.getEffective_to())) {
            totalTax = totalTax.add(tax.getValue().multiply(billed.getPrice()));
        }
    }

    CatEntry.getValue().setTax(totalTax);
}

From source file:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java

/**
 * Apply payment charges by category.//  w  ww .  ja va 2  s  .c o m
 *
 * @param opSubscription the op subscription
 * @param categoryCharge the category charge
 * @param paymentRequestSet the payment request set
 * @throws Exception 
 */
private static void applyPaymentChargesByCategory(BillingSubscription.OperatorSubscription opSubscription,
        CategoryCharge categoryCharge, Set<PaymentRequestDTO> paymentRequestSet) throws Exception {

    ChargeRate rate = opSubscription.getRate();
    TaxDAO taxDAO = new TaxDAO();
    List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList());
    BigDecimal totalCharge = BigDecimal.ZERO;
    BigDecimal totalPrice = BigDecimal.ZERO;
    BigDecimal totalTax = BigDecimal.ZERO;

    for (PaymentRequestDTO paymentRequest : paymentRequestSet) {
        totalCharge = totalCharge.add(paymentRequest.getAmount());
        BigDecimal price = BigDecimal.ZERO;

        CategoryEntity rateCategories = new CategoryEntity();

        if (rateCategories == null) {
            throw new APIManagementException(
                    "Payment Categoreis required for QUOTA charging are not specified in rate-card.xml");
        }
        BigDecimal catpercent = rate.getValue().divide(new BigDecimal(100));

        Date date = new Date(paymentRequest.getDate().getTime());
        for (Tax tax : taxList) {
            // check if the date of payment request falls between this tax
            // validity period
            if (!date.before(tax.getEffective_from()) && !date.after(tax.getEffective_to())) {
                // totalTax += taxFraction x paymentAmount
                totalTax = totalTax.add(tax.getValue().multiply(price));
            }
        }
    }

    // Get the percentage from the rate value

    // apply category wise charge percentage
}

From source file:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java

/**
 * Apply charges with tax.//from   w ww.j av  a 2s  .c om
 *
 * @param apiYear the api year
 * @param apiMonth the api month
 * @param application the application
 * @param apiName the api name
 * @param apiVersion the api version
 * @param operatorSub the operator sub
 * @param CatEntry the cat entry
 * @param rate the rate
 * @throws Exception 
 */
private static void applyChargesWithTax(String apiYear, String apiMonth, Application application,
        String apiName, String apiVersion, BillingSubscription.OperatorSubscription operatorSub,
        Map.Entry<CategoryCharge, BilledCharge> CatEntry, ChargeRate rate) throws Exception {
    String month = apiMonth;
    String year = apiYear;
    boolean isSurcharge = false;

    if (application == null) {
        throw new APIManagementException("no key generated for this api");
    }
    APIKey prodKey = getAppKey(application, APIConstants.API_KEY_TYPE_PRODUCTION);

    Set<APIRequestDTO> requestTimes = new HashSet<APIRequestDTO>();
    if (prodKey != null) {
        String api_version = apiName + ":v" + apiVersion;

        TaxDAO taxDAO = new TaxDAO();
        requestTimes = taxDAO.getAPIRequestTimesForSubscription(Short.parseShort(year), Short.parseShort(month),
                apiName, api_version, prodKey.getConsumerKey(), operatorSub.getOperator(),
                operatorSub.getOperationId(), CatEntry.getKey().getCategory(),
                CatEntry.getKey().getSubcategory());

    }

    String billCategory = CatEntry.getKey().getCategory();
    String billSubCategory = CatEntry.getKey().getSubcategory();
    BigDecimal billRate = rate.getValue();
    BigDecimal OpscomPercnt = null;

    Object SubsRate = getRateSubcategory(rate, billCategory, billSubCategory);
    if (SubsRate != null) {
        billRate = new BigDecimal((String) SubsRate);
    }

    // Surcharge value
    if (rate.getSurchargeEntity() != null) {
        billRate = new BigDecimal(rate.getSurchargeEntity().getSurchargeElementValue());
        OpscomPercnt = new BigDecimal(rate.getSurchargeEntity().getSurchargeElementOpco())
                .divide(new BigDecimal(100));
        isSurcharge = true;
    }

    TaxDAO taxDAO = new TaxDAO();
    List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList());
    BigDecimal totalCharge = BigDecimal.ZERO;
    BigDecimal totalTax = BigDecimal.ZERO;
    BigDecimal totalOpcom = BigDecimal.ZERO;
    BigDecimal totalAdscom = BigDecimal.ZERO;

    int reqCount = 0;
    for (APIRequestDTO req : requestTimes) {

        if (reqCount >= CatEntry.getValue().getCount()) {
            break;
        }

        BigDecimal charge = billRate.multiply(new BigDecimal(req.getRequestCount()));
        if (isSurcharge) {
            BigDecimal opcoCommision = billRate.multiply(OpscomPercnt);
            totalOpcom = totalOpcom.add(opcoCommision);
            totalAdscom = totalAdscom.add(charge.subtract(opcoCommision));
        } else {
            totalCharge = totalCharge.add(charge);
        }

        Date date = req.getDate();
        for (Tax tax : taxList) {

            // check if the date of payment request falls between this tax
            // validity period
            if (!date.before(tax.getEffective_from()) && !date.after(tax.getEffective_to())) {
                totalTax = totalTax.add(tax.getValue().multiply(charge));
            }
        }
        reqCount++;
    }

    CatEntry.getValue().addPrice(totalCharge);
    CatEntry.getValue().addTax(totalTax);
    CatEntry.getValue().addOpcom(totalOpcom);
    CatEntry.getValue().addAdscom(totalAdscom);

}

From source file:com.wso2telco.dep.reportingservice.northbound.NbHostObjectUtils.java

/**
 * Apply charges for payment api./* w  w  w .j av a  2  s  .c o  m*/
 *
 * @param opSubscription the op subscription
 * @param paymentRequestSet the payment request set
 * @param categoryEntry the category entry
 * @param appId the app id
 * @param apiId the api id
 * @param subId the sub id
 * @throws Exception 
 */
private static void applyChargesForPaymentApi(BillingSubscription.OperatorSubscription opSubscription,
        Set<PaymentRequestDTO> paymentRequestSet, Map.Entry<CategoryCharge, BilledCharge> categoryEntry,
        int appId, int apiId, String subId) throws Exception {

    ChargeRate rate = opSubscription.getRate();
    String billCategory = categoryEntry.getKey().getCategory();
    String billSubCategory = categoryEntry.getKey().getSubcategory();
    BigDecimal billRate = rate.getValue();

    boolean CategoryBased = rate.getCategoryBasedVal();
    TaxDAO taxDAO = new TaxDAO();
    List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList());
    Map<String, CommissionPercentagesDTO> commisionMap = null;
    BillingDAO billingDAO = new BillingDAO();
    if (!CategoryBased) {
        commisionMap = billingDAO.getCommissionPercentages(subId, appId);
    }

    BigDecimal totalspcom = BigDecimal.ZERO;
    BigDecimal totalCharge = BigDecimal.ZERO;
    BigDecimal totaladscom = BigDecimal.ZERO;
    BigDecimal totalopcom = BigDecimal.ZERO;
    BigDecimal totalTax = BigDecimal.ZERO;

    // get this flag from rate card

    for (PaymentRequestDTO paymentRequest : paymentRequestSet) {
        totalCharge = totalCharge.add(paymentRequest.getAmount());
        BigDecimal spcom = BigDecimal.ZERO;
        BigDecimal adscom = BigDecimal.ZERO;
        BigDecimal opcom = BigDecimal.ZERO;

        String category = paymentRequest.getCategory();
        String subcategory = paymentRequest.getSubcategory();
        String merchant = paymentRequest.getMerchant();

        BigDecimal adscomPercnt = rate.getCommission().getAdsCommission().divide(new BigDecimal(100));
        BigDecimal spcomPercnt = rate.getCommission().getSpCommission().divide(new BigDecimal(100));
        BigDecimal opcomPercnt = rate.getCommission().getOpcoCommission().divide(new BigDecimal(100));

        if (CategoryBased) {
            Object SubsRate = getRateSubcategory(rate, billCategory, billSubCategory);
            if (SubsRate != null) {
                RateCommission commisionRates = (RateCommission) SubsRate;
                adscomPercnt = commisionRates.getAdsCommission().divide(new BigDecimal(100));
                spcomPercnt = commisionRates.getSpCommission().divide(new BigDecimal(100));
                opcomPercnt = commisionRates.getOpcoCommission().divide(new BigDecimal(100));
            }

        } else {
            if (commisionMap.containsKey(merchant)) {
                adscomPercnt = commisionMap.get(merchant).getAdsCommission().divide(new BigDecimal(100));
                spcomPercnt = commisionMap.get(merchant).getSpCommission().divide(new BigDecimal(100));
                opcomPercnt = commisionMap.get(merchant).getOpcoCommission().divide(new BigDecimal(100));
            } else {
                throw new APIManagementException(
                        "Payment Categoreis required for MERCHANT based charging are not specified in rate-card.xml");
            }
        }

        spcom = paymentRequest.getAmount().multiply(spcomPercnt);
        totalspcom = totalspcom.add(spcom);

        opcom = paymentRequest.getAmount().multiply(opcomPercnt);
        totalopcom = totalopcom.add(opcom);

        adscom = paymentRequest.getAmount().multiply(adscomPercnt);
        totaladscom = totaladscom.add(adscom);

        Date date = new Date(paymentRequest.getDate().getTime());
        BigDecimal totalReqTax = BigDecimal.ZERO;
        for (Tax tax : taxList) {
            // check if the date of payment request falls between this tax
            // validity period
            if (!date.before(tax.getEffective_from()) && !date.after(tax.getEffective_to())) {
                // totalTax += taxFraction x paymentAmount
                totalReqTax = totalReqTax.add(tax.getValue().multiply(paymentRequest.getAmount()));
            }
        }
        totalTax = totalTax.add(totalReqTax);

        if (!CategoryBased) {
            if (opSubscription.getMerchantCharges().containsKey(merchant)) {
                opSubscription.getMerchantCharges().get(merchant).addAdscom(adscom);
                opSubscription.getMerchantCharges().get(merchant).addOpcom(opcom);
                opSubscription.getMerchantCharges().get(merchant).addSpcom(spcom);
                opSubscription.getMerchantCharges().get(merchant).addPrice(spcom);
                opSubscription.getMerchantCharges().get(merchant).addTax(totalReqTax);
                opSubscription.getMerchantCharges().get(merchant).addCount(1);
            } else {
                BilledCharge billedCharge = new BilledCharge(0);
                billedCharge.addAdscom(adscom);
                billedCharge.addOpcom(opcom);
                billedCharge.addSpcom(spcom);
                billedCharge.addPrice(spcom);
                billedCharge.addTax(totalReqTax);
                billedCharge.addCount(1);
                opSubscription.getMerchantCharges().put(merchant, billedCharge);
            }
        }
    }

    // Get the percentage from the rate value
    // BigDecimal percentage = rate.getValue().divide(new BigDecimal(100));

    // apply category wise charge percentage

    // BigDecimal price = totalCharge.multiply(percentage);

    // if (CategoryBased) {
    categoryEntry.getValue().addAdscom(totaladscom);
    categoryEntry.getValue().addOpcom(totalopcom);
    categoryEntry.getValue().addSpcom(totalspcom);
    categoryEntry.getValue().addPrice(totalspcom);
    categoryEntry.getValue().setTax(totalTax);
    // }
}

From source file:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java

/**
 * Apply charges for payment api./* ww  w  .j  a  v a  2  s . c  o  m*/
 *
 * @param opSubscription the op subscription
 * @param paymentRequestSet the payment request set
 * @param categoryEntry the category entry
 * @param appId the app id
 * @param apiId the api id
 * @param subId the sub id
 * @throws Exception 
 */
private static void applyChargesForPaymentApi(BillingSubscription.OperatorSubscription opSubscription,
        Set<PaymentRequestDTO> paymentRequestSet, Map.Entry<CategoryCharge, BilledCharge> categoryEntry,
        int appId, int apiId, String subId) throws Exception {

    ChargeRate rate = opSubscription.getRate();
    String billCategory = categoryEntry.getKey().getCategory();
    String billSubCategory = categoryEntry.getKey().getSubcategory();
    BigDecimal billRate = rate.getValue();

    boolean CategoryBased = rate.getCategoryBasedVal();
    BillingDAO billingDAO = new BillingDAO();
    TaxDAO taxDAO = new TaxDAO();
    List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList());
    Map<String, CommissionPercentagesDTO> commisionMap = null;

    if (!CategoryBased) {
        commisionMap = billingDAO.getCommissionPercentages(subId, appId);
    }

    BigDecimal totalspcom = BigDecimal.ZERO;
    BigDecimal totalCharge = BigDecimal.ZERO;
    BigDecimal totaladscom = BigDecimal.ZERO;
    BigDecimal totalopcom = BigDecimal.ZERO;
    BigDecimal totalTax = BigDecimal.ZERO;

    // get this flag from rate card

    for (PaymentRequestDTO paymentRequest : paymentRequestSet) {
        totalCharge = totalCharge.add(paymentRequest.getAmount());
        BigDecimal spcom = BigDecimal.ZERO;
        BigDecimal adscom = BigDecimal.ZERO;
        BigDecimal opcom = BigDecimal.ZERO;

        String category = paymentRequest.getCategory();
        String subcategory = paymentRequest.getSubcategory();
        String merchant = paymentRequest.getMerchant();

        BigDecimal adscomPercnt = rate.getCommission().getAdsCommission().divide(new BigDecimal(100));
        BigDecimal spcomPercnt = rate.getCommission().getSpCommission().divide(new BigDecimal(100));
        BigDecimal opcomPercnt = rate.getCommission().getOpcoCommission().divide(new BigDecimal(100));

        if (CategoryBased) {
            Object SubsRate = getRateSubcategory(rate, billCategory, billSubCategory);
            if (SubsRate != null) {
                RateCommission commisionRates = (RateCommission) SubsRate;
                adscomPercnt = commisionRates.getAdsCommission().divide(new BigDecimal(100));
                spcomPercnt = commisionRates.getSpCommission().divide(new BigDecimal(100));
                opcomPercnt = commisionRates.getOpcoCommission().divide(new BigDecimal(100));
            }

        } else {
            if (commisionMap.containsKey(merchant)) {
                adscomPercnt = commisionMap.get(merchant).getAdsCommission().divide(new BigDecimal(100));
                spcomPercnt = commisionMap.get(merchant).getSpCommission().divide(new BigDecimal(100));
                opcomPercnt = commisionMap.get(merchant).getOpcoCommission().divide(new BigDecimal(100));
            } else {
                throw new APIManagementException(
                        "Payment Categoreis required for MERCHANT based charging are not specified in rate-card.xml");
            }
        }

        spcom = paymentRequest.getAmount().multiply(spcomPercnt);
        totalspcom = totalspcom.add(spcom);

        opcom = paymentRequest.getAmount().multiply(opcomPercnt);
        totalopcom = totalopcom.add(opcom);

        adscom = paymentRequest.getAmount().multiply(adscomPercnt);
        totaladscom = totaladscom.add(adscom);

        Date date = new Date(paymentRequest.getDate().getTime());
        BigDecimal totalReqTax = BigDecimal.ZERO;
        for (Tax tax : taxList) {
            // check if the date of payment request falls between this tax
            // validity period
            if (!date.before(tax.getEffective_from()) && !date.after(tax.getEffective_to())) {
                totalReqTax = totalReqTax.add(tax.getValue().multiply(paymentRequest.getAmount()));
            }
        }
        totalTax = totalTax.add(totalReqTax);

        if (!CategoryBased) {
            if (opSubscription.getMerchantCharges().containsKey(merchant)) {
                opSubscription.getMerchantCharges().get(merchant).addAdscom(adscom);
                opSubscription.getMerchantCharges().get(merchant).addOpcom(opcom);
                opSubscription.getMerchantCharges().get(merchant).addSpcom(spcom);
                opSubscription.getMerchantCharges().get(merchant).addPrice(spcom);
                opSubscription.getMerchantCharges().get(merchant).addTax(totalReqTax);
                opSubscription.getMerchantCharges().get(merchant).addCount(1);
            } else {
                BilledCharge billedCharge = new BilledCharge(0);
                billedCharge.addAdscom(adscom);
                billedCharge.addOpcom(opcom);
                billedCharge.addSpcom(spcom);
                billedCharge.addPrice(spcom);
                billedCharge.addTax(totalReqTax);
                billedCharge.addCount(1);
                opSubscription.getMerchantCharges().put(merchant, billedCharge);
            }
        }
    }

    // Get the percentage from the rate value

    // apply category wise charge percentage

    categoryEntry.getValue().addAdscom(totaladscom);
    categoryEntry.getValue().addOpcom(totalopcom);
    categoryEntry.getValue().addSpcom(totalspcom);
    categoryEntry.getValue().addPrice(totalspcom);
    categoryEntry.getValue().setTax(totalTax);
}

From source file:org.kuali.kra.award.home.Award.java

/**
 * This method finds the latest final expiration date from the collection of AmnoutInfos
 * @return The latest final expiration date from the collection of AmnoutInfos. If there are no AmoutInfos, 1/1/1900 is returned
 *///  w w  w  . j av a2s  . c  o  m
public Date findLatestFinalExpirationDate() {
    Date latestExpDate = new Date(new GregorianCalendar(1900, Calendar.JANUARY, 1).getTimeInMillis());
    for (AwardAmountInfo amountInfo : getAwardAmountInfos()) {
        Date expDate = amountInfo.getFinalExpirationDate();
        if (expDate != null && expDate.after(latestExpDate)) {
            latestExpDate = expDate;
        }
    }
    return latestExpDate;
}

From source file:org.kuali.coeus.common.budget.impl.calculator.AbstractBudgetCalculator.java

/**
 * Use the combined &amp; sorted Prop &amp; LA rates to create Boundary objects. Each Boundary will contain start date &amp; end date. Check
 * whether any rate changes, and break at this point to create a new boundary.
 * /*ww  w .j  a v  a 2 s  .  c o  m*/
 * @return List of boundary objects
 */
public List<Boundary> createBreakupBoundaries(QueryList<AbstractBudgetRate> qlCombinedRates, Date liStartDate,
        Date liEndDate) {
    List<Boundary> boundaries = new ArrayList<Boundary>();
    if (qlCombinedRates != null && qlCombinedRates.size() > 0) {
        Date tempStartDate = liStartDate;
        Date tempEndDate = liEndDate;
        Date rateChangeDate;
        GreaterThan greaterThan = new GreaterThan(START_DATE, liStartDate);
        qlCombinedRates = qlCombinedRates.filter(greaterThan);
        qlCombinedRates.sort(START_DATE, true);
        for (AbstractBudgetRate laRate : qlCombinedRates) {
            rateChangeDate = laRate.getStartDate();
            if (rateChangeDate.after(tempStartDate)) {
                Calendar temEndCal = dateTimeService.getCalendar(rateChangeDate);
                temEndCal.add(Calendar.DAY_OF_MONTH, -1);
                try {
                    tempEndDate = dateTimeService.convertToSqlDate(temEndCal.get(Calendar.YEAR) + "-"
                            + (temEndCal.get(Calendar.MONTH) + 1) + "-" + temEndCal.get(Calendar.DAY_OF_MONTH));
                } catch (ParseException e) {
                    tempEndDate = new Date(rateChangeDate.getTime() - 86400000);
                }
                Boundary boundary = new Boundary(tempStartDate, tempEndDate);
                boundaries.add(boundary);
                tempStartDate = rateChangeDate;
            }
        }
        /**
         * add one more boundary if no rate change on endDate and atleast one boundary is present
         */
        if (boundaries.size() > 0) {
            Boundary boundary = new Boundary(tempStartDate, liEndDate);
            boundaries.add(boundary);
        }
        /**
         * if no rate changes during the period create one boundary with startDate &amp; endDate same as that for line item
         */
        if (boundaries.size() == 0) {
            Boundary boundary = new Boundary(liStartDate, liEndDate);
            boundaries.add(boundary);
        }
    }
    return boundaries;
}

From source file:org.kuali.coeus.common.budget.impl.period.BudgetPeriodRule.java

private boolean isValidNewBudgetPeriod(Budget budget, BudgetPeriod newBudgetPeriod, String errorPathPrefix) {
    MessageMap errorMap = GlobalVariables.getMessageMap();
    boolean validNewBudgetPeriod = true;
    List<BudgetPeriod> budgetPeriods = budget.getBudgetPeriods();
    Date previousPeriodStartDate = null;
    Date previousPeriodEndDate = null;
    Date periodStartDate = null;/*  ww w  . j  a  v  a 2s. com*/
    Date periodEndDate = null;
    Date newPeriodStartDate = null;
    Date newPeriodEndDate = null;
    int index = 0;

    /* check new budget period */
    newPeriodStartDate = newBudgetPeriod.getStartDate();
    newPeriodEndDate = newBudgetPeriod.getEndDate();
    errorMap.addToErrorPath(errorPathPrefix);
    if (newPeriodStartDate == null) {
        saveErrors("ERROR_PERIOD_START_REQUIRED", errorMap);
        validNewBudgetPeriod = false;
    }
    if (newPeriodEndDate == null) {
        saveErrors("ERROR_PERIOD_END_REQUIRED", errorMap);
        validNewBudgetPeriod = false;
    }
    errorMap.removeFromErrorPath(errorPathPrefix);

    if (CollectionUtils.isEmpty(budgetPeriods)) {
        newBudgetPeriod.setBudgetPeriod(1);
    }

    /* if dates are valid, check further where we can insert this new date */
    if (validNewBudgetPeriod) {
        int totalBudgetPeriods = budgetPeriods.size() - 1;
        errorMap.addToErrorPath(errorPathPrefix);
        for (BudgetPeriod budgetPeriod : budgetPeriods) {
            Date validDateBefore;
            periodStartDate = budgetPeriod.getStartDate();
            periodEndDate = budgetPeriod.getEndDate();
            String dateCompareValue = null;
            /* check first record */
            if (previousPeriodStartDate == null) {
                validDateBefore = budget.getStartDate();
            } else {
                validDateBefore = previousPeriodEndDate;
            }
            /* check if entered new period already exists in budget periods list */
            int periodNum = index;
            String[] newPeriodDateParams = { periodNum + "", periodNum + 1 + "" };
            String invalidErrorMessage = null;
            if (index == 0 || index == totalBudgetPeriods) {
                invalidErrorMessage = "ERROR_NEW_PERIOD_INVALID";
            } else {
                invalidErrorMessage = "ERROR_NEW_PERIOD_VALID";
            }
            if ((newPeriodStartDate.compareTo(periodStartDate) == 0)
                    || (newPeriodEndDate.compareTo(periodEndDate) == 0)) {
                saveErrors(invalidErrorMessage, errorMap, newPeriodDateParams);
                validNewBudgetPeriod = false;
                break;
            } else if (newPeriodStartDate.before(periodStartDate)
                    || (index == totalBudgetPeriods && newPeriodStartDate.after(periodEndDate))) {
                /* check if new period start date is before current period start date */
                boolean lastRecord = false;
                if (index == totalBudgetPeriods) {
                    lastRecord = true;
                    if (newPeriodStartDate.after(periodEndDate)) {
                        periodNum = index + 1;
                    }
                }
                /* check new budget period */
                if (newPeriodStartDate.before(budget.getStartDate())) {
                    dateCompareValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START";
                } else if (newPeriodStartDate.after(budget.getEndDate())) {
                    dateCompareValue = "ERROR_NEW_PERIOD_START_AFTER_PROJECT_END";
                } else if (newPeriodEndDate.after(budget.getEndDate())) {
                    dateCompareValue = "ERROR_NEW_PERIOD_END_DATE";
                } else if (newPeriodStartDate.before(validDateBefore)) {
                    dateCompareValue = invalidErrorMessage;
                } else if ((index < totalBudgetPeriods) && newPeriodEndDate.after(periodStartDate)) {
                    if (!lastRecord) {
                        dateCompareValue = invalidErrorMessage;
                    } else {
                        dateCompareValue = "ERROR_NEW_PERIOD_PROJECT_END";
                    }
                }
                if (dateCompareValue != null) {
                    saveErrors(dateCompareValue, errorMap, newPeriodDateParams);
                    validNewBudgetPeriod = false;
                } else {
                    newBudgetPeriod.setBudgetPeriod(periodNum + 1);
                }
                break;
            } else if (newPeriodStartDate.compareTo(periodEndDate) <= 0) {
                dateCompareValue = "ERROR_NEW_PERIOD_START_BEFORE_PREVIOUS_END";
                saveErrors(dateCompareValue, errorMap, newPeriodDateParams);
                validNewBudgetPeriod = false;
                break;
            }
            previousPeriodStartDate = budgetPeriod.getStartDate();
            previousPeriodEndDate = budgetPeriod.getEndDate();
            index++;
        }
        errorMap.removeFromErrorPath(errorPathPrefix);
    }
    return validNewBudgetPeriod;
}

From source file:org.kuali.coeus.common.budget.impl.period.BudgetPeriodRule.java

private String compareDate(Budget budget, Date periodStartDate, Date periodEndDate,
        Date previousPeriodEndDate) {
    String returnErrorValue = null;
    LOG.info("prd st dt " + periodStartDate.getTime() + periodEndDate.getTime()
            + budget.getStartDate().getTime() + budget.getEndDate().getTime());
    Date budgetEndDate = new Date(budget.getBudgetEndDate().getTime());
    Date budgetStartDate = new Date(budget.getBudgetStartDate().getTime());
    if (periodStartDate.after(budgetEndDate)) {
        LOG.info("ERROR_PERIOD_START_AFTER_PROJECT_END" + periodStartDate + budget.getEndDate());
        returnErrorValue = "ERROR_PERIOD_START_AFTER_PROJECT_END";
    } else if (periodStartDate.before(budgetStartDate)) {
        LOG.info("ERROR_PERIOD_START_BEFORE_PROJECT_START" + periodStartDate + budget.getStartDate());
        returnErrorValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START";
    } else if (periodEndDate.before(budget.getStartDate())) {
        LOG.info("ERROR_PERIOD_END_BEFORE_PROJECT_START" + periodEndDate + budget.getStartDate());
        returnErrorValue = "ERROR_PERIOD_END_BEFORE_PROJECT_START";
    } else if (periodEndDate.after(budgetEndDate)) {
        LOG.info("ERROR_PERIOD_END_AFTER_PROJECT_END" + periodEndDate + budget.getEndDate());
        returnErrorValue = "ERROR_PERIOD_END_AFTER_PROJECT_END";
    } else if (periodStartDate.after(periodEndDate)) {
        LOG.info("ERROR_PERIOD_START_AFTER_PERIOD_END" + periodStartDate + periodEndDate);
        returnErrorValue = "ERROR_PERIOD_START_AFTER_PERIOD_END";
    } else if (previousPeriodEndDate != null && !periodStartDate.after(previousPeriodEndDate)) {
        LOG.info("ERROR_PERIOD_START_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodStartDate);
        returnErrorValue = "ERROR_PERIOD_START_BEFORE_PREVIOUS_END";
    } else if (previousPeriodEndDate != null && !periodEndDate.after(previousPeriodEndDate)) {
        LOG.info("ERROR_PERIOD_END_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodEndDate);
        returnErrorValue = "ERROR_PERIOD_END_BEFORE_PREVIOUS_END";
    }/*from w w  w  .ja va 2  s  .  co  m*/
    return returnErrorValue;
}

From source file:org.kuali.coeus.common.budget.impl.personnel.BudgetPersonnelBudgetServiceImpl.java

public void calculateBudgetPersonnelBudget(Budget budget, BudgetLineItem selectedBudgetLineItem,
        BudgetPersonnelDetails budgetPersonnelDetails, int lineNumber) {
    copyLineItemToPersonnelDetails(selectedBudgetLineItem, budgetPersonnelDetails);
    budgetCalculationService.calculateBudgetLineItem(budget, budgetPersonnelDetails);
    // error message if effective data is out of range
    if (budgetPersonnelDetails.getSalaryRequested().equals(ScaleTwoDecimal.ZERO)) {
        int budgetPeriodNumber = budgetPersonnelDetails.getBudgetPeriod() - 1;
        BudgetPeriod budgetPeriod = budget.getBudgetPeriod(budgetPeriodNumber);
        Date personEffectiveDate = budgetPersonnelDetails.getBudgetPerson().getEffectiveDate();
        if (personEffectiveDate.after(budgetPeriod.getEndDate())) {
            MessageMap errorMap = globalVariableService.getMessageMap();
            // salaryrequested is hidden field, so use person
            errorMap.putError(/*from   w  w w.  jav  a  2  s .  c  o  m*/
                    "document.budgetPeriod[" + budgetPeriodNumber + "].budgetLineItems[" + budgetPeriodNumber
                            + "].budgetPersonnelDetailsList[" + lineNumber + "].personSequenceNumber",
                    KeyConstants.ERROR_EFFECTIVE_DATE_OUT_OF_RANGE,
                    new String[] { budgetPersonnelDetails.getBudgetPerson().getPersonName() });

        }
    }
}