private void setReport(
      ReportForm form,
      DbUserSession sessionUser,
      HttpSession session,
      ActionMessages errors,
      HttpServletRequest request) {
    ArrayList<OptionsList> reports = new ArrayList<OptionsList>();
    DatabaseTransaction t = null;
    try {
      t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);
      com.aldorsolutions.webfdms.beans.DbFormsAvailable[] list =
          FdmsDb.getInstance().getFormsAvailableForLocale(t, 0, 18);
      for (int i = 0; i < list.length; i++) {
        reports.add(
            new OptionsList(Integer.toString(list[i].getFormId()), list[i].getDescription()));
      }
      request.setAttribute("reports", reports);
    } catch (PersistenceException ex) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.internal"));
      saveErrors(request, errors);
      logger.error("Persistence Exception in PrintReportAction.do Perform. ", ex);

    } finally {
      if (t != null) t.closeConnection();
    }
  }
  /**
   * 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;
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws javax.servlet.ServletException, java.io.IOException {

    logger.debug("********************************************");
    logger.debug("*** Entering ProcessFirstCallInformation ***");

    CemAnStatus form = (CemAnStatus) actionForm;
    ActionErrors errors = new ActionErrors();
    formErrors = new ArrayList();
    HttpSession session = request.getSession();
    DbUserSession sessionUser = (DbUserSession) session.getAttribute(SessionValueKeys.DB_USER);

    logger.debug("ExecutorSame request value : " + request.getParameter("executorSame"));

    DatabaseTransaction t = null;
    FdmsDb fdmsdb = null;
    DbVitalsDeceased deceased = null;
    DbVitalsInformant informant = null;
    DbVitalsFirstCall firstCall = null;
    DbCase caseinfo = null;
    DbVitalsNextKin nextkin = null;
    DbPreneed preneed = null;
    DbVitalsSchedule sched = null;
    DbVitalsExecutor executor = null;
    DbCemAtneed cematneed = null;
    boolean addmode = false;
    int vitalsid = 0;
    String directive = form.getDirective();

    // Try to set the vitalsid from the form.
    try {
      vitalsid = FormatNumber.parseInteger(form.getVitalsId());
    } catch (Exception e) {
      vitalsid = 0;
    }

    cematneed = new DbCemAtneed();
    cematneed.setNew();

    if (directive.equals("cancel")) {
      // go back to case status unless no vitalsid then, show introduction.
      vitalsid = SessionHelpers.getVitalsIdFromSession(request, sessionUser);
      if (vitalsid > 0) {
        return mapping.findForward("showCaseStatusGlobal");
      } else {
        return mapping.findForward("ShowIntroductionGlobal");
      }
    }

    if (directive.equals("help")) {
      return mapping.findForward("usingHelp");
    }

    // From this point, we need to access the database
    try {
      t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);
      fdmsdb = FdmsDb.getInstance();

      if (directive.equals("redisplay")) {
        redisplayForm(t, sessionUser, form, errors);
        form.setDirective(" ");
        session.setAttribute("cemAnStatus", form);
        return new ActionForward(mapping.getInput());
      }

      validateForm(t, sessionUser, form, errors);
      // if errors found, return to input screen without saving anything
      if (!errors.isEmpty()) {
        // AppLog.info("ProcessFirstCall Invoking forward mapping getInput() after validation.");
        saveErrors(request, errors);
        request.setAttribute("formErrors", formErrors);

        form.setDirective(" ");
        session.setAttribute("cemAnStatus", form);
        return new ActionForward(mapping.getInput());
      } else {
        // AppLog.trace("ProcessFirstCall past validation.");
      }

      // Get the DbVitalDeceased and DbVitalsFirstCall objects
      if (vitalsid == 0) {
        deceased = new DbVitalsDeceased();
        deceased.setNew();
        addmode = true;
      } else {
        deceased = fdmsdb.getVitalsDeceased(t, vitalsid);
      }

      // Set the data in the DbVitalsDeceased and DbVitalsFirstCall records
      setVitalsDeceased(deceased, informant, form, errors);
      // if errors found, return to input screen without saving anything
      if (!errors.isEmpty()) {
        // AppLog.info("ProcessFirstCall Invoking forward mapping getInput() after
        // setVitalsDeceased.");
        saveErrors(request, errors);
        request.setAttribute("formErrors", formErrors);
        session.setAttribute("cemAnStatus", form);
        form.setDirective(" ");
        return new ActionForward(mapping.getInput());
      } else {
        // AppLog.trace("ProcessFirstCall past setVitalsDeceased.");
      }

      if (vitalsid == 0) {
        t.addPersistent(deceased);
        t.save();
        t.closeConnection();
        t = null;

        vitalsid = deceased.getId();
        form.setVitalsId(String.valueOf(vitalsid));
        sessionUser.setCurrentCaseID(vitalsid);
        // Need another transaction to continue with add
        t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);
        // increment next contract number if user did not change it
        // and assign to this case
        // if user changed contract# then use the one they entered.
        if (form.getContractNumber().equals(form.getNextContractNumber())) {
          int newnextno =
              SessionHelpers.nextContractNumber(sessionUser.getDbLookup(), sessionUser.getRegion());
          form.setContractNumber(String.valueOf(newnextno));
          form.setNextContractNumber(form.getContractNumber());
          // need new transaction since save in above method ends that transaction
        }
        sched = fdmsdb.getVitalsSchedule(t, vitalsid);
        sched.setDefaultAtNeedCheckList(sessionUser.getRegion(), sessionUser.getDbLookup());
      } else {
        sched = fdmsdb.getVitalsSchedule(t, vitalsid);
      }

      // Now, lets update the other Vitals information
      SessionHelpers.setVitalsIdInRequest(request, vitalsid);
      firstCall = fdmsdb.getVitalsFirstCall(t, vitalsid);
      informant = fdmsdb.getVitalsInformant(t, vitalsid);
      caseinfo = fdmsdb.getCase(t, vitalsid);
      nextkin = fdmsdb.getVitalsNextKin(t, vitalsid);
      executor = fdmsdb.getVitalsExecutor(t, vitalsid);
      // cematneed = fdmsdb.getCemAtneed(t, vitalsid);
      if (executor == null) {
        executor = new DbVitalsExecutor();
        executor.setNew();
      }
      setVitalsRest(
          t,
          sessionUser,
          deceased,
          firstCall,
          informant,
          caseinfo,
          nextkin,
          executor,
          cematneed,
          form,
          errors);
      // if errors found, return to input screen without saving anything
      if (!errors.isEmpty()) {
        // AppLog.info("ProcessFirstCall Invoking forward mapping getInput() after setVitalsRest.");
        saveErrors(request, errors);
        request.setAttribute("formErrors", formErrors);
        session.setAttribute("cemAnStatus", form);
        form.setDirective(" ");
        return new ActionForward(mapping.getInput());
      } else {
        logger.debug("no errors exist in processfirstcall information");
        // AppLog.trace("ProcessFirstCall past setVitalsRest.");
      }

      // determine whether active preneed or deceased
      preneed = fdmsdb.getPreneed(t, vitalsid);
      String relation = "Deceased";
      if (preneed.getStatus().equals(DbPreneed.ACTIVE)) {
        relation = "Preneed";
      }
      t.removePersistent(preneed);

      // update special survivor information for searching deceased, informant, case#, contract#
      DbSurvivor.addUpdateSurvivor(
          t,
          vitalsid,
          DbSurvivor.DECEASED,
          deceased.getSalutation(),
          deceased.getDecFName(),
          deceased.getDecMName(),
          deceased.getDecLName(),
          deceased.getSuffix(),
          deceased.getMaidenName(),
          deceased.getFullName(),
          deceased.getDecResStreet() + " " + deceased.getDecAptNo(),
          "",
          deceased.getDecResMailCity(),
          deceased.getDecResState(),
          deceased.getDecResZip(),
          "",
          "",
          "",
          relation,
          "",
          "",
          "");
      DbSurvivor.addUpdateSurvivor(
          t,
          vitalsid,
          DbSurvivor.INFORMANT,
          informant.getSalutation(),
          informant.getFname(),
          informant.getMname(),
          informant.getLname(),
          "",
          "",
          "",
          informant.getStreet() + " " + informant.getRoad2() + " " + informant.getRoad3(),
          "",
          informant.getCity(),
          informant.getState(),
          informant.getZip(),
          informant.getPhone(),
          "",
          informant.getInformantEmail(),
          "Informant",
          "",
          "",
          "");
      DbSurvivor.addUpdateSurvivor(
          t,
          vitalsid,
          DbSurvivor.CONTRACT,
          "",
          deceased.getDecLName(),
          "",
          caseinfo.getContractCode(),
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          deceased.getDecFName(),
          "",
          "",
          "");
      DbSurvivor.addUpdateSurvivor(
          t,
          vitalsid,
          DbSurvivor.CASECODE,
          "",
          deceased.getDecLName(),
          "",
          caseinfo.getCaseCode(),
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          deceased.getDecFName(),
          "",
          "",
          "");

      // add informant and next-of-kin as normal survivors but only during add cycle
      if (addmode) {
        // AppLog.trace("Adding informant and NOK as survivors.");
        DbSurvivor infsurv =
            new DbSurvivor(
                vitalsid,
                informant.getSalutation(),
                informant.getFname(),
                informant.getMname(),
                informant.getLname(),
                "",
                "",
                "",
                informant.getStreet() + " " + informant.getRoad2() + " " + informant.getRoad3(),
                "",
                informant.getCity(),
                informant.getState(),
                informant.getZip(),
                informant.getPhone(),
                "",
                informant.getInformantEmail(),
                informant.getRelated(),
                "",
                "",
                "",
                "");
        t.addPersistent(infsurv);
        if (!form.getNextKinSame()) {
          DbSurvivor noksurv =
              new DbSurvivor(
                  vitalsid,
                  nextkin.getSalutation(),
                  nextkin.getFirstname(),
                  "",
                  nextkin.getLastname(),
                  "",
                  "",
                  "",
                  nextkin.getStreet() + nextkin.getRoad2() + " " + nextkin.getRoad3(),
                  "",
                  nextkin.getCity(),
                  nextkin.getState(),
                  nextkin.getZip(),
                  nextkin.getPhone(),
                  "",
                  "",
                  nextkin.getRelation(),
                  "",
                  "",
                  "",
                  "");
          t.addPersistent(noksurv);
        }
      }
      t.addPersistent(cematneed);

      if (executor != null) t.addPersistent(executor);

      // Final commit and cleanup
      t.save();

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

    if (!errors.isEmpty()) {
      // AppLog.info("ProcessFirstCallInformation Invoking forward mapping getInput().");
      saveErrors(request, errors);
      request.setAttribute("formErrors", formErrors);
      form.setDirective(" ");
      session.setAttribute("cemAnStatus", form);
      return (new ActionForward(mapping.getInput()));
    }

    // remove session variables used in FirstCall page
    SessionHelpers.removeArrangerListFromSession(request);
    SessionHelpers.removeChapelListInSession(request);
    session.removeAttribute("cemAnStatus");
    SessionHelpers.setVitalsIdInRequest(request, vitalsid);

    // Since we are forwarding to another ACTION, need to go through this exercise
    /*	ActionMappings mappings = mapping.getMappings();
           String returnPath = actionForward.getPath();
           int periodpos = returnPath.indexOf(".do");
           returnPath = returnPath.substring(0,periodpos);
           ActionMapping finalMapping = mappings.findMapping(returnPath);
           Action finalAction = null;

           try {
               Class clazz = Class.forName(finalMapping.getType());
               finalAction = (Action) clazz.newInstance();
               AppLog.trace("chaining to:"+finalAction.toString());
           } catch (Exception e) {
               AppLog.warning("Could not find chained action: " + e.getMessage());
               return forwardGlobalCancel(mapping) ;
           }

           return finalAction.perform(finalMapping,form,request,response);
    */
    // return forwardShowCaseStatusGlobal(mapping);

    if (errors.isEmpty()) {
      request.setAttribute("redirect", Boolean.TRUE);
      request.setAttribute("vitalsId", new Integer(vitalsid));
    }
    return new ActionForward(mapping.getInput());
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws javax.servlet.ServletException, java.io.IOException {

    ActionErrors errors = new ActionErrors();
    HttpSession session = request.getSession();
    DbUserSession sessionUser = SessionHelpers.getUserSession(request);
    DatabaseTransaction t = null;
    DbSpeedData[] dbSpeedData = null;
    DbLocation[] dbLocation = null;
    LocaleDTO userlocale = null;

    MiscCashReceiptsForm miscCashReceipts = new MiscCashReceiptsForm();
    java.util.ArrayList locationList = new java.util.ArrayList();
    java.util.ArrayList glDescriptionList = new java.util.ArrayList();
    java.util.ArrayList cashAcctList = new java.util.ArrayList();
    java.util.ArrayList payMethodList = new java.util.ArrayList();
    java.util.ArrayList pleaseSelect = new java.util.ArrayList();

    if (sessionUser == null) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.login.invalid"));
    }

    // Database Access Logic
    try {
      t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);

      // Set the list of receipt types in session.
      SessionHelpers.setReceiptTypesInSession(request);

      // Populate the locationList collection
      dbLocation = FdmsDb.getInstance().getLocationsForRegion(t, sessionUser.getRegion());
      // AppLog.trace("DbLocation list length = " +dbLocation.length);
      for (int i = 0; i < dbLocation.length; i++) {
        String listValue = String.valueOf(dbLocation[i].getId());
        String listLabel = dbLocation[i].getName();
        locationList.add(new OptionsList(listValue, listLabel));
      }

      // Populate the glDescriptionList collection
      dbSpeedData =
          FdmsDb.getInstance()
              .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "REVTYPE");
      // AppLog.trace("DbSpeedData for REVTYPE list length = " +dbSpeedData.length);
      for (int i = 0; i < dbSpeedData.length; i++) {
        String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2);
        String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1);
        glDescriptionList.add(new OptionsList(listValue, listLabel));
      }

      // Populate the cashAcctList collection
      dbSpeedData =
          FdmsDb.getInstance()
              .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "CASHTYPE");
      // AppLog.trace("DbSpeedData for CASHTYPE list length = " +dbSpeedData.length);
      for (int i = 0; i < dbSpeedData.length; i++) {
        String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2);
        String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1);
        cashAcctList.add(new OptionsList(listValue, listLabel));
      }

      // Populate the payMethodList", payMethodList)
      userlocale =
          FdmsDb.getInstance().getLocale(sessionUser.getDbLookup(), sessionUser.getRegion());
      dbSpeedData =
          FdmsDb.getInstance()
              .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "PAYMETHOD");
      // AppLog.trace("DbSpeedData for PAYMETHOD list length = " +dbSpeedData.length);
      for (int i = 0; i < dbSpeedData.length; i++) {
        if (dbSpeedData[i].getData() != null && dbSpeedData[i].getData().length() > 1) {
          String listValue = dbSpeedData[i].getData().substring(0, 2);
          String listLabel = dbSpeedData[i].getData();
          payMethodList.add(new OptionsList(listValue, listLabel));
        }
      }

      // Form Defaults
      miscCashReceipts.setSubmitButton("");
      miscCashReceipts.setAmountOfTran("0");
      miscCashReceipts.setDateOfTran(FormatDate.getCurrentDateFormatedMMDDYYYY());
      miscCashReceipts.setFormId("None");
      miscCashReceipts.setReceiptNumber(String.valueOf(userlocale.getNextReceiptNo()));

      pleaseSelect.add(new OptionsList("", "--Select--"));
      // AppLog.trace("Finished setting miscCashReceipts form bean");

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

    // Set Form Bean Into Scope
    session.setAttribute("miscCashReceipts", miscCashReceipts);
    session.setAttribute("locationList", locationList);
    session.setAttribute("glDescriptionList", glDescriptionList);
    session.setAttribute("cashAcctList", cashAcctList);
    session.setAttribute("payMethodList", payMethodList);
    session.setAttribute("pleaseSelect", pleaseSelect);
    // AppLog.trace("Setting miscCashReceipts form bean and collection arrays into session scope.");

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

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

    return actionForward;
  }
  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;
  }
  /** Insert the method's description here. Creation date: (11/22/2002 9:31:43 AM) */
  public void setNewForm(
      HttpServletRequest request,
      DbUserSession sessionUser,
      HttpSession session,
      fdms.ui.struts.form.MiscCashReceiptsForm form,
      ActionErrors errors) {

    DatabaseTransaction t = null;
    DbSpeedData[] dbSpeedData = null;
    DbLocation[] dbLocation = null;
    LocaleDTO userlocale = null;
    ArrayList locationList = new ArrayList();
    ArrayList glDescriptionList = new ArrayList();
    ArrayList cashAcctList = new ArrayList();
    ArrayList payMethodList = new ArrayList();
    ArrayList pleaseSelect = new ArrayList();

    // Database Access Logic
    try {
      t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);

      // Set the list of receipt types in session.
      SessionHelpers.setReceiptTypesInSession(request);

      // Populate the locationList collection
      dbLocation = FdmsDb.getInstance().getLocationsForRegion(t, sessionUser.getRegion());
      // AppLog.trace("DbLocation list length = " +dbLocation.length);
      for (int i = 0; i < dbLocation.length; i++) {
        String listValue = String.valueOf(dbLocation[i].getId());
        String listLabel = dbLocation[i].getName();
        locationList.add(new OptionsList(listValue, listLabel));
      }

      // Populate the glDescriptionList collection
      dbSpeedData =
          FdmsDb.getInstance()
              .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "REVTYPE");
      // AppLog.trace("DbSpeedData for REVTYPE list length = " +dbSpeedData.length);
      for (int i = 0; i < dbSpeedData.length; i++) {
        String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2);
        String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1);
        glDescriptionList.add(new OptionsList(listValue, listLabel));
      }

      // Populate the cashAcctList collection
      dbSpeedData =
          FdmsDb.getInstance()
              .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "CASHTYPE");
      // AppLog.trace("DbSpeedData for CASHTYPE list length = " +dbSpeedData.length);
      for (int i = 0; i < dbSpeedData.length; i++) {
        String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2);
        String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1);
        cashAcctList.add(new OptionsList(listValue, listLabel));
      }

      // Populate the payMethodList", payMethodList)
      userlocale =
          FdmsDb.getInstance().getLocale(sessionUser.getDbLookup(), sessionUser.getRegion());

      dbSpeedData =
          FdmsDb.getInstance()
              .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "PAYMETHOD");
      // AppLog.trace("DbSpeedData for PAYMETHOD list length = " +dbSpeedData.length);
      for (int i = 0; i < dbSpeedData.length; i++) {
        String listValue = dbSpeedData[i].getData().substring(0, 2);
        String listLabel = dbSpeedData[i].getData();
        payMethodList.add(new OptionsList(listValue, listLabel));
      }

      // Form Defaults
      form.setSubmitButton("");
      form.setAmountOfTran("0");
      form.setDateOfTran(FormatDate.getCurrentDateFormatedMMDDYYYY());
      form.setFormId("None");
      form.setReceiptNumber(String.valueOf(userlocale.getNextReceiptNo()));

      pleaseSelect.add(new OptionsList("", "--Select--"));
      // AppLog.trace("Finished setting miscCashReceipts form bean");

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

    // Set Form Bean Into Scope
    session.setAttribute("locationList", locationList);
    session.setAttribute("glDescriptionList", glDescriptionList);
    session.setAttribute("cashAcctList", cashAcctList);
    session.setAttribute("payMethodList", payMethodList);
    session.setAttribute("pleaseSelect", pleaseSelect);
    // AppLog.trace("Setting miscCashReceipts collection arrays into session scope.");

  }
  /**
   * Called from ProcessMiscCashReceipts, this Method sets the History record from the
   * MiscCashReceipts form values. If am error occurs, the error is stored in the errors collection.
   * Creation date: (8/13/2002 3:41:43 PM)
   */
  public void setHistory(
      DatabaseTransaction t,
      DbUserSession sessionUser,
      DbHistory dbHistory,
      fdms.ui.struts.form.MiscCashReceiptsForm form,
      ActionErrors errors) {

    String errorField = new String();
    String formField = null;
    DbLocale userlocale = null;
    DatabaseTransaction tlocale = null;
    int receiptNumber = 0;

    try {

      errorField = "VitalsMasterKey";
      dbHistory.setLMainKey(0);

      errorField = "ARAcct";
      formField = "arAcct";
      dbHistory.setCHistARacct(form.getArAcct());

      errorField = "Date";
      formField = "dateOfTran";
      dbHistory.setCHistDate(
          new java.sql.Date(FormatDate.convertToDate(form.getDateOfTran()).getTime()));

      errorField = "Description";
      formField = "description";
      dbHistory.setCHistDesc(form.getDescription());

      errorField = "GLAcct";
      formField = "glAcct";
      dbHistory.setCHistGLAcct(form.getGlAcct());

      errorField = "ManualReceipt";
      formField = "manualReceiptNo";
      dbHistory.setCHistManualReceipt(form.getManualReceiptNo());

      errorField = "OriginalPosting";
      formField = "";
      dbHistory.setCHistOriginalPosting('N');

      errorField = "PayMethod";
      formField = "getPayMethod";
      dbHistory.setCHistPayMethod(form.getPayMethod());

      errorField = "Posted";
      formField = "";
      dbHistory.setCHistPosted('N');

      errorField = "SPF";
      formField = "";
      dbHistory.setCHistSPF('R');

      // Set Receipt Number from locale
      try {
        tlocale = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);
        userlocale = FdmsDb.getInstance().getLocaleWithLock(tlocale, sessionUser.getRegion());
        if (userlocale == null) {
          throw new java.sql.SQLException("No locale for user region.");
        }
        receiptNumber = userlocale.getNextReceiptNo();
        userlocale.setNextReceiptNo(receiptNumber + 1);
        tlocale.addPersistent(userlocale);
        tlocale.save();
        // AppLog.trace("ProcessMiscCashReceipts: next receipt number = " +receiptNumber);

      } catch (java.sql.SQLException e) {
        if (e.getErrorCode() == 1205) {
          // AppLog.warning("ProcessMiscCashReceipts - DbLocale locked from updating."
          // +sessionUser.getRegion());
          throw new PersistenceException("User locale temporarily locked. Try again.");
        }
        // AppLog.warning("ProcessMiscCashReceipts - invalid region for user "
        // +sessionUser.getUserName());
        throw new PersistenceException("Invalid region for user", e);
      } finally {
        if (t != null) {
          t.closeConnection();
        }
      }

      errorField = "ReceiptNo";
      dbHistory.setLHistReceiptNo(receiptNumber);

      errorField = "Amount";
      dbHistory.setLHistAmount(
          FormatNumber.parseInteger(
              String.valueOf(FormatCurrency.convertToCurrency(form.getAmountOfTran()))));

      errorField = "LocationId";
      dbHistory.setLocationId(Integer.parseInt(form.getLocationId()));

      t.addPersistent(dbHistory);

    } catch (Exception e) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.receipts.set" + errorField));
      formErrors.add(formField);
    }

    return;
  }
  private void changeLocale(
      ReportForm form,
      DbUserSession sessionUser,
      HttpSession session,
      ActionMessages errors,
      HttpServletRequest request) {

    ArrayList userLocales = (ArrayList) session.getAttribute(Constants.USER_LOCALES);

    if (userLocales != null) {

      DatabaseTransaction t = null;
      DatabaseTransaction trans = null;

      try {
        trans = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser);

        DbUser user = (DbUser) sessionUser;

        LocaleManagerBean lmb = new LocaleManagerBean(user);
        LocaleDTO locale = lmb.getLocale(Long.parseLong(form.getUserLocaleId()));

        ArrayList<DbLocation> userLocaleLocs = new ArrayList<DbLocation>();
        if (form.getUserLocaleId().compareToIgnoreCase("0") == 0) {
          // do nothing since the report will print for all locales
        } else {
          String[] locationIds = (String[]) session.getAttribute(Constants.USER_LOCATION_IDS);
          DbLocation[] dbLocations =
              FdmsDb.getInstance()
                  .getLocationsForRegion(trans, Integer.parseInt(form.getUserLocaleId()));
          if (dbLocations != null) {
            for (int i = 0; i < dbLocations.length; i++) {
              DbLocation loc = dbLocations[i];
              int locID = loc.getId();

              for (int x = 0; x < locationIds.length; x++) {
                int aLocID = Integer.parseInt(locationIds[x]);

                if (aLocID == locID) {
                  userLocaleLocs.add(loc);
                }
              }
            }
          }
        }
        session.setAttribute(Constants.USER_LOCATIONS, userLocaleLocs);
        form.setUserLocationId(String.valueOf(0));
        // t.save();

      } catch (PersistenceException ex) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.internal"));
        saveErrors(request, errors);
        logger.error("Persistence Exception in PrintReportAction.do Perform. ", ex);
      } catch (Exception ex) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.internal"));
        saveErrors(request, errors);
        logger.error("Exception in PrintReportAction.do Perform. ", ex);
      } finally {
      }

    } else {
      logger.debug("Unable to find USER_LOCALES in session");
    }
  }