예제 #1
0
  protected void apply(PdfPCell cell, RenderingContext context, PJsonObject params) {
    if (paddingLeft != null) cell.setPaddingLeft(paddingLeft.floatValue());
    if (paddingRight != null) cell.setPaddingRight(paddingRight.floatValue());
    if (paddingTop != null) cell.setPaddingTop(paddingTop.floatValue());
    if (paddingBottom != null) cell.setPaddingBottom(paddingBottom.floatValue());

    if (borderWidthLeft != null) cell.setBorderWidthLeft(borderWidthLeft.floatValue());
    if (borderWidthRight != null) cell.setBorderWidthRight(borderWidthRight.floatValue());
    if (borderWidthTop != null) cell.setBorderWidthTop(borderWidthTop.floatValue());
    if (borderWidthBottom != null) cell.setBorderWidthBottom(borderWidthBottom.floatValue());

    if (getBorderColorLeftVal(context, params) != null)
      cell.setBorderColorLeft(getBorderColorLeftVal(context, params));
    if (getBorderColorRightVal(context, params) != null)
      cell.setBorderColorRight(getBorderColorRightVal(context, params));
    if (getBorderColorTopVal(context, params) != null)
      cell.setBorderColorTop(getBorderColorTopVal(context, params));
    if (getBorderColorBottomVal(context, params) != null)
      cell.setBorderColorBottom(getBorderColorBottomVal(context, params));

    if (getBackgroundColorVal(context, params) != null)
      cell.setBackgroundColor(getBackgroundColorVal(context, params));

    if (align != null) cell.setHorizontalAlignment(align.getCode());
    if (vertAlign != null) cell.setVerticalAlignment(vertAlign.getCode());
  }
