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;
  }
  /**
   * Set the DbVitals and DbCase values from the FirstCallInformation form. Creation date:
   * (10/25/2002 11:00:39 AM)
   *
   * @param deceased com.aldorsolutions.webfdms.beans.DbVitalsDeceased
   * @param form fdms.ui.struts.form.FirstCallInformationForm
   * @param errors org.apache.struts.action.ActionErrors
   */
  public void setVitalsDeceased(
      DbVitalsDeceased deceased,
      DbVitalsInformant informant,
      CemAnStatus form,
      ActionErrors errors) {
    try {

      deceased.setDecmrmrs(form.getPrefix());
      deceased.setDecFName(form.getFirstName());
      deceased.setDecMName(form.getMiddleName());
      deceased.setDecLName(form.getLastName());
      deceased.setSuffix(form.getSuffix());
      deceased.setDecFullName(form.getMemorialName());
      deceased.setDecMaiden(form.getMaidenName());
      deceased.setDateOfBirth(FormatDate.convertToDateMMDDYYYY(form.getBirthDate()));
      deceased.setDateOfDeath(FormatDate.convertToDateMMDDYYYY(form.getDeathDate()));
      deceased.setDateOfBurial(FormatDate.convertToDateMMDDYYYY(form.getServiceDate()));

      // if the deceased's residence is the same as the informant's then update the deceased's
      // address
      if (form.getDeceasedSame()) {
        deceased.setDeceasedSame("Y");
        deceased.setDecResStreet(
            form.getInformantStreet()
                + " "
                + form.getInformantStreet2()
                + " "
                + form.getInformantStreet3());
        deceased.setDecResCityTWP(form.getInformantCity());
        deceased.setDecResState(form.getInformantState());
        deceased.setDecResZip(form.getInformantZip());
        deceased.setDecResPhone(form.getInformantPhone());
      } else {
        deceased.setDeceasedSame("N");
      }

    } catch (Exception e) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.setData"));
    }

    return;
  }
  private void validateForm(
      DatabaseTransaction t,
      DbUserSession sessionUser,
      fdms.ui.struts.form.CemAnStatus form,
      ActionErrors errors) {

    String checkDate = null;

    // Validate Arrange Date
    if (form.getArrangeDate() != null && form.getArrangeDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getArrangeDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.arrangedate"));
        formErrors.add("arrangeDate");
      }
    }

    // Chapel is required.
    if (form.getChapel() == null || form.getChapel().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.chapel"));
      formErrors.add("chapel");
    }

    // Director is required.
    if (form.getDirector() == null || form.getDirector().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.director"));
      formErrors.add("director");
    }

    // Validate PreNeed Date if entered.
    if (form.getPreneedDate() != null && form.getPreneedDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getPreneedDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.origpndate"));
        formErrors.add("preneedDate");
      }
    }

    // If the user changed the contract number, check for duplicate Contract Numbers.
    if (form.getContractNumber() != null
        && form.getContractNumber().trim().length() > 0
        && (!form.getContractNumber().equals(form.getNextContractNumber()))) {

      DbCase checkCase = new DbCase();
      checkCase.setNew();
      checkCase.setLocale(sessionUser.getRegion());
      if (form.getVitalsId() == null
          || form.getVitalsId().trim().length() == 0
          || form.getVitalsId() == "0") {
        checkCase.setId(0);
      } else {
        checkCase.setId(FormatNumber.parseInteger(form.getVitalsId()));
      }
      checkCase.setContractCode(form.getContractNumber());
      if (FdmsDb.getInstance().checkCaseExists(t, checkCase, DbCasePeer.CONTRACTCODE)) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.duplicate.contractNumber"));
        formErrors.add("contractNumber");
      }
    }

    // Deceased Memorial Name is required.
    if (form.getMemorialName() == null || form.getMemorialName().trim().length() == 0) {
      if (form.getMiddleName() != null && form.getMiddleName().trim().length() > 0) {
        form.setMemorialName(
            form.getFirstName() + " " + form.getMiddleName() + " " + form.getLastName());
      } else {
        form.setMemorialName(form.getFirstName() + " " + form.getLastName());
      }
      if (form.getMemorialName() == null || form.getMemorialName().trim().length() == 0) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.memorialName.required"));
        formErrors.add("memorialName");
      }
    }

    // Deceased First Name is required.
    if (form.getFirstName() == null || form.getFirstName().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.registration.nullFirstName"));
      formErrors.add("firstName");
    }

    // Deceased Last Name is required.
    if (form.getLastName() == null || form.getLastName().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.registration.nullLastName"));
      formErrors.add("lastName");
    }

    // Validate Date of Birth
    if (form.getBirthDate() != null && form.getBirthDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getBirthDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.birthdate"));
        formErrors.add("birthDate");
      }
    }

    // Validate Date of Death
    if (form.getDeathDate() != null && form.getDeathDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getDeathDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.deathdate"));
        formErrors.add("deathDate");
      }
    }

    // Validate Service Date
    if (form.getServiceDate() != null && form.getServiceDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getServiceDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.servicedate"));
        formErrors.add("serviceDate");
      }
    }

    // Validate Disposition Date
    if (form.getDispDate() != null && form.getDispDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getDispDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.dispdate"));
        formErrors.add("dispDate");
      }
    }

    return;
  }
  /**
   * Set the DbVitals and DbCase values from the FirstCallInformation form. Creation date:
   * (10/25/2002 11:00:39 AM)
   *
   * @param t com.aldorsolutions.webfdms.database.DatabaseTransaction
   * @param firstCall com.aldorsolutions.webfdms.beans.DbVitalsFirstCall
   * @param informant com.aldorsolutions.webfdms.beans.DbVitalsInformant
   * @param caseinfo com.aldorsolutions.webfdms.beans.DbCase
   * @param nextkin com.aldorsolutions.webfdms.beans.DbVitalsNextKin
   * @param nextkin com.aldorsolutions.webfdms.beans.DbVitalsExecutor
   * @param form fdms.ui.struts.form.FirstCallInformationForm
   * @param errors org.apache.struts.action.ActionErrors
   */
  public void setVitalsRest(
      DatabaseTransaction t,
      DbUserSession sessionUser,
      DbVitalsDeceased deceased,
      DbVitalsFirstCall firstCall,
      DbVitalsInformant informant,
      DbCase caseinfo,
      DbVitalsNextKin nextkin,
      DbVitalsExecutor executor,
      DbCemAtneed cematneed,
      CemAnStatus form,
      ActionErrors errors) {

    boolean continueDuplicate = true;

    try {
      if (form.isExecutorSame()) {
        logger.debug("Executor is the same");

        executor.setIsExecutorSame("Y");
        executor.setExecutorPersonId(form.getExecutorPersonId());
        executor.setExecutorFirstname(form.getInformantFirst());
        executor.setExecutorLastname(form.getInformantLast());
        executor.setExecutorStreet(form.getInformantStreet());
        executor.setExecutorStreet2(form.getInformantStreet2());
        executor.setExecutorStreet3(form.getInformantStreet3());
        executor.setExecutorCity(form.getInformantCity());
        executor.setExecutorState(form.getInformantState());
        executor.setExecutorZip(form.getInformantZip());
        executor.setExecutorPhone(FormatString.formatPhone(form.getInformantPhone()));
        executor.setExecutorRelation(form.getInformantRelation());
        executor.setExecutorEmail(form.getInformantEmail());

        // sets the vitals id for DbExecutor so I can insert values into database
        Persistent p = (Persistent) executor;
        p.setId(new Integer(form.getVitalsId()).intValue());

      } else {
        logger.debug("Executor is not the same");

        executor.setIsExecutorSame("N");
        executor.setExecutorPersonId(form.getExecutorPersonId());
        executor.setExecutorFirstname(form.getExecutorFirstName());
        executor.setExecutorLastname(form.getExecutorLastName());
        executor.setExecutorStreet(form.getExecutorStreet());
        executor.setExecutorStreet2(form.getExecutorStreet2());
        executor.setExecutorStreet3(form.getExecutorStreet3());
        executor.setExecutorCity(form.getExecutorCity());
        executor.setExecutorState(form.getExecutorState());
        executor.setExecutorZip(form.getExecutorZip());
        executor.setExecutorPhone(FormatString.formatPhone(form.getExecutorPhone()));
        executor.setExecutorRelation(form.getExecutorRelation());
        executor.setExecutorEmail(form.getExecutorEmail());

        // sets the vitals id for DbExecutor so I can insert values into database
        Persistent p = (Persistent) executor;
        p.setId(new Integer(form.getVitalsId()).intValue());
      }

      firstCall.setArrangeDate(FormatDate.convertToDateMMDDYYYY(form.getArrangeDate()));
      firstCall.setDispositionDate(FormatDate.convertToDateMMDDYYYY(form.getDispDate()));
      firstCall.setOriginalPnDate(FormatDate.convertToDateMMDDYYYY(form.getPreneedDate()));
      firstCall.setArrangeTime(form.getTime());
      firstCall.setPlaceDeathAddr(form.getLocationDeceased());
      firstCall.setSource(form.getSource());
      firstCall.setEmbalmingReason(form.getEmbalming());
      firstCall.setPlaceDeath(form.getPlaceDeath());
      firstCall.setPlaceDeathCity(form.getPlaceDeathCity());
      firstCall.setPlaceDeathState(form.getPlaceDeathState());
      firstCall.setPlaceDeathZip(form.getPlaceDeathZip());
      firstCall.setAgeYears(FormatNumber.parseInteger(form.getAge()));

      int chapelId = 0;
      if (form.getChapel() != null) {
        try {
          chapelId = Integer.parseInt(form.getChapel());
        } catch (NumberFormatException e) {
          // unable to parse int from String
        }
      }

      logger.debug("ChapelId : " + chapelId);

      DbLocation dbLocation = FdmsDb.getInstance().getLocation(t, chapelId);
      if (dbLocation != null) {
        firstCall.setFacilityName(dbLocation.getName());
        firstCall.setFacilityStreet(dbLocation.getAddr1());
        firstCall.setFacilityCityStZip(
            dbLocation.getCity() + ", " + dbLocation.getState() + ", " + dbLocation.getZip());
        firstCall.setFacilityLicenseNo(dbLocation.getLicenseNumber());
        firstCall.setFacilityPhone(FormatString.formatPhone(dbLocation.getPhone()));
      } else {
        firstCall.setFacilityName(form.getFacilityName());
        firstCall.setFacilityStreet(form.getFacilityStreet());
        firstCall.setFacilityCityStZip(
            form.getFacilityCity() + ", " + form.getFacilityState() + ", " + form.getFacilityZip());
        firstCall.setFacilityPhone(FormatString.formatPhone(form.getFacilityPhone()));
        firstCall.setFacilityLicenseNo(form.getFacilityLicense());
      }

      firstCall.setShippingInfo(form.getShippingInfo());

      DbArrangers dbArranger =
          FdmsDb.getInstance().getArranger(t, Integer.parseInt(form.getDirector()));
      firstCall.setArrangerName(dbArranger.getName());
      firstCall.setArrangerID(dbArranger.getId());

      informant.setSalutation(form.getInformantSalutation());
      informant.setFname(form.getInformantFirst());
      informant.setMname(form.getInformantMiddle());
      informant.setLname(form.getInformantLast());
      informant.setStreet(form.getInformantStreet());
      informant.setRoad2(form.getInformantStreet2());
      informant.setRoad3(form.getInformantStreet3());
      informant.setCity(form.getInformantCity());
      informant.setState(form.getInformantState());
      informant.setZip(form.getInformantZip());
      informant.setPhone(FormatString.formatPhone(form.getInformantPhone()));
      informant.setRelated(form.getInformantRelation());
      informant.setInformantEmail(form.getInformantEmail());

      if (form.getNextKinSame()) {
        nextkin.setSameAsInformant("Y");
        nextkin.setSalutation(form.getInformantSalutation());
        nextkin.setFirstname(form.getInformantFirst());
        nextkin.setLastname(form.getInformantLast());
        nextkin.setStreet(form.getInformantStreet());
        nextkin.setRoad2(form.getInformantStreet2());
        nextkin.setRoad3(form.getInformantStreet3());
        nextkin.setCity(form.getInformantCity());
        nextkin.setState(form.getInformantState());
        nextkin.setZip(form.getInformantZip());
        nextkin.setPhone(FormatString.formatPhone(form.getInformantPhone()));
        nextkin.setRelation(form.getInformantRelation());
      } else {
        nextkin.setSameAsInformant("N");
        nextkin.setSalutation(form.getNextKinSalutation());
        nextkin.setFirstname(form.getNextKinFirst());
        nextkin.setLastname(form.getNextKinLast());
        nextkin.setStreet(form.getNextKinStreet());
        nextkin.setRoad2(form.getNextKinStreet2());
        nextkin.setRoad3(form.getNextKinStreet3());
        nextkin.setCity(form.getNextKinCity());
        nextkin.setState(form.getNextKinState());
        nextkin.setZip(form.getNextKinZip());
        nextkin.setPhone(FormatString.formatPhone(form.getNextKinPhone()));
        nextkin.setRelation(form.getNextKinRelation());
      }

      cematneed.setCem_plottype(form.getCem_plottype());
      cematneed.setCem_section(form.getCem_section());
      cematneed.setCem_block(form.getCem_block());
      cematneed.setCem_lot_tier(form.getCem_lot_tier());
      cematneed.setCem_grave_row(form.getCem_grave_row());
      cematneed.setCem_Amount(form.getCem_Amount());
      cematneed.setCem_ANBuyerAptNo(form.getCem_ANBuyerAptNo());
      cematneed.setCem_ANBuyerCity(form.getCem_ANBuyerCity());
      cematneed.setCem_ANBuyerMidName(form.getCem_ANBuyerMidName());
      cematneed.setCem_ANBuyerTitle(form.getCem_ANBuyerTitle());
      cematneed.setCem_ANBuyerPhone(form.getCem_ANBuyerPhone());
      cematneed.setCem_ANBuyerState(form.getCem_ANBuyerState());
      cematneed.setCem_ANBuyerStreet(form.getCem_ANBuyerStreet());
      cematneed.setCem_ANBuyerFirstName(form.getCem_ANBuyerFirstName());
      cematneed.setCem_ANBuyerLastName(form.getCem_ANBuyerLastName());
      cematneed.setCem_ANBuyerZip(form.getCem_ANBuyerZip());
      cematneed.setCem_MapID(form.getCem_MapID());
      cematneed.setCem_Record(form.getCem_Record());
      cematneed.setCem_ContractDate(form.getCem_ContractDate());
      cematneed.setCem_MiscDesc(form.getCem_MiscDesc());
      cematneed.setCem_MiscAmount(form.getCem_MiscAmount());

      deceased.setDecFName(form.getBeneficiaryFirst());
      deceased.setDecMName(form.getBeneficiaryMiddle());
      deceased.setDecLName(form.getBeneficiaryLast());
      deceased.setDecResStreet(form.getBeneficiaryStreet());
      deceased.setDecResMailCity(form.getBeneficiaryCity());
      deceased.setDecResState(form.getBeneficiaryState());
      deceased.setDecResZip(form.getBeneficiaryZipCode());
      deceased.setDecResPhone(form.getBeneficiaryPhone());
      deceased.setSSNo(FormatString.removeDashes(form.getBeneficiarySocialSecurityNumber()));
      deceased.setDecFullName(form.getBeneficiaryFirst() + " " + form.getBeneficiaryLast());
      deceased.setDecmrmrs(form.getBeneficiaryTitle());
      deceased.setDecAptNo(form.getBeneficiaryAptno());

      caseinfo.setChapelLocation(dbLocation.getName());
      caseinfo.setChapelNumber(dbLocation.getId());
      caseinfo.setLocale(dbLocation.getLocaleNumber());
      caseinfo.setDeathDate(FormatDate.convertToDateYYYYMMDD(form.getDeathDate()));
      caseinfo.setServiceDate(FormatDate.convertToDateYYYYMMDD(form.getServiceDate()));
      caseinfo.setSaleDate(FormatDate.convertToDateYYYYMMDD(form.getServiceDate()));

      DatabaseTransaction x = null;

      // Regardless of whether the user changed the contract number or not, we need to make sure
      // that the
      // contract number is unique before we proceed.
      if (form.getContractNumber() != null && form.getContractNumber().trim().length() > 0) {
        try {
          x = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);
          while (continueDuplicate) {
            // Check for duplicate Contract Numbers.
            DbCase checkCase = new DbCase();
            checkCase.setNew();
            checkCase.setLocale(sessionUser.getRegion());
            checkCase.setId(deceased.getId());
            checkCase.setContractCode(form.getContractNumber());
            if (FdmsDb.getInstance().checkCaseExists(x, checkCase, DbCasePeer.CONTRACTCODE)) {
              // AppLog.trace("Contract " +form.getContractNumber() + " is a duplicate.");
              // If the user changed the contract number, give them an error
              if (!form.getNextContractNumber().equals(form.getContractNumber())) {
                errors.add(
                    ActionErrors.GLOBAL_ERROR, new ActionError("error.duplicate.contractNumber"));
                formErrors.add("contractNumber");
                continueDuplicate = false;
              } else {
                // contract number is same so need to increment and retest for duplicate
                form.setContractNumber(
                    String.valueOf(
                        SessionHelpers.nextContractNumber(
                            sessionUser.getDbLookup(), sessionUser.getRegion())));
                form.setNextContractNumber(form.getContractNumber());
                // AppLog.trace("Incremented contract# because duplicated. New next
                // number="+form.getContractNumber());
              }
            } else {
              continueDuplicate = false;
            }
          }
        } catch (Exception e) {
          logger.error("Error : ", e);
        } finally {
          if (x != null) {
            x.closeConnection();
            x = null;
          }
        }
      }

      caseinfo.setContractCode(form.getContractNumber());
      caseinfo.setCaseCode(form.getCaseNumber());

      // Add Informant as BillTo if no BillTos already exist.
      DbBillto[] dbBillTo = FdmsDb.getInstance().getBilltoForID(t, deceased.getId());
      if (dbBillTo == null || dbBillTo.length == 0) {
        if ((form.getInformantFirst() != null && form.getInformantFirst().trim().length() > 0)
            || (form.getInformantLast() != null && form.getInformantLast().trim().length() > 0)) {
          DbBillto newBillTo = new DbBillto();
          newBillTo.setNew();
          // newBillTo.setCashSale();
          newBillTo.setCity(form.getInformantCity());
          // newBillTo.setContractSigner();
          // newBillTo.setCounty();
          newBillTo.setEmailAddress(form.getInformantEmail());
          // newBillTo.setFileVersion();
          newBillTo.setFirstName(form.getInformantFirst());
          newBillTo.setHomePhone(FormatString.formatPhone(form.getInformantPhone()));
          newBillTo.setHonorific(form.getInformantSalutation());
          // newBillTo.setLanguage(form.getInformant);
          newBillTo.setLastName(form.getInformantLast());
          // newBillTo.setRefused(form.getInformant);
          newBillTo.setRelation(form.getInformantRelation());
          newBillTo.setSendInvoice("Y");
          newBillTo.setSeqNo(Short.parseShort("0"));
          // newBillTo.setSocialSecurityNo(form.getInformant);
          newBillTo.setState(form.getInformantState());
          newBillTo.setStreet1(form.getInformantStreet());
          newBillTo.setStreet2(form.getInformantStreet2());
          newBillTo.setStreet3(form.getInformantStreet3());
          // newBillTo.setStreet4(form.getInformant);
          newBillTo.setVitalsID(deceased.getId());
          // newBillTo.setWorkPhone(form.getInformant);
          newBillTo.setZip(form.getInformantZip());
          if (form.getInformantContractSigner()) {
            newBillTo.setContractSigner("Y");
          }
          t.addPersistent(newBillTo);
        }
      }

    } catch (Exception e) {
      logger.error("Exception in setVitalsRest() ", e);
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.setData"));
    }

    return;
  }