private String getFromDate(ReportForm reportForm, ActionMessages errors) {
    String fromDate = null;
    if (reportForm.getListType().compareToIgnoreCase("R") == 0
        || reportForm.getListType().compareToIgnoreCase("S") == 0) {

      // Get From Date
      try {
        fromDate = FormatDate.convertToDateYYYYMMDD(reportForm.getFromDate());
      } catch (Exception e) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.fromdate"));

        formErrors.add("fromDate");
      }

    } else if (reportForm.getListType().compareToIgnoreCase("weekly") == 0) {
      try {

        fromDate = FormatDate.convertToDateMMDDYYYY(FormatDate.getCurrentDateFormatedMMDDYYYY());

        fromDate = FormatDate.addToDateMMDDYYYY(fromDate, -8, 0);

        fromDate = FormatDate.convertUnformattedMDYtoYMD(fromDate);

      } catch (Exception e) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.fromdate"));
        formErrors.add("toDate");
      }

    } else if (reportForm.getListType().compareToIgnoreCase("monthly") == 0) {
      try {

        fromDate = FormatDate.convertToDateMMDDYYYY(FormatDate.getCurrentDateFormatedMMDDYYYY());

        fromDate = FormatDate.addToDateMMDDYYYY(fromDate, 0, -1);

        fromDate = FormatDate.convertUnformattedMDYtoYMD(fromDate);

      } catch (Exception e) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.fromdate"));
        formErrors.add("toDate");
      }
    }
    return fromDate;
  }
  /**
   * Method execute
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws javax.servlet.ServletException, java.io.IOException {

    HttpSession session = request.getSession();
    DbUserSession user = (DbUserSession) session.getAttribute(SessionValueKeys.DB_USER);
    ReportForm reportForm = (ReportForm) form;
    ActionMessages errors = new ActionMessages();

    // ArrayList <CheckListBean> checkURL = new ArrayList <CheckListBean>();
    // session.setAttribute("checkURL", checkURL);

    String requestType = reportForm.getRequestType();
    if (requestType == null) {
      requestType = "";
    }
    String pageName = "";
    reportForm.setReportURL(pageName);
    setReport(reportForm, user, session, errors, request);

    if (reportForm.getListType() == null) {
      reportForm.setListType(request.getParameter("all"));
    } else {
      reportForm.setListType(reportForm.getListType());
    }

    if (requestType.compareToIgnoreCase("changeLocale") == 0) {
      changeLocale(reportForm, user, session, errors, request);
      // changeCategory(reportForm, user, session, errors, request);
      return (mapping.findForward("localeChange"));
    } else if (requestType.compareToIgnoreCase("changeLocation") == 0) {
      // changeCategory(reportForm, user, session, errors, request);
      return (mapping.findForward("localeChange"));
    } else if (requestType.compareToIgnoreCase("changeCategory") == 0) {
      // changeCategory(reportForm, user, session, errors, request);
      return (mapping.findForward("localeChange"));
    } else {

      // ArrayList <OptionsList> reports = new ArrayList<OptionsList>();
      // reports.add( new OptionsList( "0" ,"--Select--"));
      // request.setAttribute("reports",reports);
    }

    if (requestType.compareToIgnoreCase("print") == 0) {

      //			Timer smsTimer = new Timer("SMSThread", true);
      //			CompanyManagerBean cmBean = new CompanyManagerBean();
      //			CompanyDTO company = cmBean.getCompany(user.getCompanyID());
      //			smsTimer.schedule(new SMSGenerator(company,1), 0l);

      ReportSchedulingDTO reportScheduling = new ReportSchedulingDTO();
      setReportScheduling(reportForm, reportScheduling, errors, user);
      reportScheduling.setReportType(ReportSchedulingDTO.REPORT_TYPE_REALTIME);
      reportScheduling.setStatus("Q");
      ReportSchedulingDAO reportScheDAo = new ReportSchedulingDAO(user);
      try {
        reportScheDAo.addReportScheduling(reportScheduling);
      } catch (Exception e) {

      }

      String crystalFlag =
          UtilSingleton.getInstance()
              .getProperty(user.getConfigID(), "CrystalServer.useReportingService");

      if (crystalFlag != null && "true".equals(crystalFlag)) {
        CompanyManagerBean cmBean = new CompanyManagerBean();
        CompanyDTO company = cmBean.getCompany(user.getCompanyID());
        runNow(reportScheduling, company);
      }

      reportForm.setFromDate(FormatDate.getCurrentDateFormatedMMDDYYYY());
      reportForm.setToDate(FormatDate.getCurrentDateFormatedMMDDYYYY());
      reportForm.setUserLocaleId("0");
      reportForm.setUserLocationId("0");
      reportForm.setCategory("0");

    } else if (requestType.compareToIgnoreCase("schedule") == 0) {

      ReportSchedulingDTO reportScheduling = new ReportSchedulingDTO();
      setReportScheduling(reportForm, reportScheduling, errors, user);

      int repeatNumber = 0;
      try {
        repeatNumber = FormatNumber.parseInteger(reportForm.getRepeatNumber());
      } catch (Exception e) {
        //
      }
      String fromDate = getFromDate(reportForm, errors);
      java.util.Date fDate = FormatDate.convertToDateYYMMDD(fromDate);
      String toDate = getToDate(reportForm, errors);
      java.util.Date tDate = FormatDate.convertToDateYYMMDD(toDate);
      Date rDate = new Date();
      try {
        rDate = FormatDate.convertToDate(reportForm.getRunDate());
      } catch (Exception e) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.rundate"));
        formErrors.add("runDate");
      }

      ReportSchedulingDAO reportScheDAo = new ReportSchedulingDAO(user);

      if (repeatNumber > 0) { // do more than 1 time.

        boolean scheduleNow = true;
        Timer timer = new Timer(true);

        for (int i = 0; i < repeatNumber; i++) {
          try {
            //						ReportSchedulingDTO aSchedule = new ReportSchedulingDTO();
            //						copyObj(reportScheduling,aSchedule);
            reportScheDAo.addReportScheduling(reportScheduling);
            if (scheduleNow) {
              Calendar date = Calendar.getInstance();
              date.setTime((java.util.Date) reportScheduling.getRunDate());
              // date.add(Calendar.MINUTE, 5);
              // set runtime. (CDT)
              date.set(Calendar.HOUR_OF_DAY, reportScheduling.getRunTimeHH()); // 0-23

              date.set(Calendar.MINUTE, reportScheduling.getRunTimeMM());
              if (date.getTimeInMillis() <= System.currentTimeMillis()) {
                CompanyManagerBean cmBean = new CompanyManagerBean();
                CompanyDTO company = cmBean.getCompany(user.getCompanyID());
                runNow(reportScheduling, company);
              } else {
                scheduleNow = false;
              }
            }
            // setSchedule(timer, aSchedule, user);
            ReportSchedulingDTO aSchedule = new ReportSchedulingDTO();
            copyObj(reportScheduling, aSchedule);
            reportScheduling = aSchedule;
          } catch (Exception e) {

          }

          String strFDate = FormatDate.convertDateToMMDDYYYY(fDate);
          String strTDate = FormatDate.convertDateToMMDDYYYY(tDate);
          String strRDate = FormatDate.convertDateToMMDDYYYY(rDate);
          int field = -1;
          if (reportForm.getRepeatType().compareToIgnoreCase("D") == 0) {
            field = 1;

          } else if (reportForm.getRepeatType().compareToIgnoreCase("W") == 0) {
            field = 7;

          } else if (reportForm.getRepeatType().compareToIgnoreCase("M") == 0) {
            field = 0;
          }
          if (field > -1) {
            strRDate = FormatDate.addToDateMMDDYYYY(strRDate, field, (field == 0 ? 1 : 0));
            strFDate = FormatDate.addToDateMMDDYYYY(strFDate, field, (field == 0 ? 1 : 0));
            strTDate = FormatDate.addToDateMMDDYYYY(strTDate, field, (field == 0 ? 1 : 0));
            rDate = FormatDate.convertMMDDYYYYToDateYYMMDD(strRDate);
            fDate = FormatDate.convertMMDDYYYYToDateYYMMDD(strFDate);
            tDate = FormatDate.convertMMDDYYYYToDateYYMMDD(strTDate);
            reportScheduling.setRunDate(new java.sql.Date(rDate.getTime()));
            reportScheduling.setFromDate(new java.sql.Date(fDate.getTime()));
            reportScheduling.setToDate(new java.sql.Date(tDate.getTime()));
          }
        }
      } else { // do only one time
        try {
          reportScheDAo.addReportScheduling(reportScheduling);
          Calendar date = Calendar.getInstance();
          date.setTime((java.util.Date) reportScheduling.getRunDate());
          // date.add(Calendar.MINUTE, 5);
          // set runtime. (CDT)
          date.set(Calendar.HOUR_OF_DAY, reportScheduling.getRunTimeHH()); // 0-23

          date.set(Calendar.MINUTE, reportScheduling.getRunTimeMM());
          if (date.getTimeInMillis() <= System.currentTimeMillis()) {
            CompanyManagerBean cmBean = new CompanyManagerBean();
            CompanyDTO company = cmBean.getCompany(user.getCompanyID());
            runNow(reportScheduling, company);
          }
          // setSchedule( null, reportScheduling,  user);
        } catch (Exception e) {

        }
      }
    }
    // we comment it out because we don't want it to do the pupup but let the user look at the
    // printed report list.
    // reportForm.setReportURL(pageName);
    return (mapping.findForward("localeChange"));
  }