예제 #2
0
 protected void addRow(
     final PdfPTable table, final boolean needsBorder, final Paragraph... elements) {
   for (final Paragraph element : elements) {
     final PdfPCell cell = new PdfPCell(element);
     // cell.setHorizontalAlignment(element.getAlignment());
     cell.setVerticalAlignment(Element.ALIGN_TOP);
     if (!needsBorder) cell.setBorderWidth(0);
     table.addCell(cell);
   }
 }
  /**
   * Método que dibuja el pie de la página.
   *
   * @param writer Creador de documentos.
   * @param document Documento del informe.
   */
  private void drawFooter(PdfWriter writer, Document document) {
    try {
      PdfContentByte cb = writer.getDirectContent();
      cb.saveState();

      PdfPTable table = new PdfPTable(2);
      table.setTotalWidth(new float[] {70, document.right() - document.left() - 70});
      table.setLockedWidth(true);
      table.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.getDefaultCell().setBorder(Rectangle.BOX);
      table.getDefaultCell().setBorderWidth(0.1F);
      table.getDefaultCell().setBorderColor(BORDER_COLOR);
      table.getDefaultCell().setBackgroundColor(BACKGROUND_COLOR);
      table.getDefaultCell().setFixedHeight(45);
      table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
      table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

      /*
       * Image logo = Image.getInstance(FOOTER_IMAGE_URL);
       * logo.setBorder(Rectangle.BOX); logo.setBorderWidth(0.1F);
       * logo.setBorderColor(BORDER_COLOR); table.addCell(logo);
       */
      table.addCell("");

      PdfPTable tableInfo = new PdfPTable(1);
      tableInfo.setTotalWidth(document.right() - document.left() - 75);
      tableInfo.setLockedWidth(true);
      tableInfo.setHorizontalAlignment(Element.ALIGN_CENTER);
      tableInfo.getDefaultCell().setBorder(Rectangle.NO_BORDER);
      tableInfo.getDefaultCell().setFixedHeight(20);
      tableInfo.getDefaultCell().setPadding(5);
      tableInfo.addCell(
          new Phrase(new Chunk(DateUtils.EXTENDED_DATE_FORMATTER.format(new Date()), FOOTER_FONT)));

      PdfPCell tableInfoCell = new PdfPCell(tableInfo.getDefaultCell());
      tableInfoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
      tableInfoCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
      tableInfoCell.setPhrase(new Phrase(new Chunk(DIRECCION, FOOTER_ITALIC_FONT)));
      tableInfo.addCell(tableInfoCell);
      table.addCell(tableInfo);

      table.writeSelectedRows(0, -1, document.left(), document.bottom() - 5, cb);

      cb.restoreState();
    } catch (Exception e) {
      throw new ExceptionConverter(e);
    }
  }
  private void addTable(
      JSONArray store,
      String[] res,
      String[] colIndex,
      String[] colHeader,
      String[] mainHeader,
      String[] val,
      Document document)
      throws JSONException, DocumentException {

    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallBold.setColor(tColor);
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);

    float[] colw = new float[4];
    for (int x = 0; x < 4; x++) {
      colw[x] = 150;
    }
    int col = 0;

    for (int x = 0; x < mainHeader.length; x++) {
      // table start
      PdfPTable table = new PdfPTable(colw);
      table.setTotalWidth(88);
      table.setWidthPercentage(colw, document.getPageSize());
      // table.setSpacingBefore(10);

      PdfPTable mainTable = new PdfPTable(1);
      mainTable.setTotalWidth(90);
      mainTable.setWidthPercentage(100);
      mainTable.setSpacingBefore(20);

      // header cell for mainTable
      PdfPCell headcell = null;
      headcell = new PdfPCell(new Paragraph(mainHeader[x], fontSmallBold));
      headcell.setBackgroundColor(new Color(0xEEEEEE));
      headcell.setPadding(padding);
      mainTable.addCell(headcell);
      document.add(mainTable);

      // header cell added to mainTable
      int row = 3;
      if (x == 0 || x == 4) {
        row = 4;
      } else if (x == 5) {
        row = 0;
      }
      for (; row > 0; row--) {
        for (int y = 1;
            y < colw.length + 1;
            y++) { // for each column add the colHeader and value cell
          if (col != colHeader.length) {
            if (y % 2 != 0) {
              Paragraph p = new Paragraph(colHeader[col], f1);
              if (colHeader[col].contains("Variance")) {
                p = new Paragraph(colHeader[col], fontSmallBold);
              }
              PdfPCell pcell = new PdfPCell(p);
              if (gridBorder) {
                pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
              } else {
                pcell.setBorder(0);
              }
              pcell.setPadding(padding);
              pcell.setBorderColor(new Color(0xF2F2F2));
              pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
              pcell.setVerticalAlignment(Element.ALIGN_CENTER);
              table.addCell(pcell);
            } else {
              Paragraph p;
              p = new Paragraph(val[col], f1);
              if (colHeader[col].contains("Start Variance")
                  || colHeader[col].contains("End Variance")) {
                p = new Paragraph(val[col] + " days", fontSmallBold);
              } else if (colHeader[col].contains("Duration")) {
                if (colHeader[col].contains("Duration Variance"))
                  p = new Paragraph(val[col] + " days", fontSmallBold);
                else p = new Paragraph(val[col] + " days", f1);
              } else if (colHeader[col].contains("Work")) {
                if (colHeader[col].contains("Work Variance"))
                  p = new Paragraph(val[col] + " hrs", fontSmallBold);
                else p = new Paragraph(val[col] + " hrs", f1);
              } else if (colHeader[col].contains("Cost")) {
                if (colHeader[col].contains("Cost Variance"))
                  p = new Paragraph(currSymbol + " " + val[col], fontSmallBold);
                else p = new Paragraph(currSymbol + " " + val[col], f1);
              } else if (colHeader[col].contains("Percent Complete")) {
                p = new Paragraph(val[col] + " %", f1);
              }
              PdfPCell pcell = new PdfPCell(p);
              if (gridBorder) {
                pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
              } else {
                pcell.setBorder(0);
              }
              pcell.setPadding(padding);
              pcell.setBorderColor(new Color(0xF2F2F2));
              pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
              pcell.setVerticalAlignment(Element.ALIGN_CENTER);
              table.addCell(pcell);
              col++;
            }
          }
        }
      }
      if (x == 5) {
        int y = 0;
        row = res.length / 4;
        for (; row > 0; row--) {
          for (int c = 0; c < 2; c++) {
            Paragraph p = new Paragraph(res[y], f1);
            PdfPCell pcell = new PdfPCell(p);
            if (gridBorder) {
              pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
            } else {
              pcell.setBorder(0);
            }
            pcell.setPadding(padding);
            pcell.setBorderColor(new Color(0xF2F2F2));
            pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pcell.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(pcell);
            p = new Paragraph(res[y + 1], f1);
            pcell = new PdfPCell(p);
            if (gridBorder) {
              pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
            } else {
              pcell.setBorder(0);
            }
            pcell.setPadding(padding);
            pcell.setBorderColor(new Color(0xF2F2F2));
            pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pcell.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(pcell);
            y += 2;
          }
        }
      }
      document.add(table);
    }
  }
