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:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java

/**
 * Apply tax for block charging./*  www .java  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./* www. j  a v a  2  s . co  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.//w  ww . j  av a  2 s. com
 *
 * @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 ww  .  j  a  v  a2 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./*from   ww w  .ja va  2  s  .c  om*/
 *
 * @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:com.wso2telco.dep.reportingservice.northbound.NbHostObjectUtils.java

/**
 * Checks if is subscription valid for month.
 *
 * @param subAPI the sub api/*from w  w  w. ja  va 2 s . c  o  m*/
 * @param year the year
 * @param month the month
 * @return true, if is subscription valid for month
 * @throws Exception 
 */
private static boolean isSubscriptionValidForMonth(SubscribedAPI subAPI, String year, String month)
        throws Exception {
    BillingDAO billingDAO = new BillingDAO();
    java.util.Date createdTime = billingDAO.getSubscriptionCreatedTime(subAPI.getApplication().getId(),
            subAPI.getApiId());
    Date reportDate = Date.valueOf(year + "-" + month + "-01");
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(reportDate);

    // compare created time with 1st day of next month
    calendar.add(Calendar.MONTH, 1);
    calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
    if (createdTime != null) {
        return createdTime.before(calendar.getTime());
    } else {
        return false;
    }

}

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

/**
 * Checks if is subscription valid for month.
 *
 * @param subAPI the sub api/*  w  ww . j  a  v  a  2s . com*/
 * @param year the year
 * @param month the month
 * @return true, if is subscription valid for month
 * @throws APIManagementException the API management exception
 * @throws APIMgtUsageQueryServiceClientException the API mgt usage query service client exception
 * @throws BusinessException 
 */
private static boolean isSubscriptionValidForMonth(SubscribedAPI subAPI, String year, String month)
        throws BusinessException {
    BillingDAO billingDAO = new BillingDAO();
    java.util.Date createdTime;
    try {
        createdTime = billingDAO.getSubscriptionCreatedTime(subAPI.getApplication().getId(), subAPI.getApiId());
    } catch (Exception e) {
        throw new BusinessException(ReportingServiceError.INTERNAL_SERVER_ERROR);
    }
    Date reportDate = Date.valueOf(year + "-" + month + "-01");
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(reportDate);

    // compare created time with 1st day of next month
    calendar.add(Calendar.MONTH, 1);
    calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
    if (createdTime != null) {
        return createdTime.before(calendar.getTime());
    } else {
        return false;
    }

}

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;//from   w  ww.  ja  v a 2s.  c  o  m
    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 www  .j a v  a 2  s. c  o  m*/
    return returnErrorValue;
}

From source file:org.kuali.coeus.common.budget.impl.print.BudgetBaseStream.java

/**
 * This method sets reportType to ReportTypeList for BudgetLASalary and get
 * sum of fringe, calculatedCost, calculatedCostSharing and salary by
 * grouping reportType based on budgetLASalaryKey
 * // www  .j av a 2  s  . c  om
 * @param reportTypeList
 * @param reportTypeVOList
 */
protected void setReportTypeBudgetLASalary(List<ReportType> reportTypeList,
        List<ReportTypeVO> reportTypeVOList) {
    Map<String, ReportTypeVO> reportTypeMap = new HashMap<String, ReportTypeVO>();
    for (ReportTypeVO reportTypeVO : reportTypeVOList) {
        String budgetLASalaryKey = reportTypeVO.getCostElementDesc();
        if (reportTypeMap.containsKey(budgetLASalaryKey)) {
            continue;
        }
        Date startDate = reportTypeVO.getStartDate();
        Date endDate = reportTypeVO.getEndDate();
        ScaleTwoDecimal fringe = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal calculatedCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal calculatedCostSharing = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal salary = ScaleTwoDecimal.ZERO;
        for (ReportTypeVO tempReportTypeVO : reportTypeVOList) {
            String budgetLASalaryTempKey = tempReportTypeVO.getCostElementDesc();
            if (budgetLASalaryTempKey.equals(budgetLASalaryKey)) {
                if (startDate.after(tempReportTypeVO.getStartDate())) {
                    startDate = tempReportTypeVO.getStartDate();
                }
                if (endDate.before(tempReportTypeVO.getEndDate())) {
                    endDate = tempReportTypeVO.getEndDate();
                }
                fringe = fringe.add(tempReportTypeVO.getFringe());
                calculatedCost = calculatedCost.add(tempReportTypeVO.getCalculatedCost());
                calculatedCostSharing = calculatedCostSharing.add(tempReportTypeVO.getCostSharingAmount());
                salary = salary.add(tempReportTypeVO.getSalaryRequested());
            }
        }
        ReportType reportType = getReportTypeForLASalary(fringe, salary, calculatedCost, calculatedCostSharing,
                reportTypeVO, startDate, endDate);
        reportTypeList.add(reportType);
        reportTypeMap.put(budgetLASalaryKey, reportTypeVO);
    }
}