예제 #1
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());
    }
  }
예제 #2
0
  // utility function to make an item Element.
  private Table makeItemElement(ShoppingCartItemData pItm) throws DocumentException {

    Table itmTbl = new PTable(mColumnCount);
    itmTbl.setWidth(100);
    itmTbl.setWidths(itmColumnWidth);
    itmTbl.getDefaultCell().setBorderColor(java.awt.Color.black);
    itmTbl.getDefaultCell().setVerticalAlignment(Cell.ALIGN_TOP);
    itmTbl.setOffset(0);
    itmTbl.setBorder(Table.NO_BORDER);

    if (!catalogOnly) {
      String t0 = "";
      if (pItm.getIsaInventoryItem()) {
        t0 = "i";
      }

      if (null != mSiteData
          && mSiteData.isAnInventoryAutoOrderItem(pItm.getProduct().getProductId())) {
        t0 += "a";
      }

      Cell tpc0 = new Cell(makePhrase(t0, small, true));
      if (!pItm.getIsaInventoryItem()) {
        tpc0.setBorder(0);
      }
      itmTbl.addCell(tpc0);
    }

    Cell tpc01 = new Cell(makePhrase("", normal, true));
    itmTbl.addCell(tpc01);

    String t = "";
    if (pItm.getProduct().isPackProblemSku()) {
      t += "*";
    }
    if (t.length() > 0) t += " ";
    Cell tpc1 = new Cell(makePhrase(t + pItm.getActualSkuNum(), normal, true));
    itmTbl.addCell(tpc1);

    itmTbl.addCell(makePhrase(pItm.getProduct().getCatalogProductShortDesc(), normal, true));
    if (mShowSize) {
      itmTbl.addCell(makePhrase(pItm.getProduct().getSize(), normal, true));
    }
    // itmTbl.addCell(makePhrase(pItm.getProduct().getPack(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getUom(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getManufacturerName(),normal,true));

    if (mShowPrice) {
      BigDecimal price = new BigDecimal(pItm.getPrice());
      String priceStr = "";
      try {
        priceStr = mFormatter.priceFormatWithoutCurrency(price);
      } catch (Exception exc) {
        exc.printStackTrace();
      }
      Cell pcell = new Cell(makePhrase(priceStr, normal, true));
      pcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
      itmTbl.addCell(pcell);
    }

    if (catalogOnly) {
      if (pItm.getProduct() != null
          && pItm.getProduct().getCatalogDistrMapping() != null
          && Utility.isTrue(pItm.getProduct().getCatalogDistrMapping().getStandardProductList())) {
        String yStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.y", null);
        itmTbl.addCell(makePhrase(yStr, normal, true));
      } else {
        String nStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.n", null);
        itmTbl.addCell(makePhrase(nStr, normal, true));
      }
    }

    if (!catalogOnly) {
      // BigDecimal amount = new BigDecimal(pItm.getAmount());
      itmTbl.addCell(makePhrase("", normal, true));
    }

    return itmTbl;
  }