예제 #5
0
  public void createPdf() throws ClassNotFoundException, SQLException {
    /*Declaramos documento como un objeto Document
    Asignamos el tamaño de hoja y los margenes */
    Document documento = new Document(PageSize.A4.rotate(), 1, 1, 20, 36);

    // writer es declarado como el método utilizado para escribir en el archivo
    PdfWriter writer = null;

    try {
      // Obtenemos la instancia del archivo a utilizar

      String filename =
          "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/documentos/reporteAutorizacion.pdf";

      File fichero = new File(filename);

      if (fichero.exists()) {
        System.out.println("El fichero  existe222222222");
        fichero.delete();
        System.out.println("El fichero elimino");
      } else {
        System.out.println("el fichero no existe");
      }

      writer = PdfWriter.getInstance(documento, new FileOutputStream(filename));

    } catch (Exception ex) {
      System.out.println("NO creooooo");
      ex.getMessage();
    }

    // Declaramos una instancia de los eventos en HeaderFooter
    HeaderFooter event = new HeaderFooter();
    writer.setPageEvent(event);

    // Agregamos un titulo al archivo
    documento.addTitle("ARCHIVO PDF");

    // Agregamos el autor del archivo
    documento.addAuthor("PROVIAS NACIONAL");

    // Abrimos el documento para edición
    documento.open();
    try {
      // Declaramos un texto como Paragraph
      // Le podemos dar formado como alineación, tamaño y color a la fuente.
      Paragraph title1 = new Paragraph();
      title1.setAlignment(Element.ALIGN_CENTER);

      PdfPTable ta1 = new PdfPTable(2);
      ta1.setHorizontalAlignment(Element.ALIGN_CENTER);
      ta1.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
      ta1.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

      PdfPCell cel1 = new PdfPCell();
      com.lowagie.text.Image image =
          com.lowagie.text.Image.getInstance("D:/Provias/images/imgExports.jpg");
      // image.setWidthPercentage(500);
      cel1.addElement(image);
      cel1.setHorizontalAlignment(Element.ALIGN_CENTER);
      cel1.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cel1.setBorder(Rectangle.NO_BORDER);
      ta1.addCell(cel1);
      PdfPCell cel2 = new PdfPCell();

      cel2.addElement(
          new Phrase(
              "Reporte de Autorizaciones Especiales",
              FontFactory.getFont(
                  FontFactory.HELVETICA, 12, Font.BOLD, new CMYKColor(0, 0, 0, 100))));
      cel2.setFixedHeight(90);
      cel2.setHorizontalAlignment(Element.ALIGN_CENTER);
      cel2.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cel2.setBorder(Rectangle.NO_BORDER);
      ta1.addCell(cel2);

      float[] columnWidths1 = new float[] {180f, 100f};
      ta1.setWidths(columnWidths1);
      title1.add(ta1);

      // Agregamos el texto al documento
      documento.add(title1);

      // Agregamos un salto de linea
      documento.add(new Paragraph(" "));

      // Agregamos la tabla al documento haciendo
      // la llamada al método tabla()
      documento.add(tabla());
    } catch (Exception ex) {
      System.out.println("Por!!");
      ex.getMessage();
    }

    documento.close(); // Cerramos el documento
    writer.close(); // Cerramos writer
  }
