Exemplo n.º 1
0
  private PdfPTable getNonPersonalized(UserShopForm sForm) throws DocumentException {

    PdfPTable personalInfo = new PdfPTable(2);
    personalInfo.setWidthPercentage(50);
    personalInfo.setWidths(sizes);
    personalInfo.getDefaultCell().setBorder(borderType);

    String dateStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.date:", null);
    personalInfo.addCell(makePhrase(dateStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String submittedByStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.submittedBy:", null);
    personalInfo.addCell(makePhrase(submittedByStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String companyNameStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.companyName:", null);
    personalInfo.addCell(makePhrase(companyNameStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String siteNumStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.site#:", null);
    personalInfo.addCell(makePhrase(siteNumStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String address1Str = ClwI18nUtil.getMessage(mRequest, "shop.og.text.address1:", null);
    personalInfo.addCell(makePhrase(address1Str + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String address2Str = ClwI18nUtil.getMessage(mRequest, "shop.og.text.address2:", null);
    personalInfo.addCell(makePhrase(address2Str + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String address3Str = ClwI18nUtil.getMessage(mRequest, "shop.og.text.address3:", null);
    personalInfo.addCell(makePhrase(address3Str + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String cityStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.city:", null);
    personalInfo.addCell(makePhrase(cityStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    if (sForm.getAppUser().getUserStore().isStateProvinceRequired()) {
      String state = sForm.getAppUser().getSite().getSiteAddress().getStateProvinceCd();
      if (Utility.isSet(state)) {
        String stateStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.state:", null);
        personalInfo.addCell(makePhrase(stateStr + " ", smallHeading, false));
        personalInfo.addCell(
            makePhrase("_____________________________________________ ", smallHeading, true));
      }
    }

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String postalCodeStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.postalCode:", null);
    personalInfo.addCell(makePhrase(postalCodeStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String phoneNumStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.phone#:", null);
    personalInfo.addCell(makePhrase(phoneNumStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    personalInfo.addCell(makePhrase("", smallHeading, false));
    personalInfo.addCell(makePhrase("", smallHeading, true));

    String orderPlacedByStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.orderPlacedBy:", null);
    personalInfo.addCell(makePhrase(orderPlacedByStr + " ", smallHeading, false));
    personalInfo.addCell(
        makePhrase("_____________________________________________ ", smallHeading, true));

    return personalInfo;
  }
Exemplo n.º 2
0
  public void generatePdf(
      UserShopForm sForm,
      List pItems,
      StoreData pStore,
      OutputStream pOut,
      String pImageName,
      boolean personal,
      boolean pCatalogOnly,
      String catalogLocaleCd)
      throws IOException {
    mSkuTag = ClwI18nUtil.getMessage(mRequest, "shop.og.text.ourSkuNum", null);

    try {
      catalogOnly = pCatalogOnly;
      initColumnsAdnWidths(sForm.getAppUser());
      mSiteData = sForm.getAppUser().getSite();
      AccountData mAccount = sForm.getAppUser().getUserAccount();
      String ogInvDisplay =
          mAccount.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.INVENTORY_OG_LIST_UI);
      boolean modernShoppingFl = mSiteData.hasModernInventoryShopping();
      // loop through the items to check if the footer needs to have the pack
      // Disclaimer printed on each page.
      boolean printProblemPackDisclaimer = false,
          invItems = false,
          invAutoOrderItems = false,
          nonInvItems = false,
          addNewPage = false;

      for (int i = 0; i < pItems.size(); i++) {
        ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i);
        if (sci.getProduct().isPackProblemSku()) {
          printProblemPackDisclaimer = true;
        }
        if (sci.getIsaInventoryItem()) {
          invItems = true;
          if (null != mSiteData
              && mSiteData.isAnInventoryAutoOrderItem(sci.getProduct().getProductId())) {
            invAutoOrderItems = true;
          }

        } else {
          nonInvItems = true;
          if (invItems) addNewPage = true;
        }
      }

      Phrase headPhrase = new Phrase(makeChunk("", heading, true));
      if (catalogOnly) {
        String catalogStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.catalog", null);
        headPhrase.add(makeChunk(catalogStr, heading, true));
      } else {
        if (sForm.getAppUser().getSite() != null
            && sForm.getAppUser().getSite().getBSC() != null
            && sForm.getAppUser().getSite().getBSC().getBusEntityData() != null
            && sForm.getAppUser().getSite().getBSC().getBusEntityData().getShortDesc() != null) {
          String subname =
              sForm.getAppUser().getSite().getBSC().getBusEntityData().getShortDesc() + " ";
          headPhrase.add(makeChunk(subname, heading, true));
          headPhrase.add(makeChunk(" ", heading, true));
        }
        String orderGuideStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.orderGuide", null);
        headPhrase.add(makeChunk(orderGuideStr, heading, true));
        headPhrase.add(makeChunk(" ", heading, true));
        headPhrase.add(
            makeChunk(
                sForm.getAppUser().getUserAccount().getBusEntity().getShortDesc(), heading, true));
      }
      HeaderFooter header = new HeaderFooter(headPhrase, true);
      header.setAlignment(HeaderFooter.ALIGN_RIGHT);

      // setup the document
      // pageSize,  marginLeft, marginRight,  marginTop, marginBottom
      Document document = new Document(PageSize.A4, 10, 15, 30, 15);
      PdfWriter writer = PdfWriter.getInstance(document, pOut);

      String addr =
          pStore.getPrimaryAddress().getAddress1() + " " + pStore.getPrimaryAddress().getAddress2();
      Chunk disclaimer = null;
      String fmsg = "";
      if (invItems) {
        fmsg += ClwI18nUtil.getMessage(mRequest, "shop.og.text.i-inventoryItem", null) + " ";
      }
      if (invAutoOrderItems) {
        fmsg += ClwI18nUtil.getMessage(mRequest, "shop.og.text.a-autoOrderItem", null) + " ";
      }
      if (printProblemPackDisclaimer) {
        fmsg +=
            ClwI18nUtil.getMessage(mRequest, "shop.og.text.*packAndOrUomMayDifferByRegion", null);
      }
      if (fmsg.length() > 0) {
        disclaimer = makeChunk(fmsg, smallItalic, true);
      }

      Phrase footPhrase = makeStoreFooter(pStore, disclaimer, null);

      HeaderFooter footer = new HeaderFooter(footPhrase, false);
      footer.setAlignment(HeaderFooter.ALIGN_CENTER);

      // setup the borders from the header
      header.setBorder(borderType);
      footer.setBorder(HeaderFooter.TOP);

      document.setHeader(header);
      document.setFooter(footer);
      document.open();

      // voc message
      String vocMessage = ClwI18nUtil.getMessage(mRequest, "shop.message.vocNotIncluded", null);
      document.add(makePhrase(vocMessage, smallHeading, true));
      document.add(makePhrase(null, smallHeading, true));

      drawOGHeader(document, sForm, pImageName, personal);
      if (modernShoppingFl && !"SEPARATED LIST".equals(ogInvDisplay)) {
        drawHeader(
            document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true);

        String prevCat = null;
        for (int i = 0; i < pItems.size(); i++) {
          ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i);
          Table itmTable = makeItemElement(sci);

          // if the item data will not fit onto the page,
          // make a new page, and redraw the header.

          if (writer.fitsPage(itmTable, document.bottomMargin() + 10)) {
            if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
              if (null == prevCat || !prevCat.equals(sci.getCategoryPath())) {
                document.add(makePhrase(sci.getCategoryPath(), smallHeading, true));
                document.add(makePhrase(null, smallHeading, true));
              }
              prevCat = sci.getCategoryPath();
            }
          }

          if (!writer.fitsPage(itmTable, document.bottomMargin() + 10)) {
            document.newPage();
            pageNumber = pageNumber + 1;
            drawHeader(
                document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true);
            if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
              document.add(makePhrase(sci.getCategoryPath(), smallHeading, true));
              document.add(makePhrase(null, smallHeading, true));
              prevCat = sci.getCategoryPath();
            }
          }
          document.add(itmTable);
        }

      } else {
        if (invItems) {
          drawHeader(
              document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true);

          String prevCat = null;
          for (int i = 0; i < pItems.size(); i++) {
            ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i);
            if (sci.getIsaInventoryItem() == false) {
              continue;
            }
            if (sci.getInventoryParValuesSum() <= 0) {
              // This is an inventory item that is not
              // allowed for this location.
              continue;
            }
            Table itmTable = makeItemElement(sci);

            // if the item data will not fit onto the page,
            // make a new page, and redraw the header.

            if (writer.fitsPage(itmTable, document.bottomMargin() + 10)) {
              if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
                if (null == prevCat || !prevCat.equals(sci.getCategoryPath())) {
                  document.add(makePhrase(sci.getCategoryPath(), smallHeading, true));
                  document.add(makePhrase(null, smallHeading, true));
                }
                prevCat = sci.getCategoryPath();
              }
            }

            if (!writer.fitsPage(itmTable, document.bottomMargin() + 10)) {
              document.newPage();
              pageNumber = pageNumber + 1;
              drawHeader(
                  document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, true);
              if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
                document.add(makePhrase(sci.getCategoryPath(), smallHeading, true));
                document.add(makePhrase(null, smallHeading, true));
                prevCat = sci.getCategoryPath();
              }
            }
            document.add(itmTable);
          }
        }

        if (nonInvItems) {

          if (addNewPage) {
            document.newPage();
            pageNumber = pageNumber + 1;
          }

          drawHeader(
              document, pageNumber, pStore.getStoreBusinessName().getValue(), pImageName, false);
          document.add(makeBlankLine());

          String prevCat = null;
          for (int i = 0; i < pItems.size(); i++) {
            ShoppingCartItemData sci = (ShoppingCartItemData) pItems.get(i);
            if (sci.getIsaInventoryItem()) {
              continue;
            }

            Table itmTable = makeItemElement(sci);

            // Check to see if the category needs to be put out.
            if (writer.fitsPage(itmTable, document.bottomMargin() + 10)) {
              if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
                if (null == prevCat || !prevCat.equals(sci.getCategoryPath())) {
                  document.add(makePhrase(sci.getCategoryPath(), smallHeading, true));
                  document.add(makePhrase(null, smallHeading, true));
                }
                prevCat = sci.getCategoryPath();
              }
            }

            // if the item data will not fit onto the page,
            // make a new page, and redraw the header.

            if (!writer.fitsPage(itmTable, document.bottomMargin() + 10)) {
              document.newPage();
              pageNumber = pageNumber + 1;
              drawHeader(
                  document,
                  pageNumber,
                  pStore.getStoreBusinessName().getValue(),
                  pImageName,
                  false);
              if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
                document.add(makePhrase(sci.getCategoryPath(), smallHeading, true));
                document.add(makePhrase(null, smallHeading, true));
                prevCat = sci.getCategoryPath();
              }
            }
            document.add(itmTable);
          }
        }
      }

      // close out the document
      document.close();
    } catch (DocumentException e) {
      e.printStackTrace();
      throw new IOException(e.getMessage());
    }
  }
Exemplo n.º 3
0
  private void drawOGHeader(
      Document document, UserShopForm sForm, String pImageName, boolean personal)
      throws DocumentException {

    // add the logo
    try {
      Image i = Image.getInstance(pImageName);
      float x = document.leftMargin();
      float y = document.getPageSize().getHeight() - i.getHeight() - 5;
      i.setAbsolutePosition(x, y);
      document.add(i);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (catalogOnly) {
      return;
    }

    // unfortuanately this means we are limited to PDF rendering only.
    // get the user's personal info
    PdfPTable personalInfo;
    if (personal) {
      personalInfo = getPersonalized(sForm);
    } else {
      personalInfo = getNonPersonalized(sForm);
    }

    if (null != sForm.getAppUser().getUserAccount()
        && null != sForm.getAppUser().getUserAccount().getSkuTag()) {
      String t = sForm.getAppUser().getUserAccount().getSkuTag().getValue();
      if (t != null && t.length() > 0) {
        mSkuTag = t;
      }
    }

    // Display the contact info
    PdfPTable contactInfo = new PdfPTable(2);
    contactInfo.setWidthPercentage(50);
    contactInfo.setWidths(sizes);
    contactInfo.getDefaultCell().setBorder(borderType);
    contactInfo.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    String orderOnlineStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.orderOnLine:", null);
    contactInfo.addCell(makePhrase(orderOnlineStr + " ", smallHeading, false));
    contactInfo.addCell(
        makePhrase(
            sForm.getAppUser().getUserStore().getStorePrimaryWebAddress().getValue(),
            smallHeading,
            true));

    ContactUsInfo contact = null;
    if (sForm.getAppUser().getContactUsList().size() == 1) {
      contact = (ContactUsInfo) sForm.getAppUser().getContactUsList().get(0);
    }

    String orderFaxNumber = null, bscdesc = null;
    if (sForm.getAppUser().getSite().getBSC() != null
        && sForm.getAppUser().getSite().getBSC().getFaxNumber() != null
        && sForm.getAppUser().getSite().getBSC().getFaxNumber().getPhoneNum() != null) {
      orderFaxNumber = sForm.getAppUser().getSite().getBSC().getFaxNumber().getPhoneNum();
      bscdesc = sForm.getAppUser().getSite().getBSC().getBusEntityData().getLongDesc();
    }
    if (orderFaxNumber == null && contact != null) {
      orderFaxNumber = contact.getFax();
    }

    if (orderFaxNumber != null) {
      String faxOrderStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.faxOrder:", null);
      contactInfo.addCell(makePhrase(faxOrderStr + " ", smallHeading, false));
      contactInfo.addCell(makePhrase(orderFaxNumber, smallHeading, true));
    }

    if (null != bscdesc && bscdesc.length() > 0) {
      // if there is a BSC descripton set, then show
      // that information.
      PdfPCell cell = new PdfPCell(new Paragraph(bscdesc, smallHeading));
      cell.disableBorderSide(PdfPCell.LEFT);
      cell.disableBorderSide(PdfPCell.RIGHT);
      cell.disableBorderSide(PdfPCell.TOP);
      cell.disableBorderSide(PdfPCell.BOTTOM);
      cell.setColspan(2);
      cell.setPaddingTop(6);
      contactInfo.addCell(cell);
    } else {

      // otherwise show the standard contact us information
      // request for dmsi - dhl for eric.  durval 11/1/2005.

      if (contact != null) {
        contactInfo.addCell(makePhrase(" ", smallHeading, false));
        contactInfo.addCell(makePhrase(" ", smallHeading, true));
        String contactUsStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.contactUs", null);
        contactInfo.addCell(makePhrase(contactUsStr + " ", smallHeading, false));
        contactInfo.addCell(makePhrase("", smallHeading, true));

        String phoneStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.phone:", null);
        contactInfo.addCell(makePhrase(phoneStr + " ", smallHeading, false));
        contactInfo.addCell(
            makePhrase(
                "" + contact.getPhone() + "  " + contact.getCallHours(), smallHeading, true));

        String emailStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.email:", null);
        contactInfo.addCell(makePhrase(emailStr + " ", smallHeading, false));
        contactInfo.addCell(makePhrase(contact.getEmail(), smallHeading, true));
      }
    }

    // make the two tables into one
    PdfPTable wholeTable = new PdfPTable(2);
    wholeTable.setWidthPercentage(100);

    wholeTable.setWidths(halves);
    wholeTable.getDefaultCell().setBorder(borderType);

    wholeTable.addCell(personalInfo);
    wholeTable.addCell(contactInfo);
    document.add(wholeTable);

    String ogcomments = "";

    if (null != sForm.getAppUser().getSite()
        && null != sForm.getAppUser().getSite().getComments()) {
      ogcomments = sForm.getAppUser().getSite().getComments().getValue();
    }

    if (null == ogcomments || ogcomments.length() == 0) {
      if (null != sForm.getAppUser().getUserAccount()) {
        ogcomments = sForm.getAppUser().getUserAccount().getComments().getValue();
      }
    }

    // add the comments if there are any
    if (ogcomments != null && ogcomments.length() > 0) {
      document.add(makeBlankLine());
      String commentsStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.comments:", null);
      document.add(makePhrase(commentsStr + " " + ogcomments, smallHeading, true));
    }

    document.add(makeBlankLine());
    String commentsStr = ClwI18nUtil.getMessage(mRequest, "shop.og.text.comments:", null);
    document.add(
        makePhrase(
            commentsStr
                + " "
                + "__________________________________________"
                + "__________________________________________"
                + "__________",
            smallHeading,
            true));
    document.add(
        makePhrase(
            "__________"
                + "__________________________________________"
                + "__________________________________________"
                + "__________",
            smallHeading,
            true));
    document.add(
        makePhrase(
            "__________"
                + "__________________________________________"
                + "__________________________________________"
                + "__________",
            smallHeading,
            true));

    // Add an order guide note in the next page if a note is present.
    if (null != sForm.getAppUser().getUserAccount()
        && null != sForm.getAppUser().getUserAccount().getOrderGuideNote()) {
      String t = sForm.getAppUser().getUserAccount().getOrderGuideNote().getValue();
      if (t != null && t.length() > 0) {
        document.newPage();
        pageNumber = pageNumber + 1;
        // document.add(makeBlankLine());
        document.add(makePhrase(t, smallHeading, true));
      }
    }

    PdfPTable sort = new PdfPTable(1);
    sort.setWidthPercentage(100);
    sort.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    sort.getDefaultCell().setBorder(borderType);
    if (sForm.getOrderBy() == Constants.ORDER_BY_CATEGORY) {
      String sortedByCategoryStr =
          ClwI18nUtil.getMessage(mRequest, "shop.og.text.sortedBy:Category", null);
      sort.addCell(makePhrase(sortedByCategoryStr + " ", smallHeading, false));
    } else if (sForm.getOrderBy() == Constants.ORDER_BY_CUST_SKU) {
      String sortedByOurSkuNumStr =
          ClwI18nUtil.getMessage(mRequest, "shop.og.text.sortedBy:OurSkuNum", null);
      sort.addCell(makePhrase(sortedByOurSkuNumStr, smallHeading, false));
    } else {
      String sortedByProductNameStr =
          ClwI18nUtil.getMessage(mRequest, "shop.og.text.sortedBy:ProductName", null);
      sort.addCell(makePhrase(sortedByProductNameStr, smallHeading, false));
    }
    document.add(sort);
  }