コード例 #1
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);
  }
コード例 #2
0
  private void drawHeader(
      Document document,
      int pPageNumber,
      String pSenderName,
      String pImageName,
      boolean pInventoryHeader)
      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();
    }

    // deal with header info construct the table/cells with all of
    // the header information must be the pdf specific type or the
    // table will not use the full width of the page.
    // unfortuanately this means we are limited to PDF rendering
    // only.

    // draw a line XXX this is somewhat of a hack, as there seems
    // to be no way to draw a line in the current iText API that is
    // relative to your current position in the document

    document.add(makeLine());

    // add the item header line
    PdfPTable itemHeader = new PdfPTable(mColumnCount);
    itemHeader.setWidthPercentage(100);
    itemHeader.setWidths(itmColumnWidth);
    itemHeader.getDefaultCell().setBorderWidth(2);
    itemHeader.getDefaultCell().setBackgroundColor(java.awt.Color.black);
    itemHeader.getDefaultCell().setHorizontalAlignment(Cell.ALIGN_CENTER);
    itemHeader.getDefaultCell().setVerticalAlignment(Cell.ALIGN_MIDDLE);
    itemHeader.getDefaultCell().setBorderColor(java.awt.Color.white);
    if (!catalogOnly) {
      String c1 = "";
      if (pInventoryHeader) {
        String qtyOnHandStr =
            ClwI18nUtil.getMessage(mRequest, "shop.og.table.header.qtyOnHand", null);
        itemHeader.addCell(makePhrase(qtyOnHandStr, itemHeading, false));
        String requestedQtyStr =
            ClwI18nUtil.getMessage(mRequest, "shop.og.text.requestedQty", null);
        itemHeader.addCell(makePhrase(requestedQtyStr, itemHeading, false));
        mForInventoryShopping = true;
      } else {
        itemHeader.addCell(makePhrase(" ", itemHeading, false));
        if (mForInventoryShopping) {
          c1 = ClwI18nUtil.getMessage(mRequest, "shop.og.text.requestedQty", null);
        } else {
          c1 = ClwI18nUtil.getMessage(mRequest, "shop.og.text.orderQty", null);
        }
        itemHeader.addCell(makePhrase(c1, itemHeading, false));
      }
    }
    if (catalogOnly) {
      String c1 = ClwI18nUtil.getMessage(mRequest, "shop.og.text.orderQty", null);
      itemHeader.addCell(makePhrase(c1, itemHeading, false));
    }

    itemHeader.addCell(makePhrase(mSkuTag, itemHeading, false));

    String c2 = "";
    if (pInventoryHeader) {
      c2 = ClwI18nUtil.getMessage(mRequest, "shop.og.text.inventoryProductName", null);
    } else {
      c2 = ClwI18nUtil.getMessage(mRequest, "shop.og.text.productName", null);
    }

    itemHeader.addCell(makePhrase(c2, itemHeading, false));
    if (mShowSize) {
      String sizeStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.size", null);
      itemHeader.addCell(makePhrase(sizeStr, itemHeading, false));
    }
    /*    String packStr =
      ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.pack", null);
    itemHeader.addCell(makePhrase(packStr, itemHeading, false));
    String uomStr =
      ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.uom", null);
    itemHeader.addCell(makePhrase(uomStr, itemHeading, false));*/

    CurrencyData curr = ClwI18nUtil.getCurrency(mCatalogLocaleCd);
    String currencyCode = "CHF";
    if (curr != null) {
      currencyCode = curr.getGlobalCode();
    }

    if (mShowPrice) {
      String priceStr =
          ClwI18nUtil.getMessage(
              mRequest, "shoppingItems.text.priceIn", new String[] {currencyCode});
      itemHeader.addCell(makePhrase(priceStr, itemHeading, false));
    }
    if (catalogOnly) {
      String splStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.spl", null);
      itemHeader.addCell(makePhrase(splStr, itemHeading, false));
    }
    if (!catalogOnly) {
      String amountStr =
          ClwI18nUtil.getMessage(
              mRequest, "shoppingItems.text.amountIn", new String[] {currencyCode});
      itemHeader.addCell(makePhrase(amountStr, itemHeading, false));
    }

    document.add(itemHeader);
  }