예제 #6
0
  /**
   * Create a PDF using the given input parameters.
   *
   * @param po The PurchaseOrderDocument to be used to create the pdf.
   * @param poqv The PurchaseOrderVendorQuote to be used to generate the pdf.
   * @param campusName The campus name to be used to generate the pdf.
   * @param contractManagerCampusCode The contract manager campus code to be used to generate the
   *     pdf.
   * @param logoImage The logo image file name to be used to generate the pdf.
   * @param document The pdf document whose margins have already been set.
   * @param writer The PdfWriter to write the pdf document into.
   * @param environment The current environment used (e.g. DEV if it is a development environment).
   * @throws DocumentException
   */
  private void createPOQuotePdf(
      PurchaseOrderDocument po,
      PurchaseOrderVendorQuote poqv,
      String campusName,
      String contractManagerCampusCode,
      String logoImage,
      Document document,
      PdfWriter writer,
      String environment)
      throws DocumentException {
    if (LOG.isDebugEnabled()) {
      LOG.debug("createQuotePdf() started for po number " + po.getPurapDocumentIdentifier());
    }

    // These have to be set because they are used by the onOpenDocument() and onStartPage() methods.
    this.campusName = campusName;
    this.po = po;
    this.logoImage = logoImage;
    this.environment = environment;

    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US);
    // Date format pattern: MM-dd-yyyy
    SimpleDateFormat sdf =
        PurApDateFormatUtils.getSimpleDateFormat(
            PurapConstants.NamedDateFormats.KUALI_SIMPLE_DATE_FORMAT_2);

    CampusParameter campusParameter = getCampusParameter(contractManagerCampusCode);
    String purchasingAddressFull = getPurchasingAddressFull(campusParameter);

    // Turn on the page events that handle the header and page numbers.
    PurchaseOrderQuotePdf events = new PurchaseOrderQuotePdf().getPageEvents();
    writer.setPageEvent(this); // Passing in "this" lets it know about the po, campusName, etc.

    document.open();

    PdfPCell cell;
    Paragraph p = new Paragraph();

    // ***** Info table (address, vendor, other info) *****
    LOG.debug("createQuotePdf() info table started.");
    float[] infoWidths = {0.45f, 0.55f};
    PdfPTable infoTable = new PdfPTable(infoWidths);
    infoTable.setWidthPercentage(100);
    infoTable.setHorizontalAlignment(Element.ALIGN_CENTER);
    infoTable.setSplitLate(false);

    p = new Paragraph();
    ContractManager contractManager = po.getContractManager();
    p.add(new Chunk("\n Return this form to:\n", ver_8_bold));
    p.add(new Chunk(purchasingAddressFull + "\n", cour_10_normal));
    p.add(new Chunk("\n", cour_10_normal));
    p.add(new Chunk(" Fax #: ", ver_6_normal));
    p.add(new Chunk(contractManager.getContractManagerFaxNumber() + "\n", cour_10_normal));
    p.add(new Chunk(" Contract Manager: ", ver_6_normal));
    p.add(
        new Chunk(
            contractManager.getContractManagerName()
                + " "
                + contractManager.getContractManagerPhoneNumber()
                + "\n",
            cour_10_normal));
    p.add(new Chunk("\n", cour_10_normal));
    p.add(new Chunk(" To:\n", ver_6_normal));
    StringBuffer vendorInfo = new StringBuffer();
    if (StringUtils.isNotBlank(poqv.getVendorAttentionName())) {
      vendorInfo.append("     ATTN: " + poqv.getVendorAttentionName().trim() + "\n");
    }
    vendorInfo.append("     " + poqv.getVendorName() + "\n");
    if (StringUtils.isNotBlank(poqv.getVendorLine1Address())) {
      vendorInfo.append("     " + poqv.getVendorLine1Address() + "\n");
    }
    if (StringUtils.isNotBlank(poqv.getVendorLine2Address())) {
      vendorInfo.append("     " + poqv.getVendorLine2Address() + "\n");
    }
    if (StringUtils.isNotBlank(poqv.getVendorCityName())) {
      vendorInfo.append("     " + poqv.getVendorCityName());
    }
    if ((StringUtils.isNotBlank(poqv.getVendorStateCode()))
        && (!poqv.getVendorStateCode().equals("--"))) {
      vendorInfo.append(", " + poqv.getVendorStateCode());
    }
    if (StringUtils.isNotBlank(poqv.getVendorAddressInternationalProvinceName())) {
      vendorInfo.append(", " + poqv.getVendorAddressInternationalProvinceName());
    }
    if (StringUtils.isNotBlank(poqv.getVendorPostalCode())) {
      vendorInfo.append(" " + poqv.getVendorPostalCode() + "\n");
    } else {
      vendorInfo.append("\n");
    }

    if (!KFSConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(poqv.getVendorCountryCode())
        && poqv.getVendorCountryCode() != null) {
      vendorInfo.append("     " + poqv.getVendorCountry().getName() + "\n\n");
    } else {
      vendorInfo.append("     \n\n");
    }

    p.add(new Chunk(vendorInfo.toString(), cour_10_normal));
    cell = new PdfPCell(p);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    infoTable.addCell(cell);

    p = new Paragraph();
    p.add(new Chunk("\n     R.Q. Number: ", ver_8_bold));
    p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n", cour_10_normal));
    java.sql.Date requestDate = getDateTimeService().getCurrentSqlDate();
    if (poqv.getPurchaseOrderQuoteTransmitTimestamp() != null) {
      try {
        requestDate =
            getDateTimeService().convertToSqlDate(poqv.getPurchaseOrderQuoteTransmitTimestamp());
      } catch (ParseException e) {
        throw new RuntimeException(
            "ParseException thrown when trying to convert from Timestamp to SqlDate.", e);
      }
    }
    p.add(new Chunk("     R.Q. Date: ", ver_8_bold));
    p.add(new Chunk(sdf.format(requestDate) + "\n", cour_10_normal));
    p.add(new Chunk("     RESPONSE MUST BE RECEIVED BY: ", ver_8_bold));
    if (po.getPurchaseOrderQuoteDueDate() != null) {
      p.add(new Chunk(sdf.format(po.getPurchaseOrderQuoteDueDate()) + "\n\n", cour_10_normal));
    } else {
      p.add(new Chunk("N/A\n\n", cour_10_normal));
    }

    // retrieve the quote stipulations
    StringBuffer quoteStipulations = getPoQuoteLanguage();

    p.add(new Chunk(quoteStipulations.toString(), ver_6_normal));
    p.add(new Chunk("\n ALL QUOTES MUST BE TOTALED", ver_12_normal));
    cell = new PdfPCell(p);
    infoTable.addCell(cell);

    document.add(infoTable);

    // ***** Notes and Stipulations table *****
    // The notes and stipulations table is type Table instead of PdfPTable
    // because Table has the method setCellsFitPage and I can't find an equivalent
    // in PdfPTable. Long notes or stipulations would break to the next page, leaving
    // a large white space on the previous page.
    PdfPTable notesStipulationsTable = new PdfPTable(1);
    notesStipulationsTable.setWidthPercentage(100);
    notesStipulationsTable.setSplitLate(false);

    p = new Paragraph();
    p.add(new Chunk("  Vendor Stipulations and Information\n\n", ver_6_normal));
    if ((po.getPurchaseOrderBeginDate() != null) && (po.getPurchaseOrderEndDate() != null)) {
      p.add(
          new Chunk(
              "     Order in effect from "
                  + sdf.format(po.getPurchaseOrderBeginDate())
                  + " to "
                  + sdf.format(po.getPurchaseOrderEndDate())
                  + ".\n",
              cour_10_normal));
    }
    Collection<PurchaseOrderVendorStipulation> vendorStipulationsList =
        po.getPurchaseOrderVendorStipulations();
    if (vendorStipulationsList.size() > 0) {
      StringBuffer vendorStipulations = new StringBuffer();
      for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) {
        vendorStipulations.append("     " + povs.getVendorStipulationDescription() + "\n");
      }
      p.add(new Chunk("     " + vendorStipulations.toString(), cour_10_normal));
    }

    PdfPCell tableCell = new PdfPCell(p);
    tableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    tableCell.setVerticalAlignment(Element.ALIGN_TOP);
    notesStipulationsTable.addCell(tableCell);
    document.add(notesStipulationsTable);

    // ***** Items table *****
    LOG.debug("createQuotePdf() items table started.");
    float[] itemsWidths = {0.07f, 0.1f, 0.07f, 0.50f, 0.13f, 0.13f};
    PdfPTable itemsTable = new PdfPTable(6);
    // itemsTable.setCellsFitPage(false); With this set to true a large cell will
    // skip to the next page. The default Table behaviour seems to be what we want:
    // start the large cell on the same page and continue it to the next.
    itemsTable.setWidthPercentage(100);
    itemsTable.setWidths(itemsWidths);
    itemsTable.setSplitLate(false);

    tableCell =
        createCell("Item\nNo.", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
    itemsTable.addCell(tableCell);
    tableCell =
        createCell("Quantity", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
    itemsTable.addCell(tableCell);
    tableCell = createCell("UOM", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
    itemsTable.addCell(tableCell);
    tableCell =
        createCell("Description", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
    itemsTable.addCell(tableCell);
    tableCell =
        createCell(
            "Unit Cost\n(Required)",
            false,
            false,
            false,
            false,
            Element.ALIGN_CENTER,
            ver_6_normal);
    itemsTable.addCell(tableCell);
    tableCell =
        createCell(
            "Extended Cost\n(Required)",
            false,
            false,
            false,
            false,
            Element.ALIGN_CENTER,
            ver_6_normal);
    itemsTable.addCell(tableCell);

    if (StringUtils.isNotBlank(po.getPurchaseOrderQuoteVendorNoteText())) {
      // Vendor notes line.
      itemsTable.addCell(" ");
      itemsTable.addCell(" ");
      itemsTable.addCell(" ");
      tableCell =
          createCell(
              po.getPurchaseOrderQuoteVendorNoteText(),
              false,
              false,
              false,
              false,
              Element.ALIGN_LEFT,
              cour_10_normal);
      itemsTable.addCell(tableCell);
      itemsTable.addCell(" ");
      itemsTable.addCell(" ");
    }

    for (PurchaseOrderItem poi : (List<PurchaseOrderItem>) po.getItems()) {
      if ((poi.getItemType() != null)
          && (StringUtils.isNotBlank(poi.getItemDescription()))
          && (poi.getItemType().isLineItemIndicator()
              || poi.getItemTypeCode()
                  .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)
              || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE)
              || poi.getItemTypeCode()
                  .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)
              || poi.getItemTypeCode()
                  .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) {
        // "ITEM"s display the line number; other types don't.
        String description = "";
        description =
            (StringUtils.isNotBlank(poi.getItemCatalogNumber()))
                ? poi.getItemCatalogNumber().trim() + " - "
                : "";
        description =
            description
                + ((StringUtils.isNotBlank(poi.getItemDescription()))
                    ? poi.getItemDescription().trim()
                    : "");

        // If this is a full order discount item or trade in item, we add the
        // itemType description and a dash to the purchase order item description.
        if (StringUtils.isNotBlank(poi.getItemDescription())) {
          if (poi.getItemTypeCode()
                  .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)
              || poi.getItemTypeCode()
                  .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
            description = poi.getItemType().getItemTypeDescription() + " - " + description;
          }
        }

        // We can do the normal table now because description is not too long.
        String itemLineNumber = new String();
        if (poi.getItemType().isLineItemIndicator()) {
          itemLineNumber = poi.getItemLineNumber().toString();
        } else {
          itemLineNumber = "";
        }
        tableCell =
            createCell(
                itemLineNumber, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal);
        itemsTable.addCell(tableCell);
        String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " ";
        tableCell =
            createCell(quantity, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal);
        itemsTable.addCell(tableCell);
        tableCell =
            createCell(
                poi.getItemUnitOfMeasureCode(),
                false,
                false,
                false,
                false,
                Element.ALIGN_CENTER,
                cour_10_normal);
        itemsTable.addCell(tableCell);

        tableCell =
            createCell(description, false, false, false, false, Element.ALIGN_LEFT, cour_10_normal);
        itemsTable.addCell(tableCell);
        itemsTable.addCell(" ");
        itemsTable.addCell(" ");
      }
    }

    // Blank line before totals
    createBlankRowInItemsTable(itemsTable);

    // Totals line.
    itemsTable.addCell(" ");
    itemsTable.addCell(" ");
    itemsTable.addCell(" ");
    tableCell =
        createCell("Total: ", false, false, false, false, Element.ALIGN_RIGHT, ver_10_normal);
    itemsTable.addCell(tableCell);
    itemsTable.addCell(" ");
    itemsTable.addCell(" ");
    // Blank line after totals
    createBlankRowInItemsTable(itemsTable);

    document.add(itemsTable);

    LOG.debug("createQuotePdf() vendorFillsIn table started.");
    float[] vendorFillsInWidths = {0.50f, 0.50f};
    PdfPTable vendorFillsInTable = new PdfPTable(vendorFillsInWidths);
    vendorFillsInTable.setWidthPercentage(100);
    vendorFillsInTable.setHorizontalAlignment(Element.ALIGN_CENTER);
    vendorFillsInTable.setSplitLate(false);
    vendorFillsInTable.getDefaultCell().setBorderWidth(0);
    vendorFillsInTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    vendorFillsInTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);

    // New row
    String important =
        new String(
            "\nIMPORTANT: The information and signature below MUST BE COMPLETED or your offer may be rejected.\n");
    cell = createCell(important, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    cell.setColspan(2);
    vendorFillsInTable.addCell(cell);
    // New row
    String cashDiscount =
        new String("Terms of Payment:  Cash discount_________%_________Days-Net________Days\n");
    cell = createCell(cashDiscount, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    cell.setColspan(2);
    vendorFillsInTable.addCell(cell);
    // New row
    String fob = new String(" FOB: __ Destination (Title)\n");
    cell = createCell(fob, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    vendorFillsInTable.addCell(cell);
    String freightVendor = new String(" __ Freight Vendor Paid (Allowed)\n");
    cell = createCell(freightVendor, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    vendorFillsInTable.addCell(cell);
    // New row
    String shipping = new String("          __ Shipping Point (Title)\n");
    cell = createCell(shipping, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    vendorFillsInTable.addCell(cell);
    String freightPrepaid = new String(" __ Freight Prepaid & Added Amount $_________\n");
    cell = createCell(freightPrepaid, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    vendorFillsInTable.addCell(cell);
    // New row
    String commonCarrier =
        new String("      If material will ship common carrier, please provide the following:\n");
    cell = createCell(commonCarrier, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold);
    cell.setColspan(2);
    vendorFillsInTable.addCell(cell);
    // New row
    String origin =
        new String(
            "      Point of origin and zip code: ______________________ Weight: _________ Class: _________\n");
    cell = createCell(origin, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold);
    cell.setColspan(2);
    vendorFillsInTable.addCell(cell);
    // New row
    p = new Paragraph();
    p.add(new Chunk(" Unless otherwise stated, all material to be shipped to ", ver_8_normal));
    String purchasingAddressPartial;
    if (po.getAddressToVendorIndicator()) {
      purchasingAddressPartial =
          po.getReceivingCityName()
              + ", "
              + po.getReceivingStateCode()
              + " "
              + po.getReceivingPostalCode();
    } else {
      purchasingAddressPartial =
          po.getDeliveryCityName()
              + ", "
              + po.getDeliveryStateCode()
              + " "
              + po.getDeliveryPostalCode();
    }
    p.add(new Chunk(purchasingAddressPartial + "\n", cour_10_normal));
    cell = new PdfPCell(p);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorderWidth(0);
    vendorFillsInTable.addCell(cell);
    // New row
    String offerEffective = new String(" Offer effective until (Date):_____________\n");
    cell = createCell(offerEffective, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    vendorFillsInTable.addCell(cell);
    String deliverBy = new String(" Delivery can be made by (Date):_____________\n");
    cell = createCell(deliverBy, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
    vendorFillsInTable.addCell(cell);
    // New row
    String sign = new String(" SIGN HERE:____________________________\n");
    cell = createCell(sign, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
    vendorFillsInTable.addCell(cell);
    String date = new String(" DATE:____________________________\n");
    cell = createCell(date, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
    vendorFillsInTable.addCell(cell);
    // New row
    String name = new String(" PRINT NAME:____________________________\n");
    cell = createCell(name, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
    vendorFillsInTable.addCell(cell);
    String phone = new String(" PHONE:____________________________\n");
    cell = createCell(phone, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
    vendorFillsInTable.addCell(cell);
    // New row
    String company = new String(" COMPANY:____________________________\n");
    cell = createCell(company, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
    vendorFillsInTable.addCell(cell);
    String fax = new String(" FAX:____________________________\n");
    cell = createCell(fax, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
    vendorFillsInTable.addCell(cell);

    document.add(vendorFillsInTable);
    document.close();
    LOG.debug("createQuotePdf()pdf document closed.");
  } // End of createQuotePdf()
예제 #7
0
  public void onClick$buttonImprimir() {
    String nombrepdf = "";
    try {
      Calendar cal = Calendar.getInstance();
      // lol
      Calendar cal2 = new GregorianCalendar();
      Document document = new Document();
      String nombre =
          ""
              + (cal.getTime().getYear() + 1900)
              + "_"
              + (cal.getTime().getMonth() + 1)
              + "_"
              + cal.getTime().getDate();
      String tipo = "";
      Font miFuente = new Font();
      miFuente.setStyle(Font.BOLD);
      miFuente.setColor(Color.BLUE);
      Font miFuente2 = new Font();
      miFuente2.setStyle(Font.BOLD);
      miFuente2.setColor(Color.RED);
      PdfPTable tabla;
      PdfPCell celda;
      PdfPCell c1;
      ReporteProducto rowlista;
      String dem = "";
      String esp = "";
      if (cmb_demanda.getText().equals("Mayor Demanda")) {
        dem = "mayDemanda";
      } else {
        dem = "menDemanda";
      }

      if (cmb_tipo.getText().equals("General")) {
        esp = dem + "General";
      } else {
        esp = dem + "PorCat";
      }

      if (cmb_tiempo.getText().equals("Por Año")) {
        tipo = esp + "PorAño";
        tabla = new PdfPTable(4);
        celda = new PdfPCell(new Phrase("Año", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Producto", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Categoría", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        for (int i = 0; i < lista.size(); i++) {
          rowlista = lista.get(i);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFinicial()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getProducto()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCategoria()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCantidad()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
        }
      } else {
        if (cmb_tiempo.getText().equals("Por Mes")) {
          tipo = esp + "PorMes";
          tabla = new PdfPTable(5);
          celda = new PdfPCell(new Phrase("Año", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Mes", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Producto", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Categoría", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);

        } else {
          tipo = esp + "PorFecha";
          tabla = new PdfPTable(5);
          celda = new PdfPCell(new Phrase("Fecha Inicial", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Fecha Final", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Producto", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Categoría", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
        }

        for (int i = 0; i < lista.size(); i++) {
          rowlista = lista.get(i);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFinicial()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFfinal()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getProducto()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCategoria()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCantidad()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
        }
      }
      nombrepdf = "ReporteProductos" + tipo + "_" + nombre + ".pdf";
      PdfWriter.getInstance(document, new FileOutputStream(nombrepdf));
      document.open();
      Paragraph Titulo =
          new Paragraph(
              "Reporte "
                  + cmb_tipo.getText()
                  + " de Productos de "
                  + cmb_demanda.getText()
                  + " "
                  + cmb_tiempo.getText(),
              miFuente);
      Titulo.setAlignment(Element.ALIGN_CENTER);
      Paragraph encabezado = new Paragraph("Prueba");
      encabezado.setAlignment(Element.ALIGN_CENTER);
      document.add(Titulo);
      document.add(encabezado);
      document.add(new Paragraph(" "));

      document.add(tabla);
      document.close();
    } catch (Exception e) {

      e.printStackTrace();
    }
    Hashtable h = new Hashtable();
    h.put("File", nombrepdf);
    Executions.getCurrent()
        .createComponents("Modulo_Reportes/Pdf_Viewer.zul", win_reportesproductos, h);
    File filepdf = new File(nombrepdf);
    filepdf.delete();
    /*  try {
    if ((new File(nombrepdf)).exists()) {
    	Process p = Runtime
    	   .getRuntime()
    	   .exec("rundll32 url.dll,FileProtocolHandler "+nombrepdf);
    	p.waitFor();
    	buttonImprimir.setVisible(false);
    } else {
    	alert("File is not exists!");
    }
    alert("Done!");
    	  } catch (Exception ex) {
    ex.printStackTrace();
     }*/
  }