public ActionForward execute(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws javax.servlet.ServletException, java.io.IOException {

    formErrors = new ArrayList();
    MiscCashReceiptsForm form = (MiscCashReceiptsForm) actionForm;
    ActionErrors errors = new ActionErrors();
    HttpSession session = request.getSession();
    DbUserSession sessionUser = SessionHelpers.getUserSession(request);
    DatabaseTransaction t = null;
    DbHistory dbHistory = null;

    if (form.getSubmitButton() != null && form.getSubmitButton().equals("exit")) {
      ActionForward actionForward = mapping.findForward("financial");
      return actionForward;
    }

    try {
      t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);
      // AppLog.trace("ProcessMiscCashReceipts submit ="+form.getSubmitButton());

      // --- HANDLE PRINTING A RECEIPT ---
      if (form.getFormId() != null
          && form.getFormId().trim().length() > 0
          && (!form.getFormId().equals("None"))) {
        // AppLog.trace("ProcessMiscCashReceipts printing receipt form: "+form.getFormId());
        if (FormatNumber.parseInteger(form.getFormId()) < 1) {
          // AppLog.error("ProcessMiscCashReceipts - No receipt type selected.");
          errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.tables.noselect"));
          formErrors.add("formId");
          t.closeConnection();
          return (new ActionForward(mapping.getInput()));
        }
      }

      if (form.getSubmitButton().equals("save")) {
        dbHistory = new DbHistory();
        dbHistory.setNew();
        validateData(form, errors);
        if (errors.isEmpty()) {
          setHistory(t, sessionUser, dbHistory, form, errors);
          if (errors.isEmpty()) {
            t.save();
          } else {
            // AppLog.criticalError("Exception in ProcessMiscCashReceipts.setHistory.");
          }
        } else {
          // AppLog.trace("Validation Errors in ProcessMiscCashReceipts; returning to
          // MiscCashReceipts form.");
        }
      }

      // --- HANDLE PRINTING A RECEIPT ---
      if (errors.isEmpty() && FormatNumber.parseInteger(form.getFormId()) > 0) {

        String crystalFlag =
            UtilSingleton.getInstance()
                .getProperty(sessionUser.getConfigID(), "CrystalServer.useReportingService");
        String pageName = null;

        if (crystalFlag != null && "true".equals(crystalFlag)) {
          CrystalReportManagerBean crystalServerReport =
              new CrystalReportManagerBean(sessionUser.getConfigID());
          pageName =
              crystalServerReport.printReport(
                  sessionUser,
                  FormatNumber.parseInteger(form.getFormId()),
                  "",
                  "",
                  null,
                  "",
                  Integer.toString(dbHistory.getId()),
                  true);
        } else {
          ExportReport crystal = new ExportReport();
          crystal.setRecordIdSelParam(dbHistory.getId()); // selection parameter
          pageName =
              crystal.printForm(
                  sessionUser,
                  FormatNumber.parseInteger(form.getFormId()),
                  "",
                  "",
                  null,
                  "",
                  request,
                  response,
                  servlet.getServletContext());
        }

        form = new MiscCashReceiptsForm();
        setNewForm(request, sessionUser, session, form, errors);
        form.setPreviewFile(pageName);
        // AppLog.trace("Setting miscCashReceipts collection arrays into session scope.");
        session.setAttribute("miscCashReceipts", form);
        ActionForward actionForward = mapping.findForward("showMiscCashReceipts");
        return actionForward;
      }

    } catch (PersistenceException pe) {
      logger.error("Persistence Exception in ProcessMiscCashReceipts.doPerform. " + pe);
      errors.add(
          ActionErrors.GLOBAL_ERROR, new ActionError("error.PersistenceException", pe.getCause()));
    } catch (Exception pe) {
      logger.error("Exception in ProcessMiscCashReceipts.doPerform. ", pe);
      errors.add(
          ActionErrors.GLOBAL_ERROR, new ActionError("error.GeneralException", pe.getMessage()));
    } finally {
      if (t != null) {
        t.closeConnection();
      }
    }

    // Action Forward Logic

    ActionForward actionForward = mapping.findForward("showMiscCashReceiptsGlobal");

    if (!errors.isEmpty()) {
      // AppLog.info("ProcessMiscCashReceipts Invoking forward mapping getInput() ");
      saveErrors(request, errors);
      request.setAttribute("formErrors", formErrors);
      actionForward = new ActionForward(mapping.getInput());
    }

    logger.debug("Leaving ProcessMiscCashReceipts.");
    return actionForward;
  }
  /**
   * 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"));
  }